Skip to content

Commit e534306

Browse files
committed
Widgets asModal
1 parent 138cdf0 commit e534306

File tree

17 files changed

+171
-27
lines changed

17 files changed

+171
-27
lines changed

Ajax/common/Widget.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Ajax\semantic\html\collections\form\HtmlFormField;
1818
use Ajax\semantic\html\collections\form\traits\FormTrait;
1919
use Ajax\common\html\BaseWidget;
20+
use Ajax\semantic\html\modules\HtmlModal;
2021

2122
abstract class Widget extends HtmlDoubleElement {
2223
use FieldAsTrait,FormTrait;
@@ -425,4 +426,13 @@ public function removeField($index){
425426
$this->_instanceViewer->removeField($index);
426427
return $this;
427428
}
429+
430+
public function asModal($header){
431+
$modal=new HtmlModal("modal-".$this->identifier,$header);
432+
$modal->setContent($this);
433+
if(isset($this->_form)){
434+
$this->_form->onSuccess($modal->jsHide());
435+
}
436+
return $modal;
437+
}
428438
}

Ajax/common/traits/JqueryAjaxTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCal
5050
$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n";
5151
if ($immediatly)
5252
$this->jquery_code_for_compile[]=$retour;
53-
return $retour;
53+
return $retour;
5454
}
5555

5656
protected function setAjaxDataCall($params){

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Ajax\semantic\html\base\constants\Color;
77
use Ajax\semantic\html\base\constants\Direction;
88
use Ajax\semantic\html\elements\HtmlIcon;
9+
use Ajax\service\JString;
910

1011
/**
1112
* @author jc
@@ -183,4 +184,16 @@ public function floatLeft() {
183184
public function getBaseClass() {
184185
return $this->_baseClass;
185186
}
187+
188+
protected function addBehavior(&$array,$key,$value,$before="",$after=""){
189+
if(\is_string($value)){
190+
if(isset($array[$key])){
191+
$p=JString::replaceAtFirstAndLast($array[$key], $before, "", $after, "");
192+
$array[$key]=$before.$p.$value.$after;
193+
}else
194+
$array[$key]=$before.$value.$after;
195+
}else
196+
$array[$key]=$value;
197+
return $this;
198+
}
186199
}

Ajax/semantic/html/collections/HtmlMessage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function addHeader($header){
4040
return $this->addContent($headerO,true);
4141
}
4242

43+
public function setHeader($header){
44+
return $this->addHeader($header);
45+
}
46+
4347
public function addList($elements,$ordered=false){
4448
$list=new HtmlList("list-".$this->identifier,$elements);
4549
$list->setOrdered($ordered);
@@ -96,6 +100,10 @@ public function setError(){
96100
return $this->setStyle("error");
97101
}
98102

103+
public function setWarning(){
104+
return $this->setStyle("warning");
105+
}
106+
99107
public function setMessage($message){
100108
if(\is_array($this->content)){
101109
$this->content[\sizeof($this->content)-1]=$message;

Ajax/semantic/html/collections/form/HtmlForm.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Ajax\JsUtils;
1212
use Ajax\semantic\html\collections\form\traits\FormTrait;
1313
use Ajax\semantic\components\Form;
14+
use Ajax\service\JString;
1415

1516
/**
1617
* Semantic Form component
@@ -176,8 +177,8 @@ public function run(JsUtils $js) {
176177
return $this->_bsComponent;
177178
}
178179

179-
public function addValidationParam($paramName,$paramValue){
180-
$this->_validationParams[$paramName]=$paramValue;
180+
public function addValidationParam($paramName,$paramValue,$before="",$after=""){
181+
$this->addBehavior($this->_validationParams, $paramName, $paramValue,$before,$after);
181182
return $this;
182183
}
183184

Ajax/semantic/html/collections/form/HtmlFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct($identifier, $field,$label=NULL) {
1818
parent::__construct($identifier, "div","field");
1919
$this->content=array();
2020
$this->_states=[State::ERROR,State::DISABLED];
21-
if(isset($label))
21+
if(isset($label) && $label!=="")
2222
$this->setLabel($label);
2323
$this->setField($field);
2424
$this->_validation=NULL;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function setLoading() {
4646
return $this->getForm()->addToProperty("class", "loading");
4747
}
4848

49+
public function setState($state) {
50+
$this->getForm()->addToProperty("class", $state);
51+
return $this;
52+
}
53+
4954
public function setAttached($value=true){
5055
$form=$this->getForm();
5156
if($value)
@@ -122,7 +127,7 @@ public function onValid($jsCode){
122127
*/
123128
public function onSuccess($jsCode){
124129
$form=$this->getForm();
125-
$form->addValidationParam("onSuccess", "%function(event,fields){console.log(fields);".$jsCode."}%");
130+
$form->addValidationParam("onSuccess", $jsCode,"%function(event,fields){","}%");
126131
return $form;
127132
}
128133
}

Ajax/semantic/html/modules/HtmlModal.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class HtmlModal extends HtmlSemDoubleElement {
1414
protected $_params=array();
1515
protected $_paramParts=array();
1616

17-
public function __construct($identifier, $header="", $content="", $actions=array()) {
17+
public function __construct($identifier, $header="", $content="", $actions=null) {
1818
parent::__construct($identifier, "div","ui modal");
1919
if(isset($header)){
2020
$this->setHeader($header);
@@ -171,4 +171,12 @@ public function run(JsUtils $js) {
171171
$this->addEventsOnRun($js);
172172
return $this->_bsComponent;
173173
}
174+
175+
public function jsDo($behavior) {
176+
return "$('#".$this->identifier."').modal('".$behavior."');";
177+
}
178+
179+
public function jsHide() {
180+
return $this->jsDo("hide");
181+
}
174182
}

Ajax/semantic/html/modules/HtmlProgress.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public function setTextValues($active=false, $error=false, $success=false, $warn
103103
}
104104

105105
public function onChange($jsCode) {
106-
return $this->_params["onChange"]="%function(percent, value, total){" . $jsCode . "}%";
106+
$this->addBehavior($this->_params, "onChange", $jsCode,"%function(percent, value, total){","}%");
107+
return $this;
107108
}
108109

109110
/*

Ajax/semantic/traits/SemanticWidgetsTrait.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ public function dataForm($identifier, $instance){
3838
return $this->addHtmlComponent(new DataForm($identifier,$instance));
3939
}
4040

41-
public function formLogin($identifier){
42-
return $this->addHtmlComponent(new FormLogin($identifier));
41+
public function defaultLogin($identifier,$instance=null){
42+
return $this->addHtmlComponent(FormLogin::default($identifier,$instance));
43+
}
44+
45+
public function smallLogin($identifier,$instance=null){
46+
return $this->addHtmlComponent(FormLogin::small($identifier,$instance));
4347
}
4448
}

0 commit comments

Comments
 (0)