Skip to content

Commit f2779d0

Browse files
committed
base refactoring
1 parent 5f2e51b commit f2779d0

File tree

6 files changed

+155
-86
lines changed

6 files changed

+155
-86
lines changed

Ajax/common/Widget.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,30 @@
33
namespace Ajax\common;
44

55
use Ajax\common\html\HtmlDoubleElement;
6+
use Ajax\semantic\html\elements\HtmlButton;
7+
use Ajax\semantic\widgets\datatable\PositionInTable;
8+
use Ajax\semantic\html\collections\menus\HtmlMenu;
69

710
abstract class Widget extends HtmlDoubleElement {
811

12+
/**
13+
* @var string classname
14+
*/
915
protected $_model;
1016
protected $_modelInstance;
17+
/**
18+
* @var InstanceViewer
19+
*/
1120
protected $_instanceViewer;
21+
/**
22+
* @var boolean
23+
*/
24+
protected $_toolbar;
25+
/**
26+
* @var PositionInTable
27+
*/
28+
protected $_toolbarPosition;
29+
1230

1331
public function __construct($identifier,$model,$modelInstance=NULL) {
1432
parent::__construct($identifier);
@@ -45,4 +63,42 @@ public abstract function getHtmlComponent();
4563
public function setColor($color){
4664
return $this->getHtmlComponent()->setColor($color);
4765
}
66+
67+
/**
68+
* @return \Ajax\semantic\html\collections\menus\HtmlMenu
69+
*/
70+
public function getToolbar(){
71+
if(isset($this->_toolbar)===false){
72+
$this->_toolbar=new HtmlMenu("toolbar-".$this->identifier);
73+
$this->_toolbar->setSecondary();
74+
}
75+
return $this->_toolbar;
76+
}
77+
78+
/**
79+
* Adds a new element in toolbar
80+
* @param mixed $element
81+
* @return \Ajax\common\html\HtmlDoubleElement
82+
*/
83+
public function addInToolbar($element){
84+
$tb=$this->getToolbar();
85+
return $tb->addItem($element);
86+
}
87+
88+
public function addItemInToolbar($caption,$icon=NULL){
89+
$result=$this->addInToolbar($caption);
90+
$result->addIcon($icon);
91+
return $result;
92+
}
93+
94+
public function addButtonInToolbar($caption){
95+
$bt=new HtmlButton("",$caption);
96+
return $this->addInToolbar($bt);
97+
}
98+
99+
public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){
100+
$bt=new HtmlButton("",$caption);
101+
$bt->addIcon($icon,$before,$labeled);
102+
return $this->addInToolbar($bt);
103+
}
48104
}

Ajax/semantic/widgets/datatable/InstanceViewer.php renamed to Ajax/semantic/widgets/base/InstanceViewer.php

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,21 @@
11
<?php
2-
namespace Ajax\semantic\widgets\datatable;
2+
namespace Ajax\semantic\widgets\base;
33
use Ajax\service\JString;
44

