@@ -21,36 +21,36 @@ discard block |
||
21 | 21 | use BaseTrait; |
22 | 22 | |
23 | 23 | public function __construct($identifier, $modelInstance=NULL) { |
24 | - parent::__construct($identifier, null,$modelInstance); |
|
24 | + parent::__construct($identifier, null, $modelInstance); |
|
25 | 25 | $this->_form=new HtmlForm($identifier); |
26 | 26 | $this->_init(new FormInstanceViewer($identifier), "form", $this->_form, true); |
27 | 27 | } |
28 | 28 | |
29 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
29 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
30 | 30 | return $this->identifier."-{$name}-".$this->_instanceViewer->getIdentifier(); |
31 | 31 | } |
32 | 32 | |
33 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
34 | - if(!$this->_generated){ |
|
33 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
34 | + if (!$this->_generated) { |
|
35 | 35 | $this->_instanceViewer->setInstance($this->_modelInstance); |
36 | 36 | |
37 | 37 | $form=$this->content["form"]; |
38 | 38 | $this->_generateContent($form); |
39 | 39 | |
40 | - if(isset($this->_toolbar)){ |
|
40 | + if (isset($this->_toolbar)) { |
|
41 | 41 | $this->_setToolbarPosition($form); |
42 | 42 | } |
43 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]); |
|
43 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "form", PositionInTable::AFTERTABLE]); |
|
44 | 44 | $this->_generated=true; |
45 | 45 | } |
46 | - return parent::compile($js,$view); |
|
46 | + return parent::compile($js, $view); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @param HtmlForm $form |
51 | 51 | */ |
52 | - protected function _generateContent($form){ |
|
53 | - $values= $this->_instanceViewer->getValues(); |
|
52 | + protected function _generateContent($form) { |
|
53 | + $values=$this->_instanceViewer->getValues(); |
|
54 | 54 | $count=$this->_instanceViewer->count(); |
55 | 55 | $separators=$this->_instanceViewer->getSeparators(); |
56 | 56 | $headers=$this->_instanceViewer->getHeaders(); |
@@ -58,41 +58,41 @@ discard block |
||
58 | 58 | \sort($separators); |
59 | 59 | $size=\sizeof($separators); |
60 | 60 | $nb=0; |
61 | - if($size===1){ |
|
61 | + if ($size===1) { |
|
62 | 62 | $i=-1; |
63 | - foreach ($values as $v){ |
|
64 | - $this->_generateFields($form, [$v], $headers, $i, $wrappers,$nb++); |
|
63 | + foreach ($values as $v) { |
|
64 | + $this->_generateFields($form, [$v], $headers, $i, $wrappers, $nb++); |
|
65 | 65 | $i++; |
66 | 66 | } |
67 | - }else{ |
|
67 | + } else { |
|
68 | 68 | $separators[]=$count; |
69 | - for($i=0;$i<$size;$i++){ |
|
70 | - $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
|
71 | - $this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers,$nb++); |
|
69 | + for ($i=0; $i<$size; $i++) { |
|
70 | + $fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]); |
|
71 | + $this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers, $nb++); |
|
72 | 72 | } |
73 | 73 | } |
74 | - if($this->_hasRules && !$this->getForm()->hasValidationParams()){ |
|
74 | + if ($this->_hasRules && !$this->getForm()->hasValidationParams()) { |
|
75 | 75 | $this->setValidationParams(["inline"=>true]); |
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | - protected function _generateFields($form,$values,$headers,$sepFirst,$wrappers,$nb){ |
|
79 | + protected function _generateFields($form, $values, $headers, $sepFirst, $wrappers, $nb) { |
|
80 | 80 | $wrapper=null; |
81 | - if(isset($headers[$sepFirst+1])) |
|
82 | - $form->addHeader($headers[$sepFirst+1],4,true); |
|
83 | - if(isset($wrappers[$sepFirst+1])){ |
|
81 | + if (isset($headers[$sepFirst+1])) |
|
82 | + $form->addHeader($headers[$sepFirst+1], 4, true); |
|
83 | + if (isset($wrappers[$sepFirst+1])) { |
|
84 | 84 | $wrapper=$wrappers[$sepFirst+1]; |
85 | 85 | } |
86 | - if(\sizeof($values)===1){ |
|
86 | + if (\sizeof($values)===1) { |
|
87 | 87 | $added=$form->addField($values[0]); |
88 | - }elseif(\sizeof($values)>1){ |
|
88 | + }elseif (\sizeof($values)>1) { |
|
89 | 89 | $added=$form->addFields($values); |
90 | - }else |
|
90 | + } else |
|
91 | 91 | return; |
92 | - if(isset($wrapper)){ |
|
93 | - $added->wrap($wrapper[0],$wrapper[1]); |
|
92 | + if (isset($wrapper)) { |
|
93 | + $added->wrap($wrapper[0], $wrapper[1]); |
|
94 | 94 | } |
95 | - $this->execHook("onGenerateFields",$added,$nb); |
|
95 | + $this->execHook("onGenerateFields", $added, $nb); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -100,18 +100,18 @@ discard block |
||
100 | 100 | * the generated field is the first parameter |
101 | 101 | * @param callable $callback the fonction to call when a field is generated |
102 | 102 | */ |
103 | - public function onGenerateField($callback){ |
|
104 | - $this->addHook("onGenerateFields",$callback); |
|
103 | + public function onGenerateField($callback) { |
|
104 | + $this->addHook("onGenerateFields", $callback); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @return HtmlForm |
109 | 109 | */ |
110 | - public function getForm(){ |
|
110 | + public function getForm() { |
|
111 | 111 | return $this->content["form"]; |
112 | 112 | } |
113 | 113 | |
114 | - public function addSeparatorAfter($fieldNum){ |
|
114 | + public function addSeparatorAfter($fieldNum) { |
|
115 | 115 | $fieldNum=$this->_getIndex($fieldNum); |
116 | 116 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
117 | 117 | return $this; |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | return $this; |
127 | 127 | } |
128 | 128 | |
129 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
130 | - return $this->_fieldAs(function($id,$name,$value) use ($cssStyle){ |
|
131 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
129 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
130 | + return $this->_fieldAs(function($id, $name, $value) use ($cssStyle){ |
|
131 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
132 | 132 | $button->setProperty("type", "reset"); |
133 | 133 | return $button; |
134 | - }, $index,$attributes); |
|
134 | + }, $index, $attributes); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -150,19 +150,19 @@ discard block |
||
150 | 150 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
151 | 151 | } |
152 | 152 | |
153 | - public function addDividerBefore($index,$title){ |
|
153 | + public function addDividerBefore($index, $title) { |
|
154 | 154 | $index=$this->_getIndex($index); |
155 | 155 | $this->_instanceViewer->addHeaderDividerBefore($index, $title); |
156 | 156 | return $this; |
157 | 157 | } |
158 | 158 | |
159 | - public function addWrapper($index,$contentBefore,$contentAfter=null){ |
|
159 | + public function addWrapper($index, $contentBefore, $contentAfter=null) { |
|
160 | 160 | $index=$this->_getIndex($index); |
161 | - $this->_instanceViewer->addWrapper($index, $contentBefore,$contentAfter); |
|
161 | + $this->_instanceViewer->addWrapper($index, $contentBefore, $contentAfter); |
|
162 | 162 | return $this; |
163 | 163 | } |
164 | 164 | |
165 | - public function run(JsUtils $js){ |
|
165 | + public function run(JsUtils $js) { |
|
166 | 166 | parent::run($js); |
167 | 167 | } |
168 | 168 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $this->_generateFields($form, [$v], $headers, $i, $wrappers,$nb++); |
65 | 65 | $i++; |
66 | 66 | } |
67 | - }else{ |
|
67 | + } else{ |
|
68 | 68 | $separators[]=$count; |
69 | 69 | for($i=0;$i<$size;$i++){ |
70 | 70 | $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
@@ -78,17 +78,19 @@ discard block |
||
78 | 78 | |
79 | 79 | protected function _generateFields($form,$values,$headers,$sepFirst,$wrappers,$nb){ |
80 | 80 | $wrapper=null; |
81 | - if(isset($headers[$sepFirst+1])) |
|
82 | - $form->addHeader($headers[$sepFirst+1],4,true); |
|
81 | + if(isset($headers[$sepFirst+1])) { |
|
82 | + $form->addHeader($headers[$sepFirst+1],4,true); |
|
83 | + } |
|
83 | 84 | if(isset($wrappers[$sepFirst+1])){ |
84 | 85 | $wrapper=$wrappers[$sepFirst+1]; |
85 | 86 | } |
86 | 87 | if(\sizeof($values)===1){ |
87 | 88 | $added=$form->addField($values[0]); |
88 | - }elseif(\sizeof($values)>1){ |
|
89 | + } elseif(\sizeof($values)>1){ |
|
89 | 90 | $added=$form->addFields($values); |
90 | - }else |
|
91 | - return; |
|
91 | + } else { |
|
92 | + return; |
|
93 | + } |
|
92 | 94 | if(isset($wrapper)){ |
93 | 95 | $added->wrap($wrapper[0],$wrapper[1]); |
94 | 96 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | abstract public function addToProperty($name, $value, $separator=" "); |
21 | 21 | abstract public function addLabel($caption, $style="label-default", $leftSeparator=" "); |
22 | - abstract public function addContent($content,$before=false); |
|
22 | + abstract public function addContent($content, $before=false); |
|
23 | 23 | abstract public function getField(); |
24 | 24 | abstract public function getDataField(); |
25 | 25 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | public function addLoading() { |
31 | - if ($this->_hasIcon === false) { |
|
31 | + if ($this->_hasIcon===false) { |
|
32 | 32 | throw new \Exception("Input must have an icon for showing a loader, use addIcon before"); |
33 | 33 | } |
34 | 34 | return $this->addToProperty("class", State::LOADING); |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function labeled($label, $direction=Direction::LEFT, $icon=NULL) { |
44 | 44 | $field=$this->getField(); |
45 | - $labelO=$field->addLabel($label,$direction===Direction::LEFT,$icon); |
|
46 | - $field->addToProperty("class", $direction . " labeled"); |
|
45 | + $labelO=$field->addLabel($label, $direction===Direction::LEFT, $icon); |
|
46 | + $field->addToProperty("class", $direction." labeled"); |
|
47 | 47 | return $labelO; |
48 | 48 | } |
49 | 49 | |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @param string $checkboxType |
55 | 55 | * @return HtmlLabel |
56 | 56 | */ |
57 | - public function labeledCheckbox($direction=Direction::LEFT,$caption="",$value=NULL,$checkboxType=NULL){ |
|
58 | - return $this->labeled(new HtmlCheckbox("lbl-ck-".$this->getField()->getIdentifier(),$caption,$value,$checkboxType),$direction); |
|
57 | + public function labeledCheckbox($direction=Direction::LEFT, $caption="", $value=NULL, $checkboxType=NULL) { |
|
58 | + return $this->labeled(new HtmlCheckbox("lbl-ck-".$this->getField()->getIdentifier(), $caption, $value, $checkboxType), $direction); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return HtmlLabel |
65 | 65 | */ |
66 | 66 | public function labeledToCorner($icon, $direction=Direction::LEFT) { |
67 | - return $this->labeled("", $direction . " corner", $icon)->toCorner($direction); |
|
67 | + return $this->labeled("", $direction." corner", $icon)->toCorner($direction); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false) { |
78 | 78 | $field=$this->getField(); |
79 | 79 | $actionO=$action; |
80 | - if (\is_object($action) === false) { |
|
81 | - $actionO=new HtmlButton("action-" . $this->identifier, $action); |
|
80 | + if (\is_object($action)===false) { |
|
81 | + $actionO=new HtmlButton("action-".$this->identifier, $action); |
|
82 | 82 | if (isset($icon)) |
83 | 83 | $actionO->addIcon($icon, true, $labeled); |
84 | 84 | } |
85 | - $field->addToProperty("class", $direction . " action"); |
|
86 | - $field->addContent($actionO, \strstr($direction, Direction::LEFT) !== false); |
|
85 | + $field->addToProperty("class", $direction." action"); |
|
86 | + $field->addContent($actionO, \strstr($direction, Direction::LEFT)!==false); |
|
87 | 87 | return $actionO; |
88 | 88 | } |
89 | 89 | |
@@ -93,50 +93,50 @@ discard block |
||
93 | 93 | * @param string $direction |
94 | 94 | * @return HtmlLabel |
95 | 95 | */ |
96 | - public function addDropdown($label="", $items=array(),$direction=Direction::RIGHT){ |
|
97 | - $labelO=new HtmlDropdown("dd-".$this->identifier,$label,$items); |
|
98 | - $labelO->asSelect("select-".$this->identifier,false,true); |
|
99 | - return $this->labeled($labelO,$direction); |
|
96 | + public function addDropdown($label="", $items=array(), $direction=Direction::RIGHT) { |
|
97 | + $labelO=new HtmlDropdown("dd-".$this->identifier, $label, $items); |
|
98 | + $labelO->asSelect("select-".$this->identifier, false, true); |
|
99 | + return $this->labeled($labelO, $direction); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | public function setTransparent() { |
103 | 103 | return $this->getField()->addToProperty("class", "transparent"); |
104 | 104 | } |
105 | 105 | |
106 | - public function setReadonly(){ |
|
106 | + public function setReadonly() { |
|
107 | 107 | $this->getDataField()->setProperty("readonly", ""); |
108 | 108 | return $this; |
109 | 109 | } |
110 | 110 | |
111 | - public function setName($name){ |
|
112 | - $this->getDataField()->setProperty("name",$name); |
|
111 | + public function setName($name) { |
|
112 | + $this->getDataField()->setProperty("name", $name); |
|
113 | 113 | return $this; |
114 | 114 | } |
115 | 115 | |
116 | - public function setFluid(){ |
|
117 | - $this->getField()->addToProperty("class","fluid"); |
|
116 | + public function setFluid() { |
|
117 | + $this->getField()->addToProperty("class", "fluid"); |
|
118 | 118 | return $this; |
119 | 119 | } |
120 | 120 | |
121 | 121 | public function setDisabled($disable=true) { |
122 | 122 | $field=$this->getField(); |
123 | - if($disable) |
|
123 | + if ($disable) |
|
124 | 124 | $field->addToProperty("class", "disabled"); |
125 | 125 | return $this; |
126 | 126 | } |
127 | 127 | |
128 | - public function setJsContent($content){ |
|
128 | + public function setJsContent($content) { |
|
129 | 129 | $id=""; |
130 | 130 | $field=$this->getDataField(); |
131 | - if(isset($field)){ |
|
131 | + if (isset($field)) { |
|
132 | 132 | $id=$field->getIdentifier(); |
133 | 133 | } |
134 | - if($id!==''){ |
|
134 | + if ($id!=='') { |
|
135 | 135 | return '$("#'.$id.'").val('.$content.')'; |
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | - public function getJsContent(){ |
|
139 | + public function getJsContent() { |
|
140 | 140 | return $this->setJsContent(""); |
141 | 141 | } |
142 | 142 | } |
@@ -79,8 +79,9 @@ discard block |
||
79 | 79 | $actionO=$action; |
80 | 80 | if (\is_object($action) === false) { |
81 | 81 | $actionO=new HtmlButton("action-" . $this->identifier, $action); |
82 | - if (isset($icon)) |
|
83 | - $actionO->addIcon($icon, true, $labeled); |
|
82 | + if (isset($icon)) { |
|
83 | + $actionO->addIcon($icon, true, $labeled); |
|
84 | + } |
|
84 | 85 | } |
85 | 86 | $field->addToProperty("class", $direction . " action"); |
86 | 87 | $field->addContent($actionO, \strstr($direction, Direction::LEFT) !== false); |
@@ -120,8 +121,9 @@ discard block |
||
120 | 121 | |
121 | 122 | public function setDisabled($disable=true) { |
122 | 123 | $field=$this->getField(); |
123 | - if($disable) |
|
124 | - $field->addToProperty("class", "disabled"); |
|
124 | + if($disable) { |
|
125 | + $field->addToProperty("class", "disabled"); |
|
126 | + } |
|
125 | 127 | return $this; |
126 | 128 | } |
127 | 129 |
@@ -20,35 +20,35 @@ discard block |
||
20 | 20 | * @property string $identifier |
21 | 21 | */ |
22 | 22 | trait FieldsTrait { |
23 | - abstract public function addFields($fields=NULL,$label=NULL); |
|
23 | + abstract public function addFields($fields=NULL, $label=NULL); |
|
24 | 24 | abstract public function addItem($item); |
25 | 25 | abstract public function getItem($index); |
26 | 26 | abstract public function count(); |
27 | 27 | |
28 | - protected function createItem($value){ |
|
29 | - if(\is_array($value)){ |
|
30 | - $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null))); |
|
28 | + protected function createItem($value) { |
|
29 | + if (\is_array($value)) { |
|
30 | + $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id", ""), JArray::getDefaultValue($value, "label", null), JArray::getDefaultValue($value, "type", "text"), JArray::getDefaultValue($value, "value", ""), JArray::getDefaultValue($value, "placeholder", JArray::getDefaultValue($value, "label", null))); |
|
31 | 31 | return $itemO; |
32 | - }elseif(\is_object($value)){ |
|
32 | + }elseif (\is_object($value)) { |
|
33 | 33 | $itemO=new HtmlFormField("field-".$this->identifier, $value); |
34 | 34 | return $itemO; |
35 | - }else |
|
35 | + } else |
|
36 | 36 | return new HtmlFormInput($value); |
37 | 37 | } |
38 | 38 | |
39 | - protected function createCondition($value){ |
|
39 | + protected function createCondition($value) { |
|
40 | 40 | return \is_object($value)===false || $value instanceof \Ajax\semantic\html\elements\HtmlInput; |
41 | 41 | } |
42 | 42 | |
43 | - public function addInputs($inputs,$fieldslabel=null){ |
|
43 | + public function addInputs($inputs, $fieldslabel=null) { |
|
44 | 44 | $fields=array(); |
45 | - foreach ($inputs as $input){ |
|
45 | + foreach ($inputs as $input) { |
|
46 | 46 | \extract($input); |
47 | - $f=new HtmlFormInput("",""); |
|
47 | + $f=new HtmlFormInput("", ""); |
|
48 | 48 | $f->fromArray($input); |
49 | 49 | $fields[]=$f; |
50 | 50 | } |
51 | - return $this->addFields($fields,$fieldslabel); |
|
51 | + return $this->addFields($fields, $fieldslabel); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,35 +57,35 @@ discard block |
||
57 | 57 | * @param array|mixed $values |
58 | 58 | * @return HtmlFormFields |
59 | 59 | */ |
60 | - public function setFieldsPropertyValues($property,$values){ |
|
60 | + public function setFieldsPropertyValues($property, $values) { |
|
61 | 61 | $i=0; |
62 | - if(\is_array($values)===false){ |
|
63 | - $values=\array_fill(0, $this->count(),$values); |
|
62 | + if (\is_array($values)===false) { |
|
63 | + $values=\array_fill(0, $this->count(), $values); |
|
64 | 64 | } |
65 | - foreach ($values as $value){ |
|
65 | + foreach ($values as $value) { |
|
66 | 66 | $c=$this->content[$i++]; |
67 | - if(isset($c)){ |
|
67 | + if (isset($c)) { |
|
68 | 68 | $df=$c->getDataField(); |
69 | - $df->setProperty($property,$value); |
|
69 | + $df->setProperty($property, $value); |
|
70 | 70 | } |
71 | - else{ |
|
71 | + else { |
|
72 | 72 | return $this; |
73 | 73 | } |
74 | 74 | } |
75 | 75 | return $this; |
76 | 76 | } |
77 | 77 | |
78 | - public function addFieldRule($index,$type,$prompt=NULL,$value=NULL){ |
|
78 | + public function addFieldRule($index, $type, $prompt=NULL, $value=NULL) { |
|
79 | 79 | $field=$this->getItem($index); |
80 | - if(isset($field)){ |
|
81 | - $field->addRule($type,$prompt,$value); |
|
80 | + if (isset($field)) { |
|
81 | + $field->addRule($type, $prompt, $value); |
|
82 | 82 | } |
83 | 83 | return $this; |
84 | 84 | } |
85 | 85 | |
86 | - public function addFieldRules($index,$rules){ |
|
86 | + public function addFieldRules($index, $rules) { |
|
87 | 87 | $field=$this->getItem($index); |
88 | - if(isset($field)){ |
|
88 | + if (isset($field)) { |
|
89 | 89 | $field->addRules($rules); |
90 | 90 | } |
91 | 91 | return $this; |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * @param boolean $multiple |
101 | 101 | * @return HtmlFormDropdown |
102 | 102 | */ |
103 | - public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){ |
|
104 | - return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple)); |
|
103 | + public function addDropdown($identifier, $items=array(), $label=NULL, $value=NULL, $multiple=false) { |
|
104 | + return $this->addItem(new HtmlFormDropdown($identifier, $items, $label, $value, $multiple)); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | * @param boolean $asIcons |
112 | 112 | * @return HtmlButtonGroups |
113 | 113 | */ |
114 | - public function addButtonGroups($identifier,$elements=[],$asIcons=false){ |
|
115 | - return $this->addItem(new HtmlButtonGroups($identifier,$elements,$asIcons)); |
|
114 | + public function addButtonGroups($identifier, $elements=[], $asIcons=false) { |
|
115 | + return $this->addItem(new HtmlButtonGroups($identifier, $elements, $asIcons)); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @param string $icon |
125 | 125 | * @return HtmlButtonGroups |
126 | 126 | */ |
127 | - public function addDropdownButton($identifier,$value,$items=[],$asCombo=false,$icon=null){ |
|
128 | - return $this->addItem(HtmlButton::dropdown($identifier, $value,$items,$asCombo,$icon)); |
|
127 | + public function addDropdownButton($identifier, $value, $items=[], $asCombo=false, $icon=null) { |
|
128 | + return $this->addItem(HtmlButton::dropdown($identifier, $value, $items, $asCombo, $icon)); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @param string $placeholder |
137 | 137 | * @return HtmlFormInput |
138 | 138 | */ |
139 | - public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL){ |
|
140 | - return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder)); |
|
139 | + public function addInput($identifier, $label=NULL, $type="text", $value=NULL, $placeholder=NULL) { |
|
140 | + return $this->addItem(new HtmlFormInput($identifier, $label, $type, $value, $placeholder)); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -148,22 +148,22 @@ discard block |
||
148 | 148 | * @param int $rows |
149 | 149 | * @return HtmlTextarea |
150 | 150 | */ |
151 | - public function addTextarea($identifier, $label,$value=NULL,$placeholder=NULL,$rows=5){ |
|
152 | - return $this->addItem(new HtmlFormTextarea($identifier,$label,$value,$placeholder,$rows)); |
|
151 | + public function addTextarea($identifier, $label, $value=NULL, $placeholder=NULL, $rows=5) { |
|
152 | + return $this->addItem(new HtmlFormTextarea($identifier, $label, $value, $placeholder, $rows)); |
|
153 | 153 | } |
154 | 154 | |
155 | - public function addPassword($identifier, $label=NULL){ |
|
156 | - return $this->addItem(new HtmlFormInput($identifier,$label,"password","","")); |
|
155 | + public function addPassword($identifier, $label=NULL) { |
|
156 | + return $this->addItem(new HtmlFormInput($identifier, $label, "password", "", "")); |
|
157 | 157 | } |
158 | 158 | |
159 | - public function addButton($identifier,$value,$cssStyle=NULL,$onClick=NULL){ |
|
160 | - return $this->addItem(new HtmlButton($identifier,$value,$cssStyle,$onClick)); |
|
159 | + public function addButton($identifier, $value, $cssStyle=NULL, $onClick=NULL) { |
|
160 | + return $this->addItem(new HtmlButton($identifier, $value, $cssStyle, $onClick)); |
|
161 | 161 | } |
162 | 162 | |
163 | - public function addButtonIcon($identifier,$icon,$cssStyle=NULL,$onClick=NULL){ |
|
163 | + public function addButtonIcon($identifier, $icon, $cssStyle=NULL, $onClick=NULL) { |
|
164 | 164 | $bt=new HtmlButton($identifier); |
165 | 165 | $bt->asIcon($icon); |
166 | - if(isset($onClick)) |
|
166 | + if (isset($onClick)) |
|
167 | 167 | $bt->onClick($onClick); |
168 | 168 | if (isset($cssStyle)) |
169 | 169 | $bt->addClass($cssStyle); |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | * @param string $type |
178 | 178 | * @return HtmlFormCheckbox |
179 | 179 | */ |
180 | - public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){ |
|
181 | - return $this->addItem(new HtmlFormCheckbox($identifier,$label,$value,$type)); |
|
180 | + public function addCheckbox($identifier, $label=NULL, $value=NULL, $type=NULL) { |
|
181 | + return $this->addItem(new HtmlFormCheckbox($identifier, $label, $value, $type)); |
|
182 | 182 | } |
183 | 183 | |
184 | - public function addRadio($identifier, $name,$label=NULL,$value=NULL){ |
|
185 | - return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value)); |
|
184 | + public function addRadio($identifier, $name, $label=NULL, $value=NULL) { |
|
185 | + return $this->addItem(new HtmlFormRadio($identifier, $name, $label, $value)); |
|
186 | 186 | } |
187 | 187 | |
188 | - public function addElement($identifier,$content,$label,$tagName="div",$baseClass=""){ |
|
189 | - $div=new HtmlSemDoubleElement($identifier,$tagName,$baseClass,$content); |
|
190 | - return $this->addItem(new HtmlFormField("field-".$identifier, $div,$label)); |
|
188 | + public function addElement($identifier, $content, $label, $tagName="div", $baseClass="") { |
|
189 | + $div=new HtmlSemDoubleElement($identifier, $tagName, $baseClass, $content); |
|
190 | + return $this->addItem(new HtmlFormField("field-".$identifier, $div, $label)); |
|
191 | 191 | } |
192 | 192 | } |
@@ -29,11 +29,12 @@ discard block |
||
29 | 29 | if(\is_array($value)){ |
30 | 30 | $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null))); |
31 | 31 | return $itemO; |
32 | - }elseif(\is_object($value)){ |
|
32 | + } elseif(\is_object($value)){ |
|
33 | 33 | $itemO=new HtmlFormField("field-".$this->identifier, $value); |
34 | 34 | return $itemO; |
35 | - }else |
|
36 | - return new HtmlFormInput($value); |
|
35 | + } else { |
|
36 | + return new HtmlFormInput($value); |
|
37 | + } |
|
37 | 38 | } |
38 | 39 | |
39 | 40 | protected function createCondition($value){ |
@@ -67,8 +68,7 @@ discard block |
||
67 | 68 | if(isset($c)){ |
68 | 69 | $df=$c->getDataField(); |
69 | 70 | $df->setProperty($property,$value); |
70 | - } |
|
71 | - else{ |
|
71 | + } else{ |
|
72 | 72 | return $this; |
73 | 73 | } |
74 | 74 | } |
@@ -163,10 +163,12 @@ discard block |
||
163 | 163 | public function addButtonIcon($identifier,$icon,$cssStyle=NULL,$onClick=NULL){ |
164 | 164 | $bt=new HtmlButton($identifier); |
165 | 165 | $bt->asIcon($icon); |
166 | - if(isset($onClick)) |
|
167 | - $bt->onClick($onClick); |
|
168 | - if (isset($cssStyle)) |
|
169 | - $bt->addClass($cssStyle); |
|
166 | + if(isset($onClick)) { |
|
167 | + $bt->onClick($onClick); |
|
168 | + } |
|
169 | + if (isset($cssStyle)) { |
|
170 | + $bt->addClass($cssStyle); |
|
171 | + } |
|
170 | 172 | return $this->addItem($bt); |
171 | 173 | } |
172 | 174 |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
19 | 19 | |
20 | 20 | abstract public function getUrl($url); |
21 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
22 | - abstract public function interval($jsCode,$time,$globalName=null,$immediatly=true); |
|
21 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
22 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
23 | 23 | |
24 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
25 | - if(isset($this->params["ajax"])){ |
|
24 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
25 | + if (isset($this->params["ajax"])) { |
|
26 | 26 | extract($this->params["ajax"]); |
27 | 27 | } |
28 | 28 | extract($parameters); |
@@ -32,121 +32,121 @@ discard block |
||
32 | 32 | $originalSelector=$responseElement; |
33 | 33 | $responseElement=$this->_getResponseElement($responseElement); |
34 | 34 | $retour.="var self=this;\n"; |
35 | - $before=isset($before)?$before:""; |
|
35 | + $before=isset($before) ? $before : ""; |
|
36 | 36 | $retour.=$before; |
37 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
38 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
39 | - }elseif($hasLoader==="internal"){ |
|
37 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
38 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
39 | + }elseif ($hasLoader==="internal") { |
|
40 | 40 | $retour.="\n$(this).addClass('loading');"; |
41 | 41 | } |
42 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
42 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
43 | 43 | |
44 | - $ajaxParameters["async"]=($async?"true":"false"); |
|
44 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
45 | 45 | |
46 | - if(isset($params)){ |
|
47 | - $ajaxParameters["data"]=self::_correctParams($params,$parameters); |
|
46 | + if (isset($params)) { |
|
47 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
48 | 48 | } |
49 | - if(isset($headers)){ |
|
49 | + if (isset($headers)) { |
|
50 | 50 | $ajaxParameters["headers"]=$headers; |
51 | 51 | } |
52 | 52 | $this->createAjaxParameters($ajaxParameters, $parameters); |
53 | 53 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
54 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
|
55 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
54 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
55 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
56 | 56 | if ($immediatly) |
57 | 57 | $this->jquery_code_for_compile[]=$retour; |
58 | 58 | return $retour; |
59 | 59 | } |
60 | 60 | |
61 | - protected function createAjaxParameters(&$original,$parameters){ |
|
62 | - $validParameters=["contentType"=>"%value%","dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
63 | - foreach ($validParameters as $param=>$mask){ |
|
64 | - if(isset($parameters[$param])){ |
|
61 | + protected function createAjaxParameters(&$original, $parameters) { |
|
62 | + $validParameters=["contentType"=>"%value%", "dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
63 | + foreach ($validParameters as $param=>$mask) { |
|
64 | + if (isset($parameters[$param])) { |
|
65 | 65 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
71 | - $s = ''; |
|
70 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
71 | + $s=''; |
|
72 | 72 | foreach ($ajaxParameters as $k=>$v) { |
73 | - if ($s !== '') { |
|
74 | - $s .= ','; |
|
73 | + if ($s!=='') { |
|
74 | + $s.=','; |
|
75 | 75 | } |
76 | - if(is_array($v)){ |
|
77 | - $s .= "'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
78 | - }else{ |
|
79 | - $s .= "'{$k}':{$v}"; |
|
76 | + if (is_array($v)) { |
|
77 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
78 | + } else { |
|
79 | + $s.="'{$k}':{$v}"; |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | return $s; |
83 | 83 | } |
84 | 84 | |
85 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
86 | - if(isset($jsCondition)){ |
|
85 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
86 | + if (isset($jsCondition)) { |
|
87 | 87 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
88 | 88 | } |
89 | 89 | return $jsSource; |
90 | 90 | } |
91 | 91 | |
92 | 92 | |
93 | - protected function _getAjaxUrl($url,$attr){ |
|
93 | + protected function _getAjaxUrl($url, $attr) { |
|
94 | 94 | $url=$this->_correctAjaxUrl($url); |
95 | 95 | $retour="url='".$url."';"; |
96 | 96 | $slash="/"; |
97 | - if(JString::endswith($url, "/")===true){ |
|
97 | + if (JString::endswith($url, "/")===true) { |
|
98 | 98 | $slash=""; |
99 | 99 | } |
100 | - if(JString::isNotNull($attr)){ |
|
101 | - if ($attr==="value"){ |
|
100 | + if (JString::isNotNull($attr)) { |
|
101 | + if ($attr==="value") { |
|
102 | 102 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
103 | - }elseif ($attr==="html"){ |
|
103 | + }elseif ($attr==="html") { |
|
104 | 104 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
105 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
105 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
106 | 106 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
107 | - }elseif($attr!==null && $attr!=="") |
|
107 | + }elseif ($attr!==null && $attr!=="") |
|
108 | 108 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
109 | 109 | } |
110 | 110 | return $retour; |
111 | 111 | } |
112 | 112 | |
113 | - protected function onPopstate(){ |
|
113 | + protected function onPopstate() { |
|
114 | 114 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
115 | 115 | } |
116 | 116 | |
117 | - protected function autoActiveLinks($previousURL="window.location.href"){ |
|
118 | - $result= "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
117 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
118 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
119 | 119 | $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
120 | 120 | return $result; |
121 | 121 | } |
122 | 122 | |
123 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){ |
|
124 | - $retour="";$call=null; |
|
123 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
124 | + $retour=""; $call=null; |
|
125 | 125 | if (JString::isNotNull($responseElement)) { |
126 | - if(isset($ajaxTransition)){ |
|
126 | + if (isset($ajaxTransition)) { |
|
127 | 127 | $call=$this->setAjaxDataCall($ajaxTransition); |
128 | - }elseif(isset($this->ajaxTransition)){ |
|
128 | + }elseif (isset($this->ajaxTransition)) { |
|
129 | 129 | $call=$this->ajaxTransition; |
130 | 130 | } |
131 | - if(\is_callable($call)) |
|
132 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
131 | + if (\is_callable($call)) |
|
132 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
133 | 133 | else |
134 | 134 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
135 | 135 | } |
136 | - if(isset($history)){ |
|
137 | - if($this->params["autoActiveLinks"]){ |
|
136 | + if (isset($history)) { |
|
137 | + if ($this->params["autoActiveLinks"]) { |
|
138 | 138 | $retour.=$this->autoActiveLinks("url"); |
139 | 139 | } |
140 | 140 | $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
141 | 141 | } |
142 | - if($hasLoader==="internal"){ |
|
142 | + if ($hasLoader==="internal") { |
|
143 | 143 | $retour.="\n$(self).removeClass('loading');"; |
144 | 144 | } |
145 | 145 | $retour.="\t".$jsCallback."\n"; |
146 | 146 | return $retour; |
147 | 147 | } |
148 | 148 | |
149 | - protected function _getResponseElement($responseElement){ |
|
149 | + protected function _getResponseElement($responseElement) { |
|
150 | 150 | if (JString::isNotNull($responseElement)) { |
151 | 151 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
152 | 152 | } |
@@ -156,37 +156,37 @@ discard block |
||
156 | 156 | protected function _correctAjaxUrl($url) { |
157 | 157 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
158 | 158 | $url=substr($url, 0, strlen($url)-1); |
159 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
159 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
160 | 160 | $url=$this->getUrl($url); |
161 | 161 | } |
162 | 162 | return $url; |
163 | 163 | } |
164 | 164 | |
165 | - public static function _correctParams($params,$ajaxParameters=[]){ |
|
166 | - if(JString::isNull($params)){ |
|
165 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
166 | + if (JString::isNull($params)) { |
|
167 | 167 | return ""; |
168 | 168 | } |
169 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
170 | - if( !isset($ajaxParameters['contentType'])|| !UString::contains('json', $ajaxParameters['contentType'])){ |
|
169 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
170 | + if (!isset($ajaxParameters['contentType']) || !UString::contains('json', $ajaxParameters['contentType'])) { |
|
171 | 171 | return '$.param('.$params.')'; |
172 | - }else{ |
|
172 | + } else { |
|
173 | 173 | return 'JSON.stringify('.$params.')'; |
174 | 174 | } |
175 | 175 | } |
176 | 176 | return $params; |
177 | 177 | } |
178 | 178 | |
179 | - public static function _implodeParams($parameters){ |
|
179 | + public static function _implodeParams($parameters) { |
|
180 | 180 | $allParameters=[]; |
181 | - foreach ($parameters as $params){ |
|
182 | - if(isset($params)) |
|
181 | + foreach ($parameters as $params) { |
|
182 | + if (isset($params)) |
|
183 | 183 | $allParameters[]=self::_correctParams($params); |
184 | 184 | } |
185 | 185 | return \implode("+'&'+", $allParameters); |
186 | 186 | } |
187 | 187 | |
188 | - protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) { |
|
189 | - if(!isset($ajaxLoader)){ |
|
188 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
189 | + if (!isset($ajaxLoader)) { |
|
190 | 190 | $ajaxLoader=$this->ajaxLoader; |
191 | 191 | } |
192 | 192 | $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
@@ -194,19 +194,19 @@ discard block |
||
194 | 194 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
195 | 195 | } |
196 | 196 | |
197 | - protected function setAjaxDataCall($params){ |
|
197 | + protected function setAjaxDataCall($params) { |
|
198 | 198 | $result=null; |
199 | - if(!\is_callable($params)){ |
|
200 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
201 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
199 | + if (!\is_callable($params)) { |
|
200 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
201 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
202 | 202 | }; |
203 | 203 | } |
204 | 204 | return $result; |
205 | 205 | } |
206 | 206 | |
207 | - protected function setDefaultParameters(&$parameters,$default){ |
|
208 | - foreach ($default as $k=>$v){ |
|
209 | - if(!isset($parameters[$k])) |
|
207 | + protected function setDefaultParameters(&$parameters, $default) { |
|
208 | + foreach ($default as $k=>$v) { |
|
209 | + if (!isset($parameters[$k])) |
|
210 | 210 | $parameters[$k]=$v; |
211 | 211 | } |
212 | 212 | } |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | * @param string $url The url of the request |
221 | 221 | * @param string $responseElement selector of the HTML element displaying the answer |
222 | 222 | */ |
223 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
224 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
223 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
224 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param string $responseElement selector of the HTML element displaying the answer |
231 | 231 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
232 | 232 | */ |
233 | - public function get($url, $responseElement="",$parameters=[]) { |
|
233 | + public function get($url, $responseElement="", $parameters=[]) { |
|
234 | 234 | $parameters["immediatly"]=true; |
235 | - return $this->_get($url,$responseElement,$parameters); |
|
235 | + return $this->_get($url, $responseElement, $parameters); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | * @param string $responseElement selector of the HTML element displaying the answer |
243 | 243 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
244 | 244 | */ |
245 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
245 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
246 | 246 | $parameters["immediatly"]=true; |
247 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
247 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | * @param array $parameters The ajax parameters, default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
258 | 258 | * @return string |
259 | 259 | */ |
260 | - public function ajaxInterval($method,$url, $interval,$globalName=null,$responseElement="", $parameters=[]){ |
|
261 | - return $this->interval($this->ajaxDeferred($method, $url,$responseElement,$parameters), $interval,$globalName); |
|
260 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[]) { |
|
261 | + return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | * @param string $responseElement selector of the HTML element displaying the answer |
269 | 269 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
270 | 270 | */ |
271 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
271 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
272 | 272 | $parameters["immediatly"]=false; |
273 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
273 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | * @param string $method Method used |
280 | 280 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
281 | 281 | */ |
282 | - private function _json($url, $method="get",$parameters=[]) { |
|
283 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
282 | + private function _json($url, $method="get", $parameters=[]) { |
|
283 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
284 | 284 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
285 | 285 | $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
286 | 286 | $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";" |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | ."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
289 | 289 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
290 | 290 | $parameters["jsCallback"]=$retour; |
291 | - return $this->_ajax($method, $url,null,$parameters); |
|
291 | + return $this->_ajax($method, $url, null, $parameters); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
299 | 299 | */ |
300 | 300 | public function json($url, $method="get", $parameters=[]) { |
301 | - return $this->_json($url,$method,$parameters); |
|
301 | + return $this->_json($url, $method, $parameters); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -309,9 +309,9 @@ discard block |
||
309 | 309 | * @param string $method default get |
310 | 310 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
311 | 311 | */ |
312 | - public function jsonOn($event,$element, $url,$method="get",$parameters=array()) { |
|
313 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
314 | - return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
312 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
313 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
314 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public function jsonDeferred($url, $method="get", $parameters=[]) { |
324 | 324 | $parameters["immediatly"]=false; |
325 | - return $this->_json($url,$method,$parameters); |
|
325 | + return $this->_json($url, $method, $parameters); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -333,27 +333,27 @@ discard block |
||
333 | 333 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
334 | 334 | */ |
335 | 335 | private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
336 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
336 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
337 | 337 | $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
338 | 338 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
339 | 339 | $context=isset($parameters['context']) ? $parameters['context'] : null; |
340 | - if($context===null){ |
|
340 | + if ($context===null) { |
|
341 | 341 | $parent="$('".$maskSelector."').parent()"; |
342 | - $newElm = "$('#'+newId)"; |
|
343 | - }else{ |
|
342 | + $newElm="$('#'+newId)"; |
|
343 | + } else { |
|
344 | 344 | $parent=$context; |
345 | - $newElm = $context.".find('#'+newId)"; |
|
345 | + $newElm=$context.".find('#'+newId)"; |
|
346 | 346 | } |
347 | 347 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
348 | 348 | $retour=$parent.".find('.{$rowClass}').remove();"; |
349 | 349 | $retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.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(); |
350 | 350 | newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
351 | - $retour.= $appendTo; |
|
351 | + $retour.=$appendTo; |
|
352 | 352 | $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"; |
353 | 353 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
354 | 354 | $retour.="\t".$jsCallback; |
355 | 355 | $parameters["jsCallback"]=$retour; |
356 | - return $this->_ajax($method, $url,null,$parameters); |
|
356 | + return $this->_ajax($method, $url, null, $parameters); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
365 | 365 | */ |
366 | 366 | public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
367 | - return $this->_jsonArray($maskSelector, $url,$method,$parameters); |
|
367 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -387,9 +387,9 @@ discard block |
||
387 | 387 | * @param string $method Method used, default : get |
388 | 388 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
389 | 389 | */ |
390 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) { |
|
391 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
392 | - return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
390 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
391 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
392 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | */ |
402 | 402 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
403 | 403 | $parameters["immediatly"]=false; |
404 | - return $this->_get($url, $responseElement,$parameters); |
|
404 | + return $this->_get($url, $responseElement, $parameters); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false) |
415 | 415 | */ |
416 | 416 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
417 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
418 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
417 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
418 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | * @param array $parameters default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
429 | 429 | */ |
430 | 430 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
431 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
432 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
431 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
432 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -463,15 +463,15 @@ discard block |
||
463 | 463 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true) |
464 | 464 | * @return $this |
465 | 465 | */ |
466 | - public function getHref($element,$responseElement="",$parameters=array()){ |
|
466 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
467 | 467 | $parameters["attr"]="href"; |
468 | - if(JString::isNull($responseElement)){ |
|
468 | + if (JString::isNull($responseElement)) { |
|
469 | 469 | $responseElement='%$(self).attr("data-target")%'; |
470 | 470 | } |
471 | - if(!isset($parameters["historize"])){ |
|
471 | + if (!isset($parameters["historize"])) { |
|
472 | 472 | $parameters["historize"]=true; |
473 | 473 | } |
474 | - return $this->getOnClick($element, "",$responseElement,$parameters); |
|
474 | + return $this->getOnClick($element, "", $responseElement, $parameters); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -481,20 +481,20 @@ discard block |
||
481 | 481 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
482 | 482 | * @return $this |
483 | 483 | */ |
484 | - public function postHref($element,$responseElement="",$parameters=array()){ |
|
484 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
485 | 485 | $parameters["attr"]="href"; |
486 | - if(JString::isNull($responseElement)){ |
|
486 | + if (JString::isNull($responseElement)) { |
|
487 | 487 | $responseElement='%$(this).attr("data-target")%'; |
488 | 488 | } |
489 | - if(!isset($parameters["historize"])){ |
|
489 | + if (!isset($parameters["historize"])) { |
|
490 | 490 | $parameters["historize"]=true; |
491 | 491 | } |
492 | - return $this->postOnClick($element, "","{}",$responseElement,$parameters); |
|
492 | + return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
|
493 | 493 | } |
494 | 494 | |
495 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
495 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
496 | 496 | $parameters["params"]=$params; |
497 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
497 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | * @param string $params JSON parameters |
505 | 505 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
506 | 506 | */ |
507 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
508 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
507 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
508 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | /** |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | * @param string $responseElement selector of the HTML element displaying the answer |
517 | 517 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
518 | 518 | */ |
519 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
519 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
520 | 520 | $parameters["immediatly"]=false; |
521 | 521 | return $this->_post($url, $params, $responseElement, $parameters); |
522 | 522 | } |
@@ -532,8 +532,8 @@ discard block |
||
532 | 532 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
533 | 533 | */ |
534 | 534 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
535 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
536 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
535 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
536 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -550,33 +550,33 @@ discard block |
||
550 | 550 | } |
551 | 551 | |
552 | 552 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
553 | - if(isset($this->params["ajax"])){ |
|
553 | + if (isset($this->params["ajax"])) { |
|
554 | 554 | extract($this->params["ajax"]); |
555 | 555 | } |
556 | - $params="{}";$validation=false; |
|
556 | + $params="{}"; $validation=false; |
|
557 | 557 | \extract($parameters); |
558 | - $async=($async)?"true":"false"; |
|
558 | + $async=($async) ? "true" : "false"; |
|
559 | 559 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
560 | 560 | $retour=$this->_getAjaxUrl($url, $attr); |
561 | 561 | $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
562 | 562 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
563 | - if(isset($params)){ |
|
563 | + if (isset($params)) { |
|
564 | 564 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
565 | 565 | } |
566 | 566 | $responseElement=$this->_getResponseElement($responseElement); |
567 | 567 | $retour.="var self=this;\n"; |
568 | - if($hasLoader===true){ |
|
569 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
570 | - }elseif($hasLoader==="internal"){ |
|
568 | + if ($hasLoader===true) { |
|
569 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
570 | + }elseif ($hasLoader==="internal") { |
|
571 | 571 | $retour.="\n$(this).addClass('loading');"; |
572 | 572 | } |
573 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
|
574 | - if(isset($headers)){ |
|
573 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async]; |
|
574 | + if (isset($headers)) { |
|
575 | 575 | $ajaxParameters["headers"]=$headers; |
576 | 576 | } |
577 | 577 | $this->createAjaxParameters($ajaxParameters, $parameters); |
578 | 578 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
579 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n"; |
|
579 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
580 | 580 | |
581 | 581 | if ($validation) { |
582 | 582 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -626,8 +626,8 @@ discard block |
||
626 | 626 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false) |
627 | 627 | */ |
628 | 628 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
629 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
630 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
629 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
630 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $retour.=$before; |
37 | 37 | if($hasLoader===true && JString::isNotNull($responseElement)){ |
38 | 38 | $this->addLoading($retour, $responseElement,$ajaxLoader); |
39 | - }elseif($hasLoader==="internal"){ |
|
39 | + } elseif($hasLoader==="internal"){ |
|
40 | 40 | $retour.="\n$(this).addClass('loading');"; |
41 | 41 | } |
42 | 42 | $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
@@ -53,8 +53,9 @@ discard block |
||
53 | 53 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
54 | 54 | $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
55 | 55 | $retour=$this->_addJsCondition($jsCondition,$retour); |
56 | - if ($immediatly) |
|
57 | - $this->jquery_code_for_compile[]=$retour; |
|
56 | + if ($immediatly) { |
|
57 | + $this->jquery_code_for_compile[]=$retour; |
|
58 | + } |
|
58 | 59 | return $retour; |
59 | 60 | } |
60 | 61 | |
@@ -75,7 +76,7 @@ discard block |
||
75 | 76 | } |
76 | 77 | if(is_array($v)){ |
77 | 78 | $s .= "'{$k}':{".self::implodeAjaxParameters($v)."}"; |
78 | - }else{ |
|
79 | + } else{ |
|
79 | 80 | $s .= "'{$k}':{$v}"; |
80 | 81 | } |
81 | 82 | } |
@@ -100,12 +101,13 @@ discard block |
||
100 | 101 | if(JString::isNotNull($attr)){ |
101 | 102 | if ($attr==="value"){ |
102 | 103 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
103 | - }elseif ($attr==="html"){ |
|
104 | + } elseif ($attr==="html"){ |
|
104 | 105 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
105 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
106 | + } elseif(\substr($attr, 0,3)==="js:"){ |
|
106 | 107 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
107 | - }elseif($attr!==null && $attr!=="") |
|
108 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
108 | + } elseif($attr!==null && $attr!=="") { |
|
109 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
110 | + } |
|
109 | 111 | } |
110 | 112 | return $retour; |
111 | 113 | } |
@@ -125,13 +127,14 @@ discard block |
||
125 | 127 | if (JString::isNotNull($responseElement)) { |
126 | 128 | if(isset($ajaxTransition)){ |
127 | 129 | $call=$this->setAjaxDataCall($ajaxTransition); |
128 | - }elseif(isset($this->ajaxTransition)){ |
|
130 | + } elseif(isset($this->ajaxTransition)){ |
|
129 | 131 | $call=$this->ajaxTransition; |
130 | 132 | } |
131 | - if(\is_callable($call)) |
|
132 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
133 | - else |
|
134 | - $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
133 | + if(\is_callable($call)) { |
|
134 | + $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
135 | + } else { |
|
136 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
137 | + } |
|
135 | 138 | } |
136 | 139 | if(isset($history)){ |
137 | 140 | if($this->params["autoActiveLinks"]){ |
@@ -154,8 +157,9 @@ discard block |
||
154 | 157 | } |
155 | 158 | |
156 | 159 | protected function _correctAjaxUrl($url) { |
157 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
158 | - $url=substr($url, 0, strlen($url)-1); |
|
160 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
161 | + $url=substr($url, 0, strlen($url)-1); |
|
162 | + } |
|
159 | 163 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
160 | 164 | $url=$this->getUrl($url); |
161 | 165 | } |
@@ -169,7 +173,7 @@ discard block |
||
169 | 173 | if(\preg_match("@^\{.*?\}$@", $params)){ |
170 | 174 | if( !isset($ajaxParameters['contentType'])|| !UString::contains('json', $ajaxParameters['contentType'])){ |
171 | 175 | return '$.param('.$params.')'; |
172 | - }else{ |
|
176 | + } else{ |
|
173 | 177 | return 'JSON.stringify('.$params.')'; |
174 | 178 | } |
175 | 179 | } |
@@ -179,8 +183,9 @@ discard block |
||
179 | 183 | public static function _implodeParams($parameters){ |
180 | 184 | $allParameters=[]; |
181 | 185 | foreach ($parameters as $params){ |
182 | - if(isset($params)) |
|
183 | - $allParameters[]=self::_correctParams($params); |
|
186 | + if(isset($params)) { |
|
187 | + $allParameters[]=self::_correctParams($params); |
|
188 | + } |
|
184 | 189 | } |
185 | 190 | return \implode("+'&'+", $allParameters); |
186 | 191 | } |
@@ -206,8 +211,9 @@ discard block |
||
206 | 211 | |
207 | 212 | protected function setDefaultParameters(&$parameters,$default){ |
208 | 213 | foreach ($default as $k=>$v){ |
209 | - if(!isset($parameters[$k])) |
|
210 | - $parameters[$k]=$v; |
|
214 | + if(!isset($parameters[$k])) { |
|
215 | + $parameters[$k]=$v; |
|
216 | + } |
|
211 | 217 | } |
212 | 218 | } |
213 | 219 | |
@@ -340,7 +346,7 @@ discard block |
||
340 | 346 | if($context===null){ |
341 | 347 | $parent="$('".$maskSelector."').parent()"; |
342 | 348 | $newElm = "$('#'+newId)"; |
343 | - }else{ |
|
349 | + } else{ |
|
344 | 350 | $parent=$context; |
345 | 351 | $newElm = $context.".find('#'+newId)"; |
346 | 352 | } |
@@ -567,7 +573,7 @@ discard block |
||
567 | 573 | $retour.="var self=this;\n"; |
568 | 574 | if($hasLoader===true){ |
569 | 575 | $this->addLoading($retour, $responseElement,$ajaxLoader); |
570 | - }elseif($hasLoader==="internal"){ |
|
576 | + } elseif($hasLoader==="internal"){ |
|
571 | 577 | $retour.="\n$(this).addClass('loading');"; |
572 | 578 | } |
573 | 579 | $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
@@ -585,8 +591,9 @@ discard block |
||
585 | 591 | $retour.="$('#".$form."').submit();\n"; |
586 | 592 | } |
587 | 593 | $retour=$this->_addJsCondition($jsCondition, $retour); |
588 | - if ($immediatly) |
|
589 | - $this->jquery_code_for_compile[]=$retour; |
|
594 | + if ($immediatly) { |
|
595 | + $this->jquery_code_for_compile[]=$retour; |
|
596 | + } |
|
590 | 597 | return $retour; |
591 | 598 | } |
592 | 599 |