Skip to content

Commit 772d83b

Browse files
committed
$attributes on submit button+array with widgets
1 parent 04d259d commit 772d83b

File tree

8 files changed

+52
-14
lines changed

8 files changed

+52
-14
lines changed

Ajax/common/Widget.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ public function __construct($identifier,$model,$modelInstance=NULL) {
5555
parent::__construct($identifier);
5656
$this->_template="%wrapContentBefore%%content%%wrapContentAfter%";
5757
$this->setModel($model);
58-
if(isset($modelInstance));
58+
if(isset($modelInstance)){
59+
if(\is_array($modelInstance)){
60+
$modelInstance=\json_decode(\json_encode($modelInstance), FALSE);
61+
}
5962
$this->show($modelInstance);
63+
}
6064
$this->_generated=false;
6165
}
6266

@@ -105,6 +109,10 @@ public function setInstanceViewer($_instanceViewer) {
105109

106110
abstract public function getHtmlComponent();
107111

112+
public function setAttached($value=true){
113+
return $this->getHtmlComponent()->setAttached($value);
114+
}
115+
108116
public function setColor($color){
109117
return $this->getHtmlComponent()->setColor($color);
110118
}
@@ -260,9 +268,9 @@ public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labe
260268
return $this->addInToolbar($bt);
261269
}
262270

263-
public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL){
271+
public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){
264272
$button=new HtmlButton($identifier,$value,$cssStyle);
265-
$this->_buttonAsSubmit($button,"click",$url,$responseElement);
273+
$this->_buttonAsSubmit($button,"click",$url,$responseElement,$parameters);
266274
return $this->addInToolbar($button);
267275
}
268276

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract public function addToPropertyCtrl($name, $value, $typeCtrl);
1414
*/
1515
public function setAttachment($toElement, $side=Side::BOTH) {
1616
if (isset($toElement)) {
17-
$toElement->addToPropertyCtrl("class", "attached", array ("attached" ));
17+
$toElement->setAttached(true);
1818
}
1919
return $this->addToPropertyCtrl("class", $side . " attached", Side::getConstantValues("attached"));
2020
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ public function setActive($value=true){
151151
return $this;
152152
}
153153

154+
public function setAttached($value=true){
155+
if($value)
156+
$this->addToPropertyCtrl("class", "attached", array ("attached" ));
157+
return $this;
158+
}
159+
154160
/**
155161
* can be formatted to appear on dark backgrounds
156162
*/

Ajax/semantic/html/collections/form/traits/FormTrait.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public function setLoading() {
4040
return $this->getForm()->addToProperty("class", "loading");
4141
}
4242

43+
public function setAttached($value=true){
44+
$form=$this->getForm();
45+
if($value)
46+
$form->addToPropertyCtrl("class", "attached", array ("attached" ));
47+
return $form;
48+
}
49+
4350
public function addErrorMessage(){
4451
return $this->getForm()->addContent((new HtmlMessage(""))->setError());
4552
}
@@ -73,11 +80,14 @@ public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseE
7380
return $this->_buttonAsSubmit($bt, "click",$url,$responseElement);
7481
}
7582

76-
protected function _buttonAsSubmit(&$button,$event,$url,$responseElement=NULL){
83+
protected function _buttonAsSubmit(&$button,$event,$url,$responseElement=NULL,$parameters=NULL){
7784
$form=$this->getForm();
7885
if(isset($url) && isset($responseElement)){
7986
$button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');");
80-
$form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", ["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url]));
87+
$params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url];
88+
if(\is_array($parameters))
89+
$params=\array_merge($params,$parameters);
90+
$form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params));
8191
}
8292
return $button;
8393
}

Ajax/semantic/html/collections/table/traits/TableTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public function setBasic($very=false) {
2222
return $table->addToPropertyCtrl("class", "basic", array ("basic" ));
2323
}
2424

25+
public function setCompact($very=false) {
26+
$table=$this->getTable();
27+
if ($very)
28+
$table->addToPropertyCtrl("class", "very", array ("very" ));
29+
return $table->addToPropertyCtrl("class", "compact", array ("compact" ));
30+
}
31+
2532
public function setCollapsing() {
2633
return $this->addToPropertyTable("class", "collapsing");
2734
}

Ajax/semantic/widgets/base/FieldAsTrait.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract protected function _getFieldIdentifier($prefix,$name="");
2929
abstract public function setValueFunction($index,$callback);
3030
abstract protected function _getFieldName($index);
3131
abstract protected function _getFieldCaption($index);
32-
abstract protected function _buttonAsSubmit(&$button,$event,$url,$responseElement=NULL);
32+
abstract protected function _buttonAsSubmit(&$button,$event,$url,$responseElement=NULL,$parameters=NULL);
3333

3434
/**
3535
* @param HtmlFormField $element
@@ -44,6 +44,8 @@ protected function _applyAttributes($element,&$attributes,$index){
4444
}
4545
}
4646
unset($attributes["rules"]);
47+
unset($attributes["ajax"]);
48+
unset($attributes["visibleHover"]);
4749
$element->fromArray($attributes);
4850
}
4951

@@ -234,9 +236,9 @@ public function fieldAs($index,$type,$attributes=NULL){
234236
}
235237

236238
public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){
237-
return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle){
239+
return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){
238240
$button=new HtmlButton($id,$value,$cssStyle);
239-
$this->_buttonAsSubmit($button,"click",$url,$responseElement);
241+
$this->_buttonAsSubmit($button,"click",$url,$responseElement,$attributes["ajax"]);
240242
return $button;
241243
}, $index,$attributes,"submit");
242244
}

Ajax/semantic/widgets/base/InstanceViewer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ protected function _getValue($property,$index){
7979
}else{
8080
if(isset($this->values[$index])){
8181
$value= $this->values[$index]($property,$this->instance,$index);
82-
}else{
83-
$value=$property;
82+
}elseif(isset($this->instance->{$property})){
83+
$value=$this->instance->{$property};
84+
}
85+
else{
86+
$value=null;
8487
}
8588
}
8689
}

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,12 @@ public function asForm(){
367367
}
368368

369369
public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){
370-
return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index){
370+
return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index,$attributes){
371371
$button=new HtmlButton($id,$value,$cssStyle);
372-
$button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement);
373-
return $this->_visibleOver($button);
372+
$button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]);
373+
if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"])
374+
$this->_visibleOver($button);
375+
return $button;
374376
}, $index,$attributes);
375377
}
376378

0 commit comments

Comments
 (0)