55
class InstanceViewer {
6-
private $instance;
7-
private $reflect;
8-
private $properties;
9-
private $captions;
10-
private $visibleProperties;
11-
private $values;
12-
private $afterCompile;
6+
protected $instance;
7+
protected $reflect;
8+
protected $properties;
9+
protected $visibleProperties;
10+
protected $values;
11+
protected $afterCompile;
1312
public static $index=0;
1413

15-
public function __construct($instance=NULL,$captions=NULL){
14+
public function __construct($instance=NULL){
1615
$this->values=[];
1716
$this->afterCompile=[];
1817
if(isset($instance))
1918
$this->setInstance($instance);
20-
$this->setCaptions($captions);
21-
}
22-
23-
public function getCaption($index){
24-
if($this->properties[$index] instanceof \ReflectionProperty)
25-
return $this->properties[$index]->getName();
26-
elseif(\is_callable($this->properties[$index]))
27-
return "";
28-
else
29-
return $this->properties[$index];
30-
}
31-
32-
public function getCaptions(){
33-
if(isset($this->captions)){
34-
$result= $this->captions;
35-
for($i=\sizeof($result);$i<$this->count();$i++){
36-
$result[]="";
37-
}
38-
return $result;
39-
}
40-
$captions=[];
41-
$index=0;
42-
$count=$this->count();
43-
while($index<$count){
44-
$captions[]=$this->getCaption($index++);
45-
}
46-
return $captions;
4719
}
4820

4921
public function getValues(){
@@ -174,11 +146,6 @@ private function getDefaultProperties(){
174146
return $result;
175147
}
176148

177-
public function setCaptions($captions) {
178-
$this->captions=$captions;
179-
return $this;
180-
}
181-
182149
public function setVisibleProperties($visibleProperties) {
183150
$this->visibleProperties=$visibleProperties;
184151
return $this;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace Ajax\semantic\widgets\base;
3+
use Ajax\semantic\widgets\base\InstanceViewer;
4+
5+
class InstanceViewerCaption extends InstanceViewer {
6+
protected $captions;
7+
8+
public function __construct($instance=NULL,$captions=NULL){
9+
parent::__construct($instance);
10+
$this->setCaptions($captions);
11+
}
12+
13+
public function getCaption($index){
14+
if($this->properties[$index] instanceof \ReflectionProperty)
15+
return $this->properties[$index]->getName();
16+
elseif(\is_callable($this->properties[$index]))
17+
return "";
18+
else
19+
return $this->properties[$index];
20+
}
21+
22+
public function getCaptions(){
23+
if(isset($this->captions)){
24+
$result= $this->captions;
25+
for($i=\sizeof($result);$i<$this->count();$i++){
26+
$result[]="";
27+
}
28+
return $result;
29+
}
30+
$captions=[];
31+
$index=0;
32+
$count=$this->count();
33+
while($index<$count){
34+
$captions[]=$this->getCaption($index++);
35+
}
36+
return $captions;
37+
}
38+
39+
public function setCaptions($captions) {
40+
$this->captions=$captions;
41+
return $this;
42+
}
43+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Ajax\semantic\widgets\dataelement;
4+
5+
use Ajax\common\Widget;
6+
7+
/**
8+
* DataElement widget for displaying an instance of model
9+
* @version 1.0
10+
* @author jc
11+
* @since 2.2
12+
*
13+
*/
14+
class DataElement extends Widget {
15+
16+
public function __construct($identifier, $model, $modelInstance=NULL) {
17+
parent::__construct($identifier, $model, $modelInstance=NULL);
18+
}
19+
20+
public function getHtmlComponent() {
21+
// TODO Auto-generated method stub
22+
}
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Ajax\semantic\widgets\dataform;
4+
5+
use Ajax\common\Widget;
6+
7+
/**
8+
* DataForm widget for editing model objects
9+
* @version 1.0
10+
* @author jc
11+
* @since 2.2
12+
*
13+
*/
14+
class DataForm extends Widget {
15+
16+
public function getHtmlComponent() {
17+
// TODO Auto-generated method stub
18+
}
19+
}

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
use Ajax\semantic\html\collections\menus\HtmlPaginationMenu;
1010
use Ajax\semantic\html\modules\checkbox\HtmlCheckbox;
1111
use Ajax\semantic\html\elements\HtmlButton;
12-
use Ajax\semantic\html\collections\menus\HtmlMenu;
1312
use Ajax\semantic\html\base\constants\Direction;
1413
use Ajax\service\JArray;
1514
use Ajax\semantic\widgets\base\FieldAsTrait;
1615
use Ajax\semantic\html\base\HtmlSemDoubleElement;
16+
use Ajax\semantic\widgets\base\InstanceViewerCaption;
1717

1818
/**
1919
* DataTable widget for displaying list of objects
20+
* @version 1.0
2021
* @author jc
22+
* @since 2.2
2123
*
2224
*/
2325
class DataTable extends Widget {
@@ -27,9 +29,7 @@ class DataTable extends Widget {
2729
protected $_urls;
2830
protected $_pagination;
2931
protected $_hasCheckboxes;
30-
protected $_toolbar;
3132
protected $_compileParts;
32-
protected $_toolbarPosition;
3333

3434
public function run(JsUtils $js){
3535
if($this->_hasCheckboxes && isset($js)){
@@ -43,7 +43,7 @@ public function run(JsUtils $js){
4343

4444
public function __construct($identifier,$model,$modelInstance=NULL) {
4545
parent::__construct($identifier, $model,$modelInstance);
46-
$this->_instanceViewer=new InstanceViewer();
46+
$this->_instanceViewer=new InstanceViewerCaption();
4747
$this->content=["table"=>new HtmlTable($identifier, 0,0)];
4848
$this->_toolbarPosition=PositionInTable::BEFORETABLE;
4949
}
@@ -92,10 +92,10 @@ private function _generateContent($table){
9292
if(isset($this->_pagination)){
9393
$objects=$this->_pagination->getObjects($this->_modelInstance);
9494
}
95-
InstanceViewer::setIndex(0);
95+
InstanceViewerCaption::setIndex(0);
9696
$table->fromDatabaseObjects($objects, function($instance){
9797
$this->_instanceViewer->setInstance($instance);
98-
InstanceViewer::$index++;
98+
InstanceViewerCaption::$index++;
9999
$result= $this->_instanceViewer->getValues();
100100
if($this->_hasCheckboxes){
101101
$ck=new HtmlCheckbox("ck-".$this->identifier,"");
@@ -342,45 +342,6 @@ public function setSelectable(){
342342
return $this;
343343
}
344344

345-
/**
346-
* @return \Ajax\semantic\html\collections\menus\HtmlMenu
347-
*/
348-
public function getToolbar(){
349-
if(isset($this->_toolbar)===false){
350-
$this->_toolbar=new HtmlMenu("toolbar-".$this->identifier);
351-
$this->_toolbar->setSecondary();
352-
}
353-
return $this->_toolbar;
354-
}
355-
356-
/**
357-
* Adds a new element in toolbar
358-
* @param mixed $element
359-
* @return \Ajax\common\html\HtmlDoubleElement
360-
*/
361-
public function addInToolbar($element){
362-
$tb=$this->getToolbar();
363-
return $tb->addItem($element);
364-
}
365-
366-
public function addItemInToolbar($caption,$icon=NULL){
367-
$result=$this->addInToolbar($caption);
368-
$result->addIcon($icon);
369-
return $result;
370-
}
371-
372-
public function addButtonInToolbar($caption){
373-
$bt=new HtmlButton("",$caption);
374-
return $this->addInToolbar($bt);
375-
}
376-
377-
public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){
378-
$bt=new HtmlButton("",$caption);
379-
$bt->addIcon($icon,$before,$labeled);
380-
return $this->addInToolbar($bt);
381-
}
382-
383-
384345
public function addSearchInToolbar(){
385346
return $this->addInToolbar($this->getSearchField())->setPosition("right");
386347
}

0 commit comments

Comments
 (0)