Skip to content

Commit 3c0bc3b

Browse files
committed
Widget constructor opt.
1 parent 8b49e38 commit 3c0bc3b

File tree

7 files changed

+29
-13
lines changed

7 files changed

+29
-13
lines changed

Ajax/common/Widget.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ abstract class Widget extends HtmlDoubleElement {
3333
*/
3434
protected $_toolbarPosition;
3535

36+
protected $_edition;
37+
3638

3739
public function __construct($identifier,$model,$modelInstance=NULL) {
3840
parent::__construct($identifier);
@@ -42,6 +44,13 @@ public function __construct($identifier,$model,$modelInstance=NULL) {
4244
$this->show($modelInstance);
4345
}
4446

47+
protected function _init($instanceViewer,$contentKey,$content,$edition){
48+
$this->_instanceViewer=$instanceViewer;
49+
$this->content=[$contentKey=>$content];
50+
$this->_toolbarPosition=PositionInTable::BEFORETABLE;
51+
$this->_edition=$edition;
52+
}
53+
4554
protected function _getFieldIdentifier($prefix){
4655
return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier();
4756
}
@@ -193,4 +202,10 @@ public function setCaptionCallback($captionCallback) {
193202
$this->_instanceViewer->setCaptionCallback($captionCallback);
194203
return $this;
195204
}
205+
206+
public function setEdition($_edition) {
207+
$this->_edition=$_edition;
208+
return $this;
209+
}
210+
196211
}

Ajax/semantic/html/base/traits/BaseTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@ public function setSize($size) {
107107

108108
/**
109109
* show it is currently unable to be interacted with
110+
* @param boolean $disable
110111
* @return \Ajax\semantic\html\elements\HtmlSemDoubleElement
111112
*/
112-
public function setDisabled() {
113-
return $this->addToProperty("class", "disabled");
113+
public function setDisabled($disable=true) {
114+
if($disable)
115+
$this->addToProperty("class", "disabled");
116+
return $this;
114117
}
115118

116119
/**

Ajax/semantic/html/base/traits/TableElementTrait.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public function setError() {
2424
return $this->addState(State::ERROR);
2525
}
2626

27-
public function setDisabled() {
28-
return $this->addState(State::DISABLED);
27+
public function setDisabled($disable=true) {
28+
if($disable)
29+
$this->addState(State::DISABLED);
30+
return $this;
2931
}
3032
}

Ajax/semantic/widgets/base/FieldAsTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/**
1515
* @author jc
1616
* @property InstanceViewer $_instanceViewer
17+
* @property boolean $_edition
1718
*/
1819

1920
trait FieldAsTrait{
@@ -37,6 +38,7 @@ protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=nul
3738
$element=$elementCallback($this->_getFieldIdentifier($prefix),$name,$value,"");
3839
if(\is_array($attributes))
3940
$this->_applyAttributes($element, $attributes,$index);
41+
$element->setDisabled($this->_edition);
4042
return $element;
4143
});
4244
return $this;

Ajax/semantic/widgets/dataelement/DataElement.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ class DataElement extends Widget {
2020

2121
public function __construct($identifier, $modelInstance=NULL) {
2222
parent::__construct($identifier, null,$modelInstance);
23-
$this->_instanceViewer=new InstanceViewer($identifier);
24-
$this->content=["table"=>new HtmlTable($identifier, 0,2)];
23+
$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,2), false);
2524
$this->content["table"]->setDefinition();
26-
$this->_toolbarPosition=PositionInTable::BEFORETABLE;
2725
}
2826

2927
public function compile(JsUtils $js=NULL,&$view=NULL){

Ajax/semantic/widgets/dataform/DataForm.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ class DataForm extends Widget {
2121

2222
public function __construct($identifier, $modelInstance=NULL) {
2323
parent::__construct($identifier, null,$modelInstance);
24-
$this->_instanceViewer=new FormInstanceViewer($identifier);
25-
$this->content=["form"=>new HtmlForm($identifier)];
26-
$this->_toolbarPosition=PositionInTable::BEFORETABLE;
24+
$this->_init(new FormInstanceViewer($identifier), "form", new HtmlForm($identifier), true);
2725
}
2826

2927
public function compile(JsUtils $js=NULL,&$view=NULL){

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ public function run(JsUtils $js){
4242

4343
public function __construct($identifier,$model,$modelInstance=NULL) {
4444
parent::__construct($identifier, $model,$modelInstance);
45-
$this->_instanceViewer=new InstanceViewer($identifier);
46-
$this->content=["table"=>new HtmlTable($identifier, 0,0)];
47-
$this->_toolbarPosition=PositionInTable::BEFORETABLE;
45+
$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false);
4846
}
4947

5048
/**

0 commit comments

Comments
 (0)