@@ -48,8 +48,9 @@ discard block |
||
48 | 48 | |
49 | 49 | public function setAttached($value=true){ |
50 | 50 | $form=$this->getForm(); |
51 | - if($value) |
|
52 | - $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
51 | + if($value) { |
|
52 | + $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
53 | + } |
|
53 | 54 | return $form; |
54 | 55 | } |
55 | 56 | |
@@ -91,8 +92,9 @@ discard block |
||
91 | 92 | if(isset($url) && isset($responseElement)){ |
92 | 93 | $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');",true,true); |
93 | 94 | $params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url,"stopPropagation"=>true]; |
94 | - if(\is_array($parameters)) |
|
95 | - $params=\array_merge($params,$parameters); |
|
95 | + if(\is_array($parameters)) { |
|
96 | + $params=\array_merge($params,$parameters); |
|
97 | + } |
|
96 | 98 | $form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params)); |
97 | 99 | } |
98 | 100 | return $button; |
@@ -12,28 +12,28 @@ discard block |
||
12 | 12 | * @author jc |
13 | 13 | * |
14 | 14 | */ |
15 | -trait FormTrait{ |
|
15 | +trait FormTrait { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @return HtmlForm |
19 | 19 | */ |
20 | 20 | abstract protected function getForm(); |
21 | 21 | |
22 | - protected function addCompoValidation($compo,$field){ |
|
22 | + protected function addCompoValidation($compo, $field) { |
|
23 | 23 | $validation=$field->getValidation(); |
24 | - if(isset($validation)){ |
|
24 | + if (isset($validation)) { |
|
25 | 25 | $validation->setIdentifier($field->getDataField()->getIdentifier()); |
26 | 26 | $compo->addFieldValidation($validation); |
27 | 27 | } |
28 | 28 | return $compo; |
29 | 29 | } |
30 | 30 | |
31 | - protected function _runValidationParams(&$compo,JsUtils $js=NULL){ |
|
31 | + protected function _runValidationParams(&$compo, JsUtils $js=NULL) { |
|
32 | 32 | $form=$this->getForm(); |
33 | 33 | $params=$form->getValidationParams(); |
34 | - if(isset($params["_ajaxSubmit"]) && $params["_ajaxSubmit"] instanceof AjaxCall){ |
|
34 | + if (isset($params["_ajaxSubmit"]) && $params["_ajaxSubmit"] instanceof AjaxCall) { |
|
35 | 35 | $compilation=$params["_ajaxSubmit"]->compile($js); |
36 | - $compilation=str_ireplace("\"","%quote%", $compilation); |
|
36 | + $compilation=str_ireplace("\"", "%quote%", $compilation); |
|
37 | 37 | $this->onSuccess($compilation); |
38 | 38 | $form->removeValidationParam("_ajaxSubmit"); |
39 | 39 | } |
@@ -51,14 +51,14 @@ discard block |
||
51 | 51 | return $this; |
52 | 52 | } |
53 | 53 | |
54 | - public function setAttached($value=true){ |
|
54 | + public function setAttached($value=true) { |
|
55 | 55 | $form=$this->getForm(); |
56 | - if($value) |
|
57 | - $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
56 | + if ($value) |
|
57 | + $form->addToPropertyCtrl("class", "attached", array("attached")); |
|
58 | 58 | return $form; |
59 | 59 | } |
60 | 60 | |
61 | - public function addErrorMessage(){ |
|
61 | + public function addErrorMessage() { |
|
62 | 62 | return $this->getForm()->addContent((new HtmlMessage(""))->setError()); |
63 | 63 | } |
64 | 64 | |
@@ -73,38 +73,38 @@ discard block |
||
73 | 73 | * @param string $responseElement |
74 | 74 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
75 | 75 | */ |
76 | - public function submitOn($event,$identifier,$url,$responseElement){ |
|
76 | + public function submitOn($event, $identifier, $url, $responseElement) { |
|
77 | 77 | $form=$this->getForm(); |
78 | 78 | $elem=$form->getElementById($identifier, $form->getContent()); |
79 | - if(isset($elem)){ |
|
80 | - $this->_buttonAsSubmit($elem, $event,$url,$responseElement); |
|
79 | + if (isset($elem)) { |
|
80 | + $this->_buttonAsSubmit($elem, $event, $url, $responseElement); |
|
81 | 81 | } |
82 | 82 | return $form; |
83 | 83 | } |
84 | 84 | |
85 | - public function submitOnClick($identifier,$url,$responseElement){ |
|
85 | + public function submitOnClick($identifier, $url, $responseElement) { |
|
86 | 86 | return $this->submitOn("click", $identifier, $url, $responseElement); |
87 | 87 | } |
88 | 88 | |
89 | - public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL){ |
|
90 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
91 | - return $this->_buttonAsSubmit($bt, "click",$url,$responseElement); |
|
89 | + public function addSubmit($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL) { |
|
90 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
91 | + return $this->_buttonAsSubmit($bt, "click", $url, $responseElement); |
|
92 | 92 | } |
93 | 93 | |
94 | - protected function _buttonAsSubmit(HtmlButton &$button,$event,$url,$responseElement=NULL,$parameters=NULL){ |
|
94 | + protected function _buttonAsSubmit(HtmlButton&$button, $event, $url, $responseElement=NULL, $parameters=NULL) { |
|
95 | 95 | $form=$this->getForm(); |
96 | - if(isset($url) && isset($responseElement)){ |
|
97 | - $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');",true,true); |
|
98 | - $params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url,"stopPropagation"=>true]; |
|
99 | - if(\is_array($parameters)) |
|
100 | - $params=\array_merge($params,$parameters); |
|
96 | + if (isset($url) && isset($responseElement)) { |
|
97 | + $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');", true, true); |
|
98 | + $params=["form"=>$form->getIdentifier(), "responseElement"=>$responseElement, "url"=>$url, "stopPropagation"=>true]; |
|
99 | + if (\is_array($parameters)) |
|
100 | + $params=\array_merge($params, $parameters); |
|
101 | 101 | $form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params)); |
102 | 102 | } |
103 | 103 | return $button; |
104 | 104 | } |
105 | 105 | |
106 | - public function addReset($identifier,$value,$cssStyle=NULL){ |
|
107 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
106 | + public function addReset($identifier, $value, $cssStyle=NULL) { |
|
107 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
108 | 108 | $bt->setProperty("type", "reset"); |
109 | 109 | return $bt; |
110 | 110 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @param string $jsCode |
115 | 115 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
116 | 116 | */ |
117 | - public function onValid($jsCode){ |
|
117 | + public function onValid($jsCode) { |
|
118 | 118 | $form=$this->getForm(); |
119 | 119 | $form->addValidationParam("onValid", "%function(){".$jsCode."}%"); |
120 | 120 | return $form; |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * @param string $jsCode can use event and fields parameters |
126 | 126 | * @return HtmlForm |
127 | 127 | */ |
128 | - public function onSuccess($jsCode){ |
|
128 | + public function onSuccess($jsCode) { |
|
129 | 129 | $form=$this->getForm(); |
130 | - $form->addValidationParam("onSuccess", $jsCode,"%function(event,fields){","}%"); |
|
130 | + $form->addValidationParam("onSuccess", $jsCode, "%function(event,fields){", "}%"); |
|
131 | 131 | return $form; |
132 | 132 | } |
133 | 133 | } |
134 | 134 | \ No newline at end of file |
@@ -10,17 +10,17 @@ discard block |
||
10 | 10 | * @author jc |
11 | 11 | * @property string identifier |
12 | 12 | */ |
13 | -trait HasCheckboxesTrait{ |
|
13 | +trait HasCheckboxesTrait { |
|
14 | 14 | protected $_hasCheckboxes; |
15 | 15 | protected $_hasCheckedMessage=false; |
16 | 16 | protected $_checkedMessage; |
17 | 17 | protected $_checkedClass; |
18 | 18 | |
19 | - abstract public function addInToolbar($element,$callback=NULL); |
|
19 | + abstract public function addInToolbar($element, $callback=NULL); |
|
20 | 20 | |
21 | - protected function _runCheckboxes(JsUtils $js){ |
|
21 | + protected function _runCheckboxes(JsUtils $js) { |
|
22 | 22 | $checkedMessageCall=""; |
23 | - if($this->_hasCheckedMessage){ |
|
23 | + if ($this->_hasCheckedMessage) { |
|
24 | 24 | $msg=$this->getCheckedMessage(); |
25 | 25 | $checkedMessageFunction="function updateChecked(){var msg='".$msg[0]."',count=\$('#{$this->identifier} [name=\"selection[]\"]:checked').length,all=\$('#{$this->identifier} [name=\"selection[]\"]').length; |
26 | 26 | if(count==1) msg='".$msg[1]."'; |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | \$('#checked-count-".$this->identifier."').contents().filter(function() {return this.nodeType == 3;}).each(function(){this.textContent = msg.replace('{count}',count);}); |
29 | 29 | \$('#toolbar-{$this->identifier} .visibleOnChecked').toggle(count>0);}\$('#toolbar-".$this->identifier." .visibleOnChecked').hide();"; |
30 | 30 | $checkedMessageCall="updateChecked();"; |
31 | - if(isset($this->_checkedClass)){ |
|
31 | + if (isset($this->_checkedClass)) { |
|
32 | 32 | $checkedMessageCall.="$(this).closest('tr').toggleClass('".$this->_checkedClass."',$(this).prop('checked'));"; |
33 | 33 | } |
34 | - $js->exec($checkedMessageFunction,true); |
|
34 | + $js->exec($checkedMessageFunction, true); |
|
35 | 35 | } |
36 | 36 | $js->execOn("change", "#".$this->identifier." [name='selection[]']", " |
37 | 37 | var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true; |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$checkedMessageCall); |
40 | 40 | } |
41 | 41 | |
42 | - protected function _generateMainCheckbox(&$captions){ |
|
43 | - $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
|
42 | + protected function _generateMainCheckbox(&$captions) { |
|
43 | + $ck=new HtmlCheckbox("main-ck-".$this->identifier, ""); |
|
44 | 44 | $checkedMessageCall=""; |
45 | - if($this->_hasCheckedMessage) |
|
45 | + if ($this->_hasCheckedMessage) |
|
46 | 46 | $checkedMessageCall="updateChecked();"; |
47 | 47 | |
48 | 48 | $ck->setOnChecked($this->_setAllChecked("true").$checkedMessageCall); |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | \array_unshift($captions, $ck); |
51 | 51 | } |
52 | 52 | |
53 | - protected function _setAllChecked($checked){ |
|
53 | + protected function _setAllChecked($checked) { |
|
54 | 54 | $result="$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',".$checked.");"; |
55 | - if(isset($this->_checkedClass)){ |
|
55 | + if (isset($this->_checkedClass)) { |
|
56 | 56 | $result.="$('#".$this->identifier." tr').toggleClass('".$this->_checkedClass."',".$checked.");"; |
57 | 57 | } |
58 | 58 | return $result; |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | protected function getCheckedMessage() { |
71 | - $result= $this->_checkedMessage; |
|
72 | - if(!isset($result)){ |
|
73 | - $result=[0=>"none selected",1=>"one item selected","other"=>"{count} items selected"]; |
|
71 | + $result=$this->_checkedMessage; |
|
72 | + if (!isset($result)) { |
|
73 | + $result=[0=>"none selected", 1=>"one item selected", "other"=>"{count} items selected"]; |
|
74 | 74 | } |
75 | 75 | return $result; |
76 | 76 | } |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | * @param array $checkedMessage |
91 | 91 | * @param callable $callback |
92 | 92 | */ |
93 | - public function addCountCheckedInToolbar(array $checkedMessage=null,$callback=null){ |
|
94 | - if(isset($checkedMessage)) |
|
93 | + public function addCountCheckedInToolbar(array $checkedMessage=null, $callback=null) { |
|
94 | + if (isset($checkedMessage)) |
|
95 | 95 | $this->_checkedMessage=$checkedMessage; |
96 | 96 | $checkedMessage=$this->getCheckedMessage(); |
97 | 97 | $this->_hasCheckboxes=true; |
98 | 98 | $this->_hasCheckedMessage=true; |
99 | - $element=new HtmlLabel("checked-count-".$this->identifier,$checkedMessage[0]); |
|
100 | - $this->addInToolbar($element,$callback); |
|
99 | + $element=new HtmlLabel("checked-count-".$this->identifier, $checkedMessage[0]); |
|
100 | + $this->addInToolbar($element, $callback); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | public function setCheckedClass($_checkedClass) { |
@@ -42,8 +42,9 @@ discard block |
||
42 | 42 | protected function _generateMainCheckbox(&$captions){ |
43 | 43 | $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
44 | 44 | $checkedMessageCall=""; |
45 | - if($this->_hasCheckedMessage) |
|
46 | - $checkedMessageCall="updateChecked();"; |
|
45 | + if($this->_hasCheckedMessage) { |
|
46 | + $checkedMessageCall="updateChecked();"; |
|
47 | + } |
|
47 | 48 | |
48 | 49 | $ck->setOnChecked($this->_setAllChecked("true").$checkedMessageCall); |
49 | 50 | $ck->setOnUnchecked($this->_setAllChecked("false").$checkedMessageCall); |
@@ -91,8 +92,9 @@ discard block |
||
91 | 92 | * @param callable $callback |
92 | 93 | */ |
93 | 94 | public function addCountCheckedInToolbar(array $checkedMessage=null,$callback=null){ |
94 | - if(isset($checkedMessage)) |
|
95 | - $this->_checkedMessage=$checkedMessage; |
|
95 | + if(isset($checkedMessage)) { |
|
96 | + $this->_checkedMessage=$checkedMessage; |
|
97 | + } |
|
96 | 98 | $checkedMessage=$this->getCheckedMessage(); |
97 | 99 | $this->_hasCheckboxes=true; |
98 | 100 | $this->_hasCheckedMessage=true; |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | */ |
23 | 23 | class DataTable extends Widget { |
24 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait; |
|
24 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait; |
|
25 | 25 | protected $_searchField; |
26 | 26 | protected $_urls; |
27 | 27 | protected $_pagination; |
@@ -32,33 +32,33 @@ discard block |
||
32 | 32 | protected $_targetSelector; |
33 | 33 | |
34 | 34 | |
35 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
36 | - parent::__construct($identifier, $model,$modelInstance); |
|
37 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
35 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
36 | + parent::__construct($identifier, $model, $modelInstance); |
|
37 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
38 | 38 | $this->_urls=[]; |
39 | 39 | } |
40 | 40 | |
41 | - public function run(JsUtils $js){ |
|
42 | - if($this->_hasCheckboxes && isset($js)){ |
|
41 | + public function run(JsUtils $js) { |
|
42 | + if ($this->_hasCheckboxes && isset($js)) { |
|
43 | 43 | $this->_runCheckboxes($js); |
44 | 44 | } |
45 | - if($this->_visibleHover){ |
|
46 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
47 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
45 | + if ($this->_visibleHover) { |
|
46 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
47 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
48 | 48 | } |
49 | - if(\is_array($this->_deleteBehavior)) |
|
50 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
51 | - if(\is_array($this->_editBehavior)) |
|
52 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
49 | + if (\is_array($this->_deleteBehavior)) |
|
50 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
51 | + if (\is_array($this->_editBehavior)) |
|
52 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
53 | 53 | return parent::run($js); |
54 | 54 | } |
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
59 | - if(isset($this->_urls[$op])){ |
|
60 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
61 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params); |
|
58 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
59 | + if (isset($this->_urls[$op])) { |
|
60 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
61 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
@@ -71,62 +71,62 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | |
74 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
75 | - if(!$this->_generated){ |
|
74 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
75 | + if (!$this->_generated) { |
|
76 | 76 | $this->_instanceViewer->setInstance($this->_model); |
77 | 77 | $captions=$this->_instanceViewer->getCaptions(); |
78 | 78 | |
79 | 79 | $table=$this->content["table"]; |
80 | 80 | |
81 | - if($this->_hasCheckboxes){ |
|
81 | + if ($this->_hasCheckboxes) { |
|
82 | 82 | $this->_generateMainCheckbox($captions); |
83 | 83 | } |
84 | 84 | |
85 | 85 | $table->setRowCount(0, \sizeof($captions)); |
86 | 86 | $table->setHeaderValues($captions); |
87 | - if(isset($this->_compileParts)) |
|
87 | + if (isset($this->_compileParts)) |
|
88 | 88 | $table->setCompileParts($this->_compileParts); |
89 | 89 | |
90 | - if(isset($this->_searchField) && isset($js)){ |
|
91 | - if(isset($this->_urls["refresh"])) |
|
92 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
90 | + if (isset($this->_searchField) && isset($js)) { |
|
91 | + if (isset($this->_urls["refresh"])) |
|
92 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $this->_generateContent($table); |
96 | 96 | |
97 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
97 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
98 | 98 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
99 | 99 | } |
100 | 100 | |
101 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
101 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
102 | 102 | $this->_generatePagination($table); |
103 | 103 | } |
104 | - if(isset($this->_toolbar)){ |
|
104 | + if (isset($this->_toolbar)) { |
|
105 | 105 | $this->_setToolbarPosition($table, $captions); |
106 | 106 | } |
107 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
107 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
108 | 108 | $this->_compileForm(); |
109 | 109 | $this->_generated=true; |
110 | 110 | } |
111 | - return parent::compile($js,$view); |
|
111 | + return parent::compile($js, $view); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | |
115 | 115 | |
116 | - protected function _generateContent($table){ |
|
116 | + protected function _generateContent($table) { |
|
117 | 117 | $objects=$this->_modelInstance; |
118 | - if(isset($this->_pagination)){ |
|
118 | + if (isset($this->_pagination)) { |
|
119 | 119 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
120 | 120 | } |
121 | 121 | InstanceViewer::setIndex(0); |
122 | 122 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
123 | 123 | $this->_instanceViewer->setInstance($instance); |
124 | 124 | InstanceViewer::$index++; |
125 | - $values= $this->_instanceViewer->getValues(); |
|
126 | - if($this->_hasCheckboxes){ |
|
127 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
125 | + $values=$this->_instanceViewer->getValues(); |
|
126 | + if ($this->_hasCheckboxes) { |
|
127 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
128 | 128 | $field=$ck->getField(); |
129 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
129 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
130 | 130 | $field->setProperty("name", "selection[]"); |
131 | 131 | \array_unshift($values, $ck); |
132 | 132 | } |
@@ -137,37 +137,37 @@ discard block |
||
137 | 137 | }); |
138 | 138 | } |
139 | 139 | |
140 | - private function _generatePagination($table){ |
|
140 | + private function _generatePagination($table) { |
|
141 | 141 | $footer=$table->getFooter(); |
142 | 142 | $footer->mergeCol(); |
143 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
143 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
144 | 144 | $menu->floatRight(); |
145 | 145 | $menu->setActiveItem($this->_pagination->getPage()-1); |
146 | 146 | $footer->setValues($menu); |
147 | - if(isset($this->_urls["refresh"])) |
|
148 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
147 | + if (isset($this->_urls["refresh"])) |
|
148 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
149 | 149 | } |
150 | 150 | |
151 | - protected function _getFieldName($index){ |
|
151 | + protected function _getFieldName($index) { |
|
152 | 152 | return parent::_getFieldName($index)."[]"; |
153 | 153 | } |
154 | 154 | |
155 | - protected function _getFieldCaption($index){ |
|
155 | + protected function _getFieldCaption($index) { |
|
156 | 156 | return null; |
157 | 157 | } |
158 | 158 | |
159 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
160 | - switch ($this->_toolbarPosition){ |
|
159 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
160 | + switch ($this->_toolbarPosition) { |
|
161 | 161 | case PositionInTable::BEFORETABLE: |
162 | 162 | case PositionInTable::AFTERTABLE: |
163 | - if(isset($this->_compileParts)===false){ |
|
163 | + if (isset($this->_compileParts)===false) { |
|
164 | 164 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
165 | 165 | } |
166 | 166 | break; |
167 | 167 | case PositionInTable::HEADER: |
168 | 168 | case PositionInTable::FOOTER: |
169 | 169 | case PositionInTable::BODY: |
170 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
170 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
171 | 171 | break; |
172 | 172 | } |
173 | 173 | } |
@@ -179,23 +179,23 @@ discard block |
||
179 | 179 | * @param callable $callback function called after the field compilation |
180 | 180 | * @return \Ajax\semantic\widgets\datatable\DataTable |
181 | 181 | */ |
182 | - public function afterCompile($index,$callback){ |
|
183 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
182 | + public function afterCompile($index, $callback) { |
|
183 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
184 | 184 | return $this; |
185 | 185 | } |
186 | 186 | |
187 | - private function addToolbarRow($part,$table,$captions){ |
|
187 | + private function addToolbarRow($part, $table, $captions) { |
|
188 | 188 | $hasPart=$table->hasPart($part); |
189 | - if($hasPart){ |
|
189 | + if ($hasPart) { |
|
190 | 190 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
191 | - }else{ |
|
191 | + } else { |
|
192 | 192 | $row=$table->getPart($part)->getRow(0); |
193 | 193 | } |
194 | 194 | $row->mergeCol(); |
195 | 195 | $row->setValues([$this->_toolbar]); |
196 | 196 | } |
197 | 197 | |
198 | - public function getHtmlComponent(){ |
|
198 | + public function getHtmlComponent() { |
|
199 | 199 | return $this->content["table"]; |
200 | 200 | } |
201 | 201 | |
@@ -209,36 +209,36 @@ discard block |
||
209 | 209 | * @return \Ajax\semantic\widgets\datatable\DataTable |
210 | 210 | */ |
211 | 211 | public function setUrls($urls) { |
212 | - if(\is_array($urls)){ |
|
213 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
214 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
215 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
216 | - }else{ |
|
217 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
212 | + if (\is_array($urls)) { |
|
213 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
214 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
215 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
216 | + } else { |
|
217 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
218 | 218 | } |
219 | 219 | return $this; |
220 | 220 | } |
221 | 221 | |
222 | - public function paginate($items_per_page=10,$page=1){ |
|
223 | - $this->_pagination=new Pagination($items_per_page,4,$page); |
|
222 | + public function paginate($items_per_page=10, $page=1) { |
|
223 | + $this->_pagination=new Pagination($items_per_page, 4, $page); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
227 | 227 | |
228 | - public function refresh($compileParts=["tbody"]){ |
|
228 | + public function refresh($compileParts=["tbody"]) { |
|
229 | 229 | $this->_compileParts=$compileParts; |
230 | 230 | return $this; |
231 | 231 | } |
232 | 232 | |
233 | 233 | |
234 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
234 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
235 | 235 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
236 | 236 | } |
237 | 237 | |
238 | - public function getSearchField(){ |
|
239 | - if(isset($this->_searchField)===false){ |
|
240 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
241 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
238 | + public function getSearchField() { |
|
239 | + if (isset($this->_searchField)===false) { |
|
240 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
241 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
242 | 242 | } |
243 | 243 | return $this->_searchField; |
244 | 244 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | return $this; |
255 | 255 | } |
256 | 256 | |
257 | - public function asForm(){ |
|
257 | + public function asForm() { |
|
258 | 258 | return $this->getForm(); |
259 | 259 | } |
260 | 260 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | protected function getTargetSelector() { |
264 | 264 | $result=$this->_targetSelector; |
265 | - if(!isset($result)) |
|
265 | + if (!isset($result)) |
|
266 | 266 | $result="#".$this->identifier; |
267 | 267 | return $result; |
268 | 268 | } |
@@ -46,10 +46,12 @@ discard block |
||
46 | 46 | $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
47 | 47 | $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
48 | 48 | } |
49 | - if(\is_array($this->_deleteBehavior)) |
|
50 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
51 | - if(\is_array($this->_editBehavior)) |
|
52 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
49 | + if(\is_array($this->_deleteBehavior)) { |
|
50 | + $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
51 | + } |
|
52 | + if(\is_array($this->_editBehavior)) { |
|
53 | + $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
54 | + } |
|
53 | 55 | return parent::run($js); |
54 | 56 | } |
55 | 57 | |
@@ -84,12 +86,14 @@ discard block |
||
84 | 86 | |
85 | 87 | $table->setRowCount(0, \sizeof($captions)); |
86 | 88 | $table->setHeaderValues($captions); |
87 | - if(isset($this->_compileParts)) |
|
88 | - $table->setCompileParts($this->_compileParts); |
|
89 | + if(isset($this->_compileParts)) { |
|
90 | + $table->setCompileParts($this->_compileParts); |
|
91 | + } |
|
89 | 92 | |
90 | 93 | if(isset($this->_searchField) && isset($js)){ |
91 | - if(isset($this->_urls["refresh"])) |
|
92 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
94 | + if(isset($this->_urls["refresh"])) { |
|
95 | + $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
96 | + } |
|
93 | 97 | } |
94 | 98 | |
95 | 99 | $this->_generateContent($table); |
@@ -144,8 +148,9 @@ discard block |
||
144 | 148 | $menu->floatRight(); |
145 | 149 | $menu->setActiveItem($this->_pagination->getPage()-1); |
146 | 150 | $footer->setValues($menu); |
147 | - if(isset($this->_urls["refresh"])) |
|
148 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
151 | + if(isset($this->_urls["refresh"])) { |
|
152 | + $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
153 | + } |
|
149 | 154 | } |
150 | 155 | |
151 | 156 | protected function _getFieldName($index){ |
@@ -188,7 +193,7 @@ discard block |
||
188 | 193 | $hasPart=$table->hasPart($part); |
189 | 194 | if($hasPart){ |
190 | 195 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
191 | - }else{ |
|
196 | + } else{ |
|
192 | 197 | $row=$table->getPart($part)->getRow(0); |
193 | 198 | } |
194 | 199 | $row->mergeCol(); |
@@ -213,7 +218,7 @@ discard block |
||
213 | 218 | $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
214 | 219 | $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
215 | 220 | $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
216 | - }else{ |
|
221 | + } else{ |
|
217 | 222 | $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
218 | 223 | } |
219 | 224 | return $this; |
@@ -262,8 +267,9 @@ discard block |
||
262 | 267 | |
263 | 268 | protected function getTargetSelector() { |
264 | 269 | $result=$this->_targetSelector; |
265 | - if(!isset($result)) |
|
266 | - $result="#".$this->identifier; |
|
270 | + if(!isset($result)) { |
|
271 | + $result="#".$this->identifier; |
|
272 | + } |
|
267 | 273 | return $result; |
268 | 274 | } |
269 | 275 |
@@ -12,10 +12,10 @@ |
||
12 | 12 | parent::__construct($identifier, $instance, $captions); |
13 | 13 | } |
14 | 14 | |
15 | - public function getValue($index){ |
|
15 | + public function getValue($index) { |
|
16 | 16 | $result=parent::getValue($index); |
17 | - if($result instanceof HtmlFormField){ |
|
18 | - $lbl=new HtmlSemDoubleElement("lbl-".$this->widgetIdentifier."-".$index,"label","",$this->getCaption($index)); |
|
17 | + if ($result instanceof HtmlFormField) { |
|
18 | + $lbl=new HtmlSemDoubleElement("lbl-".$this->widgetIdentifier."-".$index, "label", "", $this->getCaption($index)); |
|
19 | 19 | $lbl->setProperty("for", $result->getDataField()->getIdentifier()); |
20 | 20 | $this->captions[$index]=$lbl; |
21 | 21 | } |
@@ -18,49 +18,49 @@ discard block |
||
18 | 18 | class DataElement extends Widget { |
19 | 19 | |
20 | 20 | public function __construct($identifier, $modelInstance=NULL) { |
21 | - parent::__construct($identifier, null,$modelInstance); |
|
22 | - $this->_init(new DeInstanceViewer($identifier), "table", new HtmlTable($identifier, 0,2), false); |
|
21 | + parent::__construct($identifier, null, $modelInstance); |
|
22 | + $this->_init(new DeInstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 2), false); |
|
23 | 23 | $this->content["table"]->setDefinition(); |
24 | 24 | } |
25 | 25 | |
26 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
27 | - if(!$this->_generated){ |
|
26 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
27 | + if (!$this->_generated) { |
|
28 | 28 | $this->_instanceViewer->setInstance($this->_modelInstance); |
29 | 29 | |
30 | 30 | $table=$this->content["table"]; |
31 | 31 | $this->_generateContent($table); |
32 | 32 | |
33 | - if(isset($this->_toolbar)){ |
|
33 | + if (isset($this->_toolbar)) { |
|
34 | 34 | $this->_setToolbarPosition($table); |
35 | 35 | } |
36 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
36 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
37 | 37 | $this->_compileForm(); |
38 | 38 | $this->_generated=true; |
39 | 39 | } |
40 | - return parent::compile($js,$view); |
|
40 | + return parent::compile($js, $view); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @param HtmlTable $table |
45 | 45 | */ |
46 | - protected function _generateContent($table){ |
|
47 | - $values= $this->_instanceViewer->getValues(); |
|
46 | + protected function _generateContent($table) { |
|
47 | + $values=$this->_instanceViewer->getValues(); |
|
48 | 48 | $captions=$this->_instanceViewer->getCaptions(); |
49 | 49 | $count=$this->_instanceViewer->count(); |
50 | - for($i=0;$i<$count;$i++){ |
|
51 | - $table->addRow([$captions[$i],$values[$i]]); |
|
50 | + for ($i=0; $i<$count; $i++) { |
|
51 | + $table->addRow([$captions[$i], $values[$i]]); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - protected function _getFieldName($index){ |
|
55 | + protected function _getFieldName($index) { |
|
56 | 56 | return $this->_instanceViewer->getFieldName($index); |
57 | 57 | } |
58 | 58 | |
59 | - protected function _getFieldCaption($index){ |
|
59 | + protected function _getFieldCaption($index) { |
|
60 | 60 | return null; |
61 | 61 | } |
62 | 62 | |
63 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
63 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
64 | 64 | return $this->identifier."-{$prefix}-".$name; |
65 | 65 | } |
66 | 66 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | return $this; |
93 | 93 | } |
94 | 94 | |
95 | - public function asForm(){ |
|
95 | + public function asForm() { |
|
96 | 96 | return $this->getForm(); |
97 | 97 | } |
98 | 98 | } |
99 | 99 | \ No newline at end of file |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | protected $ajaxTransition; |
18 | 18 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
19 | 19 | |
20 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
20 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
21 | 21 | protected function addLoading(&$retour, $responseElement) { |
22 | 22 | $loading_notifier='<div class="ajax-loader">'; |
23 | 23 | if ($this->ajaxLoader=='') { |
@@ -30,66 +30,66 @@ discard block |
||
30 | 30 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
31 | 31 | } |
32 | 32 | |
33 | - public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
34 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
33 | + public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
34 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
35 | 35 | } |
36 | - public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
37 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
36 | + public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
37 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
38 | 38 | } |
39 | 39 | |
40 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
41 | - if(JString::isNull($params)){$params="{}";} |
|
40 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
41 | + if (JString::isNull($params)) {$params="{}"; } |
|
42 | 42 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
43 | 43 | $retour=$this->_getAjaxUrl($url, $attr); |
44 | 44 | $responseElement=$this->_getResponseElement($responseElement); |
45 | 45 | $retour.="var self=this;\n"; |
46 | - if($hasLoader===true){ |
|
46 | + if ($hasLoader===true) { |
|
47 | 47 | $this->addLoading($retour, $responseElement); |
48 | 48 | } |
49 | 49 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
50 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
51 | 51 | if ($immediatly) |
52 | 52 | $this->jquery_code_for_compile[]=$retour; |
53 | 53 | return $retour; |
54 | 54 | } |
55 | 55 | |
56 | - protected function setAjaxDataCall($params){ |
|
56 | + protected function setAjaxDataCall($params) { |
|
57 | 57 | $result=null; |
58 | - if(!\is_callable($params)){ |
|
59 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
60 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
58 | + if (!\is_callable($params)) { |
|
59 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
60 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
61 | 61 | }; |
62 | 62 | } |
63 | 63 | return $result; |
64 | 64 | } |
65 | 65 | |
66 | - protected function _getAjaxUrl($url,$attr){ |
|
66 | + protected function _getAjaxUrl($url, $attr) { |
|
67 | 67 | $url=$this->_correctAjaxUrl($url); |
68 | 68 | $retour="url='".$url."';"; |
69 | 69 | $slash="/"; |
70 | - if(JString::endswith($url, "/")===true) |
|
70 | + if (JString::endswith($url, "/")===true) |
|
71 | 71 | $slash=""; |
72 | - if(JString::isNotNull($attr)){ |
|
72 | + if (JString::isNotNull($attr)) { |
|
73 | 73 | if ($attr==="value") |
74 | 74 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
75 | 75 | elseif ($attr==="html") |
76 | 76 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
77 | - elseif($attr!=null && $attr!=="") |
|
77 | + elseif ($attr!=null && $attr!=="") |
|
78 | 78 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
79 | 79 | } |
80 | 80 | return $retour; |
81 | 81 | } |
82 | 82 | |
83 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
84 | - $retour="";$call=null; |
|
83 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
84 | + $retour=""; $call=null; |
|
85 | 85 | if ($responseElement!=="") { |
86 | - if(isset($ajaxTransition)){ |
|
86 | + if (isset($ajaxTransition)) { |
|
87 | 87 | $call=$this->setAjaxDataCall($ajaxTransition); |
88 | - }elseif(isset($this->ajaxTransition)){ |
|
88 | + }elseif (isset($this->ajaxTransition)) { |
|
89 | 89 | $call=$this->ajaxTransition; |
90 | 90 | } |
91 | - if(\is_callable($call)) |
|
92 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
91 | + if (\is_callable($call)) |
|
92 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
93 | 93 | else |
94 | 94 | $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
95 | 95 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | return $retour; |
98 | 98 | } |
99 | 99 | |
100 | - protected function _getResponseElement($responseElement){ |
|
100 | + protected function _getResponseElement($responseElement) { |
|
101 | 101 | if ($responseElement!=="") { |
102 | 102 | $responseElement=Javascript::prep_value($responseElement); |
103 | 103 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | protected function _correctAjaxUrl($url) { |
108 | 108 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
109 | 109 | $url=substr($url, 0, strlen($url)-1); |
110 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
110 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
111 | 111 | $url=$this->jsUtils->getUrl($url); |
112 | 112 | } |
113 | 113 | return $url; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param string $jsCallback javascript code to execute after the request |
122 | 122 | * @param boolean $immediatly |
123 | 123 | */ |
124 | - public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
124 | + public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
125 | 125 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
126 | 126 | $retour=$this->_getAjaxUrl($url, $attr); |
127 | 127 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string $url the request address |
143 | 143 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
144 | 144 | */ |
145 | - public function _jsonOn($event,$element, $url,$parameters=array()) { |
|
145 | + public function _jsonOn($event, $element, $url, $parameters=array()) { |
|
146 | 146 | $preventDefault=true; |
147 | 147 | $stopPropagation=true; |
148 | 148 | $jsCallback=null; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $params="{}"; |
153 | 153 | $immediatly=true; |
154 | 154 | extract($parameters); |
155 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
155 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | * @param string $context jquery DOM element, array container. |
165 | 165 | * @param boolean $immediatly |
166 | 166 | */ |
167 | - public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null,$immediatly=false) { |
|
167 | + public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null, $immediatly=false) { |
|
168 | 168 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
169 | 169 | $retour=$this->_getAjaxUrl($url, $attr); |
170 | - if($context===null){ |
|
170 | + if ($context===null) { |
|
171 | 171 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
172 | - $newElm = "$('#'+newId)"; |
|
173 | - }else{ |
|
172 | + $newElm="$('#'+newId)"; |
|
173 | + } else { |
|
174 | 174 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
175 | - $newElm = $context.".find('#'+newId)"; |
|
175 | + $newElm=$context.".find('#'+newId)"; |
|
176 | 176 | } |
177 | 177 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
178 | 178 | $retour.="\tdata=$.parseJSON(data);$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone();newElm.attr('id',newId);\n"; |
179 | - $retour.= $appendTo; |
|
179 | + $retour.=$appendTo; |
|
180 | 180 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('[['+key+']]')>-1){\n"."\t\t\t\tcontent=$(html.split('[['+key+']]').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
181 | 181 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
182 | 182 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -191,30 +191,30 @@ discard block |
||
191 | 191 | * @param string $url the request address |
192 | 192 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get", "context"=>null) |
193 | 193 | */ |
194 | - public function _jsonArrayOn($event,$element, $maskSelector,$url,$parameters=array()) { |
|
194 | + public function _jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
195 | 195 | $preventDefault=true; |
196 | 196 | $stopPropagation=true; |
197 | 197 | $jsCallback=null; |
198 | 198 | $attr="id"; |
199 | 199 | $method="get"; |
200 | - $context = null; |
|
200 | + $context=null; |
|
201 | 201 | $params="{}"; |
202 | 202 | $immediatly=true; |
203 | 203 | extract($parameters); |
204 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
204 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
205 | 205 | } |
206 | 206 | |
207 | - public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
207 | + public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
208 | 208 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
209 | 209 | $retour=$this->_getAjaxUrl($url, $attr); |
210 | 210 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
211 | 211 | $responseElement=$this->_getResponseElement($responseElement); |
212 | 212 | $retour.="var self=this;\n"; |
213 | - if($hasLoader===true){ |
|
213 | + if ($hasLoader===true) { |
|
214 | 214 | $this->addLoading($retour, $responseElement); |
215 | 215 | } |
216 | 216 | $retour.="$.post(url,params).done(function( data ) {\n"; |
217 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
217 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
218 | 218 | |
219 | 219 | if ($validation) { |
220 | 220 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @param string $responseElement |
238 | 238 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null,"jqueryDone"=>"html") |
239 | 239 | */ |
240 | - public function _getOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
240 | + public function _getOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
241 | 241 | $preventDefault=true; |
242 | 242 | $stopPropagation=true; |
243 | 243 | $jsCallback=null; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $jqueryDone="html"; |
248 | 248 | $ajaxTransition=null; |
249 | 249 | extract($parameters); |
250 | - return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
250 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @param string $responseElement |
261 | 261 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null) |
262 | 262 | */ |
263 | - public function _postOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
263 | + public function _postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
264 | 264 | $preventDefault=true; |
265 | 265 | $stopPropagation=true; |
266 | 266 | $jsCallback=null; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | $jqueryDone="html"; |
271 | 271 | $ajaxTransition=null; |
272 | 272 | extract($parameters); |
273 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
273 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string $responseElement |
284 | 284 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null,"immediatly"=>true) |
285 | 285 | */ |
286 | - public function _postFormOn($event,$element, $url, $form, $responseElement="", $parameters=array()) { |
|
286 | + public function _postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
287 | 287 | $preventDefault=true; |
288 | 288 | $stopPropagation=true; |
289 | 289 | $validation=false; |
@@ -294,6 +294,6 @@ discard block |
||
294 | 294 | $jqueryDone="html"; |
295 | 295 | $ajaxTransition=null; |
296 | 296 | extract($parameters); |
297 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
297 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
298 | 298 | } |
299 | 299 | } |
300 | 300 | \ No newline at end of file |
@@ -48,8 +48,9 @@ discard block |
||
48 | 48 | } |
49 | 49 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
50 | 50 | $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
51 | - if ($immediatly) |
|
52 | - $this->jquery_code_for_compile[]=$retour; |
|
51 | + if ($immediatly) { |
|
52 | + $this->jquery_code_for_compile[]=$retour; |
|
53 | + } |
|
53 | 54 | return $retour; |
54 | 55 | } |
55 | 56 | |
@@ -67,15 +68,17 @@ discard block |
||
67 | 68 | $url=$this->_correctAjaxUrl($url); |
68 | 69 | $retour="url='".$url."';"; |
69 | 70 | $slash="/"; |
70 | - if(JString::endswith($url, "/")===true) |
|
71 | - $slash=""; |
|
71 | + if(JString::endswith($url, "/")===true) { |
|
72 | + $slash=""; |
|
73 | + } |
|
72 | 74 | if(JString::isNotNull($attr)){ |
73 | - if ($attr==="value") |
|
74 | - $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
75 | - elseif ($attr==="html") |
|
76 | - $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
77 | - elseif($attr!=null && $attr!=="") |
|
78 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
75 | + if ($attr==="value") { |
|
76 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
77 | + } elseif ($attr==="html") { |
|
78 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
79 | + } elseif($attr!=null && $attr!=="") { |
|
80 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
81 | + } |
|
79 | 82 | } |
80 | 83 | return $retour; |
81 | 84 | } |
@@ -85,13 +88,14 @@ discard block |
||
85 | 88 | if ($responseElement!=="") { |
86 | 89 | if(isset($ajaxTransition)){ |
87 | 90 | $call=$this->setAjaxDataCall($ajaxTransition); |
88 | - }elseif(isset($this->ajaxTransition)){ |
|
91 | + } elseif(isset($this->ajaxTransition)){ |
|
89 | 92 | $call=$this->ajaxTransition; |
90 | 93 | } |
91 | - if(\is_callable($call)) |
|
92 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
93 | - else |
|
94 | - $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
|
94 | + if(\is_callable($call)) { |
|
95 | + $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
96 | + } else { |
|
97 | + $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
|
98 | + } |
|
95 | 99 | } |
96 | 100 | $retour.="\t".$jsCallback."\n"; |
97 | 101 | return $retour; |
@@ -105,8 +109,9 @@ discard block |
||
105 | 109 | } |
106 | 110 | |
107 | 111 | protected function _correctAjaxUrl($url) { |
108 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
109 | - $url=substr($url, 0, strlen($url)-1); |
|
112 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
113 | + $url=substr($url, 0, strlen($url)-1); |
|
114 | + } |
|
110 | 115 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
111 | 116 | $url=$this->jsUtils->getUrl($url); |
112 | 117 | } |
@@ -130,8 +135,9 @@ discard block |
||
130 | 135 | $retour.="\t".$jsCallback."\n". |
131 | 136 | "\t$(document).trigger('jsonReady',[data]);\n". |
132 | 137 | "});\n"; |
133 | - if ($immediatly) |
|
134 | - $this->jquery_code_for_compile[]=$retour; |
|
138 | + if ($immediatly) { |
|
139 | + $this->jquery_code_for_compile[]=$retour; |
|
140 | + } |
|
135 | 141 | return $retour; |
136 | 142 | } |
137 | 143 | |
@@ -170,7 +176,7 @@ discard block |
||
170 | 176 | if($context===null){ |
171 | 177 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
172 | 178 | $newElm = "$('#'+newId)"; |
173 | - }else{ |
|
179 | + } else{ |
|
174 | 180 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
175 | 181 | $newElm = $context.".find('#'+newId)"; |
176 | 182 | } |
@@ -180,8 +186,9 @@ discard block |
||
180 | 186 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('[['+key+']]')>-1){\n"."\t\t\t\tcontent=$(html.split('[['+key+']]').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
181 | 187 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
182 | 188 | $retour.="\t".$jsCallback."\n"."});\n"; |
183 | - if ($immediatly) |
|
184 | - $this->jquery_code_for_compile[]=$retour; |
|
189 | + if ($immediatly) { |
|
190 | + $this->jquery_code_for_compile[]=$retour; |
|
191 | + } |
|
185 | 192 | return $retour; |
186 | 193 | } |
187 | 194 | /** |
@@ -222,8 +229,9 @@ discard block |
||
222 | 229 | }});\n"; |
223 | 230 | $retour.="$('#".$form."').submit();\n"; |
224 | 231 | } |
225 | - if ($immediatly) |
|
226 | - $this->jquery_code_for_compile[]=$retour; |
|
232 | + if ($immediatly) { |
|
233 | + $this->jquery_code_for_compile[]=$retour; |
|
234 | + } |
|
227 | 235 | return $retour; |
228 | 236 | } |
229 | 237 |
@@ -2,51 +2,51 @@ |
||
2 | 2 | namespace Ajax\service; |
3 | 3 | class JString { |
4 | 4 | |
5 | - public static function contains($hay,$needle){ |
|
6 | - return strpos($hay, $needle) !== false; |
|
5 | + public static function contains($hay, $needle) { |
|
6 | + return strpos($hay, $needle)!==false; |
|
7 | 7 | } |
8 | 8 | public static function startswith($hay, $needle) { |
9 | - return substr($hay, 0, strlen($needle)) === $needle; |
|
9 | + return substr($hay, 0, strlen($needle))===$needle; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | public static function endswith($hay, $needle) { |
13 | - return substr($hay, -strlen($needle)) === $needle; |
|
13 | + return substr($hay, -strlen($needle))===$needle; |
|
14 | 14 | } |
15 | 15 | |
16 | - public static function isNull($s){ |
|
16 | + public static function isNull($s) { |
|
17 | 17 | return (!isset($s) || NULL===$s || ""===$s); |
18 | 18 | } |
19 | - public static function isNotNull($s){ |
|
19 | + public static function isNotNull($s) { |
|
20 | 20 | return (isset($s) && NULL!==$s && ""!==$s); |
21 | 21 | } |
22 | 22 | |
23 | - public static function isBoolean($value){ |
|
23 | + public static function isBoolean($value) { |
|
24 | 24 | return \is_bool($value) || $value==1 || $value==0; |
25 | 25 | } |
26 | 26 | |
27 | - public static function isBooleanTrue($value){ |
|
27 | + public static function isBooleanTrue($value) { |
|
28 | 28 | return $value==1 || $value; |
29 | 29 | } |
30 | 30 | |
31 | - public static function isBooleanFalse($value){ |
|
31 | + public static function isBooleanFalse($value) { |
|
32 | 32 | return $value==0 || !$value; |
33 | 33 | } |
34 | 34 | |
35 | - public static function camelCaseToSeparated($input,$separator=" "){ |
|
35 | + public static function camelCaseToSeparated($input, $separator=" ") { |
|
36 | 36 | return strtolower(preg_replace('/(?<!^)[A-Z]/', $separator.'$0', $input)); |
37 | 37 | } |
38 | 38 | |
39 | - public static function replaceAtFirst($subject,$from, $to){ |
|
40 | - $from = '/\A'.preg_quote($from, '/').'/'; |
|
39 | + public static function replaceAtFirst($subject, $from, $to) { |
|
40 | + $from='/\A'.preg_quote($from, '/').'/'; |
|
41 | 41 | return \preg_replace($from, $to, $subject, 1); |
42 | 42 | } |
43 | 43 | |
44 | - public static function replaceAtLast($subject,$from, $to){ |
|
45 | - $from = '/'.preg_quote($from, '/').'\z/'; |
|
44 | + public static function replaceAtLast($subject, $from, $to) { |
|
45 | + $from='/'.preg_quote($from, '/').'\z/'; |
|
46 | 46 | return \preg_replace($from, $to, $subject, 1); |
47 | 47 | } |
48 | 48 | |
49 | - public static function replaceAtFirstAndLast($subject,$fromFirst,$toFirst,$fromLast,$toLast){ |
|
49 | + public static function replaceAtFirstAndLast($subject, $fromFirst, $toFirst, $fromLast, $toLast) { |
|
50 | 50 | $s=self::replaceAtFirst($subject, $fromFirst, $toFirst); |
51 | 51 | return self::replaceAtLast($s, $fromLast, $toLast); |
52 | 52 | } |
@@ -16,17 +16,17 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @see \Ajax\semantic\widgets\dataform\DataForm::__construct() |
18 | 18 | */ |
19 | - public function __construct($identifier,$modelInstance=null,$fieldsOrder,$fieldsDefinition,$fields=[],$captions=[],$separators=[]) { |
|
20 | - if(!isset($modelInstance)){ |
|
19 | + public function __construct($identifier, $modelInstance=null, $fieldsOrder, $fieldsDefinition, $fields=[], $captions=[], $separators=[]) { |
|
20 | + if (!isset($modelInstance)) { |
|
21 | 21 | $modelInstance=$this->getDefaultModelInstance(); |
22 | 22 | } |
23 | - parent::__construct($identifier,$modelInstance); |
|
24 | - $this->_initForm($fieldsOrder, $fieldsDefinition,$fields,$captions,$separators); |
|
23 | + parent::__construct($identifier, $modelInstance); |
|
24 | + $this->_initForm($fieldsOrder, $fieldsDefinition, $fields, $captions, $separators); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | abstract protected function getDefaultModelInstance(); |
28 | 28 | |
29 | - protected function _initForm($fieldsOrder,$fieldsDefinition,$fields=[],$captions=[],$separators=[]){ |
|
29 | + protected function _initForm($fieldsOrder, $fieldsDefinition, $fields=[], $captions=[], $separators=[]) { |
|
30 | 30 | $this->_fieldsOrder=$fieldsOrder; |
31 | 31 | $this->setFields($fields); |
32 | 32 | $this->setSeparators($separators); |
@@ -34,26 +34,26 @@ discard block |
||
34 | 34 | $this->setCaptions($captions); |
35 | 35 | } |
36 | 36 | |
37 | - protected function _getIndex($fieldName){ |
|
37 | + protected function _getIndex($fieldName) { |
|
38 | 38 | $index=$fieldName; |
39 | - if(\is_string($fieldName)){ |
|
39 | + if (\is_string($fieldName)) { |
|
40 | 40 | $index=\array_search($fieldName, $this->_fieldsOrder); |
41 | 41 | } |
42 | 42 | return $index; |
43 | 43 | } |
44 | - protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){ |
|
44 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
45 | 45 | $index=$this->_getIndex($index); |
46 | - return parent::_fieldAs($elementCallback, $index,$attributes,$prefix); |
|
46 | + return parent::_fieldAs($elementCallback, $index, $attributes, $prefix); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | |
50 | - public function removeField($fieldName){ |
|
50 | + public function removeField($fieldName) { |
|
51 | 51 | parent::removeField($fieldName); |
52 | - \array_splice($this->_fieldsOrder,$this->_getIndex($fieldName),1); |
|
52 | + \array_splice($this->_fieldsOrder, $this->_getIndex($fieldName), 1); |
|
53 | 53 | return $this; |
54 | 54 | } |
55 | 55 | |
56 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
57 | - return parent::compile($js,$view); |
|
56 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
57 | + return parent::compile($js, $view); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | \ No newline at end of file |
@@ -47,15 +47,17 @@ |
||
47 | 47 | |
48 | 48 | |
49 | 49 | public function addSeparatorAfter($fieldNum){ |
50 | - if(\array_search($fieldNum, $this->separators)===false) |
|
51 | - $this->separators[]=$fieldNum; |
|
50 | + if(\array_search($fieldNum, $this->separators)===false) { |
|
51 | + $this->separators[]=$fieldNum; |
|
52 | + } |
|
52 | 53 | return $this; |
53 | 54 | } |
54 | 55 | |
55 | 56 | public function addHeaderDividerBefore($fieldNum,$header){ |
56 | 57 | $this->headers[$fieldNum]=$header; |
57 | - if($fieldNum>0) |
|
58 | - $this->addSeparatorAfter($fieldNum-1); |
|
58 | + if($fieldNum>0) { |
|
59 | + $this->addSeparatorAfter($fieldNum-1); |
|
60 | + } |
|
59 | 61 | return $this; |
60 | 62 | } |
61 | 63 |
@@ -11,58 +11,58 @@ discard block |
||
11 | 11 | protected $headers; |
12 | 12 | protected $wrappers; |
13 | 13 | |
14 | - public function __construct($identifier,$instance=NULL, $captions=NULL) { |
|
15 | - parent::__construct($identifier,$instance=NULL, $captions=NULL); |
|
14 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
15 | + parent::__construct($identifier, $instance=NULL, $captions=NULL); |
|
16 | 16 | $this->separators=[-1]; |
17 | 17 | $this->headers=[]; |
18 | 18 | $this->wrappers=[]; |
19 | - $this->defaultValueFunction=function($name,$value,$index){ |
|
19 | + $this->defaultValueFunction=function($name, $value, $index) { |
|
20 | 20 | $caption=$this->getCaption($index); |
21 | - $input=new HtmlFormInput($this->widgetIdentifier."-".$name,$caption,"text",$value); |
|
21 | + $input=new HtmlFormInput($this->widgetIdentifier."-".$name, $caption, "text", $value); |
|
22 | 22 | $input->setName($name); |
23 | 23 | return $input; |
24 | 24 | }; |
25 | 25 | } |
26 | 26 | |
27 | - protected function _beforeAddProperty($index,&$field){ |
|
28 | - if(JString::endswith($field, "\n")===true){ |
|
27 | + protected function _beforeAddProperty($index, &$field) { |
|
28 | + if (JString::endswith($field, "\n")===true) { |
|
29 | 29 | $this->addSeparatorAfter($index); |
30 | 30 | } |
31 | - if($index>1 && JString::startswith($field, "\n")===true){ |
|
31 | + if ($index>1 && JString::startswith($field, "\n")===true) { |
|
32 | 32 | $this->addSeparatorAfter($index-1); |
33 | 33 | } |
34 | 34 | $field=\str_replace("\n", "", $field); |
35 | - if(($header=$this->hasHeader($field))!==false){ |
|
35 | + if (($header=$this->hasHeader($field))!==false) { |
|
36 | 36 | $this->addHeaderDividerBefore($index, $header); |
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - protected function hasHeader(&$field){ |
|
41 | - $matches=[];$result=false; |
|
42 | - if(\preg_match('/\{(.*?)\}/s', $field, $matches)===1){ |
|
40 | + protected function hasHeader(&$field) { |
|
41 | + $matches=[]; $result=false; |
|
42 | + if (\preg_match('/\{(.*?)\}/s', $field, $matches)===1) { |
|
43 | 43 | $result=$matches[1]; |
44 | - $field=\str_replace("{".$result."}","", $field); |
|
44 | + $field=\str_replace("{".$result."}", "", $field); |
|
45 | 45 | } |
46 | 46 | return $result; |
47 | 47 | } |
48 | 48 | |
49 | 49 | |
50 | 50 | |
51 | - public function addSeparatorAfter($fieldNum){ |
|
52 | - if(\array_search($fieldNum, $this->separators)===false) |
|
51 | + public function addSeparatorAfter($fieldNum) { |
|
52 | + if (\array_search($fieldNum, $this->separators)===false) |
|
53 | 53 | $this->separators[]=$fieldNum; |
54 | 54 | return $this; |
55 | 55 | } |
56 | 56 | |
57 | - public function addHeaderDividerBefore($fieldNum,$header){ |
|
57 | + public function addHeaderDividerBefore($fieldNum, $header) { |
|
58 | 58 | $this->headers[$fieldNum]=$header; |
59 | - if($fieldNum>0) |
|
59 | + if ($fieldNum>0) |
|
60 | 60 | $this->addSeparatorAfter($fieldNum-1); |
61 | 61 | return $this; |
62 | 62 | } |
63 | 63 | |
64 | - public function addWrapper($fieldNum,$contentBefore,$contentAfter=null){ |
|
65 | - $this->wrappers[$fieldNum]=[$contentBefore,$contentAfter]; |
|
64 | + public function addWrapper($fieldNum, $contentBefore, $contentAfter=null) { |
|
65 | + $this->wrappers[$fieldNum]=[$contentBefore, $contentAfter]; |
|
66 | 66 | return $this; |
67 | 67 | } |
68 | 68 | |
@@ -70,15 +70,15 @@ discard block |
||
70 | 70 | return $this->separators; |
71 | 71 | } |
72 | 72 | |
73 | - public function removeSeparator($index){ |
|
74 | - \array_splice($this->separators,$index,1); |
|
73 | + public function removeSeparator($index) { |
|
74 | + \array_splice($this->separators, $index, 1); |
|
75 | 75 | } |
76 | 76 | |
77 | - public function removeField($index){ |
|
77 | + public function removeField($index) { |
|
78 | 78 | parent::removeField($index); |
79 | 79 | $pos=\array_search($index, $this->separators); |
80 | - if($pos!==false){ |
|
81 | - for($i=$pos+1;$i<\sizeof($this->separators);$i++){ |
|
80 | + if ($pos!==false) { |
|
81 | + for ($i=$pos+1; $i<\sizeof($this->separators); $i++) { |
|
82 | 82 | $this->separators[$i]--; |
83 | 83 | } |
84 | 84 | \array_splice($this->separators, $pos, 1); |