@@ -15,6 +15,7 @@ |
||
15 | 15 | * {@inheritdoc} |
16 | 16 | * |
17 | 17 | * @see \Ajax\semantic\widgets\dataform\DataForm::__construct() |
18 | + * @param string $identifier |
|
18 | 19 | */ |
19 | 20 | public function __construct($identifier,$modelInstance=null,$fieldsOrder,$fieldsDefinition,$fields=[],$captions=[],$separators=[]) { |
20 | 21 | if(!isset($modelInstance)){ |
@@ -16,17 +16,17 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @see \Ajax\semantic\widgets\dataform\DataForm::__construct() |
18 | 18 | */ |
19 | - public function __construct($identifier,$modelInstance=null,$fieldsOrder,$fieldsDefinition,$fields=[],$captions=[],$separators=[]) { |
|
20 | - if(!isset($modelInstance)){ |
|
19 | + public function __construct($identifier, $modelInstance=null, $fieldsOrder, $fieldsDefinition, $fields=[], $captions=[], $separators=[]) { |
|
20 | + if (!isset($modelInstance)) { |
|
21 | 21 | $modelInstance=$this->getDefaultModelInstance(); |
22 | 22 | } |
23 | - parent::__construct($identifier,$modelInstance); |
|
24 | - $this->_initForm($fieldsOrder, $fieldsDefinition,$fields,$captions,$separators); |
|
23 | + parent::__construct($identifier, $modelInstance); |
|
24 | + $this->_initForm($fieldsOrder, $fieldsDefinition, $fields, $captions, $separators); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | abstract protected function getDefaultModelInstance(); |
28 | 28 | |
29 | - protected function _initForm($fieldsOrder,$fieldsDefinition,$fields=[],$captions=[],$separators=[]){ |
|
29 | + protected function _initForm($fieldsOrder, $fieldsDefinition, $fields=[], $captions=[], $separators=[]) { |
|
30 | 30 | $this->_fieldsOrder=$fieldsOrder; |
31 | 31 | $this->setFields($fields); |
32 | 32 | $this->setSeparators($separators); |
@@ -34,26 +34,26 @@ discard block |
||
34 | 34 | $this->setCaptions($captions); |
35 | 35 | } |
36 | 36 | |
37 | - protected function _getIndex($fieldName){ |
|
37 | + protected function _getIndex($fieldName) { |
|
38 | 38 | $index=$fieldName; |
39 | - if(\is_string($fieldName)){ |
|
39 | + if (\is_string($fieldName)) { |
|
40 | 40 | $index=\array_search($fieldName, $this->_fieldsOrder); |
41 | 41 | } |
42 | 42 | return $index; |
43 | 43 | } |
44 | - protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){ |
|
44 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
45 | 45 | $index=$this->_getIndex($index); |
46 | - return parent::_fieldAs($elementCallback, $index,$attributes,$prefix); |
|
46 | + return parent::_fieldAs($elementCallback, $index, $attributes, $prefix); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | |
50 | - public function removeField($fieldName){ |
|
50 | + public function removeField($fieldName) { |
|
51 | 51 | parent::removeField($fieldName); |
52 | - \array_splice($this->_fieldsOrder,$this->_getIndex($fieldName),1); |
|
52 | + \array_splice($this->_fieldsOrder, $this->_getIndex($fieldName), 1); |
|
53 | 53 | return $this; |
54 | 54 | } |
55 | 55 | |
56 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
57 | - return parent::compile($js,$view); |
|
56 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
57 | + return parent::compile($js, $view); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | \ No newline at end of file |
@@ -121,6 +121,10 @@ |
||
121 | 121 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
122 | 122 | } |
123 | 123 | |
124 | + /** |
|
125 | + * @param integer $index |
|
126 | + * @param string $title |
|
127 | + */ |
|
124 | 128 | public function addDividerBefore($index,$title){ |
125 | 129 | $index=$this->_getIndex($index); |
126 | 130 | $this->_instanceViewer->addHeaderDividerBefore($index, $title); |
@@ -19,55 +19,55 @@ 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){ |
|
32 | - if(!$this->_generated){ |
|
31 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
32 | + if (!$this->_generated) { |
|
33 | 33 | $this->_instanceViewer->setInstance($this->_modelInstance); |
34 | 34 | |
35 | 35 | $form=$this->content["form"]; |
36 | 36 | $this->_generateContent($form); |
37 | 37 | |
38 | - if(isset($this->_toolbar)){ |
|
38 | + if (isset($this->_toolbar)) { |
|
39 | 39 | $this->_setToolbarPosition($form); |
40 | 40 | } |
41 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]); |
|
41 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "form", PositionInTable::AFTERTABLE]); |
|
42 | 42 | $this->_generated=true; |
43 | 43 | } |
44 | - return parent::compile($js,$view); |
|
44 | + return parent::compile($js, $view); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @param HtmlForm $form |
49 | 49 | */ |
50 | - protected function _generateContent($form){ |
|
51 | - $values= $this->_instanceViewer->getValues(); |
|
50 | + protected function _generateContent($form) { |
|
51 | + $values=$this->_instanceViewer->getValues(); |
|
52 | 52 | $count=$this->_instanceViewer->count(); |
53 | 53 | $separators=$this->_instanceViewer->getSeparators(); |
54 | 54 | $headers=$this->_instanceViewer->getHeaders(); |
55 | 55 | \sort($separators); |
56 | 56 | $size=\sizeof($separators); |
57 | - if($size===1){ |
|
58 | - foreach ($values as $v){ |
|
57 | + if ($size===1) { |
|
58 | + foreach ($values as $v) { |
|
59 | 59 | $form->addField($v); |
60 | 60 | } |
61 | - }else{ |
|
61 | + } else { |
|
62 | 62 | $separators[]=$count; |
63 | - for($i=0;$i<$size;$i++){ |
|
64 | - $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
|
65 | - if(isset($headers[$separators[$i]+1])) |
|
66 | - $form->addHeader($headers[$separators[$i]+1],4,true); |
|
63 | + for ($i=0; $i<$size; $i++) { |
|
64 | + $fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]); |
|
65 | + if (isset($headers[$separators[$i]+1])) |
|
66 | + $form->addHeader($headers[$separators[$i]+1], 4, true); |
|
67 | 67 | //TODO check why $fields is empty |
68 | - if(\sizeof($fields)===1){ |
|
68 | + if (\sizeof($fields)===1) { |
|
69 | 69 | $form->addField($fields[0]); |
70 | - }elseif(\sizeof($fields)>1){ |
|
70 | + }elseif (\sizeof($fields)>1) { |
|
71 | 71 | $form->addFields($fields); |
72 | 72 | } |
73 | 73 | } |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | * {@inheritDoc} |
79 | 79 | * @see \Ajax\common\Widget::getForm() |
80 | 80 | */ |
81 | - public function getForm(){ |
|
81 | + public function getForm() { |
|
82 | 82 | return $this->content["form"]; |
83 | 83 | } |
84 | 84 | |
85 | - public function addSeparatorAfter($fieldNum){ |
|
85 | + public function addSeparatorAfter($fieldNum) { |
|
86 | 86 | $fieldNum=$this->_getIndex($fieldNum); |
87 | 87 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
88 | 88 | return $this; |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | return $this; |
98 | 98 | } |
99 | 99 | |
100 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
101 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
102 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
100 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
101 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
102 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
103 | 103 | $button->setProperty("type", "reset"); |
104 | 104 | return $button; |
105 | - }, $index,$attributes); |
|
105 | + }, $index, $attributes); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
122 | 122 | } |
123 | 123 | |
124 | - public function addDividerBefore($index,$title){ |
|
124 | + public function addDividerBefore($index, $title) { |
|
125 | 125 | $index=$this->_getIndex($index); |
126 | 126 | $this->_instanceViewer->addHeaderDividerBefore($index, $title); |
127 | 127 | return $this; |
128 | 128 | } |
129 | 129 | |
130 | - public function run(JsUtils $js){ |
|
130 | + public function run(JsUtils $js) { |
|
131 | 131 | return parent::run($js); |
132 | 132 | } |
133 | 133 | } |
134 | 134 | \ No newline at end of file |
@@ -58,16 +58,17 @@ |
||
58 | 58 | foreach ($values as $v){ |
59 | 59 | $form->addField($v); |
60 | 60 | } |
61 | - }else{ |
|
61 | + } else{ |
|
62 | 62 | $separators[]=$count; |
63 | 63 | for($i=0;$i<$size;$i++){ |
64 | 64 | $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
65 | - if(isset($headers[$separators[$i]+1])) |
|
66 | - $form->addHeader($headers[$separators[$i]+1],4,true); |
|
65 | + if(isset($headers[$separators[$i]+1])) { |
|
66 | + $form->addHeader($headers[$separators[$i]+1],4,true); |
|
67 | + } |
|
67 | 68 | //TODO check why $fields is empty |
68 | 69 | if(\sizeof($fields)===1){ |
69 | 70 | $form->addField($fields[0]); |
70 | - }elseif(\sizeof($fields)>1){ |
|
71 | + } elseif(\sizeof($fields)>1){ |
|
71 | 72 | $form->addFields($fields); |
72 | 73 | } |
73 | 74 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | use Ajax\semantic\html\modules\HtmlModal; |
21 | 21 | |
22 | 22 | abstract class Widget extends HtmlDoubleElement { |
23 | - use FieldAsTrait,FormTrait; |
|
23 | + use FieldAsTrait, FormTrait; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @var string classname |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | protected $_generated; |
54 | 54 | |
55 | 55 | |
56 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
56 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
57 | 57 | parent::__construct($identifier); |
58 | 58 | $this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
59 | 59 | $this->setModel($model); |
60 | - if(isset($modelInstance)){ |
|
61 | - if(\is_array($modelInstance)){ |
|
60 | + if (isset($modelInstance)) { |
|
61 | + if (\is_array($modelInstance)) { |
|
62 | 62 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
63 | 63 | } |
64 | 64 | $this->show($modelInstance); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->_generated=false; |
67 | 67 | } |
68 | 68 | |
69 | - protected function _init($instanceViewer,$contentKey,$content,$edition){ |
|
69 | + protected function _init($instanceViewer, $contentKey, $content, $edition) { |
|
70 | 70 | $this->_instanceViewer=$instanceViewer; |
71 | 71 | $this->content=[$contentKey=>$content]; |
72 | 72 | $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
@@ -77,25 +77,25 @@ discard block |
||
77 | 77 | * @param int|string $fieldName |
78 | 78 | * @return int|string |
79 | 79 | */ |
80 | - protected function _getIndex($fieldName){ |
|
80 | + protected function _getIndex($fieldName) { |
|
81 | 81 | return $fieldName; |
82 | 82 | } |
83 | 83 | |
84 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
84 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
85 | 85 | return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
86 | 86 | } |
87 | 87 | |
88 | - protected function _getFieldName($index){ |
|
88 | + protected function _getFieldName($index) { |
|
89 | 89 | return $this->_instanceViewer->getFieldName($index); |
90 | 90 | } |
91 | 91 | |
92 | - protected function _getFieldCaption($index){ |
|
92 | + protected function _getFieldCaption($index) { |
|
93 | 93 | return $this->_instanceViewer->getCaption($index); |
94 | 94 | } |
95 | 95 | |
96 | - abstract protected function _setToolbarPosition($table,$captions=NULL); |
|
96 | + abstract protected function _setToolbarPosition($table, $captions=NULL); |
|
97 | 97 | |
98 | - public function show($modelInstance){ |
|
98 | + public function show($modelInstance) { |
|
99 | 99 | $this->_modelInstance=$modelInstance; |
100 | 100 | } |
101 | 101 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | abstract public function getHtmlComponent(); |
121 | 121 | |
122 | - public function setAttached($value=true){ |
|
122 | + public function setAttached($value=true) { |
|
123 | 123 | return $this->getHtmlComponent()->setAttached($value); |
124 | 124 | } |
125 | 125 | |
@@ -130,66 +130,66 @@ discard block |
||
130 | 130 | * @param callable $callback function called after the field compilation |
131 | 131 | * @return Widget |
132 | 132 | */ |
133 | - public function afterCompile($index,$callback){ |
|
133 | + public function afterCompile($index, $callback) { |
|
134 | 134 | $index=$this->_getIndex($index); |
135 | 135 | $this->_instanceViewer->afterCompile($index, $callback); |
136 | 136 | return $this; |
137 | 137 | } |
138 | 138 | |
139 | - public function setColor($color){ |
|
139 | + public function setColor($color) { |
|
140 | 140 | return $this->getHtmlComponent()->setColor($color); |
141 | 141 | } |
142 | 142 | |
143 | 143 | |
144 | - public function setCaptions($captions){ |
|
144 | + public function setCaptions($captions) { |
|
145 | 145 | $this->_instanceViewer->setCaptions($captions); |
146 | 146 | return $this; |
147 | 147 | } |
148 | 148 | |
149 | - public function setCaption($index,$caption){ |
|
149 | + public function setCaption($index, $caption) { |
|
150 | 150 | $this->_instanceViewer->setCaption($this->_getIndex($index), $caption); |
151 | 151 | return $this; |
152 | 152 | } |
153 | 153 | |
154 | - public function setFields($fields){ |
|
154 | + public function setFields($fields) { |
|
155 | 155 | $this->_instanceViewer->setVisibleProperties($fields); |
156 | 156 | return $this; |
157 | 157 | } |
158 | 158 | |
159 | - public function addField($field){ |
|
159 | + public function addField($field) { |
|
160 | 160 | $this->_instanceViewer->addField($field); |
161 | 161 | return $this; |
162 | 162 | } |
163 | 163 | |
164 | - public function addMessage($attributes=NULL,$fieldName="message"){ |
|
164 | + public function addMessage($attributes=NULL, $fieldName="message") { |
|
165 | 165 | $this->_instanceViewer->addField($fieldName); |
166 | 166 | $count=$this->_instanceViewer->visiblePropertiesCount(); |
167 | - return $this->fieldAsMessage($count-1,$attributes); |
|
167 | + return $this->fieldAsMessage($count-1, $attributes); |
|
168 | 168 | } |
169 | 169 | |
170 | - public function addErrorMessage(){ |
|
171 | - return $this->addMessage(["error"=>true],"message"); |
|
170 | + public function addErrorMessage() { |
|
171 | + return $this->addMessage(["error"=>true], "message"); |
|
172 | 172 | } |
173 | 173 | |
174 | - public function insertField($index,$field){ |
|
174 | + public function insertField($index, $field) { |
|
175 | 175 | $index=$this->_getIndex($index); |
176 | 176 | $this->_instanceViewer->insertField($index, $field); |
177 | 177 | return $this; |
178 | 178 | } |
179 | 179 | |
180 | - public function insertInField($index,$field){ |
|
180 | + public function insertInField($index, $field) { |
|
181 | 181 | $index=$this->_getIndex($index); |
182 | 182 | $this->_instanceViewer->insertInField($index, $field); |
183 | 183 | return $this; |
184 | 184 | } |
185 | 185 | |
186 | - public function setValueFunction($index,$callback){ |
|
186 | + public function setValueFunction($index, $callback) { |
|
187 | 187 | $index=$this->_getIndex($index); |
188 | 188 | $this->_instanceViewer->setValueFunction($index, $callback); |
189 | 189 | return $this; |
190 | 190 | } |
191 | 191 | |
192 | - public function setIdentifierFunction($callback){ |
|
192 | + public function setIdentifierFunction($callback) { |
|
193 | 193 | $this->_instanceViewer->setIdentifierFunction($callback); |
194 | 194 | return $this; |
195 | 195 | } |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | /** |
198 | 198 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
199 | 199 | */ |
200 | - public function getToolbar(){ |
|
201 | - if(isset($this->_toolbar)===false){ |
|
200 | + public function getToolbar() { |
|
201 | + if (isset($this->_toolbar)===false) { |
|
202 | 202 | $this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
203 | 203 | } |
204 | 204 | return $this->_toolbar; |
@@ -210,15 +210,15 @@ discard block |
||
210 | 210 | * @param callable $callback function to call on $element |
211 | 211 | * @return \Ajax\common\html\HtmlDoubleElement |
212 | 212 | */ |
213 | - public function addInToolbar($element,$callback=NULL){ |
|
213 | + public function addInToolbar($element, $callback=NULL) { |
|
214 | 214 | $tb=$this->getToolbar(); |
215 | - if($element instanceof BaseWidget){ |
|
216 | - if($element->getIdentifier()===""){ |
|
215 | + if ($element instanceof BaseWidget) { |
|
216 | + if ($element->getIdentifier()==="") { |
|
217 | 217 | $element->setIdentifier("tb-item-".$this->identifier."-".$tb->count()); |
218 | 218 | } |
219 | 219 | } |
220 | - if(isset($callback)){ |
|
221 | - if(\is_callable($callback)){ |
|
220 | + if (isset($callback)) { |
|
221 | + if (\is_callable($callback)) { |
|
222 | 222 | $callback($element); |
223 | 223 | } |
224 | 224 | } |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | * @param callable $callback function($element) |
232 | 232 | * @return \Ajax\common\html\HtmlDoubleElement |
233 | 233 | */ |
234 | - public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){ |
|
235 | - $result=$this->addInToolbar($caption,$callback); |
|
236 | - if(isset($icon)) |
|
234 | + public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) { |
|
235 | + $result=$this->addInToolbar($caption, $callback); |
|
236 | + if (isset($icon)) |
|
237 | 237 | $result->addIcon($icon); |
238 | 238 | return $result; |
239 | 239 | } |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | * @param callable $callback function($element) |
244 | 244 | * @return \Ajax\common\Widget |
245 | 245 | */ |
246 | - public function addItemsInToolbar(array $items,$callback=NULL){ |
|
247 | - if(JArray::isAssociative($items)){ |
|
248 | - foreach ($items as $icon=>$item){ |
|
249 | - $this->addItemInToolbar($item,$icon,$callback); |
|
246 | + public function addItemsInToolbar(array $items, $callback=NULL) { |
|
247 | + if (JArray::isAssociative($items)) { |
|
248 | + foreach ($items as $icon=>$item) { |
|
249 | + $this->addItemInToolbar($item, $icon, $callback); |
|
250 | 250 | } |
251 | - }else{ |
|
252 | - foreach ($items as $item){ |
|
253 | - $this->addItemInToolbar($item,null,$callback); |
|
251 | + } else { |
|
252 | + foreach ($items as $item) { |
|
253 | + $this->addItemInToolbar($item, null, $callback); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | return $this; |
@@ -262,12 +262,12 @@ discard block |
||
262 | 262 | * @param callable $callback function($element) |
263 | 263 | * @return \Ajax\common\html\HtmlDoubleElement |
264 | 264 | */ |
265 | - public function addDropdownInToolbar($value,$items,$callback=NULL){ |
|
265 | + public function addDropdownInToolbar($value, $items, $callback=NULL) { |
|
266 | 266 | $dd=$value; |
267 | 267 | if (\is_string($value)) { |
268 | - $dd=new HtmlDropdown("dropdown-". $this->identifier."-".$value, $value, $items); |
|
268 | + $dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items); |
|
269 | 269 | } |
270 | - return $this->addInToolbar($dd,$callback); |
|
270 | + return $this->addInToolbar($dd, $callback); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | * @param callable $callback function($element) |
277 | 277 | * @return \Ajax\common\html\HtmlDoubleElement |
278 | 278 | */ |
279 | - public function addButtonInToolbar($caption,$cssStyle=null,$callback=NULL){ |
|
280 | - $bt=new HtmlButton("bt-".$caption,$caption,$cssStyle); |
|
281 | - return $this->addInToolbar($bt,$callback); |
|
279 | + public function addButtonInToolbar($caption, $cssStyle=null, $callback=NULL) { |
|
280 | + $bt=new HtmlButton("bt-".$caption, $caption, $cssStyle); |
|
281 | + return $this->addInToolbar($bt, $callback); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | * @param callable $callback function($element) |
288 | 288 | * @return \Ajax\common\html\HtmlDoubleElement |
289 | 289 | */ |
290 | - public function addButtonsInToolbar(array $captions,$asIcon=false,$callback=NULL){ |
|
291 | - $bts=new HtmlButtonGroups("",$captions,$asIcon); |
|
292 | - return $this->addInToolbar($bts,$callback); |
|
290 | + public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) { |
|
291 | + $bts=new HtmlButtonGroups("", $captions, $asIcon); |
|
292 | + return $this->addInToolbar($bts, $callback); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -299,15 +299,15 @@ discard block |
||
299 | 299 | * @param boolean $labeled |
300 | 300 | * @return \Ajax\common\html\HtmlDoubleElement |
301 | 301 | */ |
302 | - public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
|
303 | - $bt=new HtmlButton("",$caption); |
|
304 | - $bt->addIcon($icon,$before,$labeled); |
|
302 | + public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) { |
|
303 | + $bt=new HtmlButton("", $caption); |
|
304 | + $bt->addIcon($icon, $before, $labeled); |
|
305 | 305 | return $this->addInToolbar($bt); |
306 | 306 | } |
307 | 307 | |
308 | - public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){ |
|
309 | - $button=new HtmlButton($identifier,$value,$cssStyle); |
|
310 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,$parameters); |
|
308 | + public function addSubmitInToolbar($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
309 | + $button=new HtmlButton($identifier, $value, $cssStyle); |
|
310 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, $parameters); |
|
311 | 311 | return $this->addInToolbar($button); |
312 | 312 | } |
313 | 313 | |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | * @param callable $defaultValueFunction function parameters are : $name : the field name, $value : the field value ,$index : the field index, $instance : the active instance of model |
338 | 338 | * @return \Ajax\common\Widget |
339 | 339 | */ |
340 | - public function setDefaultValueFunction($defaultValueFunction){ |
|
340 | + public function setDefaultValueFunction($defaultValueFunction) { |
|
341 | 341 | $this->_instanceViewer->setDefaultValueFunction($defaultValueFunction); |
342 | 342 | return $this; |
343 | 343 | } |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @param string|boolean $disable |
347 | 347 | * @return string |
348 | 348 | */ |
349 | - public function jsDisabled($disable=true){ |
|
349 | + public function jsDisabled($disable=true) { |
|
350 | 350 | return "$('#".$this->identifier." .ui.input,#".$this->identifier." .ui.dropdown,#".$this->identifier." .ui.checkbox').toggleClass('disabled',".$disable.");"; |
351 | 351 | } |
352 | 352 | |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | * @param callable $callback function($element) |
356 | 356 | * @return \Ajax\common\html\HtmlDoubleElement |
357 | 357 | */ |
358 | - public function addEditButtonInToolbar($caption,$callback=NULL){ |
|
359 | - $bt=new HtmlButton($this->identifier."-editBtn",$caption); |
|
358 | + public function addEditButtonInToolbar($caption, $callback=NULL) { |
|
359 | + $bt=new HtmlButton($this->identifier."-editBtn", $caption); |
|
360 | 360 | $bt->setToggle(); |
361 | 361 | $bt->setActive($this->_edition); |
362 | 362 | $bt->onClick($this->jsDisabled(Javascript::prep_value("!$(event.target).hasClass('active')"))); |
363 | - return $this->addInToolbar($bt,$callback); |
|
363 | + return $this->addInToolbar($bt, $callback); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | public function setToolbar(HtmlMenu $_toolbar) { |
@@ -374,35 +374,35 @@ discard block |
||
374 | 374 | } |
375 | 375 | |
376 | 376 | public function getForm() { |
377 | - if(!isset($this->_form)){ |
|
377 | + if (!isset($this->_form)) { |
|
378 | 378 | $this->_form=new HtmlForm("frm-".$this->identifier); |
379 | 379 | $this->setEdition(true); |
380 | 380 | } |
381 | 381 | return $this->_form; |
382 | 382 | } |
383 | 383 | |
384 | - public function run(JsUtils $js){ |
|
384 | + public function run(JsUtils $js) { |
|
385 | 385 | $result=parent::run($js); |
386 | - if(isset($this->_form)){ |
|
386 | + if (isset($this->_form)) { |
|
387 | 387 | $result=$this->runForm($js); |
388 | 388 | } |
389 | 389 | return $result; |
390 | 390 | } |
391 | 391 | |
392 | - protected function runForm(JsUtils $js){ |
|
392 | + protected function runForm(JsUtils $js) { |
|
393 | 393 | $fields=$this->getContentInstances(HtmlFormField::class); |
394 | - foreach ($fields as $field){ |
|
394 | + foreach ($fields as $field) { |
|
395 | 395 | $this->_form->addField($field); |
396 | 396 | } |
397 | 397 | return $this->_form->run($js); |
398 | 398 | } |
399 | 399 | |
400 | - protected function _compileForm(){ |
|
401 | - if(isset($this->_form)){ |
|
400 | + protected function _compileForm() { |
|
401 | + if (isset($this->_form)) { |
|
402 | 402 | $noValidate=""; |
403 | - if(\sizeof($this->_form->getValidationParams())>0) |
|
403 | + if (\sizeof($this->_form->getValidationParams())>0) |
|
404 | 404 | $noValidate="novalidate"; |
405 | - $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">","</form>"); |
|
405 | + $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">", "</form>"); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
@@ -411,26 +411,26 @@ discard block |
||
411 | 411 | return $this; |
412 | 412 | } |
413 | 413 | |
414 | - public function moveFieldTo($from,$to){ |
|
414 | + public function moveFieldTo($from, $to) { |
|
415 | 415 | return $this->_instanceViewer->moveFieldTo($from, $to); |
416 | 416 | } |
417 | 417 | |
418 | - public function swapFields($index1,$index2){ |
|
418 | + public function swapFields($index1, $index2) { |
|
419 | 419 | $index1=$this->_getIndex($index1); |
420 | 420 | $index2=$this->_getIndex($index2); |
421 | 421 | return $this->_instanceViewer->swapFields($index1, $index2); |
422 | 422 | } |
423 | 423 | |
424 | - public function removeField($index){ |
|
424 | + public function removeField($index) { |
|
425 | 425 | $index=$this->_getIndex($index); |
426 | 426 | $this->_instanceViewer->removeField($index); |
427 | 427 | return $this; |
428 | 428 | } |
429 | 429 | |
430 | - public function asModal($header){ |
|
431 | - $modal=new HtmlModal("modal-".$this->identifier,$header); |
|
430 | + public function asModal($header) { |
|
431 | + $modal=new HtmlModal("modal-".$this->identifier, $header); |
|
432 | 432 | $modal->setContent($this); |
433 | - if(isset($this->_form)){ |
|
433 | + if (isset($this->_form)) { |
|
434 | 434 | $this->_form->onSuccess($modal->jsHide()); |
435 | 435 | } |
436 | 436 | return $modal; |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | protected $ajaxTransition; |
18 | 18 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
19 | 19 | |
20 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
20 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
21 | 21 | protected function addLoading(&$retour, $responseElement) { |
22 | 22 | $loading_notifier='<div class="ajax-loader">'; |
23 | 23 | if ($this->ajaxLoader=='') { |
@@ -30,66 +30,66 @@ discard block |
||
30 | 30 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
31 | 31 | } |
32 | 32 | |
33 | - public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
34 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
33 | + public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
34 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
35 | 35 | } |
36 | - public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
37 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
36 | + public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
37 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
38 | 38 | } |
39 | 39 | |
40 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
41 | - if(JString::isNull($params)){$params="{}";} |
|
40 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
41 | + if (JString::isNull($params)) {$params="{}"; } |
|
42 | 42 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
43 | 43 | $retour=$this->_getAjaxUrl($url, $attr); |
44 | 44 | $responseElement=$this->_getResponseElement($responseElement); |
45 | 45 | $retour.="var self=this;\n"; |
46 | - if($hasLoader===true){ |
|
46 | + if ($hasLoader===true) { |
|
47 | 47 | $this->addLoading($retour, $responseElement); |
48 | 48 | } |
49 | 49 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
50 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
51 | 51 | if ($immediatly) |
52 | 52 | $this->jquery_code_for_compile[]=$retour; |
53 | 53 | return $retour; |
54 | 54 | } |
55 | 55 | |
56 | - protected function setAjaxDataCall($params){ |
|
56 | + protected function setAjaxDataCall($params) { |
|
57 | 57 | $result=null; |
58 | - if(!\is_callable($params)){ |
|
59 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
60 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
58 | + if (!\is_callable($params)) { |
|
59 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
60 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
61 | 61 | }; |
62 | 62 | } |
63 | 63 | return $result; |
64 | 64 | } |
65 | 65 | |
66 | - protected function _getAjaxUrl($url,$attr){ |
|
66 | + protected function _getAjaxUrl($url, $attr) { |
|
67 | 67 | $url=$this->_correctAjaxUrl($url); |
68 | 68 | $retour="url='".$url."';"; |
69 | 69 | $slash="/"; |
70 | - if(JString::endswith($url, "/")===true) |
|
70 | + if (JString::endswith($url, "/")===true) |
|
71 | 71 | $slash=""; |
72 | - if(JString::isNotNull($attr)){ |
|
72 | + if (JString::isNotNull($attr)) { |
|
73 | 73 | if ($attr==="value") |
74 | 74 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
75 | 75 | elseif ($attr==="html") |
76 | 76 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
77 | - elseif($attr!=null && $attr!=="") |
|
77 | + elseif ($attr!=null && $attr!=="") |
|
78 | 78 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
79 | 79 | } |
80 | 80 | return $retour; |
81 | 81 | } |
82 | 82 | |
83 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
84 | - $retour="";$call=null; |
|
83 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
84 | + $retour=""; $call=null; |
|
85 | 85 | if ($responseElement!=="") { |
86 | - if(isset($ajaxTransition)){ |
|
86 | + if (isset($ajaxTransition)) { |
|
87 | 87 | $call=$this->setAjaxDataCall($ajaxTransition); |
88 | - }elseif(isset($this->ajaxTransition)){ |
|
88 | + }elseif (isset($this->ajaxTransition)) { |
|
89 | 89 | $call=$this->ajaxTransition; |
90 | 90 | } |
91 | - if(\is_callable($call)) |
|
92 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
91 | + if (\is_callable($call)) |
|
92 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
93 | 93 | else |
94 | 94 | $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
95 | 95 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | return $retour; |
98 | 98 | } |
99 | 99 | |
100 | - protected function _getResponseElement($responseElement){ |
|
100 | + protected function _getResponseElement($responseElement) { |
|
101 | 101 | if ($responseElement!=="") { |
102 | 102 | $responseElement=Javascript::prep_value($responseElement); |
103 | 103 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | protected function _correctAjaxUrl($url) { |
108 | 108 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
109 | 109 | $url=substr($url, 0, strlen($url)-1); |
110 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
110 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
111 | 111 | $url=$this->jsUtils->getUrl($url); |
112 | 112 | } |
113 | 113 | return $url; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param string $jsCallback javascript code to execute after the request |
122 | 122 | * @param boolean $immediatly |
123 | 123 | */ |
124 | - public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
124 | + public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
125 | 125 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
126 | 126 | $retour=$this->_getAjaxUrl($url, $attr); |
127 | 127 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string $url the request address |
143 | 143 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
144 | 144 | */ |
145 | - public function _jsonOn($event,$element, $url,$parameters=array()) { |
|
145 | + public function _jsonOn($event, $element, $url, $parameters=array()) { |
|
146 | 146 | $preventDefault=true; |
147 | 147 | $stopPropagation=true; |
148 | 148 | $jsCallback=null; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $params="{}"; |
153 | 153 | $immediatly=true; |
154 | 154 | extract($parameters); |
155 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
155 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | * @param string $context jquery DOM element, array container. |
165 | 165 | * @param boolean $immediatly |
166 | 166 | */ |
167 | - public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null,$immediatly=false) { |
|
167 | + public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null, $immediatly=false) { |
|
168 | 168 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
169 | 169 | $retour=$this->_getAjaxUrl($url, $attr); |
170 | - if($context===null){ |
|
170 | + if ($context===null) { |
|
171 | 171 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
172 | - $newElm = "$('#'+newId)"; |
|
173 | - }else{ |
|
172 | + $newElm="$('#'+newId)"; |
|
173 | + } else { |
|
174 | 174 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
175 | - $newElm = $context.".find('#'+newId)"; |
|
175 | + $newElm=$context.".find('#'+newId)"; |
|
176 | 176 | } |
177 | 177 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
178 | 178 | $retour.="\tdata=$.parseJSON(data);$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone();newElm.attr('id',newId);\n"; |
179 | - $retour.= $appendTo; |
|
179 | + $retour.=$appendTo; |
|
180 | 180 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('[['+key+']]')>-1){\n"."\t\t\t\tcontent=$(html.split('[['+key+']]').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
181 | 181 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
182 | 182 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -191,30 +191,30 @@ discard block |
||
191 | 191 | * @param string $url the request address |
192 | 192 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get", "context"=>null) |
193 | 193 | */ |
194 | - public function _jsonArrayOn($event,$element, $maskSelector,$url,$parameters=array()) { |
|
194 | + public function _jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
195 | 195 | $preventDefault=true; |
196 | 196 | $stopPropagation=true; |
197 | 197 | $jsCallback=null; |
198 | 198 | $attr="id"; |
199 | 199 | $method="get"; |
200 | - $context = null; |
|
200 | + $context=null; |
|
201 | 201 | $params="{}"; |
202 | 202 | $immediatly=true; |
203 | 203 | extract($parameters); |
204 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
204 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
205 | 205 | } |
206 | 206 | |
207 | - public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
207 | + public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
208 | 208 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
209 | 209 | $retour=$this->_getAjaxUrl($url, $attr); |
210 | 210 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
211 | 211 | $responseElement=$this->_getResponseElement($responseElement); |
212 | 212 | $retour.="var self=this;\n"; |
213 | - if($hasLoader===true){ |
|
213 | + if ($hasLoader===true) { |
|
214 | 214 | $this->addLoading($retour, $responseElement); |
215 | 215 | } |
216 | 216 | $retour.="$.post(url,params).done(function( data ) {\n"; |
217 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
217 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
218 | 218 | |
219 | 219 | if ($validation) { |
220 | 220 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @param string $responseElement |
238 | 238 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null,"jqueryDone"=>"html") |
239 | 239 | */ |
240 | - public function _getOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
240 | + public function _getOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
241 | 241 | $preventDefault=true; |
242 | 242 | $stopPropagation=true; |
243 | 243 | $jsCallback=null; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $jqueryDone="html"; |
248 | 248 | $ajaxTransition=null; |
249 | 249 | extract($parameters); |
250 | - return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
250 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @param string $responseElement |
261 | 261 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null) |
262 | 262 | */ |
263 | - public function _postOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
263 | + public function _postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
264 | 264 | $preventDefault=true; |
265 | 265 | $stopPropagation=true; |
266 | 266 | $jsCallback=null; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | $jqueryDone="html"; |
271 | 271 | $ajaxTransition=null; |
272 | 272 | extract($parameters); |
273 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
273 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string $responseElement |
284 | 284 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null,"immediatly"=>true) |
285 | 285 | */ |
286 | - public function _postFormOn($event,$element, $url, $form, $responseElement="", $parameters=array()) { |
|
286 | + public function _postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
287 | 287 | $preventDefault=true; |
288 | 288 | $stopPropagation=true; |
289 | 289 | $validation=false; |
@@ -294,6 +294,6 @@ discard block |
||
294 | 294 | $jqueryDone="html"; |
295 | 295 | $ajaxTransition=null; |
296 | 296 | extract($parameters); |
297 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
297 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
298 | 298 | } |
299 | 299 | } |
300 | 300 | \ No newline at end of file |
@@ -48,8 +48,9 @@ discard block |
||
48 | 48 | } |
49 | 49 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
50 | 50 | $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
51 | - if ($immediatly) |
|
52 | - $this->jquery_code_for_compile[]=$retour; |
|
51 | + if ($immediatly) { |
|
52 | + $this->jquery_code_for_compile[]=$retour; |
|
53 | + } |
|
53 | 54 | return $retour; |
54 | 55 | } |
55 | 56 | |
@@ -67,15 +68,17 @@ discard block |
||
67 | 68 | $url=$this->_correctAjaxUrl($url); |
68 | 69 | $retour="url='".$url."';"; |
69 | 70 | $slash="/"; |
70 | - if(JString::endswith($url, "/")===true) |
|
71 | - $slash=""; |
|
71 | + if(JString::endswith($url, "/")===true) { |
|
72 | + $slash=""; |
|
73 | + } |
|
72 | 74 | if(JString::isNotNull($attr)){ |
73 | - if ($attr==="value") |
|
74 | - $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
75 | - elseif ($attr==="html") |
|
76 | - $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
77 | - elseif($attr!=null && $attr!=="") |
|
78 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
75 | + if ($attr==="value") { |
|
76 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
77 | + } elseif ($attr==="html") { |
|
78 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
79 | + } elseif($attr!=null && $attr!=="") { |
|
80 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
81 | + } |
|
79 | 82 | } |
80 | 83 | return $retour; |
81 | 84 | } |
@@ -85,13 +88,14 @@ discard block |
||
85 | 88 | if ($responseElement!=="") { |
86 | 89 | if(isset($ajaxTransition)){ |
87 | 90 | $call=$this->setAjaxDataCall($ajaxTransition); |
88 | - }elseif(isset($this->ajaxTransition)){ |
|
91 | + } elseif(isset($this->ajaxTransition)){ |
|
89 | 92 | $call=$this->ajaxTransition; |
90 | 93 | } |
91 | - if(\is_callable($call)) |
|
92 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
93 | - else |
|
94 | - $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
|
94 | + if(\is_callable($call)) { |
|
95 | + $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
96 | + } else { |
|
97 | + $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
|
98 | + } |
|
95 | 99 | } |
96 | 100 | $retour.="\t".$jsCallback."\n"; |
97 | 101 | return $retour; |
@@ -105,8 +109,9 @@ discard block |
||
105 | 109 | } |
106 | 110 | |
107 | 111 | protected function _correctAjaxUrl($url) { |
108 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
109 | - $url=substr($url, 0, strlen($url)-1); |
|
112 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
113 | + $url=substr($url, 0, strlen($url)-1); |
|
114 | + } |
|
110 | 115 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
111 | 116 | $url=$this->jsUtils->getUrl($url); |
112 | 117 | } |
@@ -130,8 +135,9 @@ discard block |
||
130 | 135 | $retour.="\t".$jsCallback."\n". |
131 | 136 | "\t$(document).trigger('jsonReady',[data]);\n". |
132 | 137 | "});\n"; |
133 | - if ($immediatly) |
|
134 | - $this->jquery_code_for_compile[]=$retour; |
|
138 | + if ($immediatly) { |
|
139 | + $this->jquery_code_for_compile[]=$retour; |
|
140 | + } |
|
135 | 141 | return $retour; |
136 | 142 | } |
137 | 143 | |
@@ -170,7 +176,7 @@ discard block |
||
170 | 176 | if($context===null){ |
171 | 177 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
172 | 178 | $newElm = "$('#'+newId)"; |
173 | - }else{ |
|
179 | + } else{ |
|
174 | 180 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
175 | 181 | $newElm = $context.".find('#'+newId)"; |
176 | 182 | } |
@@ -180,8 +186,9 @@ discard block |
||
180 | 186 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('[['+key+']]')>-1){\n"."\t\t\t\tcontent=$(html.split('[['+key+']]').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
181 | 187 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
182 | 188 | $retour.="\t".$jsCallback."\n"."});\n"; |
183 | - if ($immediatly) |
|
184 | - $this->jquery_code_for_compile[]=$retour; |
|
189 | + if ($immediatly) { |
|
190 | + $this->jquery_code_for_compile[]=$retour; |
|
191 | + } |
|
185 | 192 | return $retour; |
186 | 193 | } |
187 | 194 | /** |
@@ -222,8 +229,9 @@ discard block |
||
222 | 229 | }});\n"; |
223 | 230 | $retour.="$('#".$form."').submit();\n"; |
224 | 231 | } |
225 | - if ($immediatly) |
|
226 | - $this->jquery_code_for_compile[]=$retour; |
|
232 | + if ($immediatly) { |
|
233 | + $this->jquery_code_for_compile[]=$retour; |
|
234 | + } |
|
227 | 235 | return $retour; |
228 | 236 | } |
229 | 237 |
@@ -2,51 +2,51 @@ |
||
2 | 2 | namespace Ajax\service; |
3 | 3 | class JString { |
4 | 4 | |
5 | - public static function contains($hay,$needle){ |
|
6 | - return strpos($hay, $needle) !== false; |
|
5 | + public static function contains($hay, $needle) { |
|
6 | + return strpos($hay, $needle)!==false; |
|
7 | 7 | } |
8 | 8 | public static function startswith($hay, $needle) { |
9 | - return substr($hay, 0, strlen($needle)) === $needle; |
|
9 | + return substr($hay, 0, strlen($needle))===$needle; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | public static function endswith($hay, $needle) { |
13 | - return substr($hay, -strlen($needle)) === $needle; |
|
13 | + return substr($hay, -strlen($needle))===$needle; |
|
14 | 14 | } |
15 | 15 | |
16 | - public static function isNull($s){ |
|
16 | + public static function isNull($s) { |
|
17 | 17 | return (!isset($s) || NULL===$s || ""===$s); |
18 | 18 | } |
19 | - public static function isNotNull($s){ |
|
19 | + public static function isNotNull($s) { |
|
20 | 20 | return (isset($s) && NULL!==$s && ""!==$s); |
21 | 21 | } |
22 | 22 | |
23 | - public static function isBoolean($value){ |
|
23 | + public static function isBoolean($value) { |
|
24 | 24 | return \is_bool($value) || $value==1 || $value==0; |
25 | 25 | } |
26 | 26 | |
27 | - public static function isBooleanTrue($value){ |
|
27 | + public static function isBooleanTrue($value) { |
|
28 | 28 | return $value==1 || $value; |
29 | 29 | } |
30 | 30 | |
31 | - public static function isBooleanFalse($value){ |
|
31 | + public static function isBooleanFalse($value) { |
|
32 | 32 | return $value==0 || !$value; |
33 | 33 | } |
34 | 34 | |
35 | - public static function camelCaseToSeparated($input,$separator=" "){ |
|
35 | + public static function camelCaseToSeparated($input, $separator=" ") { |
|
36 | 36 | return strtolower(preg_replace('/(?<!^)[A-Z]/', $separator.'$0', $input)); |
37 | 37 | } |
38 | 38 | |
39 | - public static function replaceAtFirst($subject,$from, $to){ |
|
40 | - $from = '/\A'.preg_quote($from, '/').'/'; |
|
39 | + public static function replaceAtFirst($subject, $from, $to) { |
|
40 | + $from='/\A'.preg_quote($from, '/').'/'; |
|
41 | 41 | return \preg_replace($from, $to, $subject, 1); |
42 | 42 | } |
43 | 43 | |
44 | - public static function replaceAtLast($subject,$from, $to){ |
|
45 | - $from = '/'.preg_quote($from, '/').'\z/'; |
|
44 | + public static function replaceAtLast($subject, $from, $to) { |
|
45 | + $from='/'.preg_quote($from, '/').'\z/'; |
|
46 | 46 | return \preg_replace($from, $to, $subject, 1); |
47 | 47 | } |
48 | 48 | |
49 | - public static function replaceAtFirstAndLast($subject,$fromFirst,$toFirst,$fromLast,$toLast){ |
|
49 | + public static function replaceAtFirstAndLast($subject, $fromFirst, $toFirst, $fromLast, $toLast) { |
|
50 | 50 | $s=self::replaceAtFirst($subject, $fromFirst, $toFirst); |
51 | 51 | return self::replaceAtLast($s, $fromLast, $toLast); |
52 | 52 | } |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | * @param array $instances |
17 | 17 | * @return DataTable |
18 | 18 | */ |
19 | - public function dataTable($identifier,$model, $instances){ |
|
20 | - return $this->addHtmlComponent(new DataTable($identifier,$model,$instances)); |
|
19 | + public function dataTable($identifier, $model, $instances) { |
|
20 | + return $this->addHtmlComponent(new DataTable($identifier, $model, $instances)); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | * @param object $instance |
26 | 26 | * @return DataElement |
27 | 27 | */ |
28 | - public function dataElement($identifier, $instance){ |
|
29 | - return $this->addHtmlComponent(new DataElement($identifier,$instance)); |
|
28 | + public function dataElement($identifier, $instance) { |
|
29 | + return $this->addHtmlComponent(new DataElement($identifier, $instance)); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -34,15 +34,15 @@ discard block |
||
34 | 34 | * @param object $instance |
35 | 35 | * @return DataForm |
36 | 36 | */ |
37 | - public function dataForm($identifier, $instance){ |
|
38 | - return $this->addHtmlComponent(new DataForm($identifier,$instance)); |
|
37 | + public function dataForm($identifier, $instance) { |
|
38 | + return $this->addHtmlComponent(new DataForm($identifier, $instance)); |
|
39 | 39 | } |
40 | 40 | |
41 | - public function defaultLogin($identifier,$instance=null){ |
|
42 | - return $this->addHtmlComponent(FormLogin::default($identifier,$instance)); |
|
41 | + public function defaultLogin($identifier, $instance=null) { |
|
42 | + return $this->addHtmlComponent(FormLogin::default($identifier, $instance)); |
|
43 | 43 | } |
44 | 44 | |
45 | - public function smallLogin($identifier,$instance=null){ |
|
46 | - return $this->addHtmlComponent(FormLogin::small($identifier,$instance)); |
|
45 | + public function smallLogin($identifier, $instance=null) { |
|
46 | + return $this->addHtmlComponent(FormLogin::small($identifier, $instance)); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | \ No newline at end of file |
@@ -25,23 +25,23 @@ discard block |
||
25 | 25 | * @property boolean $_edition |
26 | 26 | * @property mixed _modelInstance |
27 | 27 | */ |
28 | -trait FieldAsTrait{ |
|
28 | +trait FieldAsTrait { |
|
29 | 29 | |
30 | - abstract protected function _getFieldIdentifier($prefix,$name=""); |
|
31 | - abstract public function setValueFunction($index,$callback); |
|
30 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
31 | + abstract public function setValueFunction($index, $callback); |
|
32 | 32 | abstract protected function _getFieldName($index); |
33 | 33 | abstract protected function _getFieldCaption($index); |
34 | - abstract protected function _buttonAsSubmit(HtmlButton &$button,$event,$url,$responseElement=NULL,$parameters=NULL); |
|
34 | + abstract protected function _buttonAsSubmit(HtmlButton&$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @param HtmlFormField $element |
38 | 38 | * @param array $attributes |
39 | 39 | */ |
40 | - protected function _applyAttributes($element,&$attributes,$index){ |
|
41 | - if(isset($attributes["callback"])){ |
|
40 | + protected function _applyAttributes($element, &$attributes, $index) { |
|
41 | + if (isset($attributes["callback"])) { |
|
42 | 42 | $callback=$attributes["callback"]; |
43 | - if(\is_callable($callback)){ |
|
44 | - $callback($element,$this->_modelInstance,$index); |
|
43 | + if (\is_callable($callback)) { |
|
44 | + $callback($element, $this->_modelInstance, $index); |
|
45 | 45 | unset($attributes["callback"]); |
46 | 46 | } |
47 | 47 | } |
@@ -51,43 +51,43 @@ discard block |
||
51 | 51 | $element->fromArray($attributes); |
52 | 52 | } |
53 | 53 | |
54 | - private function _getLabelField($caption,$icon=NULL){ |
|
55 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
54 | + private function _getLabelField($caption, $icon=NULL) { |
|
55 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
56 | 56 | return $label; |
57 | 57 | } |
58 | 58 | |
59 | 59 | |
60 | - protected function _addRules($element,&$attributes){ |
|
61 | - if(isset($attributes["rules"])){ |
|
60 | + protected function _addRules($element, &$attributes) { |
|
61 | + if (isset($attributes["rules"])) { |
|
62 | 62 | $rules=$attributes["rules"]; |
63 | - if(\is_array($rules)){ |
|
63 | + if (\is_array($rules)) { |
|
64 | 64 | $element->addRules($rules); |
65 | 65 | } |
66 | - else{ |
|
66 | + else { |
|
67 | 67 | $element->addRule($rules); |
68 | 68 | } |
69 | 69 | unset($attributes["rules"]); |
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
73 | - protected function _prepareFormFields(&$field,$name,&$attributes){ |
|
73 | + protected function _prepareFormFields(&$field, $name, &$attributes) { |
|
74 | 74 | $field->setName($name); |
75 | 75 | $this->_addRules($field, $attributes); |
76 | 76 | return $field; |
77 | 77 | } |
78 | 78 | |
79 | - protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){ |
|
80 | - $this->setValueFunction($index,function($value,$instance,$index) use (&$attributes,$elementCallback,$prefix){ |
|
79 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
80 | + $this->setValueFunction($index, function($value, $instance, $index) use (&$attributes, $elementCallback, $prefix){ |
|
81 | 81 | $caption=$this->_getFieldCaption($index); |
82 | 82 | $name=$this->_getFieldName($index); |
83 | - $id=$this->_getFieldIdentifier($prefix,$name); |
|
84 | - if(isset($attributes["name"])){ |
|
83 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
84 | + if (isset($attributes["name"])) { |
|
85 | 85 | $name=$attributes["name"]; |
86 | 86 | unset($attributes["name"]); |
87 | 87 | } |
88 | - $element=$elementCallback($id,$name,$value,$caption); |
|
89 | - if(\is_array($attributes)){ |
|
90 | - $this->_applyAttributes($element, $attributes,$index); |
|
88 | + $element=$elementCallback($id, $name, $value, $caption); |
|
89 | + if (\is_array($attributes)) { |
|
90 | + $this->_applyAttributes($element, $attributes, $index); |
|
91 | 91 | } |
92 | 92 | $element->setDisabled(!$this->_edition); |
93 | 93 | return $element; |
@@ -96,169 +96,169 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
100 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
101 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
99 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
100 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
101 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
102 | 102 | return $pb; |
103 | 103 | }); |
104 | 104 | return $this; |
105 | 105 | } |
106 | 106 | |
107 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
108 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
109 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
107 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
108 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
109 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
110 | 110 | return $rating; |
111 | 111 | }); |
112 | 112 | return $this; |
113 | 113 | } |
114 | 114 | |
115 | - public function fieldAsLabel($index,$icon=NULL){ |
|
116 | - $this->setValueFunction($index,function($caption) use($icon){ |
|
117 | - $lbl=$this->_getLabelField($caption,$icon); |
|
115 | + public function fieldAsLabel($index, $icon=NULL) { |
|
116 | + $this->setValueFunction($index, function($caption) use($icon){ |
|
117 | + $lbl=$this->_getLabelField($caption, $icon); |
|
118 | 118 | return $lbl; |
119 | 119 | }); |
120 | 120 | return $this; |
121 | 121 | } |
122 | 122 | |
123 | - public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
|
124 | - return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
|
125 | - $header=new HtmlHeader($id,$niveau,$value); |
|
126 | - if(isset($icon)) |
|
123 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
124 | + return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){ |
|
125 | + $header=new HtmlHeader($id, $niveau, $value); |
|
126 | + if (isset($icon)) |
|
127 | 127 | $header->asIcon($icon, $value); |
128 | 128 | return $header; |
129 | - }, $index,$attributes,"header"); |
|
129 | + }, $index, $attributes, "header"); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
133 | - public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
|
134 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
135 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
133 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
134 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
135 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
136 | 136 | return $image; |
137 | 137 | }); |
138 | 138 | return $this; |
139 | 139 | } |
140 | 140 | |
141 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
142 | - return $this->_fieldAs(function($id,$name,$value){ |
|
143 | - $img=new HtmlImage($id,$value); |
|
141 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
142 | + return $this->_fieldAs(function($id, $name, $value) { |
|
143 | + $img=new HtmlImage($id, $value); |
|
144 | 144 | $img->asAvatar(); |
145 | 145 | return $img; |
146 | - }, $index,$attributes,"avatar"); |
|
146 | + }, $index, $attributes, "avatar"); |
|
147 | 147 | } |
148 | 148 | |
149 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
150 | - return $this->_fieldAs(function($id,$name,$value){ |
|
151 | - $input= new HtmlRadio($id,$name,$value,$value); |
|
149 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
150 | + return $this->_fieldAs(function($id, $name, $value) { |
|
151 | + $input=new HtmlRadio($id, $name, $value, $value); |
|
152 | 152 | return $input; |
153 | - }, $index,$attributes,"radio"); |
|
153 | + }, $index, $attributes, "radio"); |
|
154 | 154 | } |
155 | 155 | |
156 | - public function fieldAsRadios($index,$elements=[],$attributes=NULL){ |
|
157 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements){ |
|
158 | - return HtmlFormFields::radios($name,$elements,$caption,$value); |
|
159 | - }, $index,$attributes,"radios"); |
|
156 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
157 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements){ |
|
158 | + return HtmlFormFields::radios($name, $elements, $caption, $value); |
|
159 | + }, $index, $attributes, "radios"); |
|
160 | 160 | } |
161 | 161 | |
162 | - public function fieldAsInput($index,$attributes=NULL){ |
|
163 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
164 | - $input= new HtmlFormInput($id,$caption,"text",$value); |
|
162 | + public function fieldAsInput($index, $attributes=NULL) { |
|
163 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
164 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
165 | 165 | return $this->_prepareFormFields($input, $name, $attributes); |
166 | - }, $index,$attributes,"input"); |
|
166 | + }, $index, $attributes, "input"); |
|
167 | 167 | } |
168 | 168 | |
169 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
170 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
171 | - $textarea=new HtmlFormTextarea($id,$caption,$value); |
|
169 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
170 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
171 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
172 | 172 | $textarea->setName($name); |
173 | 173 | return $textarea; |
174 | - }, $index,$attributes,"textarea"); |
|
174 | + }, $index, $attributes, "textarea"); |
|
175 | 175 | } |
176 | 176 | |
177 | - public function fieldAsHidden($index,$attributes=NULL){ |
|
178 | - if(!\is_array($attributes)){ |
|
177 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
178 | + if (!\is_array($attributes)) { |
|
179 | 179 | $attributes=[]; |
180 | 180 | } |
181 | 181 | $attributes["imputType"]="hidden"; |
182 | - return $this->fieldAsInput($index,$attributes); |
|
182 | + return $this->fieldAsInput($index, $attributes); |
|
183 | 183 | } |
184 | 184 | |
185 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
186 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
187 | - $input=new HtmlFormCheckbox($id,$caption,$this->_instanceViewer->getIdentifier()); |
|
185 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
186 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
187 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
188 | 188 | $input->setChecked(JString::isBooleanTrue($value)); |
189 | 189 | $input->setName($name); |
190 | 190 | return $input; |
191 | - }, $index,$attributes,"ck"); |
|
191 | + }, $index, $attributes, "ck"); |
|
192 | 192 | } |
193 | 193 | |
194 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
195 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($elements,$multiple){ |
|
196 | - $dd=new HtmlFormDropdown($id,$elements,$caption,$value); |
|
197 | - $dd->asSelect($name,$multiple); |
|
194 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
195 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($elements, $multiple){ |
|
196 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value); |
|
197 | + $dd->asSelect($name, $multiple); |
|
198 | 198 | return $dd; |
199 | - }, $index,$attributes,"dd"); |
|
199 | + }, $index, $attributes, "dd"); |
|
200 | 200 | } |
201 | 201 | |
202 | - public function fieldAsMessage($index,$attributes=NULL){ |
|
203 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
204 | - $mess= new HtmlMessage("message-".$id,$caption); |
|
202 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
203 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
204 | + $mess=new HtmlMessage("message-".$id, $caption); |
|
205 | 205 | $mess->addHeader($value); |
206 | 206 | return $mess; |
207 | - }, $index,$attributes,"message"); |
|
207 | + }, $index, $attributes, "message"); |
|
208 | 208 | } |
209 | 209 | |
210 | - public function fieldAsLink($index,$attributes=NULL){ |
|
211 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
212 | - $lnk= new HtmlLink("message-".$id,"#",$caption); |
|
210 | + public function fieldAsLink($index, $attributes=NULL) { |
|
211 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
212 | + $lnk=new HtmlLink("message-".$id, "#", $caption); |
|
213 | 213 | return $lnk; |
214 | - }, $index,$attributes,"link"); |
|
214 | + }, $index, $attributes, "link"); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /**Change fields type |
218 | 218 | * @param array $types an array or associative array $type=>$attributes |
219 | 219 | */ |
220 | - public function fieldsAs(array $types){ |
|
220 | + public function fieldsAs(array $types) { |
|
221 | 221 | $i=0; |
222 | - if(JArray::isAssociative($types)){ |
|
223 | - foreach ($types as $type=>$attributes){ |
|
224 | - if(\is_int($type)) |
|
225 | - $this->fieldAs($i++,$attributes,[]); |
|
226 | - else{ |
|
227 | - $type=preg_replace('/\d/', '', $type ); |
|
228 | - $this->fieldAs($i++,$type,[$attributes]); |
|
222 | + if (JArray::isAssociative($types)) { |
|
223 | + foreach ($types as $type=>$attributes) { |
|
224 | + if (\is_int($type)) |
|
225 | + $this->fieldAs($i++, $attributes, []); |
|
226 | + else { |
|
227 | + $type=preg_replace('/\d/', '', $type); |
|
228 | + $this->fieldAs($i++, $type, [$attributes]); |
|
229 | 229 | } |
230 | 230 | } |
231 | - }else{ |
|
232 | - foreach ($types as $type){ |
|
233 | - $this->fieldAs($i++,$type); |
|
231 | + } else { |
|
232 | + foreach ($types as $type) { |
|
233 | + $this->fieldAs($i++, $type); |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | } |
237 | 237 | |
238 | - public function fieldAs($index,$type,$attributes=NULL){ |
|
238 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
239 | 239 | $method="fieldAs".\ucfirst($type); |
240 | - if(\method_exists($this, $method)){ |
|
241 | - if(!\is_array($attributes)){ |
|
240 | + if (\method_exists($this, $method)) { |
|
241 | + if (!\is_array($attributes)) { |
|
242 | 242 | $attributes=[$index]; |
243 | - }else{ |
|
243 | + } else { |
|
244 | 244 | \array_unshift($attributes, $index); |
245 | 245 | } |
246 | - \call_user_func_array([$this,$method], $attributes); |
|
246 | + \call_user_func_array([$this, $method], $attributes); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
250 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
251 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){ |
|
252 | - $button=new HtmlButton($id,$caption,$cssStyle); |
|
253 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,@$attributes["ajax"]); |
|
250 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
251 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes){ |
|
252 | + $button=new HtmlButton($id, $caption, $cssStyle); |
|
253 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]); |
|
254 | 254 | return $button; |
255 | - }, $index,$attributes,"submit"); |
|
255 | + }, $index, $attributes, "submit"); |
|
256 | 256 | } |
257 | 257 | |
258 | - public function fieldAsButton($index,$cssStyle=NULL,$attributes=NULL){ |
|
259 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
260 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
258 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
259 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
260 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
261 | 261 | return $button; |
262 | - }, $index,$attributes,"button"); |
|
262 | + }, $index, $attributes, "button"); |
|
263 | 263 | } |
264 | 264 | } |
265 | 265 | \ No newline at end of file |
@@ -13,41 +13,41 @@ |
||
13 | 13 | * @param string $identifier |
14 | 14 | * @param object $modelInstance |
15 | 15 | */ |
16 | - public function __construct($identifier,$modelInstance=null,$fieldsOrder=[],$fieldsDefinition=[],$fields=[],$captions=[],$separators=[]) { |
|
17 | - parent::__construct($identifier,$modelInstance,$fieldsOrder,$fieldsDefinition,$fields,$captions,$separators); |
|
16 | + public function __construct($identifier, $modelInstance=null, $fieldsOrder=[], $fieldsDefinition=[], $fields=[], $captions=[], $separators=[]) { |
|
17 | + parent::__construct($identifier, $modelInstance, $fieldsOrder, $fieldsDefinition, $fields, $captions, $separators); |
|
18 | 18 | } |
19 | 19 | |
20 | - protected function getDefaultModelInstance(){ |
|
20 | + protected function getDefaultModelInstance() { |
|
21 | 21 | return new UserModel(); |
22 | 22 | } |
23 | 23 | |
24 | - public static function default($identifier,$modelInstance=null){ |
|
25 | - return new FormLogin($identifier,$modelInstance, |
|
26 | - ["message","login","password","remember","forget","submit"], |
|
27 | - ["message"=>["icon"=>"sign in"],"input0"=>["rules"=>"empty"],"input1"=>["inputType"=>"password","rules"=>"empty"],"checkbox","link","submit"=>"green fluid"], |
|
28 | - ["Connection","login","password","remember","forget","submit"], |
|
29 | - ["Please enter login and password to connect","Login","Password","Remember me.","Forgot your password?","Connection"], |
|
30 | - [0,2,4,5]); |
|
24 | + public static function default($identifier, $modelInstance=null){ |
|
25 | + return new FormLogin($identifier, $modelInstance, |
|
26 | + ["message", "login", "password", "remember", "forget", "submit"], |
|
27 | + ["message"=>["icon"=>"sign in"], "input0"=>["rules"=>"empty"], "input1"=>["inputType"=>"password", "rules"=>"empty"], "checkbox", "link", "submit"=>"green fluid"], |
|
28 | + ["Connection", "login", "password", "remember", "forget", "submit"], |
|
29 | + ["Please enter login and password to connect", "Login", "Password", "Remember me.", "Forgot your password?", "Connection"], |
|
30 | + [0, 2, 4, 5]); |
|
31 | 31 | } |
32 | 32 | |
33 | - public static function smallInline($identifier,$modelInstance=null){ |
|
34 | - $result=new FormLogin($identifier,$modelInstance, |
|
35 | - ["login","password","submit"], |
|
36 | - ["input0"=>["rules"=>"empty"],"input1"=>["inputType"=>"password","rules"=>"empty"],"submit"=>"green basic"], |
|
37 | - ["login","password","submit"], |
|
38 | - ["","","Connection"], |
|
33 | + public static function smallInline($identifier, $modelInstance=null) { |
|
34 | + $result=new FormLogin($identifier, $modelInstance, |
|
35 | + ["login", "password", "submit"], |
|
36 | + ["input0"=>["rules"=>"empty"], "input1"=>["inputType"=>"password", "rules"=>"empty"], "submit"=>"green basic"], |
|
37 | + ["login", "password", "submit"], |
|
38 | + ["", "", "Connection"], |
|
39 | 39 | [2]); |
40 | 40 | $result->addDividerBefore(0, "Connection"); |
41 | 41 | return $result; |
42 | 42 | } |
43 | 43 | |
44 | - public static function small($identifier,$modelInstance=null){ |
|
45 | - $result=new FormLogin($identifier,$modelInstance, |
|
46 | - ["login","password","submit"], |
|
47 | - ["input0"=>["rules"=>"empty"],"input1"=>["inputType"=>"password","rules"=>"empty"],"submit"=>"green basic"], |
|
48 | - ["login","password","submit"], |
|
49 | - ["Login","Password","Connection"], |
|
50 | - [1,2]); |
|
44 | + public static function small($identifier, $modelInstance=null) { |
|
45 | + $result=new FormLogin($identifier, $modelInstance, |
|
46 | + ["login", "password", "submit"], |
|
47 | + ["input0"=>["rules"=>"empty"], "input1"=>["inputType"=>"password", "rules"=>"empty"], "submit"=>"green basic"], |
|
48 | + ["login", "password", "submit"], |
|
49 | + ["Login", "Password", "Connection"], |
|
50 | + [1, 2]); |
|
51 | 51 | $result->addDividerBefore(0, "Connection"); |
52 | 52 | return $result; |
53 | 53 | } |
@@ -10,51 +10,51 @@ discard block |
||
10 | 10 | protected $separators; |
11 | 11 | protected $headers; |
12 | 12 | |
13 | - public function __construct($identifier,$instance=NULL, $captions=NULL) { |
|
14 | - parent::__construct($identifier,$instance=NULL, $captions=NULL); |
|
13 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
14 | + parent::__construct($identifier, $instance=NULL, $captions=NULL); |
|
15 | 15 | $this->separators=[-1]; |
16 | 16 | $this->headers=[]; |
17 | - $this->defaultValueFunction=function($name,$value,$index){ |
|
17 | + $this->defaultValueFunction=function($name, $value, $index) { |
|
18 | 18 | $caption=$this->getCaption($index); |
19 | - $input=new HtmlFormInput($this->widgetIdentifier."-".$name,$caption,"text",$value); |
|
19 | + $input=new HtmlFormInput($this->widgetIdentifier."-".$name, $caption, "text", $value); |
|
20 | 20 | $input->setName($name); |
21 | 21 | return $input; |
22 | 22 | }; |
23 | 23 | } |
24 | 24 | |
25 | - protected function _beforeAddProperty($index,&$field){ |
|
26 | - if(JString::endswith($field, "\n")===true){ |
|
25 | + protected function _beforeAddProperty($index, &$field) { |
|
26 | + if (JString::endswith($field, "\n")===true) { |
|
27 | 27 | $this->addSeparatorAfter($index); |
28 | 28 | } |
29 | - if($index>1 && JString::startswith($field, "\n")===true){ |
|
29 | + if ($index>1 && JString::startswith($field, "\n")===true) { |
|
30 | 30 | $this->addSeparatorAfter($index-1); |
31 | 31 | } |
32 | 32 | $field=\str_replace("\n", "", $field); |
33 | - if(($header=$this->hasHeader($field))!==false){ |
|
33 | + if (($header=$this->hasHeader($field))!==false) { |
|
34 | 34 | $this->addHeaderDividerBefore($index, $header); |
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | - protected function hasHeader(&$field){ |
|
39 | - $matches=[];$result=false; |
|
40 | - if(\preg_match('/\{(.*?)\}/s', $field, $matches)===1){ |
|
38 | + protected function hasHeader(&$field) { |
|
39 | + $matches=[]; $result=false; |
|
40 | + if (\preg_match('/\{(.*?)\}/s', $field, $matches)===1) { |
|
41 | 41 | $result=$matches[1]; |
42 | - $field=\str_replace("{".$result."}","", $field); |
|
42 | + $field=\str_replace("{".$result."}", "", $field); |
|
43 | 43 | } |
44 | 44 | return $result; |
45 | 45 | } |
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | - public function addSeparatorAfter($fieldNum){ |
|
50 | - if(\array_search($fieldNum, $this->separators)===false) |
|
49 | + public function addSeparatorAfter($fieldNum) { |
|
50 | + if (\array_search($fieldNum, $this->separators)===false) |
|
51 | 51 | $this->separators[]=$fieldNum; |
52 | 52 | return $this; |
53 | 53 | } |
54 | 54 | |
55 | - public function addHeaderDividerBefore($fieldNum,$header){ |
|
55 | + public function addHeaderDividerBefore($fieldNum, $header) { |
|
56 | 56 | $this->headers[$fieldNum]=$header; |
57 | - if($fieldNum>0) |
|
57 | + if ($fieldNum>0) |
|
58 | 58 | $this->addSeparatorAfter($fieldNum-1); |
59 | 59 | return $this; |
60 | 60 | } |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | return $this->separators; |
64 | 64 | } |
65 | 65 | |
66 | - public function removeSeparator($index){ |
|
67 | - \array_splice($this->separators,$index,1); |
|
66 | + public function removeSeparator($index) { |
|
67 | + \array_splice($this->separators, $index, 1); |
|
68 | 68 | } |
69 | 69 | |
70 | - public function removeField($index){ |
|
70 | + public function removeField($index) { |
|
71 | 71 | parent::removeField($index); |
72 | 72 | $pos=\array_search($index, $this->separators); |
73 | - if($pos!==false){ |
|
74 | - for($i=$pos+1;$i<\sizeof($this->separators);$i++){ |
|
73 | + if ($pos!==false) { |
|
74 | + for ($i=$pos+1; $i<\sizeof($this->separators); $i++) { |
|
75 | 75 | $this->separators[$i]--; |
76 | 76 | } |
77 | 77 | \array_splice($this->separators, $pos, 1); |
@@ -47,15 +47,17 @@ |
||
47 | 47 | |
48 | 48 | |
49 | 49 | public function addSeparatorAfter($fieldNum){ |
50 | - if(\array_search($fieldNum, $this->separators)===false) |
|
51 | - $this->separators[]=$fieldNum; |
|
50 | + if(\array_search($fieldNum, $this->separators)===false) { |
|
51 | + $this->separators[]=$fieldNum; |
|
52 | + } |
|
52 | 53 | return $this; |
53 | 54 | } |
54 | 55 | |
55 | 56 | public function addHeaderDividerBefore($fieldNum,$header){ |
56 | 57 | $this->headers[$fieldNum]=$header; |
57 | - if($fieldNum>0) |
|
58 | - $this->addSeparatorAfter($fieldNum-1); |
|
58 | + if($fieldNum>0) { |
|
59 | + $this->addSeparatorAfter($fieldNum-1); |
|
60 | + } |
|
59 | 61 | return $this; |
60 | 62 | } |
61 | 63 |