@@ -35,6 +35,10 @@ discard block |
||
35 | 35 | protected $_targetSelector; |
36 | 36 | protected $_checkedMessage; |
37 | 37 | |
38 | + /** |
|
39 | + * @param string $identifier |
|
40 | + * @param string $model |
|
41 | + */ |
|
38 | 42 | public function __construct($identifier,$model,$modelInstance=NULL) { |
39 | 43 | parent::__construct($identifier, $model,$modelInstance); |
40 | 44 | $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
@@ -74,6 +78,9 @@ discard block |
||
74 | 78 | if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$checkedMessageCall); |
75 | 79 | } |
76 | 80 | |
81 | + /** |
|
82 | + * @param string $op |
|
83 | + */ |
|
77 | 84 | protected function _generateBehavior($op,$params,JsUtils $js){ |
78 | 85 | if(isset($this->_urls[$op])){ |
79 | 86 | $params=\array_merge($params,["attr"=>"data-ajax"]); |
@@ -211,6 +218,9 @@ discard block |
||
211 | 218 | return $this; |
212 | 219 | } |
213 | 220 | |
221 | + /** |
|
222 | + * @param PositionInTable $part |
|
223 | + */ |
|
214 | 224 | private function addToolbarRow($part,$table,$captions){ |
215 | 225 | $hasPart=$table->hasPart($part); |
216 | 226 | if($hasPart){ |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | */ |
24 | 24 | class DataTable extends Widget { |
25 | - use TableTrait,DataTableFieldAsTrait; |
|
25 | + use TableTrait, DataTableFieldAsTrait; |
|
26 | 26 | protected $_searchField; |
27 | 27 | protected $_urls; |
28 | 28 | protected $_pagination; |
@@ -35,30 +35,30 @@ discard block |
||
35 | 35 | protected $_targetSelector; |
36 | 36 | protected $_checkedMessage; |
37 | 37 | |
38 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
39 | - parent::__construct($identifier, $model,$modelInstance); |
|
40 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
38 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
39 | + parent::__construct($identifier, $model, $modelInstance); |
|
40 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
41 | 41 | $this->_urls=[]; |
42 | 42 | } |
43 | 43 | |
44 | - public function run(JsUtils $js){ |
|
45 | - if($this->_hasCheckboxes && isset($js)){ |
|
44 | + public function run(JsUtils $js) { |
|
45 | + if ($this->_hasCheckboxes && isset($js)) { |
|
46 | 46 | $this->_runCheckboxes($js); |
47 | 47 | } |
48 | - if($this->_visibleHover){ |
|
49 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
50 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
48 | + if ($this->_visibleHover) { |
|
49 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
50 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
51 | 51 | } |
52 | - if(\is_array($this->_deleteBehavior)) |
|
53 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
54 | - if(\is_array($this->_editBehavior)) |
|
55 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
52 | + if (\is_array($this->_deleteBehavior)) |
|
53 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
54 | + if (\is_array($this->_editBehavior)) |
|
55 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
56 | 56 | return parent::run($js); |
57 | 57 | } |
58 | 58 | |
59 | - protected function _runCheckboxes(JsUtils $js){ |
|
59 | + protected function _runCheckboxes(JsUtils $js) { |
|
60 | 60 | $checkedMessageCall=""; |
61 | - if($this->_hasCheckedMessage){ |
|
61 | + if ($this->_hasCheckedMessage) { |
|
62 | 62 | $msg=$this->getCheckedMessage(); |
63 | 63 | $checkedMessageFunction="function updateChecked(){var msg='".$msg[0]."',count=\$('#{$this->identifier} [name=\"selection[]\"]:checked').length,all=\$('#{$this->identifier} [name=\"selection[]\"]').length; |
64 | 64 | if(count==1) msg='".$msg[1]."'; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | \$('#checked-count-".$this->identifier."').contents().filter(function() {return this.nodeType == 3;}).each(function(){this.textContent = msg.replace('{count}',count);}); |
67 | 67 | \$('#toolbar-{$this->identifier} .visibleOnChecked').toggle(count>0);}\$('#toolbar-".$this->identifier." .visibleOnChecked').hide();"; |
68 | 68 | $checkedMessageCall="updateChecked();"; |
69 | - $js->exec($checkedMessageFunction,true); |
|
69 | + $js->exec($checkedMessageFunction, true); |
|
70 | 70 | } |
71 | 71 | $js->execOn("change", "#".$this->identifier." [name='selection[]']", " |
72 | 72 | var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true; |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$checkedMessageCall); |
75 | 75 | } |
76 | 76 | |
77 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
78 | - if(isset($this->_urls[$op])){ |
|
79 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
80 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params); |
|
77 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
78 | + if (isset($this->_urls[$op])) { |
|
79 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
80 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
@@ -90,70 +90,70 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | |
93 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
94 | - if(!$this->_generated){ |
|
93 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
94 | + if (!$this->_generated) { |
|
95 | 95 | $this->_instanceViewer->setInstance($this->_model); |
96 | 96 | $captions=$this->_instanceViewer->getCaptions(); |
97 | 97 | |
98 | 98 | $table=$this->content["table"]; |
99 | 99 | |
100 | - if($this->_hasCheckboxes){ |
|
100 | + if ($this->_hasCheckboxes) { |
|
101 | 101 | $this->_generateMainCheckbox($captions); |
102 | 102 | } |
103 | 103 | |
104 | 104 | $table->setRowCount(0, \sizeof($captions)); |
105 | 105 | $table->setHeaderValues($captions); |
106 | - if(isset($this->_compileParts)) |
|
106 | + if (isset($this->_compileParts)) |
|
107 | 107 | $table->setCompileParts($this->_compileParts); |
108 | 108 | |
109 | - if(isset($this->_searchField) && isset($js)){ |
|
110 | - if(isset($this->_urls["refresh"])) |
|
111 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
109 | + if (isset($this->_searchField) && isset($js)) { |
|
110 | + if (isset($this->_urls["refresh"])) |
|
111 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $this->_generateContent($table); |
115 | 115 | |
116 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
116 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
117 | 117 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
118 | 118 | } |
119 | 119 | |
120 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
120 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
121 | 121 | $this->_generatePagination($table); |
122 | 122 | } |
123 | - if(isset($this->_toolbar)){ |
|
123 | + if (isset($this->_toolbar)) { |
|
124 | 124 | $this->_setToolbarPosition($table, $captions); |
125 | 125 | } |
126 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
126 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
127 | 127 | $this->_compileForm(); |
128 | 128 | $this->_generated=true; |
129 | 129 | } |
130 | - return parent::compile($js,$view); |
|
130 | + return parent::compile($js, $view); |
|
131 | 131 | } |
132 | 132 | |
133 | - private function _generateMainCheckbox(&$captions){ |
|
134 | - $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
|
133 | + private function _generateMainCheckbox(&$captions) { |
|
134 | + $ck=new HtmlCheckbox("main-ck-".$this->identifier, ""); |
|
135 | 135 | $checkedMessageCall=""; |
136 | - if($this->_hasCheckedMessage) |
|
136 | + if ($this->_hasCheckedMessage) |
|
137 | 137 | $checkedMessageCall="updateChecked();"; |
138 | 138 | $ck->setOnChecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',true);".$checkedMessageCall); |
139 | 139 | $ck->setOnUnchecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',false);".$checkedMessageCall); |
140 | 140 | \array_unshift($captions, $ck); |
141 | 141 | } |
142 | 142 | |
143 | - protected function _generateContent($table){ |
|
143 | + protected function _generateContent($table) { |
|
144 | 144 | $objects=$this->_modelInstance; |
145 | - if(isset($this->_pagination)){ |
|
145 | + if (isset($this->_pagination)) { |
|
146 | 146 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
147 | 147 | } |
148 | 148 | InstanceViewer::setIndex(0); |
149 | 149 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
150 | 150 | $this->_instanceViewer->setInstance($instance); |
151 | 151 | InstanceViewer::$index++; |
152 | - $values= $this->_instanceViewer->getValues(); |
|
153 | - if($this->_hasCheckboxes){ |
|
154 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
152 | + $values=$this->_instanceViewer->getValues(); |
|
153 | + if ($this->_hasCheckboxes) { |
|
154 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
155 | 155 | $field=$ck->getField(); |
156 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
156 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
157 | 157 | $field->setProperty("name", "selection[]"); |
158 | 158 | \array_unshift($values, $ck); |
159 | 159 | } |
@@ -164,37 +164,37 @@ discard block |
||
164 | 164 | }); |
165 | 165 | } |
166 | 166 | |
167 | - private function _generatePagination($table){ |
|
167 | + private function _generatePagination($table) { |
|
168 | 168 | $footer=$table->getFooter(); |
169 | 169 | $footer->mergeCol(); |
170 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
170 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
171 | 171 | $menu->floatRight(); |
172 | 172 | $menu->setActiveItem($this->_pagination->getPage()-1); |
173 | 173 | $footer->setValues($menu); |
174 | - if(isset($this->_urls["refresh"])) |
|
175 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
174 | + if (isset($this->_urls["refresh"])) |
|
175 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
176 | 176 | } |
177 | 177 | |
178 | - protected function _getFieldName($index){ |
|
178 | + protected function _getFieldName($index) { |
|
179 | 179 | return parent::_getFieldName($index)."[]"; |
180 | 180 | } |
181 | 181 | |
182 | - protected function _getFieldCaption($index){ |
|
182 | + protected function _getFieldCaption($index) { |
|
183 | 183 | return null; |
184 | 184 | } |
185 | 185 | |
186 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
187 | - switch ($this->_toolbarPosition){ |
|
186 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
187 | + switch ($this->_toolbarPosition) { |
|
188 | 188 | case PositionInTable::BEFORETABLE: |
189 | 189 | case PositionInTable::AFTERTABLE: |
190 | - if(isset($this->_compileParts)===false){ |
|
190 | + if (isset($this->_compileParts)===false) { |
|
191 | 191 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
192 | 192 | } |
193 | 193 | break; |
194 | 194 | case PositionInTable::HEADER: |
195 | 195 | case PositionInTable::FOOTER: |
196 | 196 | case PositionInTable::BODY: |
197 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
197 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
198 | 198 | break; |
199 | 199 | } |
200 | 200 | } |
@@ -206,23 +206,23 @@ discard block |
||
206 | 206 | * @param callable $callback function called after the field compilation |
207 | 207 | * @return \Ajax\semantic\widgets\datatable\DataTable |
208 | 208 | */ |
209 | - public function afterCompile($index,$callback){ |
|
210 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
209 | + public function afterCompile($index, $callback) { |
|
210 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
211 | 211 | return $this; |
212 | 212 | } |
213 | 213 | |
214 | - private function addToolbarRow($part,$table,$captions){ |
|
214 | + private function addToolbarRow($part, $table, $captions) { |
|
215 | 215 | $hasPart=$table->hasPart($part); |
216 | - if($hasPart){ |
|
216 | + if ($hasPart) { |
|
217 | 217 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
218 | - }else{ |
|
218 | + } else { |
|
219 | 219 | $row=$table->getPart($part)->getRow(0); |
220 | 220 | } |
221 | 221 | $row->mergeCol(); |
222 | 222 | $row->setValues([$this->_toolbar]); |
223 | 223 | } |
224 | 224 | |
225 | - public function getHtmlComponent(){ |
|
225 | + public function getHtmlComponent() { |
|
226 | 226 | return $this->content["table"]; |
227 | 227 | } |
228 | 228 | |
@@ -236,18 +236,18 @@ discard block |
||
236 | 236 | * @return \Ajax\semantic\widgets\datatable\DataTable |
237 | 237 | */ |
238 | 238 | public function setUrls($urls) { |
239 | - if(\is_array($urls)){ |
|
240 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
241 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
242 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
243 | - }else{ |
|
244 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
239 | + if (\is_array($urls)) { |
|
240 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
241 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
242 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
243 | + } else { |
|
244 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
245 | 245 | } |
246 | 246 | return $this; |
247 | 247 | } |
248 | 248 | |
249 | - public function paginate($items_per_page=10,$page=1){ |
|
250 | - $this->_pagination=new Pagination($items_per_page,4,$page); |
|
249 | + public function paginate($items_per_page=10, $page=1) { |
|
250 | + $this->_pagination=new Pagination($items_per_page, 4, $page); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | public function getHasCheckboxes() { |
@@ -259,20 +259,20 @@ discard block |
||
259 | 259 | return $this; |
260 | 260 | } |
261 | 261 | |
262 | - public function refresh($compileParts=["tbody"]){ |
|
262 | + public function refresh($compileParts=["tbody"]) { |
|
263 | 263 | $this->_compileParts=$compileParts; |
264 | 264 | return $this; |
265 | 265 | } |
266 | 266 | |
267 | 267 | |
268 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
268 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
269 | 269 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
270 | 270 | } |
271 | 271 | |
272 | - public function getSearchField(){ |
|
273 | - if(isset($this->_searchField)===false){ |
|
274 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
275 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
272 | + public function getSearchField() { |
|
273 | + if (isset($this->_searchField)===false) { |
|
274 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
275 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
276 | 276 | } |
277 | 277 | return $this->_searchField; |
278 | 278 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | return $this; |
289 | 289 | } |
290 | 290 | |
291 | - public function asForm(){ |
|
291 | + public function asForm() { |
|
292 | 292 | return $this->getForm(); |
293 | 293 | } |
294 | 294 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | |
297 | 297 | protected function getTargetSelector() { |
298 | 298 | $result=$this->_targetSelector; |
299 | - if(!isset($result)) |
|
299 | + if (!isset($result)) |
|
300 | 300 | $result="#".$this->identifier; |
301 | 301 | return $result; |
302 | 302 | } |
@@ -312,9 +312,9 @@ discard block |
||
312 | 312 | } |
313 | 313 | |
314 | 314 | protected function getCheckedMessage() { |
315 | - $result= $this->_checkedMessage; |
|
316 | - if(!isset($result)){ |
|
317 | - $result=[0=>"none selected",1=>"one item selected","other"=>"{count} items selected"]; |
|
315 | + $result=$this->_checkedMessage; |
|
316 | + if (!isset($result)) { |
|
317 | + $result=[0=>"none selected", 1=>"one item selected", "other"=>"{count} items selected"]; |
|
318 | 318 | } |
319 | 319 | return $result; |
320 | 320 | } |
@@ -334,14 +334,14 @@ discard block |
||
334 | 334 | * @param array $checkedMessage |
335 | 335 | * @param callable $callback |
336 | 336 | */ |
337 | - public function addCountCheckedInToolbar(array $checkedMessage=null,$callback=null){ |
|
338 | - if(isset($checkedMessage)) |
|
337 | + public function addCountCheckedInToolbar(array $checkedMessage=null, $callback=null) { |
|
338 | + if (isset($checkedMessage)) |
|
339 | 339 | $this->_checkedMessage=$checkedMessage; |
340 | 340 | $checkedMessage=$this->getCheckedMessage(); |
341 | 341 | $this->_hasCheckboxes=true; |
342 | 342 | $this->_hasCheckedMessage=true; |
343 | - $element=new HtmlLabel("checked-count-".$this->identifier,$checkedMessage[0]); |
|
344 | - $this->addInToolbar($element,$callback); |
|
343 | + $element=new HtmlLabel("checked-count-".$this->identifier, $checkedMessage[0]); |
|
344 | + $this->addInToolbar($element, $callback); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 |
@@ -12,15 +12,28 @@ discard block |
||
12 | 12 | * @property InstanceViewer $_instanceViewer |
13 | 13 | */ |
14 | 14 | trait DataTableFieldAsTrait{ |
15 | + |
|
16 | + /** |
|
17 | + * @param \Closure $field |
|
18 | + */ |
|
15 | 19 | abstract public function addField($field); |
20 | + |
|
21 | + /** |
|
22 | + * @param integer $index |
|
23 | + * @param \Closure $field |
|
24 | + */ |
|
16 | 25 | abstract public function insertField($index,$field); |
26 | + |
|
27 | + /** |
|
28 | + * @param \Closure $field |
|
29 | + */ |
|
17 | 30 | abstract public function insertInField($index,$field); |
18 | 31 | abstract public function fieldAs($index,$type,$attributes=NULL); |
19 | 32 | /** |
20 | 33 | * @param string $caption |
21 | 34 | * @param callable $callback |
22 | 35 | * @param boolean $visibleHover |
23 | - * @return callable |
|
36 | + * @return \Closure |
|
24 | 37 | */ |
25 | 38 | private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
26 | 39 | return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
@@ -30,7 +43,7 @@ discard block |
||
30 | 43 | * @param callable $thisCallback |
31 | 44 | * @param array $parameters |
32 | 45 | * @param callable $callback |
33 | - * @return callable |
|
46 | + * @return \Closure |
|
34 | 47 | */ |
35 | 48 | private function getCallable($thisCallback,$parameters,$callback=null){ |
36 | 49 | $result=function($instance) use($thisCallback,$parameters,$callback){ |
@@ -82,6 +95,9 @@ discard block |
||
82 | 95 | }, $index,$attributes); |
83 | 96 | } |
84 | 97 | |
98 | + /** |
|
99 | + * @param HtmlButton $element |
|
100 | + */ |
|
85 | 101 | protected function _visibleOver($element){ |
86 | 102 | $this->_visibleHover=true; |
87 | 103 | return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
@@ -92,7 +108,7 @@ discard block |
||
92 | 108 | * @param string $caption |
93 | 109 | * @param callable $callback |
94 | 110 | * @param boolean $visibleHover |
95 | - * @return \Ajax\semantic\widgets\datatable\DataTable |
|
111 | + * @return DataTableFieldAsTrait |
|
96 | 112 | */ |
97 | 113 | public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
98 | 114 | $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
@@ -104,7 +120,7 @@ discard block |
||
104 | 120 | * @param int $index |
105 | 121 | * @param string $caption |
106 | 122 | * @param callable $callback |
107 | - * @return \Ajax\semantic\widgets\datatable\DataTable |
|
123 | + * @return DataTableFieldAsTrait |
|
108 | 124 | */ |
109 | 125 | public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
110 | 126 | $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
@@ -116,18 +132,26 @@ discard block |
||
116 | 132 | * @param int $index |
117 | 133 | * @param string $caption |
118 | 134 | * @param callable $callback |
119 | - * @return \Ajax\semantic\widgets\datatable\DataTable |
|
135 | + * @return DataTableFieldAsTrait |
|
120 | 136 | */ |
121 | 137 | public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
122 | 138 | $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
123 | 139 | return $this; |
124 | 140 | } |
125 | 141 | |
142 | + /** |
|
143 | + * @param string $icon |
|
144 | + * @param string $class |
|
145 | + */ |
|
126 | 146 | private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
127 | 147 | $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
128 | 148 | return $this; |
129 | 149 | } |
130 | 150 | |
151 | + /** |
|
152 | + * @param string $icon |
|
153 | + * @param string $class |
|
154 | + */ |
|
131 | 155 | private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
132 | 156 | $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
133 | 157 | return $this; |
@@ -143,7 +167,7 @@ discard block |
||
143 | 167 | |
144 | 168 | /** |
145 | 169 | * @param boolean $visibleHover |
146 | - * @param boolean $generateBehavior |
|
170 | + * @param boolean $deleteBehavior |
|
147 | 171 | * @param callable $callback |
148 | 172 | * @return \Ajax\semantic\widgets\datatable\DataTableFieldAsTrait |
149 | 173 | */ |
@@ -11,19 +11,19 @@ discard block |
||
11 | 11 | * @property boolean $_visibleHover |
12 | 12 | * @property InstanceViewer $_instanceViewer |
13 | 13 | */ |
14 | -trait DataTableFieldAsTrait{ |
|
14 | +trait DataTableFieldAsTrait { |
|
15 | 15 | abstract public function addField($field); |
16 | - abstract public function insertField($index,$field); |
|
17 | - abstract public function insertInField($index,$field); |
|
18 | - abstract public function fieldAs($index,$type,$attributes=NULL); |
|
16 | + abstract public function insertField($index, $field); |
|
17 | + abstract public function insertInField($index, $field); |
|
18 | + abstract public function fieldAs($index, $type, $attributes=NULL); |
|
19 | 19 | /** |
20 | 20 | * @param string $caption |
21 | 21 | * @param callable $callback |
22 | 22 | * @param boolean $visibleHover |
23 | 23 | * @return callable |
24 | 24 | */ |
25 | - private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
|
26 | - return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
|
25 | + private function getFieldButtonCallable($caption, $visibleHover=true, $callback=null) { |
|
26 | + return $this->getCallable("getFieldButton", [$caption, $visibleHover], $callback); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -32,19 +32,19 @@ discard block |
||
32 | 32 | * @param callable $callback |
33 | 33 | * @return callable |
34 | 34 | */ |
35 | - private function getCallable($thisCallback,$parameters,$callback=null){ |
|
36 | - $result=function($instance) use($thisCallback,$parameters,$callback){ |
|
37 | - $object=call_user_func_array(array($this,$thisCallback), $parameters); |
|
38 | - if(isset($callback)){ |
|
39 | - if(\is_callable($callback)){ |
|
40 | - $callback($object,$instance); |
|
35 | + private function getCallable($thisCallback, $parameters, $callback=null) { |
|
36 | + $result=function($instance) use($thisCallback, $parameters, $callback){ |
|
37 | + $object=call_user_func_array(array($this, $thisCallback), $parameters); |
|
38 | + if (isset($callback)) { |
|
39 | + if (\is_callable($callback)) { |
|
40 | + $callback($object, $instance); |
|
41 | 41 | } |
42 | 42 | } |
43 | - if($object instanceof HtmlSemDoubleElement){ |
|
44 | - $object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
|
45 | - if($object->propertyContains("class","visibleover")){ |
|
43 | + if ($object instanceof HtmlSemDoubleElement) { |
|
44 | + $object->setProperty("data-ajax", $this->_instanceViewer->getIdentifier()); |
|
45 | + if ($object->propertyContains("class", "visibleover")) { |
|
46 | 46 | $this->_visibleHover=true; |
47 | - $object->setProperty("style","visibility:hidden;"); |
|
47 | + $object->setProperty("style", "visibility:hidden;"); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | return $object; |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | * @param string $caption |
57 | 57 | * @return HtmlButton |
58 | 58 | */ |
59 | - private function getFieldButton($caption,$visibleHover=true){ |
|
60 | - $bt= new HtmlButton("",$caption); |
|
61 | - if($visibleHover) |
|
59 | + private function getFieldButton($caption, $visibleHover=true) { |
|
60 | + $bt=new HtmlButton("", $caption); |
|
61 | + if ($visibleHover) |
|
62 | 62 | $this->_visibleOver($bt); |
63 | 63 | return $bt; |
64 | 64 | } |
@@ -72,19 +72,19 @@ discard block |
||
72 | 72 | * @param array $attributes associative array (<b>ajax</b> key is for ajax post) |
73 | 73 | * @return \Ajax\semantic\widgets\datatable\DataTable |
74 | 74 | */ |
75 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
76 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index,$attributes){ |
|
77 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
78 | - $button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]); |
|
79 | - if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
75 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
76 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $index, $attributes){ |
|
77 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
78 | + $button->postOnClick($url, "$(event.target).closest('tr').find(':input').serialize()", $responseElement, $attributes["ajax"]); |
|
79 | + if (!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
80 | 80 | $this->_visibleOver($button); |
81 | 81 | return $button; |
82 | - }, $index,$attributes); |
|
82 | + }, $index, $attributes); |
|
83 | 83 | } |
84 | 84 | |
85 | - protected function _visibleOver($element){ |
|
85 | + protected function _visibleOver($element) { |
|
86 | 86 | $this->_visibleHover=true; |
87 | - return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
|
87 | + return $element->addToProperty("class", "visibleover")->setProperty("style", "visibility:hidden;"); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @param boolean $visibleHover |
95 | 95 | * @return \Ajax\semantic\widgets\datatable\DataTable |
96 | 96 | */ |
97 | - public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
|
98 | - $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
|
97 | + public function addFieldButton($caption, $visibleHover=true, $callback=null) { |
|
98 | + $this->addField($this->getCallable("getFieldButton", [$caption, $visibleHover], $callback)); |
|
99 | 99 | return $this; |
100 | 100 | } |
101 | 101 | |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * @param callable $callback |
107 | 107 | * @return \Ajax\semantic\widgets\datatable\DataTable |
108 | 108 | */ |
109 | - public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
110 | - $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
109 | + public function insertFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
110 | + $this->insertField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
111 | 111 | return $this; |
112 | 112 | } |
113 | 113 | |
@@ -118,25 +118,25 @@ discard block |
||
118 | 118 | * @param callable $callback |
119 | 119 | * @return \Ajax\semantic\widgets\datatable\DataTable |
120 | 120 | */ |
121 | - public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
122 | - $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
121 | + public function insertInFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
122 | + $this->insertInField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
123 | 123 | return $this; |
124 | 124 | } |
125 | 125 | |
126 | - private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
|
127 | - $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
126 | + private function addDefaultButton($icon, $class=null, $visibleHover=true, $callback=null) { |
|
127 | + $this->addField($this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
128 | 128 | return $this; |
129 | 129 | } |
130 | 130 | |
131 | - private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
|
132 | - $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
131 | + private function insertDefaultButtonIn($index, $icon, $class=null, $visibleHover=true, $callback=null) { |
|
132 | + $this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
133 | 133 | return $this; |
134 | 134 | } |
135 | 135 | |
136 | - private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
|
137 | - $bt=$this->getFieldButton("",$visibleHover); |
|
136 | + private function getDefaultButton($icon, $class=null, $visibleHover=true) { |
|
137 | + $bt=$this->getFieldButton("", $visibleHover); |
|
138 | 138 | $bt->asIcon($icon); |
139 | - if(isset($class)) |
|
139 | + if (isset($class)) |
|
140 | 140 | $bt->addClass($class); |
141 | 141 | return $bt; |
142 | 142 | } |
@@ -147,30 +147,30 @@ discard block |
||
147 | 147 | * @param callable $callback |
148 | 148 | * @return \Ajax\semantic\widgets\datatable\DataTableFieldAsTrait |
149 | 149 | */ |
150 | - public function addDeleteButton($visibleHover=true,$deleteBehavior=[],$callback=null){ |
|
150 | + public function addDeleteButton($visibleHover=true, $deleteBehavior=[], $callback=null) { |
|
151 | 151 | $this->_deleteBehavior=$deleteBehavior; |
152 | - return $this->addDefaultButton("remove","_delete red basic",$visibleHover,$callback); |
|
152 | + return $this->addDefaultButton("remove", "_delete red basic", $visibleHover, $callback); |
|
153 | 153 | } |
154 | 154 | |
155 | - public function addEditButton($visibleHover=true,$editBehavior=[],$callback=null){ |
|
155 | + public function addEditButton($visibleHover=true, $editBehavior=[], $callback=null) { |
|
156 | 156 | $this->_editBehavior=$editBehavior; |
157 | - return $this->addDefaultButton("edit","_edit basic",$visibleHover,$callback); |
|
157 | + return $this->addDefaultButton("edit", "_edit basic", $visibleHover, $callback); |
|
158 | 158 | } |
159 | 159 | |
160 | - public function addEditDeleteButtons($visibleHover=true,$behavior=[],$callbackEdit=null,$callbackDelete=null){ |
|
161 | - $this->addEditButton($visibleHover,$behavior,$callbackEdit); |
|
160 | + public function addEditDeleteButtons($visibleHover=true, $behavior=[], $callbackEdit=null, $callbackDelete=null) { |
|
161 | + $this->addEditButton($visibleHover, $behavior, $callbackEdit); |
|
162 | 162 | $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
163 | - $this->insertDeleteButtonIn($index,$visibleHover,$behavior,$callbackDelete); |
|
163 | + $this->insertDeleteButtonIn($index, $visibleHover, $behavior, $callbackDelete); |
|
164 | 164 | return $this; |
165 | 165 | } |
166 | 166 | |
167 | - public function insertDeleteButtonIn($index,$visibleHover=true,$deleteBehavior=true,$callback=null){ |
|
167 | + public function insertDeleteButtonIn($index, $visibleHover=true, $deleteBehavior=true, $callback=null) { |
|
168 | 168 | $this->_deleteBehavior=$deleteBehavior; |
169 | - return $this->insertDefaultButtonIn($index,"remove","_delete red basic",$visibleHover,$callback); |
|
169 | + return $this->insertDefaultButtonIn($index, "remove", "_delete red basic", $visibleHover, $callback); |
|
170 | 170 | } |
171 | 171 | |
172 | - public function insertEditButtonIn($index,$visibleHover=true,$editBehavior=[],$callback=null){ |
|
172 | + public function insertEditButtonIn($index, $visibleHover=true, $editBehavior=[], $callback=null) { |
|
173 | 173 | $this->_editBehavior=$editBehavior; |
174 | - return $this->insertDefaultButtonIn($index,"edit","_edit basic",$visibleHover,$callback); |
|
174 | + return $this->insertDefaultButtonIn($index, "edit", "_edit basic", $visibleHover, $callback); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | \ No newline at end of file |
@@ -33,15 +33,15 @@ |
||
33 | 33 | if ($stopPropagation===true) { |
34 | 34 | $result.=Javascript::$stopPropagation; |
35 | 35 | } |
36 | - switch($this->method) { |
|
36 | + switch ($this->method) { |
|
37 | 37 | case "get": |
38 | - $result.=$js->getDeferred($url, $responseElement, $params, $callback, $attr,$jqueryDone,$ajaxTransition); |
|
38 | + $result.=$js->getDeferred($url, $responseElement, $params, $callback, $attr, $jqueryDone, $ajaxTransition); |
|
39 | 39 | break; |
40 | 40 | case "post": |
41 | - $result.=$js->postDeferred($url, $responseElement, $params, $callback, $attr,$hasLoader,$jqueryDone,$ajaxTransition); |
|
41 | + $result.=$js->postDeferred($url, $responseElement, $params, $callback, $attr, $hasLoader, $jqueryDone, $ajaxTransition); |
|
42 | 42 | break; |
43 | 43 | case "postForm": |
44 | - $result.=$js->postFormDeferred($url, $form, $responseElement, $validation, $callback, $attr,$hasLoader,$jqueryDone,$ajaxTransition); |
|
44 | + $result.=$js->postFormDeferred($url, $form, $responseElement, $validation, $callback, $attr, $hasLoader, $jqueryDone, $ajaxTransition); |
|
45 | 45 | break; |
46 | 46 | } |
47 | 47 | return $result; |
@@ -1,23 +1,23 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Ajax\service; |
3 | 3 | class AjaxTransition { |
4 | - public static function none($responseElement,$jqueryDone="html"){ |
|
4 | + public static function none($responseElement, $jqueryDone="html") { |
|
5 | 5 | return "$({$responseElement}).{$jqueryDone}( data )"; |
6 | 6 | } |
7 | 7 | |
8 | - public static function fade($responseElement,$jqueryDone="html"){ |
|
8 | + public static function fade($responseElement, $jqueryDone="html") { |
|
9 | 9 | return "$({$responseElement}).hide().{$jqueryDone}( data ).fadeIn()"; |
10 | 10 | } |
11 | 11 | |
12 | - public static function slide($responseElement,$jqueryDone="html"){ |
|
12 | + public static function slide($responseElement, $jqueryDone="html") { |
|
13 | 13 | return "$({$responseElement}).hide().{$jqueryDone}( data ).slideDown()"; |
14 | 14 | } |
15 | 15 | |
16 | - public static function bSlidedown($responseElement,$jqueryDone="html"){ |
|
16 | + public static function bSlidedown($responseElement, $jqueryDone="html") { |
|
17 | 17 | return "$({$responseElement}).{$jqueryDone}( data ).transition('slide down in')"; |
18 | 18 | } |
19 | 19 | |
20 | - public static function bScale($responseElement,$jqueryDone="html"){ |
|
20 | + public static function bScale($responseElement, $jqueryDone="html") { |
|
21 | 21 | return "$({$responseElement}).{$jqueryDone}( data ).transition('scale in')"; |
22 | 22 | } |
23 | 23 | } |
24 | 24 | \ No newline at end of file |
@@ -15,16 +15,16 @@ discard block |
||
15 | 15 | * @license Apache 2 http://www.apache.org/licenses/ |
16 | 16 | **/ |
17 | 17 | class Jquery { |
18 | - use JqueryEventsTrait,JqueryAjaxTrait,JqueryActionsTrait; |
|
18 | + use JqueryEventsTrait, JqueryAjaxTrait, JqueryActionsTrait; |
|
19 | 19 | protected $_ui; |
20 | 20 | protected $_bootstrap; |
21 | 21 | protected $_semantic; |
22 | - protected $jquery_code_for_compile=array (); |
|
22 | + protected $jquery_code_for_compile=array(); |
|
23 | 23 | protected $jsUtils; |
24 | 24 | protected $params; |
25 | 25 | |
26 | - protected $jquery_events=array ( |
|
27 | - "bind","blur","change","click","dblclick","delegate","die","error","focus","focusin","focusout","hover","keydown","keypress","keyup","live","load","mousedown","mousseenter","mouseleave","mousemove","mouseout","mouseover","mouseup","off","on","one","ready","resize","scroll","select","submit","toggle","trigger","triggerHandler","undind","undelegate","unload" |
|
26 | + protected $jquery_events=array( |
|
27 | + "bind", "blur", "change", "click", "dblclick", "delegate", "die", "error", "focus", "focusin", "focusout", "hover", "keydown", "keypress", "keyup", "live", "load", "mousedown", "mousseenter", "mouseleave", "mousemove", "mouseout", "mouseover", "mouseup", "off", "on", "one", "ready", "resize", "scroll", "select", "submit", "toggle", "trigger", "triggerHandler", "undind", "undelegate", "unload" |
|
28 | 28 | ); |
29 | 29 | |
30 | 30 | public function ui($ui=NULL) { |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | return $this->_semantic; |
49 | 49 | } |
50 | 50 | |
51 | - public function __construct($params,$jsUtils) { |
|
51 | + public function __construct($params, $jsUtils) { |
|
52 | 52 | $this->params=array(); |
53 | - foreach ( $params as $key => $val ) { |
|
53 | + foreach ($params as $key => $val) { |
|
54 | 54 | $this->params[$key]=$params[$key]; |
55 | 55 | } |
56 | 56 | $this->jsUtils=$jsUtils; |
57 | - if(isset($params["ajaxTransition"])) |
|
57 | + if (isset($params["ajaxTransition"])) |
|
58 | 58 | $this->ajaxTransition=$this->setAjaxDataCall($params["ajaxTransition"]); |
59 | 59 | } |
60 | 60 | |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function _output($array_js='') { |
118 | 118 | if (!is_array($array_js)) { |
119 | - $array_js=array ( |
|
119 | + $array_js=array( |
|
120 | 120 | $array_js |
121 | 121 | ); |
122 | 122 | } |
123 | 123 | |
124 | - foreach ( $array_js as $js ) { |
|
124 | + foreach ($array_js as $js) { |
|
125 | 125 | $this->jquery_code_for_compile[]="\t$js\n"; |
126 | 126 | } |
127 | 127 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param string $param |
134 | 134 | * @param boolean $immediatly delayed if false |
135 | 135 | */ |
136 | - public function _genericCallValue($jQueryCall,$element='this', $param="", $immediatly=false) { |
|
136 | + public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) { |
|
137 | 137 | $element=Javascript::prep_element($element); |
138 | 138 | if (isset($param)) { |
139 | 139 | $param=Javascript::prep_value($param); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param boolean $immediatly delayed if false |
153 | 153 | * @return string |
154 | 154 | */ |
155 | - public function _genericCallElement($jQueryCall,$to='this', $element, $immediatly=false) { |
|
155 | + public function _genericCallElement($jQueryCall, $to='this', $element, $immediatly=false) { |
|
156 | 156 | $to=Javascript::prep_element($to); |
157 | 157 | $element=Javascript::prep_element($element); |
158 | 158 | $str="$({$to}).{$jQueryCall}({$element});"; |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function sortable($element, $options=array()) { |
172 | 172 | if (count($options)>0) { |
173 | - $sort_options=array (); |
|
174 | - foreach ( $options as $k => $v ) { |
|
173 | + $sort_options=array(); |
|
174 | + foreach ($options as $k => $v) { |
|
175 | 175 | $sort_options[]="\n\t\t".$k.': '.$v.""; |
176 | 176 | } |
177 | 177 | $sort_options=implode(",", $sort_options); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @param boolean $stopPropagation Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. |
204 | 204 | * @return string |
205 | 205 | */ |
206 | - public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true) { |
|
206 | + public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true) { |
|
207 | 207 | if (\is_array($js)) { |
208 | 208 | $js=implode("\n\t\t", $js); |
209 | 209 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | $event="\n\t$(".Javascript::prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n"; |
218 | 218 | else |
219 | 219 | $event="\n\t$(".Javascript::prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n"; |
220 | - if($immediatly) |
|
220 | + if ($immediatly) |
|
221 | 221 | $this->jquery_code_for_compile[]=$event; |
222 | 222 | return $event; |
223 | 223 | } |
@@ -243,29 +243,29 @@ discard block |
||
243 | 243 | $script='$(document).ready(function() {'."\n"; |
244 | 244 | $script.=implode('', $this->jquery_code_for_compile); |
245 | 245 | $script.='})'; |
246 | - if($this->params["defer"]){ |
|
246 | + if ($this->params["defer"]) { |
|
247 | 247 | $script=$this->defer($script); |
248 | 248 | } |
249 | 249 | $script.=";"; |
250 | 250 | $this->jquery_code_for_compile=array(); |
251 | - if($this->params["debug"]===false){ |
|
251 | + if ($this->params["debug"]===false) { |
|
252 | 252 | $script=$this->minify($script); |
253 | 253 | } |
254 | 254 | $output=($script_tags===FALSE) ? $script : $this->inline($script); |
255 | 255 | |
256 | - if ($view!==NULL){ |
|
257 | - $this->jsUtils->createScriptVariable($view,$view_var, $output); |
|
256 | + if ($view!==NULL) { |
|
257 | + $this->jsUtils->createScriptVariable($view, $view_var, $output); |
|
258 | 258 | } |
259 | 259 | return $output; |
260 | 260 | } |
261 | 261 | |
262 | - private function defer($script){ |
|
262 | + private function defer($script) { |
|
263 | 263 | $result="window.defer=function (method) {if (window.jQuery) method(); else setTimeout(function() { defer(method) }, 50);};"; |
264 | 264 | $result.="window.defer(function(){".$script."})"; |
265 | 265 | return $result; |
266 | 266 | } |
267 | 267 | |
268 | - private function _compileLibrary($library){ |
|
268 | + private function _compileLibrary($library) { |
|
269 | 269 | if ($library!=NULL) { |
270 | 270 | if ($library->isAutoCompile()) { |
271 | 271 | $library->compile(true); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return void |
284 | 284 | */ |
285 | 285 | public function _clear_compile() { |
286 | - $this->jquery_code_for_compile=array (); |
|
286 | + $this->jquery_code_for_compile=array(); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -292,18 +292,18 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public function _document_ready($js) { |
294 | 294 | if (!is_array($js)) { |
295 | - $js=array ( |
|
295 | + $js=array( |
|
296 | 296 | $js |
297 | 297 | ); |
298 | 298 | } |
299 | 299 | |
300 | - foreach ( $js as $script ) { |
|
300 | + foreach ($js as $script) { |
|
301 | 301 | $this->jquery_code_for_compile[]=$script; |
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | 305 | private function minify($input) { |
306 | - if(trim($input) === "") return $input; |
|
306 | + if (trim($input)==="") return $input; |
|
307 | 307 | return preg_replace( |
308 | 308 | array( |
309 | 309 | // Remove comment(s) |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
26 | 26 | * @param string|callable $ajaxTransition |
27 | 27 | */ |
28 | - public function get($url, $responseElement="", $params="{}", $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
29 | - return $this->js->_get($url, $params, $responseElement, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true); |
|
28 | + public function get($url, $responseElement="", $params="{}", $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
29 | + return $this->js->_get($url, $params, $responseElement, $jsCallback, NULL, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @param string $jsCallback javascript code to execute after the request |
38 | 38 | * @param boolean $immediatly |
39 | 39 | */ |
40 | - public function json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
41 | - return $this->js->_json($url, $method, $params, $jsCallback, $attr, $context,$immediatly); |
|
40 | + public function json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
41 | + return $this->js->_json($url, $method, $params, $jsCallback, $attr, $context, $immediatly); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * @param string $url the request address |
49 | 49 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
50 | 50 | */ |
51 | - public function jsonOn($event,$element, $url,$parameters=array()) { |
|
52 | - return $this->js->_jsonOn($event, $element, $url,$parameters); |
|
51 | + public function jsonOn($event, $element, $url, $parameters=array()) { |
|
52 | + return $this->js->_jsonOn($event, $element, $url, $parameters); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param string $jsCallback javascript code to execute after the request |
72 | 72 | */ |
73 | 73 | public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL) { |
74 | - return $this->js->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, NULL,true); |
|
74 | + return $this->js->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, NULL, true); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | * @param string $url the request url |
94 | 94 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
95 | 95 | */ |
96 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$parameters=array()) { |
|
97 | - return $this->js->_jsonArrayOn($event,$element,$maskSelector, $url, $parameters); |
|
96 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
97 | + return $this->js->_jsonArrayOn($event, $element, $maskSelector, $url, $parameters); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
109 | 109 | * @param string|callable $ajaxTransition |
110 | 110 | */ |
111 | - public function getDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL,$attr="id",$jqueryDone="html",$ajaxTransition=null) { |
|
112 | - return $this->js->_get($url, $params, $responseElement, $jsCallback, $attr, false,$jqueryDone,$ajaxTransition); |
|
111 | + public function getDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id", $jqueryDone="html", $ajaxTransition=null) { |
|
112 | + return $this->js->_get($url, $params, $responseElement, $jsCallback, $attr, false, $jqueryDone, $ajaxTransition); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
149 | 149 | * @param string|callable $ajaxTransition |
150 | 150 | */ |
151 | - public function post($url, $responseElement="", $params="{}", $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
152 | - return $this->js->_post($url, $params, $responseElement, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true); |
|
151 | + public function post($url, $responseElement="", $params="{}", $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
152 | + return $this->js->_post($url, $params, $responseElement, $jsCallback, NULL, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
165 | 165 | * @param string|callable $ajaxTransition |
166 | 166 | */ |
167 | - public function postDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
168 | - return $this->js->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false); |
|
167 | + public function postDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
168 | + return $this->js->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, false); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null) |
180 | 180 | */ |
181 | 181 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
182 | - return $this->js->_postOn($event, $element, $url, $params, $responseElement, $parameters); |
|
182 | + return $this->js->_postOn($event, $element, $url, $params, $responseElement, $parameters); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
206 | 206 | * @param string|callable $ajaxTransition |
207 | 207 | */ |
208 | - public function postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
209 | - return $this->js->_postForm($url, $form, $responseElement, $validation, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true); |
|
208 | + public function postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
209 | + return $this->js->_postForm($url, $form, $responseElement, $validation, $jsCallback, NULL, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
222 | 222 | * @param string|callable $ajaxTransition |
223 | 223 | */ |
224 | - public function postFormDeferred($url, $form, $responseElement, $validation=false, $jsCallback=NULL,$attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
225 | - return $this->js->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false); |
|
224 | + public function postFormDeferred($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
225 | + return $this->js->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, false); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null) |
237 | 237 | */ |
238 | 238 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
239 | - return $this->js->_postFormOn($event,$element, $url, $form, $responseElement, $parameters); |
|
239 | + return $this->js->_postFormOn($event, $element, $url, $form, $responseElement, $parameters); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -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) && \method_exists("Ajax\service\AjaxTransition",$params)){ |
|
59 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
60 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
58 | + if (!\is_callable($params) && \method_exists("Ajax\service\AjaxTransition", $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 |