Skip to content

Commit f5f4952

Browse files
committed
DataElement colwidth + list icons
1 parent 5f7aeed commit f5f4952

File tree

5 files changed

+79
-23
lines changed

5 files changed

+79
-23
lines changed

Ajax/semantic/html/collections/table/HtmlTable.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ public function getPart($key) {
5757
return $this->content[$key];
5858
}
5959

60+
protected function _getFirstPart(){
61+
if(isset($this->content["thead"])){
62+
return $this->content["thead"];
63+
}
64+
return $this->content["tbody"];
65+
}
66+
67+
6068
/**
6169
* Returns/create eventually the body of the table
6270
* @return HtmlTableContent
@@ -374,22 +382,34 @@ public function setActiveRowSelector($class="active",$event="click",$multiple=fa
374382
}
375383

376384
public function hideColumn($colIndex){
377-
if($this->hasPart("thead")){
378-
$this->getHeader()->hideColumn($colIndex);
385+
if(isset($this->content["thead"])){
386+
$this->content["thead"]->hideColumn($colIndex);
379387
}
380-
$this->getBody()->hideColumn($colIndex);
381-
if($this->hasPart("tfoot")){
382-
$this->getFooter()->hideColumn($colIndex);
388+
$this->content["tbody"]->hideColumn($colIndex);
389+
if(isset($this->content["tfoot"])){
390+
$this->content["tfoot"]->hideColumn($colIndex);
383391
}
384392
return $this;
385393
}
386-
394+
387395
public function setColWidth($colIndex,$width){
388-
if($this->hasPart("thead")){
389-
$this->getHeader()->getCell(0, $colIndex)->setWidth($width);
390-
}else{
391-
if($this->getBody()->count()>0)
392-
$this->getBody()->getCell(0, $colIndex)->setWidth($width);
396+
$part=$this->_getFirstPart();
397+
if($part!==null && $part->count()>0)
398+
$part->getCell(0, $colIndex)->setWidth($width);
399+
return $this;
400+
}
401+
402+
public function setColWidths($widths){
403+
$part=$this->_getFirstPart();
404+
if($part!==null && $part->col()>0){
405+
$count=$part->getColCount();
406+
if(!\is_array($widths)){
407+
$widths=\array_fill(0, $count, $widths);
408+
}
409+
$max=\min(\sizeof($widths),$count);
410+
for($i=0;$i<$max;$i++){
411+
$part->getCell(0, $i)->setWidth($widths[$i]);
412+
}
393413
}
394414
return $this;
395415
}

Ajax/semantic/html/content/table/HtmlTR.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public function setColCount($colCount) {
3232
return $this;
3333
}
3434

35+
public function getColCount(){
36+
return $this->count();
37+
}
38+
3539
/**
3640
*
3741
* {@inheritDoc}

Ajax/semantic/html/elements/HtmlList.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,15 @@ public function addCheckedList($items=array(), $masterItem=NULL, $values=array()
113113
$this->_hasCheckedList=true;
114114
return $this;
115115
}
116+
117+
public function setIcons($icons){
118+
if(!\is_array($icons)){
119+
$icons=\array_fill(0, \sizeof($this->content), $icons);
120+
}
121+
$max=\min(\sizeof($icons),\sizeof($this->content));
122+
for($i=0;$i<$max;$i++){
123+
$this->content[$i]->addIcon($icons[$i]);
124+
}
125+
return $this;
126+
}
116127
}

Ajax/semantic/widgets/dataelement/DataElement.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
*/
1818
class DataElement extends Widget {
19+
protected $_colWidths;
1920

2021
public function __construct($identifier, $modelInstance=NULL) {
2122
parent::__construct($identifier, null,$modelInstance);
@@ -33,6 +34,9 @@ public function compile(JsUtils $js=NULL,&$view=NULL){
3334
if(isset($this->_toolbar)){
3435
$this->_setToolbarPosition($table);
3536
}
37+
if(isset($this->_colWidths)){
38+
$this->_applyStyleAttributes($table);
39+
}
3640
$this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]);
3741
$this->_compileForm();
3842
$this->_generated=true;
@@ -47,11 +51,15 @@ protected function _generateContent($table){
4751
$values= $this->_instanceViewer->getValues();
4852
$captions=$this->_instanceViewer->getCaptions();
4953
$count=$this->_instanceViewer->count();
54+
5055
for($i=0;$i<$count;$i++){
5156
$table->addRow([$captions[$i],$values[$i]]);
5257
}
5358
}
5459

60+
protected function _applyStyleAttributes(HtmlTable $table){
61+
$table->setColWidths($this->_colWidths);
62+
}
5563
protected function _getFieldName($index){
5664
return $this->_instanceViewer->getFieldName($index);
5765
}
@@ -95,4 +103,19 @@ public function onNewRow($callback) {
95103
public function asForm(){
96104
return $this->getForm();
97105
}
106+
107+
public function setColCaptionWidth($width){
108+
$this->_colWidths[0]=$width;
109+
return $this;
110+
}
111+
112+
public function setColValueWidth($width) {
113+
$this->_colWidths[1]=$width;
114+
return $this;
115+
}
116+
117+
public function setColWidths($widths){
118+
$this->_colWidths=$widths;
119+
return $this;
120+
}
98121
}

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,10 @@ public function compile(JsUtils $js=NULL,&$view=NULL){
8686
if(!$this->_generated){
8787
$this->_instanceViewer->setInstance($this->_model);
8888
$captions=$this->_instanceViewer->getCaptions();
89-
9089
$table=$this->content["table"];
91-
9290
if($this->_hasCheckboxes){
9391
$this->_generateMainCheckbox($captions);
9492
}
95-
9693
$table->setRowCount(0, \sizeof($captions));
9794
$this->_generateHeader($table,$captions);
9895

@@ -119,17 +116,20 @@ public function compile(JsUtils $js=NULL,&$view=NULL){
119116

120117
$this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]);
121118
$this->_compileForm();
122-
if(isset($this->_hiddenColumns))
123-
$this->_hideColumns();
119+
$this->_applyStyleAttributes($table);
120+
$this->_generated=true;
121+
}
122+
return parent::compile($js,$view);
123+
}
124+
125+
protected function _applyStyleAttributes($table){
126+
if(isset($this->_hiddenColumns))
127+
$this->_hideColumns();
124128
if(isset($this->_colWidths)){
125129
foreach ($this->_colWidths as $colIndex=>$width){
126130
$table->setColWidth($colIndex,$width);
127131
}
128132
}
129-
130-
$this->_generated=true;
131-
}
132-
return parent::compile($js,$view);
133133
}
134134

135135
protected function _hideColumns(){
@@ -432,7 +432,7 @@ public function hideColumn($colIndex){
432432
$this->_hiddenColumns[]=$colIndex;
433433
return $this;
434434
}
435-
435+
436436
public function setColWidth($colIndex,$width){
437437
$this->_colWidths[$colIndex]=$width;
438438
return $this;
@@ -441,6 +441,4 @@ public function setColWidths($_colWidths) {
441441
$this->_colWidths = $_colWidths;
442442
return $this;
443443
}
444-
445-
446444
}

0 commit comments

Comments
 (0)