@@ -53,6 +53,9 @@ discard block |
||
53 | 53 | $element->setStyle($value); |
54 | 54 | } |
55 | 55 | |
56 | + /** |
|
57 | + * @param HtmlDropdown $bt |
|
58 | + */ |
|
56 | 59 | private function dropdownAsButton($bt) { |
57 | 60 | $this->addExistingDropDown($bt); |
58 | 61 | $bt->setTagName("button"); |
@@ -81,6 +84,9 @@ discard block |
||
81 | 84 | return $result; |
82 | 85 | } |
83 | 86 | |
87 | + /** |
|
88 | + * @param integer $iid |
|
89 | + */ |
|
84 | 90 | private function _addArrayElement(array $element,$iid){ |
85 | 91 | if (array_key_exists("glyph", $element)) |
86 | 92 | $bt=new HtmlGlyphButton($this->identifier."-button-".$iid); |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @return HtmlButtongroups default : "" |
40 | 40 | */ |
41 | 41 | public function setSize($size) { |
42 | - foreach ( $this->elements as $element ) { |
|
42 | + foreach ($this->elements as $element) { |
|
43 | 43 | $element->setSize($size); |
44 | 44 | } |
45 | 45 | if (is_int($size)) { |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | public function setStyle($value) { |
52 | - foreach ( $this->elements as $element ) |
|
52 | + foreach ($this->elements as $element) |
|
53 | 53 | $element->setStyle($value); |
54 | 54 | } |
55 | 55 | |
@@ -69,29 +69,29 @@ discard block |
||
69 | 69 | public function addElement($element) { |
70 | 70 | $result=$element; |
71 | 71 | $iid=sizeof($this->elements)+1; |
72 | - if (($element instanceof HtmlDropdown)||($element instanceof HtmlSplitbutton)) { |
|
72 | + if (($element instanceof HtmlDropdown) || ($element instanceof HtmlSplitbutton)) { |
|
73 | 73 | $this->addExistingDropDown($element); |
74 | 74 | } elseif (\is_array($element)) { |
75 | - $result=$this->_addArrayElement($element,$iid); |
|
75 | + $result=$this->_addArrayElement($element, $iid); |
|
76 | 76 | } elseif (is_string($element)) { |
77 | - $result=new HtmlButton($this->identifier."-button-".$iid,$element); |
|
77 | + $result=new HtmlButton($this->identifier."-button-".$iid, $element); |
|
78 | 78 | } |
79 | - if($result instanceof HtmlButton) |
|
79 | + if ($result instanceof HtmlButton) |
|
80 | 80 | $this->elements[]=$result; |
81 | 81 | return $result; |
82 | 82 | } |
83 | 83 | |
84 | - private function _addArrayElement(array $element,$iid){ |
|
84 | + private function _addArrayElement(array $element, $iid) { |
|
85 | 85 | if (array_key_exists("glyph", $element)) |
86 | 86 | $bt=new HtmlGlyphButton($this->identifier."-button-".$iid); |
87 | 87 | elseif (array_key_exists("btnCaption", $element)) { |
88 | 88 | if (array_key_exists("split", $element)) |
89 | 89 | $bt=new HtmlSplitbutton($this->identifier."-dropdown-".$iid); |
90 | - else{ |
|
90 | + else { |
|
91 | 91 | $bt=new HtmlDropdown($this->identifier."-dropdown-".$iid); |
92 | 92 | $this->dropdownAsButton($bt); |
93 | 93 | } |
94 | - } else{ |
|
94 | + } else { |
|
95 | 95 | $bt=new HtmlButton($this->identifier."-button-".$iid); |
96 | 96 | $bt->fromArray($element); |
97 | 97 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | public function addElements($elements) { |
102 | - foreach ( $elements as $element ) { |
|
102 | + foreach ($elements as $element) { |
|
103 | 103 | $this->addElement($element); |
104 | 104 | } |
105 | 105 | return $this; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | } else |
120 | 120 | $value="btn-group-".$value; |
121 | 121 | if (strstr($value, "justified")) { |
122 | - foreach ( $this->elements as $element ) { |
|
122 | + foreach ($this->elements as $element) { |
|
123 | 123 | $element->wrap('<div class="btn-group" role="group">', '</div>'); |
124 | 124 | } |
125 | 125 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @see \Ajax\bootstrap\html\base\BaseHtml::on() |
151 | 151 | */ |
152 | 152 | public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
153 | - foreach ( $this->elements as $element ) { |
|
153 | + foreach ($this->elements as $element) { |
|
154 | 154 | $element->on($event, $jsCode, $stopPropagation, $preventDefault); |
155 | 155 | } |
156 | 156 | return $this; |
@@ -36,6 +36,10 @@ discard block |
||
36 | 36 | protected $_targetSelector; |
37 | 37 | protected $_checkedMessage; |
38 | 38 | |
39 | + /** |
|
40 | + * @param string $identifier |
|
41 | + * @param string $model |
|
42 | + */ |
|
39 | 43 | public function __construct($identifier,$model,$modelInstance=NULL) { |
40 | 44 | parent::__construct($identifier, $model,$modelInstance); |
41 | 45 | $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
@@ -75,6 +79,9 @@ discard block |
||
75 | 79 | if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$checkedMessageCall); |
76 | 80 | } |
77 | 81 | |
82 | + /** |
|
83 | + * @param string $op |
|
84 | + */ |
|
78 | 85 | protected function _generateBehavior($op,JsUtils $js){ |
79 | 86 | if(isset($this->_urls[$op])) |
80 | 87 | $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),["attr"=>"data-ajax"]); |
@@ -210,6 +217,9 @@ discard block |
||
210 | 217 | return $this; |
211 | 218 | } |
212 | 219 | |
220 | + /** |
|
221 | + * @param PositionInTable $part |
|
222 | + */ |
|
213 | 223 | private function addToolbarRow($part,$table,$captions){ |
214 | 224 | $hasPart=$table->hasPart($part); |
215 | 225 | if($hasPart){ |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | */ |
25 | 25 | class DataTable extends Widget { |
26 | - use TableTrait,DataTableFieldAsTrait; |
|
26 | + use TableTrait, DataTableFieldAsTrait; |
|
27 | 27 | protected $_searchField; |
28 | 28 | protected $_urls; |
29 | 29 | protected $_pagination; |
@@ -36,30 +36,30 @@ discard block |
||
36 | 36 | protected $_targetSelector; |
37 | 37 | protected $_checkedMessage; |
38 | 38 | |
39 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
40 | - parent::__construct($identifier, $model,$modelInstance); |
|
41 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
39 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
40 | + parent::__construct($identifier, $model, $modelInstance); |
|
41 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
42 | 42 | $this->_urls=[]; |
43 | 43 | } |
44 | 44 | |
45 | - public function run(JsUtils $js){ |
|
46 | - if($this->_hasCheckboxes && isset($js)){ |
|
45 | + public function run(JsUtils $js) { |
|
46 | + if ($this->_hasCheckboxes && isset($js)) { |
|
47 | 47 | $this->_runCheckboxes($js); |
48 | 48 | } |
49 | - if($this->_visibleHover){ |
|
50 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
51 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
49 | + if ($this->_visibleHover) { |
|
50 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
51 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
52 | 52 | } |
53 | - if($this->_hasDelete) |
|
53 | + if ($this->_hasDelete) |
|
54 | 54 | $this->_generateBehavior("delete", $js); |
55 | - if($this->_hasEdit) |
|
55 | + if ($this->_hasEdit) |
|
56 | 56 | $this->_generateBehavior("edit", $js); |
57 | 57 | return parent::run($js); |
58 | 58 | } |
59 | 59 | |
60 | - protected function _runCheckboxes(JsUtils $js){ |
|
60 | + protected function _runCheckboxes(JsUtils $js) { |
|
61 | 61 | $checkedMessageCall=""; |
62 | - if($this->_hasCheckedMessage){ |
|
62 | + if ($this->_hasCheckedMessage) { |
|
63 | 63 | $msg=$this->getCheckedMessage(); |
64 | 64 | $checkedMessageFunction="function updateChecked(){var msg='".$msg[0]."',count=\$('#{$this->identifier} [name=\"selection[]\"]:checked').length,all=\$('#{$this->identifier} [name=\"selection[]\"]').length; |
65 | 65 | if(count==1) msg='".$msg[1]."'; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | \$('#checked-count-".$this->identifier."').contents().filter(function() {return this.nodeType == 3;}).each(function(){this.textContent = msg.replace('{count}',count);}); |
68 | 68 | \$('#toolbar-{$this->identifier} .visibleOnChecked').toggle(count>0);}\$('#toolbar-".$this->identifier." .visibleOnChecked').hide();"; |
69 | 69 | $checkedMessageCall="updateChecked();"; |
70 | - $js->exec($checkedMessageFunction,true); |
|
70 | + $js->exec($checkedMessageFunction, true); |
|
71 | 71 | } |
72 | 72 | $js->execOn("change", "#".$this->identifier." [name='selection[]']", " |
73 | 73 | var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true; |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$checkedMessageCall); |
76 | 76 | } |
77 | 77 | |
78 | - protected function _generateBehavior($op,JsUtils $js){ |
|
79 | - if(isset($this->_urls[$op])) |
|
80 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),["attr"=>"data-ajax"]); |
|
78 | + protected function _generateBehavior($op, JsUtils $js) { |
|
79 | + if (isset($this->_urls[$op])) |
|
80 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), ["attr"=>"data-ajax"]); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -89,70 +89,70 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | |
92 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
93 | - if(!$this->_generated){ |
|
92 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
93 | + if (!$this->_generated) { |
|
94 | 94 | $this->_instanceViewer->setInstance($this->_model); |
95 | 95 | $captions=$this->_instanceViewer->getCaptions(); |
96 | 96 | |
97 | 97 | $table=$this->content["table"]; |
98 | 98 | |
99 | - if($this->_hasCheckboxes){ |
|
99 | + if ($this->_hasCheckboxes) { |
|
100 | 100 | $this->_generateMainCheckbox($captions); |
101 | 101 | } |
102 | 102 | |
103 | 103 | $table->setRowCount(0, \sizeof($captions)); |
104 | 104 | $table->setHeaderValues($captions); |
105 | - if(isset($this->_compileParts)) |
|
105 | + if (isset($this->_compileParts)) |
|
106 | 106 | $table->setCompileParts($this->_compileParts); |
107 | 107 | |
108 | - if(isset($this->_searchField) && isset($js)){ |
|
109 | - if(isset($this->_urls["refresh"])) |
|
110 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
108 | + if (isset($this->_searchField) && isset($js)) { |
|
109 | + if (isset($this->_urls["refresh"])) |
|
110 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $this->_generateContent($table); |
114 | 114 | |
115 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
115 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
116 | 116 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
117 | 117 | } |
118 | 118 | |
119 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
119 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
120 | 120 | $this->_generatePagination($table); |
121 | 121 | } |
122 | - if(isset($this->_toolbar)){ |
|
122 | + if (isset($this->_toolbar)) { |
|
123 | 123 | $this->_setToolbarPosition($table, $captions); |
124 | 124 | } |
125 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
125 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
126 | 126 | $this->_compileForm(); |
127 | 127 | $this->_generated=true; |
128 | 128 | } |
129 | - return parent::compile($js,$view); |
|
129 | + return parent::compile($js, $view); |
|
130 | 130 | } |
131 | 131 | |
132 | - private function _generateMainCheckbox(&$captions){ |
|
133 | - $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
|
132 | + private function _generateMainCheckbox(&$captions) { |
|
133 | + $ck=new HtmlCheckbox("main-ck-".$this->identifier, ""); |
|
134 | 134 | $checkedMessageCall=""; |
135 | - if($this->_hasCheckedMessage) |
|
135 | + if ($this->_hasCheckedMessage) |
|
136 | 136 | $checkedMessageCall="updateChecked();"; |
137 | 137 | $ck->setOnChecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',true);".$checkedMessageCall); |
138 | 138 | $ck->setOnUnchecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',false);".$checkedMessageCall); |
139 | 139 | \array_unshift($captions, $ck); |
140 | 140 | } |
141 | 141 | |
142 | - protected function _generateContent($table){ |
|
142 | + protected function _generateContent($table) { |
|
143 | 143 | $objects=$this->_modelInstance; |
144 | - if(isset($this->_pagination)){ |
|
144 | + if (isset($this->_pagination)) { |
|
145 | 145 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
146 | 146 | } |
147 | 147 | InstanceViewer::setIndex(0); |
148 | 148 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
149 | 149 | $this->_instanceViewer->setInstance($instance); |
150 | 150 | InstanceViewer::$index++; |
151 | - $values= $this->_instanceViewer->getValues(); |
|
152 | - if($this->_hasCheckboxes){ |
|
153 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
151 | + $values=$this->_instanceViewer->getValues(); |
|
152 | + if ($this->_hasCheckboxes) { |
|
153 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
154 | 154 | $field=$ck->getField(); |
155 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
155 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
156 | 156 | $field->setProperty("name", "selection[]"); |
157 | 157 | \array_unshift($values, $ck); |
158 | 158 | } |
@@ -163,37 +163,37 @@ discard block |
||
163 | 163 | }); |
164 | 164 | } |
165 | 165 | |
166 | - private function _generatePagination($table){ |
|
166 | + private function _generatePagination($table) { |
|
167 | 167 | $footer=$table->getFooter(); |
168 | 168 | $footer->mergeCol(); |
169 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
169 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
170 | 170 | $menu->floatRight(); |
171 | 171 | $menu->setActiveItem($this->_pagination->getPage()-1); |
172 | 172 | $footer->setValues($menu); |
173 | - if(isset($this->_urls["refresh"])) |
|
174 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
173 | + if (isset($this->_urls["refresh"])) |
|
174 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
175 | 175 | } |
176 | 176 | |
177 | - protected function _getFieldName($index){ |
|
177 | + protected function _getFieldName($index) { |
|
178 | 178 | return parent::_getFieldName($index)."[]"; |
179 | 179 | } |
180 | 180 | |
181 | - protected function _getFieldCaption($index){ |
|
181 | + protected function _getFieldCaption($index) { |
|
182 | 182 | return null; |
183 | 183 | } |
184 | 184 | |
185 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
186 | - switch ($this->_toolbarPosition){ |
|
185 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
186 | + switch ($this->_toolbarPosition) { |
|
187 | 187 | case PositionInTable::BEFORETABLE: |
188 | 188 | case PositionInTable::AFTERTABLE: |
189 | - if(isset($this->_compileParts)===false){ |
|
189 | + if (isset($this->_compileParts)===false) { |
|
190 | 190 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
191 | 191 | } |
192 | 192 | break; |
193 | 193 | case PositionInTable::HEADER: |
194 | 194 | case PositionInTable::FOOTER: |
195 | 195 | case PositionInTable::BODY: |
196 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
196 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
197 | 197 | break; |
198 | 198 | } |
199 | 199 | } |
@@ -205,23 +205,23 @@ discard block |
||
205 | 205 | * @param callable $callback function called after the field compilation |
206 | 206 | * @return \Ajax\semantic\widgets\datatable\DataTable |
207 | 207 | */ |
208 | - public function afterCompile($index,$callback){ |
|
209 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
208 | + public function afterCompile($index, $callback) { |
|
209 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
210 | 210 | return $this; |
211 | 211 | } |
212 | 212 | |
213 | - private function addToolbarRow($part,$table,$captions){ |
|
213 | + private function addToolbarRow($part, $table, $captions) { |
|
214 | 214 | $hasPart=$table->hasPart($part); |
215 | - if($hasPart){ |
|
215 | + if ($hasPart) { |
|
216 | 216 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
217 | - }else{ |
|
217 | + } else { |
|
218 | 218 | $row=$table->getPart($part)->getRow(0); |
219 | 219 | } |
220 | 220 | $row->mergeCol(); |
221 | 221 | $row->setValues([$this->_toolbar]); |
222 | 222 | } |
223 | 223 | |
224 | - public function getHtmlComponent(){ |
|
224 | + public function getHtmlComponent() { |
|
225 | 225 | return $this->content["table"]; |
226 | 226 | } |
227 | 227 | |
@@ -235,18 +235,18 @@ discard block |
||
235 | 235 | * @return \Ajax\semantic\widgets\datatable\DataTable |
236 | 236 | */ |
237 | 237 | public function setUrls($urls) { |
238 | - if(\is_array($urls)){ |
|
239 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
240 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
241 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
242 | - }else{ |
|
243 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
238 | + if (\is_array($urls)) { |
|
239 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
240 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
241 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
242 | + } else { |
|
243 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
244 | 244 | } |
245 | 245 | return $this; |
246 | 246 | } |
247 | 247 | |
248 | - public function paginate($items_per_page=10,$page=1){ |
|
249 | - $this->_pagination=new Pagination($items_per_page,4,$page); |
|
248 | + public function paginate($items_per_page=10, $page=1) { |
|
249 | + $this->_pagination=new Pagination($items_per_page, 4, $page); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | public function getHasCheckboxes() { |
@@ -258,20 +258,20 @@ discard block |
||
258 | 258 | return $this; |
259 | 259 | } |
260 | 260 | |
261 | - public function refresh($compileParts=["tbody"]){ |
|
261 | + public function refresh($compileParts=["tbody"]) { |
|
262 | 262 | $this->_compileParts=$compileParts; |
263 | 263 | return $this; |
264 | 264 | } |
265 | 265 | |
266 | 266 | |
267 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
267 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
268 | 268 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
269 | 269 | } |
270 | 270 | |
271 | - public function getSearchField(){ |
|
272 | - if(isset($this->_searchField)===false){ |
|
273 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
274 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
271 | + public function getSearchField() { |
|
272 | + if (isset($this->_searchField)===false) { |
|
273 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
274 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
275 | 275 | } |
276 | 276 | return $this->_searchField; |
277 | 277 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | return $this; |
288 | 288 | } |
289 | 289 | |
290 | - public function asForm(){ |
|
290 | + public function asForm() { |
|
291 | 291 | return $this->getForm(); |
292 | 292 | } |
293 | 293 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | |
296 | 296 | protected function getTargetSelector() { |
297 | 297 | $result=$this->_targetSelector; |
298 | - if(!isset($result)) |
|
298 | + if (!isset($result)) |
|
299 | 299 | $result="#".$this->identifier; |
300 | 300 | return $result; |
301 | 301 | } |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | protected function getCheckedMessage() { |
314 | - $result= $this->_checkedMessage; |
|
315 | - if(!isset($result)){ |
|
316 | - $result=[0=>"none selected",1=>"one item selected","other"=>"{count} items selected"]; |
|
314 | + $result=$this->_checkedMessage; |
|
315 | + if (!isset($result)) { |
|
316 | + $result=[0=>"none selected", 1=>"one item selected", "other"=>"{count} items selected"]; |
|
317 | 317 | } |
318 | 318 | return $result; |
319 | 319 | } |
@@ -333,14 +333,14 @@ discard block |
||
333 | 333 | * @param array $checkedMessage |
334 | 334 | * @param callable $callback |
335 | 335 | */ |
336 | - public function addCountCheckedInToolbar(array $checkedMessage=null,$callback=null){ |
|
337 | - if(isset($checkedMessage)) |
|
336 | + public function addCountCheckedInToolbar(array $checkedMessage=null, $callback=null) { |
|
337 | + if (isset($checkedMessage)) |
|
338 | 338 | $this->_checkedMessage=$checkedMessage; |
339 | 339 | $checkedMessage=$this->getCheckedMessage(); |
340 | 340 | $this->_hasCheckboxes=true; |
341 | 341 | $this->_hasCheckedMessage=true; |
342 | - $element=new HtmlLabel("checked-count-".$this->identifier,$checkedMessage[0]); |
|
343 | - $this->addInToolbar($element,$callback); |
|
342 | + $element=new HtmlLabel("checked-count-".$this->identifier, $checkedMessage[0]); |
|
343 | + $this->addInToolbar($element, $callback); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * @version 1.3 |
16 | 16 | */ |
17 | 17 | abstract class BaseHtml extends BaseWidget { |
18 | - use BaseHtmlEventsTrait,BaseHtmlPropertiesTrait; |
|
18 | + use BaseHtmlEventsTrait, BaseHtmlPropertiesTrait; |
|
19 | 19 | protected $_template; |
20 | 20 | protected $tagName; |
21 | - protected $_wrapBefore=array (); |
|
22 | - protected $_wrapAfter=array (); |
|
21 | + protected $_wrapBefore=array(); |
|
22 | + protected $_wrapAfter=array(); |
|
23 | 23 | protected $_bsComponent; |
24 | 24 | |
25 | 25 | /** |
@@ -29,14 +29,14 @@ discard block |
||
29 | 29 | */ |
30 | 30 | abstract public function run(JsUtils $js); |
31 | 31 | |
32 | - private function _callSetter($setter,$key,$value,&$array){ |
|
32 | + private function _callSetter($setter, $key, $value, &$array) { |
|
33 | 33 | $result=false; |
34 | 34 | if (method_exists($this, $setter) && !JString::startswith($key, "_")) { |
35 | 35 | try { |
36 | 36 | $this->$setter($value); |
37 | 37 | unset($array[$key]); |
38 | 38 | $result=true; |
39 | - } catch ( \Exception $e ) { |
|
39 | + }catch (\Exception $e) { |
|
40 | 40 | $result=false; |
41 | 41 | } |
42 | 42 | } |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | protected function getTemplate(JsUtils $js=NULL) { |
47 | - return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
47 | + return PropertyWrapper::wrap($this->_wrapBefore, $js).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | protected function ctrl($name, $value, $typeCtrl) { |
51 | 51 | if (\is_array($typeCtrl)) { |
52 | - if (array_search($value, $typeCtrl) === false) { |
|
53 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
52 | + if (array_search($value, $typeCtrl)===false) { |
|
53 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
54 | 54 | } |
55 | 55 | } else { |
56 | 56 | if (!$typeCtrl($value)) { |
57 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
57 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | return true; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | |
65 | 65 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
66 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
66 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
67 | 67 | return $name=$value; |
68 | 68 | } |
69 | 69 | return $this; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
73 | 73 | if (\is_array($typeCtrl)) { |
74 | 74 | $this->removeOldValues($name, $typeCtrl); |
75 | - $name.=$separator . $value; |
|
75 | + $name.=$separator.$value; |
|
76 | 76 | } |
77 | 77 | return $this; |
78 | 78 | } |
@@ -80,17 +80,17 @@ discard block |
||
80 | 80 | |
81 | 81 | |
82 | 82 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
83 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
83 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
84 | 84 | if (\is_array($typeCtrl)) { |
85 | 85 | $this->removeOldValues($name, $typeCtrl); |
86 | 86 | } |
87 | - $name.=$separator . $value; |
|
87 | + $name.=$separator.$value; |
|
88 | 88 | } |
89 | 89 | return $this; |
90 | 90 | } |
91 | 91 | |
92 | 92 | protected function addToMember(&$name, $value, $separator=" ") { |
93 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
93 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
94 | 94 | return $this; |
95 | 95 | } |
96 | 96 | |
@@ -101,17 +101,17 @@ discard block |
||
101 | 101 | $oldValue=trim($oldValue); |
102 | 102 | } |
103 | 103 | |
104 | - protected function _getElementBy($callback,$elements){ |
|
104 | + protected function _getElementBy($callback, $elements) { |
|
105 | 105 | if (\is_array($elements)) { |
106 | 106 | $flag=false; |
107 | 107 | $index=0; |
108 | - while ( !$flag && $index < sizeof($elements) ) { |
|
108 | + while (!$flag && $index<sizeof($elements)) { |
|
109 | 109 | if ($elements[$index] instanceof BaseHtml) |
110 | 110 | $flag=($callback($elements[$index])); |
111 | 111 | $index++; |
112 | 112 | } |
113 | - if ($flag === true) |
|
114 | - return $elements[$index - 1]; |
|
113 | + if ($flag===true) |
|
114 | + return $elements[$index-1]; |
|
115 | 115 | } elseif ($elements instanceof BaseHtml) { |
116 | 116 | if ($callback($elements)) |
117 | 117 | return $elements; |
@@ -139,13 +139,13 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public function fromArray($array) { |
142 | - foreach ( $this as $key => $value ) { |
|
143 | - if(array_key_exists($key, $array)===true) |
|
144 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
142 | + foreach ($this as $key => $value) { |
|
143 | + if (array_key_exists($key, $array)===true) |
|
144 | + $this->_callSetter("set".ucfirst($key), $key, $array[$key], $array); |
|
145 | 145 | } |
146 | - foreach ( $array as $key => $value ) { |
|
147 | - if($this->_callSetter($key, $key, $value, $array)===false){ |
|
148 | - $this->_callSetter("set" . ucfirst($key), $key, $value, $array); |
|
146 | + foreach ($array as $key => $value) { |
|
147 | + if ($this->_callSetter($key, $key, $value, $array)===false) { |
|
148 | + $this->_callSetter("set".ucfirst($key), $key, $value, $array); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | return $array; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | public function fromDatabaseObjects($objects, $function) { |
155 | 155 | if (isset($objects)) { |
156 | - foreach ( $objects as $object ) { |
|
156 | + foreach ($objects as $object) { |
|
157 | 157 | $this->fromDatabaseObject($object, $function); |
158 | 158 | } |
159 | 159 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | |
176 | 176 | public function getElementById($identifier, $elements) { |
177 | - return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
|
177 | + return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier; }, $elements); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | public function getBsComponent() { |
@@ -188,19 +188,19 @@ discard block |
||
188 | 188 | |
189 | 189 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
190 | 190 | $result=$this->getTemplate($js); |
191 | - foreach ( $this as $key => $value ) { |
|
192 | - if (JString::startswith($key, "_") === false && $key !== "events") { |
|
191 | + foreach ($this as $key => $value) { |
|
192 | + if (JString::startswith($key, "_")===false && $key!=="events") { |
|
193 | 193 | if (\is_array($value)) { |
194 | 194 | $v=PropertyWrapper::wrap($value, $js); |
195 | 195 | } else { |
196 | 196 | $v=$value; |
197 | 197 | } |
198 | - $result=str_ireplace("%" . $key . "%", $v, $result); |
|
198 | + $result=str_ireplace("%".$key."%", $v, $result); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | if (isset($js)===true) { |
202 | 202 | $this->run($js); |
203 | - if (isset($view) === true) { |
|
203 | + if (isset($view)===true) { |
|
204 | 204 | $js->addViewElement($this->identifier, $result, $view); |
205 | 205 | } |
206 | 206 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | protected $ajaxDataCall; |
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,62 +30,62 @@ 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",$immediatly=false) { |
|
34 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$immediatly); |
|
33 | + public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $immediatly=false) { |
|
34 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $immediatly); |
|
35 | 35 | } |
36 | - public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$immediatly=false) { |
|
37 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$immediatly); |
|
36 | + public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $immediatly=false) { |
|
37 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $immediatly); |
|
38 | 38 | } |
39 | 39 | |
40 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$immediatly=false) { |
|
41 | - if(JString::isNull($params)){$params="{}";} |
|
40 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $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,$jsCallback)."});\n"; |
|
50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $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(){ |
|
57 | - $this->ajaxDataCall=function ($responseElement,$jqueryDone="html"){ |
|
58 | - return JQueryAjaxEffect::{$this->params["ajaxEffect"]}($responseElement,$jqueryDone); |
|
56 | + protected function setAjaxDataCall() { |
|
57 | + $this->ajaxDataCall=function($responseElement, $jqueryDone="html") { |
|
58 | + return JQueryAjaxEffect::{$this->params["ajaxEffect"]}($responseElement, $jqueryDone); |
|
59 | 59 | }; |
60 | 60 | } |
61 | 61 | |
62 | - protected function _getAjaxUrl($url,$attr){ |
|
62 | + protected function _getAjaxUrl($url, $attr) { |
|
63 | 63 | $url=$this->_correctAjaxUrl($url); |
64 | 64 | $retour="url='".$url."';"; |
65 | 65 | $slash="/"; |
66 | - if(JString::endswith($url, "/")===true) |
|
66 | + if (JString::endswith($url, "/")===true) |
|
67 | 67 | $slash=""; |
68 | - if(JString::isNotNull($attr)){ |
|
68 | + if (JString::isNotNull($attr)) { |
|
69 | 69 | if ($attr==="value") |
70 | 70 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
71 | 71 | elseif ($attr==="html") |
72 | 72 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
73 | - elseif($attr!=null && $attr!=="") |
|
73 | + elseif ($attr!=null && $attr!=="") |
|
74 | 74 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
75 | 75 | } |
76 | 76 | return $retour; |
77 | 77 | } |
78 | 78 | |
79 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$jsCallback){ |
|
80 | - $retour="";$call=$this->ajaxDataCall; |
|
79 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $jsCallback) { |
|
80 | + $retour=""; $call=$this->ajaxDataCall; |
|
81 | 81 | if ($responseElement!=="") { |
82 | - $retour=$call($responseElement,$jqueryDone); |
|
82 | + $retour=$call($responseElement, $jqueryDone); |
|
83 | 83 | } |
84 | 84 | $retour.="\t".$jsCallback."\n"; |
85 | 85 | return $retour; |
86 | 86 | } |
87 | 87 | |
88 | - protected function _getResponseElement($responseElement){ |
|
88 | + protected function _getResponseElement($responseElement) { |
|
89 | 89 | if ($responseElement!=="") { |
90 | 90 | $responseElement=Javascript::prep_value($responseElement); |
91 | 91 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | protected function _correctAjaxUrl($url) { |
96 | 96 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
97 | 97 | $url=substr($url, 0, strlen($url)-1); |
98 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
98 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
99 | 99 | $url=$this->jsUtils->getUrl($url); |
100 | 100 | } |
101 | 101 | return $url; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param string $jsCallback javascript code to execute after the request |
110 | 110 | * @param boolean $immediatly |
111 | 111 | */ |
112 | - public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
112 | + public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
113 | 113 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
114 | 114 | $retour=$this->_getAjaxUrl($url, $attr); |
115 | 115 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @param string $url the request address |
131 | 131 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
132 | 132 | */ |
133 | - public function _jsonOn($event,$element, $url,$parameters=array()) { |
|
133 | + public function _jsonOn($event, $element, $url, $parameters=array()) { |
|
134 | 134 | $preventDefault=true; |
135 | 135 | $stopPropagation=true; |
136 | 136 | $jsCallback=null; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | $params="{}"; |
141 | 141 | $immediatly=true; |
142 | 142 | extract($parameters); |
143 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
143 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -152,19 +152,19 @@ discard block |
||
152 | 152 | * @param string $context jquery DOM element, array container. |
153 | 153 | * @param boolean $immediatly |
154 | 154 | */ |
155 | - public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null,$immediatly=false) { |
|
155 | + public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null, $immediatly=false) { |
|
156 | 156 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
157 | 157 | $retour=$this->_getAjaxUrl($url, $attr); |
158 | - if($context===null){ |
|
158 | + if ($context===null) { |
|
159 | 159 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
160 | - $newElm = "$('#'+newId)"; |
|
161 | - }else{ |
|
160 | + $newElm="$('#'+newId)"; |
|
161 | + } else { |
|
162 | 162 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
163 | - $newElm = $context.".find('#'+newId)"; |
|
163 | + $newElm=$context.".find('#'+newId)"; |
|
164 | 164 | } |
165 | 165 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
166 | 166 | $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"; |
167 | - $retour.= $appendTo; |
|
167 | + $retour.=$appendTo; |
|
168 | 168 | $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"; |
169 | 169 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
170 | 170 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -179,30 +179,30 @@ discard block |
||
179 | 179 | * @param string $url the request address |
180 | 180 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get", "context"=>null) |
181 | 181 | */ |
182 | - public function _jsonArrayOn($event,$element, $maskSelector,$url,$parameters=array()) { |
|
182 | + public function _jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
183 | 183 | $preventDefault=true; |
184 | 184 | $stopPropagation=true; |
185 | 185 | $jsCallback=null; |
186 | 186 | $attr="id"; |
187 | 187 | $method="get"; |
188 | - $context = null; |
|
188 | + $context=null; |
|
189 | 189 | $params="{}"; |
190 | 190 | $immediatly=true; |
191 | 191 | extract($parameters); |
192 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
192 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
193 | 193 | } |
194 | 194 | |
195 | - public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$immediatly=false) { |
|
195 | + public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $immediatly=false) { |
|
196 | 196 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
197 | 197 | $retour=$this->_getAjaxUrl($url, $attr); |
198 | 198 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
199 | 199 | $responseElement=$this->_getResponseElement($responseElement); |
200 | 200 | $retour.="var self=this;\n"; |
201 | - if($hasLoader===true){ |
|
201 | + if ($hasLoader===true) { |
|
202 | 202 | $this->addLoading($retour, $responseElement); |
203 | 203 | } |
204 | 204 | $retour.="$.post(url,params).done(function( data ) {\n"; |
205 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$jsCallback)."});\n"; |
|
205 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $jsCallback)."});\n"; |
|
206 | 206 | |
207 | 207 | if ($validation) { |
208 | 208 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param string $responseElement |
226 | 226 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html") |
227 | 227 | */ |
228 | - public function _getOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
228 | + public function _getOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
229 | 229 | $preventDefault=true; |
230 | 230 | $stopPropagation=true; |
231 | 231 | $jsCallback=null; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | $immediatly=true; |
235 | 235 | $jqueryDone="html"; |
236 | 236 | extract($parameters); |
237 | - return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone), $event, $preventDefault, $stopPropagation,$immediatly); |
|
237 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone), $event, $preventDefault, $stopPropagation, $immediatly); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * @param string $responseElement |
248 | 248 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true) |
249 | 249 | */ |
250 | - public function _postOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
250 | + public function _postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
251 | 251 | $preventDefault=true; |
252 | 252 | $stopPropagation=true; |
253 | 253 | $jsCallback=null; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | $immediatly=true; |
257 | 257 | $jqueryDone="html"; |
258 | 258 | extract($parameters); |
259 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone), $event, $preventDefault, $stopPropagation,$immediatly); |
|
259 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone), $event, $preventDefault, $stopPropagation, $immediatly); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @param string $responseElement |
270 | 270 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true) |
271 | 271 | */ |
272 | - public function _postFormOn($event,$element, $url, $form, $responseElement="", $parameters=array()) { |
|
272 | + public function _postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
273 | 273 | $preventDefault=true; |
274 | 274 | $stopPropagation=true; |
275 | 275 | $validation=false; |
@@ -279,6 +279,6 @@ discard block |
||
279 | 279 | $immediatly=true; |
280 | 280 | $jqueryDone="html"; |
281 | 281 | extract($parameters); |
282 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone), $event, $preventDefault, $stopPropagation,$immediatly); |
|
282 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone), $event, $preventDefault, $stopPropagation, $immediatly); |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | \ No newline at end of file |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Ajax\service; |
3 | 3 | class JQueryAjaxEffect { |
4 | - public static function none($responseElement,$jqueryDone="html"){ |
|
4 | + public static function none($responseElement, $jqueryDone="html") { |
|
5 | 5 | return "\t$({$responseElement}).{$jqueryDone}( data );\n"; |
6 | 6 | } |
7 | 7 | |
8 | - public static function fade($responseElement,$jqueryDone="html"){ |
|
8 | + public static function fade($responseElement, $jqueryDone="html") { |
|
9 | 9 | return "\t$({$responseElement}).hide().{$jqueryDone}( data ).fadeIn();\n"; |
10 | 10 | } |
11 | 11 | |
12 | - public static function slide($responseElement,$jqueryDone="html"){ |
|
12 | + public static function slide($responseElement, $jqueryDone="html") { |
|
13 | 13 | return "\t$({$responseElement}).hide().{$jqueryDone}( data ).slideDown();\n"; |
14 | 14 | } |
15 | 15 | } |
16 | 16 | \ No newline at end of file |
@@ -6,28 +6,28 @@ discard block |
||
6 | 6 | use Ajax\service\AjaxCall; |
7 | 7 | use Ajax\JsUtils; |
8 | 8 | |
9 | -trait FormTrait{ |
|
9 | +trait FormTrait { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @return HtmlForm |
13 | 13 | */ |
14 | 14 | abstract protected function getForm(); |
15 | 15 | |
16 | - protected function addCompoValidation($compo,$field){ |
|
16 | + protected function addCompoValidation($compo, $field) { |
|
17 | 17 | $validation=$field->getValidation(); |
18 | - if(isset($validation)){ |
|
18 | + if (isset($validation)) { |
|
19 | 19 | $validation->setIdentifier($field->getDataField()->getIdentifier()); |
20 | 20 | $compo->addFieldValidation($validation); |
21 | 21 | } |
22 | 22 | return $compo; |
23 | 23 | } |
24 | 24 | |
25 | - protected function _runValidationParams(&$compo,JsUtils $js=NULL){ |
|
25 | + protected function _runValidationParams(&$compo, JsUtils $js=NULL) { |
|
26 | 26 | $form=$this->getForm(); |
27 | 27 | $params=$form->getValidationParams(); |
28 | - if(isset($params["_ajaxSubmit"]) && $params["_ajaxSubmit"] instanceof AjaxCall){ |
|
28 | + if (isset($params["_ajaxSubmit"]) && $params["_ajaxSubmit"] instanceof AjaxCall) { |
|
29 | 29 | $compilation=$params["_ajaxSubmit"]->compile($js); |
30 | - $compilation=str_ireplace("\"","%quote%", $compilation); |
|
30 | + $compilation=str_ireplace("\"", "%quote%", $compilation); |
|
31 | 31 | $this->onSuccess($compilation); |
32 | 32 | $form->removeValidationParam("_ajaxSubmit"); |
33 | 33 | } |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | return $this->getForm()->addToProperty("class", "loading"); |
41 | 41 | } |
42 | 42 | |
43 | - public function setAttached($value=true){ |
|
43 | + public function setAttached($value=true) { |
|
44 | 44 | $form=$this->getForm(); |
45 | - if($value) |
|
46 | - $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
45 | + if ($value) |
|
46 | + $form->addToPropertyCtrl("class", "attached", array("attached")); |
|
47 | 47 | return $form; |
48 | 48 | } |
49 | 49 | |
50 | - public function addErrorMessage(){ |
|
50 | + public function addErrorMessage() { |
|
51 | 51 | return $this->getForm()->addContent((new HtmlMessage(""))->setError()); |
52 | 52 | } |
53 | 53 | |
@@ -62,38 +62,38 @@ discard block |
||
62 | 62 | * @param string $responseElement |
63 | 63 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
64 | 64 | */ |
65 | - public function submitOn($event,$identifier,$url,$responseElement){ |
|
65 | + public function submitOn($event, $identifier, $url, $responseElement) { |
|
66 | 66 | $form=$this->getForm(); |
67 | 67 | $elem=$form->getElementById($identifier, $form->getContent()); |
68 | - if(isset($elem)){ |
|
69 | - $this->_buttonAsSubmit($elem, $event,$url,$responseElement); |
|
68 | + if (isset($elem)) { |
|
69 | + $this->_buttonAsSubmit($elem, $event, $url, $responseElement); |
|
70 | 70 | } |
71 | 71 | return $form; |
72 | 72 | } |
73 | 73 | |
74 | - public function submitOnClick($identifier,$url,$responseElement){ |
|
74 | + public function submitOnClick($identifier, $url, $responseElement) { |
|
75 | 75 | return $this->submitOn("click", $identifier, $url, $responseElement); |
76 | 76 | } |
77 | 77 | |
78 | - public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL){ |
|
79 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
80 | - return $this->_buttonAsSubmit($bt, "click",$url,$responseElement); |
|
78 | + public function addSubmit($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL) { |
|
79 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
80 | + return $this->_buttonAsSubmit($bt, "click", $url, $responseElement); |
|
81 | 81 | } |
82 | 82 | |
83 | - protected function _buttonAsSubmit(&$button,$event,$url,$responseElement=NULL,$parameters=NULL){ |
|
83 | + protected function _buttonAsSubmit(&$button, $event, $url, $responseElement=NULL, $parameters=NULL) { |
|
84 | 84 | $form=$this->getForm(); |
85 | - if(isset($url) && isset($responseElement)){ |
|
85 | + if (isset($url) && isset($responseElement)) { |
|
86 | 86 | $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');"); |
87 | - $params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url,"stopPropagation"=>true]; |
|
88 | - if(\is_array($parameters)) |
|
89 | - $params=\array_merge($params,$parameters); |
|
87 | + $params=["form"=>$form->getIdentifier(), "responseElement"=>$responseElement, "url"=>$url, "stopPropagation"=>true]; |
|
88 | + if (\is_array($parameters)) |
|
89 | + $params=\array_merge($params, $parameters); |
|
90 | 90 | $form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params)); |
91 | 91 | } |
92 | 92 | return $button; |
93 | 93 | } |
94 | 94 | |
95 | - public function addReset($identifier,$value,$cssStyle=NULL){ |
|
96 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
95 | + public function addReset($identifier, $value, $cssStyle=NULL) { |
|
96 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
97 | 97 | $bt->setProperty("type", "reset"); |
98 | 98 | return $bt; |
99 | 99 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param string $jsCode |
104 | 104 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
105 | 105 | */ |
106 | - public function onValid($jsCode){ |
|
106 | + public function onValid($jsCode) { |
|
107 | 107 | $form=$this->getForm(); |
108 | 108 | $form->addValidationParam("onValid", "%function(){".$jsCode."}%"); |
109 | 109 | return $form; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @param string $jsCode can use event and fields parameters |
115 | 115 | * @return HtmlForm |
116 | 116 | */ |
117 | - public function onSuccess($jsCode){ |
|
117 | + public function onSuccess($jsCode) { |
|
118 | 118 | $form=$this->getForm(); |
119 | 119 | $form->addValidationParam("onSuccess", "%function(event,fields){console.log(fields);".$jsCode."}%"); |
120 | 120 | return $form; |
@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | * @property boolean $_edition |
24 | 24 | * @property mixed _modelInstance |
25 | 25 | */ |
26 | -trait FieldAsTrait{ |
|
26 | +trait FieldAsTrait { |
|
27 | 27 | |
28 | - abstract protected function _getFieldIdentifier($prefix,$name=""); |
|
29 | - abstract public function setValueFunction($index,$callback); |
|
28 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
29 | + abstract public function setValueFunction($index, $callback); |
|
30 | 30 | abstract protected function _getFieldName($index); |
31 | 31 | abstract protected function _getFieldCaption($index); |
32 | - abstract protected function _buttonAsSubmit(&$button,$event,$url,$responseElement=NULL,$parameters=NULL); |
|
32 | + abstract protected function _buttonAsSubmit(&$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * @param HtmlFormField $element |
36 | 36 | * @param array $attributes |
37 | 37 | */ |
38 | - protected function _applyAttributes($element,&$attributes,$index){ |
|
39 | - if(isset($attributes["callback"])){ |
|
38 | + protected function _applyAttributes($element, &$attributes, $index) { |
|
39 | + if (isset($attributes["callback"])) { |
|
40 | 40 | $callback=$attributes["callback"]; |
41 | - if(\is_callable($callback)){ |
|
42 | - $callback($element,$this->_modelInstance,$index); |
|
41 | + if (\is_callable($callback)) { |
|
42 | + $callback($element, $this->_modelInstance, $index); |
|
43 | 43 | unset($attributes["callback"]); |
44 | 44 | } |
45 | 45 | } |
@@ -49,42 +49,42 @@ discard block |
||
49 | 49 | $element->fromArray($attributes); |
50 | 50 | } |
51 | 51 | |
52 | - private function _getLabelField($caption,$icon=NULL){ |
|
53 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
52 | + private function _getLabelField($caption, $icon=NULL) { |
|
53 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
54 | 54 | return $label; |
55 | 55 | } |
56 | 56 | |
57 | - protected function _addRules($element,&$attributes){ |
|
58 | - if(isset($attributes["rules"])){ |
|
57 | + protected function _addRules($element, &$attributes) { |
|
58 | + if (isset($attributes["rules"])) { |
|
59 | 59 | $rules=$attributes["rules"]; |
60 | - if(\is_array($rules)){ |
|
60 | + if (\is_array($rules)) { |
|
61 | 61 | $element->addRules($rules); |
62 | 62 | } |
63 | - else{ |
|
63 | + else { |
|
64 | 64 | $element->addRule($rules); |
65 | 65 | } |
66 | 66 | unset($attributes["rules"]); |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - protected function _prepareFormFields(&$field,$name,&$attributes){ |
|
70 | + protected function _prepareFormFields(&$field, $name, &$attributes) { |
|
71 | 71 | $field->setName($name); |
72 | 72 | $this->_addRules($field, $attributes); |
73 | 73 | return $field; |
74 | 74 | } |
75 | 75 | |
76 | - protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){ |
|
77 | - $this->setValueFunction($index,function($value) use ($index,&$attributes,$elementCallback,$prefix){ |
|
76 | + protected function _fieldAs($elementCallback, $index, $attributes=NULL, $prefix=null) { |
|
77 | + $this->setValueFunction($index, function($value) use ($index, &$attributes, $elementCallback, $prefix){ |
|
78 | 78 | $caption=$this->_getFieldCaption($index); |
79 | 79 | $name=$this->_getFieldName($index); |
80 | - $id=$this->_getFieldIdentifier($prefix,$name); |
|
81 | - if(isset($attributes["name"])){ |
|
80 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
81 | + if (isset($attributes["name"])) { |
|
82 | 82 | $name=$attributes["name"]; |
83 | 83 | unset($attributes["name"]); |
84 | 84 | } |
85 | - $element=$elementCallback($id,$name,$value,$caption); |
|
86 | - if(\is_array($attributes)){ |
|
87 | - $this->_applyAttributes($element, $attributes,$index); |
|
85 | + $element=$elementCallback($id, $name, $value, $caption); |
|
86 | + if (\is_array($attributes)) { |
|
87 | + $this->_applyAttributes($element, $attributes, $index); |
|
88 | 88 | } |
89 | 89 | $element->setDisabled(!$this->_edition); |
90 | 90 | return $element; |
@@ -93,160 +93,160 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | |
96 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
97 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
98 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
96 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
97 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
98 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
99 | 99 | return $pb; |
100 | 100 | }); |
101 | 101 | return $this; |
102 | 102 | } |
103 | 103 | |
104 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
105 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
106 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
104 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
105 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
106 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
107 | 107 | return $rating; |
108 | 108 | }); |
109 | 109 | return $this; |
110 | 110 | } |
111 | 111 | |
112 | - public function fieldAsLabel($index,$icon=NULL){ |
|
113 | - $this->setValueFunction($index,function($caption) use($icon){ |
|
114 | - $lbl=$this->_getLabelField($caption,$icon); |
|
112 | + public function fieldAsLabel($index, $icon=NULL) { |
|
113 | + $this->setValueFunction($index, function($caption) use($icon){ |
|
114 | + $lbl=$this->_getLabelField($caption, $icon); |
|
115 | 115 | return $lbl; |
116 | 116 | }); |
117 | 117 | return $this; |
118 | 118 | } |
119 | 119 | |
120 | - public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
|
121 | - return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
|
122 | - $header=new HtmlHeader($id,$niveau,$value); |
|
123 | - if(isset($icon)) |
|
120 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
121 | + return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){ |
|
122 | + $header=new HtmlHeader($id, $niveau, $value); |
|
123 | + if (isset($icon)) |
|
124 | 124 | $header->asIcon($icon, $value); |
125 | 125 | return $header; |
126 | - }, $index,$attributes,"header"); |
|
126 | + }, $index, $attributes, "header"); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | |
130 | - public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
|
131 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
132 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
130 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
131 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
132 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
133 | 133 | return $image; |
134 | 134 | }); |
135 | 135 | return $this; |
136 | 136 | } |
137 | 137 | |
138 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
139 | - return $this->_fieldAs(function($id,$name,$value){ |
|
140 | - $img=new HtmlImage($id,$value); |
|
138 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
139 | + return $this->_fieldAs(function($id, $name, $value) { |
|
140 | + $img=new HtmlImage($id, $value); |
|
141 | 141 | $img->asAvatar(); |
142 | 142 | return $img; |
143 | - }, $index,$attributes,"avatar"); |
|
143 | + }, $index, $attributes, "avatar"); |
|
144 | 144 | } |
145 | 145 | |
146 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
147 | - return $this->_fieldAs(function($id,$name,$value){ |
|
148 | - $input= new HtmlRadio($id,$name,$value,$value); |
|
146 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
147 | + return $this->_fieldAs(function($id, $name, $value) { |
|
148 | + $input=new HtmlRadio($id, $name, $value, $value); |
|
149 | 149 | return $input; |
150 | - }, $index,$attributes,"radio"); |
|
150 | + }, $index, $attributes, "radio"); |
|
151 | 151 | } |
152 | 152 | |
153 | - public function fieldAsRadios($index,$elements=[],$attributes=NULL){ |
|
154 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements){ |
|
155 | - return HtmlFormFields::radios($name,$elements,$caption,$value); |
|
156 | - }, $index,$attributes,"radios"); |
|
153 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
154 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements){ |
|
155 | + return HtmlFormFields::radios($name, $elements, $caption, $value); |
|
156 | + }, $index, $attributes, "radios"); |
|
157 | 157 | } |
158 | 158 | |
159 | - public function fieldAsInput($index,$attributes=NULL){ |
|
160 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
161 | - $input= new HtmlFormInput($id,$caption,"text",$value); |
|
159 | + public function fieldAsInput($index, $attributes=NULL) { |
|
160 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
161 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
162 | 162 | return $this->_prepareFormFields($input, $name, $attributes); |
163 | - }, $index,$attributes,"input"); |
|
163 | + }, $index, $attributes, "input"); |
|
164 | 164 | } |
165 | 165 | |
166 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
167 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
168 | - $textarea=new HtmlFormTextarea($id,$caption,$value); |
|
166 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
167 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
168 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
169 | 169 | $textarea->setName($name); |
170 | 170 | return $textarea; |
171 | - }, $index,$attributes,"textarea"); |
|
171 | + }, $index, $attributes, "textarea"); |
|
172 | 172 | } |
173 | 173 | |
174 | - public function fieldAsHidden($index,$attributes=NULL){ |
|
175 | - if(!\is_array($attributes)){ |
|
174 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
175 | + if (!\is_array($attributes)) { |
|
176 | 176 | $attributes=[]; |
177 | 177 | } |
178 | 178 | $attributes["imputType"]="hidden"; |
179 | - return $this->fieldAsInput($index,$attributes); |
|
179 | + return $this->fieldAsInput($index, $attributes); |
|
180 | 180 | } |
181 | 181 | |
182 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
183 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
184 | - $input=new HtmlFormCheckbox($id,$caption,$this->_instanceViewer->getIdentifier()); |
|
182 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
183 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
184 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
185 | 185 | $input->setChecked(JString::isBooleanTrue($value)); |
186 | 186 | $input->setName($name); |
187 | 187 | return $input; |
188 | - }, $index,$attributes,"ck"); |
|
188 | + }, $index, $attributes, "ck"); |
|
189 | 189 | } |
190 | 190 | |
191 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
192 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($elements,$multiple){ |
|
193 | - $dd=new HtmlFormDropdown($id,$elements,$caption,$value); |
|
194 | - $dd->asSelect($name,$multiple); |
|
191 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
192 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($elements, $multiple){ |
|
193 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value); |
|
194 | + $dd->asSelect($name, $multiple); |
|
195 | 195 | return $dd; |
196 | - }, $index,$attributes,"dd"); |
|
196 | + }, $index, $attributes, "dd"); |
|
197 | 197 | } |
198 | 198 | |
199 | - public function fieldAsMessage($index,$attributes=NULL){ |
|
200 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
201 | - $mess= new HtmlMessage("message-".$id,$value); |
|
199 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
200 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
201 | + $mess=new HtmlMessage("message-".$id, $value); |
|
202 | 202 | $mess->addHeader($caption); |
203 | 203 | return $mess; |
204 | - }, $index,$attributes,"message"); |
|
204 | + }, $index, $attributes, "message"); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /**Change fields type |
208 | 208 | * @param array $types an array or associative array $type=>$attribute |
209 | 209 | */ |
210 | - public function fieldsAs(array $types){ |
|
210 | + public function fieldsAs(array $types) { |
|
211 | 211 | $i=0; |
212 | - if(JArray::isAssociative($types)){ |
|
213 | - foreach ($types as $type=>$attributes){ |
|
214 | - if(\is_int($type)) |
|
215 | - $this->fieldAs($i++,$attributes,[]); |
|
212 | + if (JArray::isAssociative($types)) { |
|
213 | + foreach ($types as $type=>$attributes) { |
|
214 | + if (\is_int($type)) |
|
215 | + $this->fieldAs($i++, $attributes, []); |
|
216 | 216 | else |
217 | - $this->fieldAs($i++,$type,$attributes); |
|
217 | + $this->fieldAs($i++, $type, $attributes); |
|
218 | 218 | } |
219 | - }else{ |
|
220 | - foreach ($types as $type){ |
|
221 | - $this->fieldAs($i++,$type); |
|
219 | + } else { |
|
220 | + foreach ($types as $type) { |
|
221 | + $this->fieldAs($i++, $type); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | - public function fieldAs($index,$type,$attributes=NULL){ |
|
226 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
227 | 227 | $method="fieldAs".\ucfirst($type); |
228 | - if(\method_exists($this, $method)){ |
|
229 | - if(!\is_array($attributes)){ |
|
228 | + if (\method_exists($this, $method)) { |
|
229 | + if (!\is_array($attributes)) { |
|
230 | 230 | $attributes=[$index]; |
231 | - }else{ |
|
231 | + } else { |
|
232 | 232 | \array_unshift($attributes, $index); |
233 | 233 | } |
234 | - \call_user_func_array([$this,$method], $attributes); |
|
234 | + \call_user_func_array([$this, $method], $attributes); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | |
238 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
239 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){ |
|
240 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
241 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,@$attributes["ajax"]); |
|
238 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
239 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes){ |
|
240 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
241 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]); |
|
242 | 242 | return $button; |
243 | - }, $index,$attributes,"submit"); |
|
243 | + }, $index, $attributes, "submit"); |
|
244 | 244 | } |
245 | 245 | |
246 | - public function fieldAsButton($index,$cssStyle=NULL,$attributes=NULL){ |
|
247 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
248 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
246 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
247 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
248 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
249 | 249 | return $button; |
250 | - }, $index,$attributes,"button"); |
|
250 | + }, $index, $attributes, "button"); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | \ No newline at end of file |
@@ -9,22 +9,22 @@ discard block |
||
9 | 9 | class FormInstanceViewer extends InstanceViewer { |
10 | 10 | protected $separators; |
11 | 11 | |
12 | - public function __construct($identifier,$instance=NULL, $captions=NULL) { |
|
13 | - parent::__construct($identifier,$instance=NULL, $captions=NULL); |
|
12 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
13 | + parent::__construct($identifier, $instance=NULL, $captions=NULL); |
|
14 | 14 | $this->separators=[-1]; |
15 | - $this->defaultValueFunction=function($name,$value,$index){ |
|
15 | + $this->defaultValueFunction=function($name, $value, $index) { |
|
16 | 16 | $caption=$this->getCaption($index); |
17 | - $input=new HtmlFormInput($this->widgetIdentifier."-".$name,$caption,"text",$value); |
|
17 | + $input=new HtmlFormInput($this->widgetIdentifier."-".$name, $caption, "text", $value); |
|
18 | 18 | $input->setName($name); |
19 | 19 | return $input; |
20 | 20 | }; |
21 | 21 | } |
22 | 22 | |
23 | - protected function _beforeAddProperty($index,&$field){ |
|
24 | - if(JString::endswith($field, "\n")===true){ |
|
23 | + protected function _beforeAddProperty($index, &$field) { |
|
24 | + if (JString::endswith($field, "\n")===true) { |
|
25 | 25 | $this->addSeparatorAfter($index); |
26 | 26 | } |
27 | - if($index>1 && JString::startswith($field, "\n")===true){ |
|
27 | + if ($index>1 && JString::startswith($field, "\n")===true) { |
|
28 | 28 | $this->addSeparatorAfter($index-1); |
29 | 29 | } |
30 | 30 | $field=\str_replace("\n", "", $field); |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | - public function addSeparatorAfter($fieldNum){ |
|
36 | - if(\array_search($fieldNum, $this->separators)===false) |
|
35 | + public function addSeparatorAfter($fieldNum) { |
|
36 | + if (\array_search($fieldNum, $this->separators)===false) |
|
37 | 37 | $this->separators[]=$fieldNum; |
38 | 38 | return $this; |
39 | 39 | } |
@@ -19,49 +19,49 @@ discard block |
||
19 | 19 | class DataForm extends Widget { |
20 | 20 | |
21 | 21 | public function __construct($identifier, $modelInstance=NULL) { |
22 | - parent::__construct($identifier, null,$modelInstance); |
|
22 | + parent::__construct($identifier, null, $modelInstance); |
|
23 | 23 | $this->_form=new HtmlForm($identifier); |
24 | 24 | $this->_init(new FormInstanceViewer($identifier), "form", $this->_form, true); |
25 | 25 | } |
26 | 26 | |
27 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
27 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
28 | 28 | return $this->identifier."-{$name}-".$this->_instanceViewer->getIdentifier(); |
29 | 29 | } |
30 | 30 | |
31 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
31 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
32 | 32 | $this->_instanceViewer->setInstance($this->_modelInstance); |
33 | 33 | |
34 | 34 | $form=$this->content["form"]; |
35 | 35 | $this->_generateContent($form); |
36 | 36 | |
37 | - if(isset($this->_toolbar)){ |
|
37 | + if (isset($this->_toolbar)) { |
|
38 | 38 | $this->_setToolbarPosition($form); |
39 | 39 | } |
40 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]); |
|
41 | - return parent::compile($js,$view); |
|
40 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "form", PositionInTable::AFTERTABLE]); |
|
41 | + return parent::compile($js, $view); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @param HtmlForm $form |
46 | 46 | */ |
47 | - protected function _generateContent($form){ |
|
48 | - $values= $this->_instanceViewer->getValues(); |
|
47 | + protected function _generateContent($form) { |
|
48 | + $values=$this->_instanceViewer->getValues(); |
|
49 | 49 | $count=$this->_instanceViewer->count(); |
50 | 50 | |
51 | 51 | $separators=$this->_instanceViewer->getSeparators(); |
52 | 52 | $size=\sizeof($separators); |
53 | - if($size===1){ |
|
54 | - foreach ($values as $v){ |
|
53 | + if ($size===1) { |
|
54 | + foreach ($values as $v) { |
|
55 | 55 | $form->addField($v); |
56 | 56 | } |
57 | - }else{ |
|
57 | + } else { |
|
58 | 58 | $separators[]=$count; |
59 | - for($i=0;$i<$size;$i++){ |
|
60 | - $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
|
59 | + for ($i=0; $i<$size; $i++) { |
|
60 | + $fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]); |
|
61 | 61 | //TODO check why $fields is empty |
62 | - if(\sizeof($fields)===1){ |
|
62 | + if (\sizeof($fields)===1) { |
|
63 | 63 | $form->addField($fields[0]); |
64 | - }elseif(\sizeof($fields)>1){ |
|
64 | + }elseif (\sizeof($fields)>1) { |
|
65 | 65 | $form->addFields($fields); |
66 | 66 | } |
67 | 67 | } |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | * {@inheritDoc} |
73 | 73 | * @see \Ajax\common\Widget::getForm() |
74 | 74 | */ |
75 | - public function getForm(){ |
|
75 | + public function getForm() { |
|
76 | 76 | return $this->content["form"]; |
77 | 77 | } |
78 | 78 | |
79 | - public function addSeparatorAfter($fieldNum){ |
|
79 | + public function addSeparatorAfter($fieldNum) { |
|
80 | 80 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
81 | 81 | return $this; |
82 | 82 | } |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | return $this; |
91 | 91 | } |
92 | 92 | |
93 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
94 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
95 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
93 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
94 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
95 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
96 | 96 | $button->setProperty("type", "reset"); |
97 | 97 | return $button; |
98 | - }, $index,$attributes); |
|
98 | + }, $index, $attributes); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
115 | 115 | } |
116 | 116 | |
117 | - public function run(JsUtils $js){ |
|
117 | + public function run(JsUtils $js) { |
|
118 | 118 | return parent::run($js); |
119 | 119 | } |
120 | 120 | } |
121 | 121 | \ No newline at end of file |