Completed
Push — master ( 364809...26095a )
by Jean-Christophe
10:25
created
Ajax/semantic/html/collections/form/HtmlForm.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 
33 33
 	public function __construct($identifier, $elements=array()) {
34 34
 		parent::__construct($identifier, "form", "ui form");
35
-		$this->_states=[ State::ERROR,State::SUCCESS,State::WARNING,State::DISABLED ];
35
+		$this->_states=[State::ERROR, State::SUCCESS, State::WARNING, State::DISABLED];
36 36
 		$this->setProperty("name", $this->identifier);
37
-		$this->_fields=array ();
37
+		$this->_fields=array();
38 38
 		$this->_validationParams=[];
39 39
 		$this->addItems($elements);
40 40
 	}
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
 	 * @param string $caption
57 57
 	 * @return \Ajax\semantic\html\collections\form\HtmlForm
58 58
 	 */
59
-	public function addDivider($caption=NULL){
60
-		return $this->addContent(new HtmlDivider("",$caption));
59
+	public function addDivider($caption=NULL) {
60
+		return $this->addContent(new HtmlDivider("", $caption));
61 61
 	}
62 62
 
63 63
 	public function addFields($fields=NULL, $label=NULL) {
64 64
 		if (isset($fields)) {
65 65
 			if (!$fields instanceof HtmlFormFields) {
66
-				if (\is_array($fields) === false) {
66
+				if (\is_array($fields)===false) {
67 67
 					$fields=\func_get_args();
68 68
 					$end=\end($fields);
69 69
 					if (\is_string($end)) {
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 						$label=NULL;
74 74
 				}
75 75
 				$this->_fields=\array_merge($this->_fields, $fields);
76
-				$fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count(), $fields);
76
+				$fields=new HtmlFormFields("fields-".$this->identifier."-".$this->count(), $fields);
77 77
 			}
78 78
 			if (isset($label))
79 79
 				$fields=new HtmlFormField("", $fields, $label);
80 80
 		} else {
81
-			$fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count());
81
+			$fields=new HtmlFormFields("fields-".$this->identifier."-".$this->count());
82 82
 		}
83 83
 		$this->addItem($fields);
84 84
 		return $fields;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 
87 87
 	public function addItem($item) {
88 88
 		$item=parent::addItem($item);
89
-		if (\is_subclass_of($item, HtmlFormField::class) === true) {
89
+		if (\is_subclass_of($item, HtmlFormField::class)===true) {
90 90
 			$this->_fields[]=$item;
91 91
 		}
92 92
 		return $item;
@@ -118,17 +118,17 @@  discard block
 block discarded – undo
118 118
 		return $this->addItem($field);
119 119
 	}
120 120
 
121
-	public function addFieldRule($index,$type,$prompt=NULL,$value=NULL){
121
+	public function addFieldRule($index, $type, $prompt=NULL, $value=NULL) {
122 122
 		$field=$this->getItem($index);
123
-		if(isset($field)){
124
-			$field->addRule($type,$prompt,$value);
123
+		if (isset($field)) {
124
+			$field->addRule($type, $prompt, $value);
125 125
 		}
126 126
 		return $this;
127 127
 	}
128 128
 
129
-	public function addFieldRules($index,$rules){
129
+	public function addFieldRules($index, $rules) {
130 130
 		$field=$this->getItem($index);
131
-		if(isset($field)){
131
+		if (isset($field)) {
132 132
 			$field->addRules($rules);
133 133
 		}
134 134
 		return $this;
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
 		return $this->addItem($message);
155 155
 	}
156 156
 
157
-	private function addCompoValidation($js,$compo,$field){
157
+	private function addCompoValidation($js, $compo, $field) {
158 158
 		$validation=$field->getValidation();
159
-		if(isset($validation)){
160
-			if(isset($compo)===false){
159
+		if (isset($validation)) {
160
+			if (isset($compo)===false) {
161 161
 				$compo=$js->semantic()->form("#".$this->identifier);
162 162
 			}
163 163
 			$validation->setIdentifier($field->getField()->getIdentifier());
@@ -168,26 +168,26 @@  discard block
 block discarded – undo
168 168
 
169 169
 	public function run(JsUtils $js) {
170 170
 		$compo=NULL;
171
-		foreach ($this->_fields as $field){
172
-			if($field instanceof HtmlFormField)
171
+		foreach ($this->_fields as $field) {
172
+			if ($field instanceof HtmlFormField)
173 173
 				$compo=$this->addCompoValidation($js, $compo, $field);
174 174
 		}
175
-		foreach ($this->content as $field){
176
-			if($field instanceof HtmlFormFields){
175
+		foreach ($this->content as $field) {
176
+			if ($field instanceof HtmlFormFields) {
177 177
 				$items=$field->getItems();
178
-				foreach ($items as $_field){
179
-					if($_field instanceof HtmlFormField)
178
+				foreach ($items as $_field) {
179
+					if ($_field instanceof HtmlFormField)
180 180
 						$compo=$this->addCompoValidation($js, $compo, $_field);
181 181
 				}
182 182
 			}
183 183
 		}
184
-		if(isset($compo)===false){
184
+		if (isset($compo)===false) {
185 185
 			return parent::run($js);
186 186
 		}
187
-		if(isset($this->_validationParams["_ajaxSubmit"])){
188
-			if($this->_validationParams["_ajaxSubmit"] instanceof AjaxCall){
187
+		if (isset($this->_validationParams["_ajaxSubmit"])) {
188
+			if ($this->_validationParams["_ajaxSubmit"] instanceof AjaxCall) {
189 189
 				$compilation=$this->_validationParams["_ajaxSubmit"]->compile($js);
190
-				$compilation=str_ireplace("\"","%quote%", $compilation);
190
+				$compilation=str_ireplace("\"", "%quote%", $compilation);
191 191
 				$this->onSuccess($compilation);
192 192
 				unset($this->_validationParams["_ajaxSubmit"]);
193 193
 			}
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		return $this->addToProperty("class", "loading");
203 203
 	}
204 204
 
205
-	public function addErrorMessage(){
205
+	public function addErrorMessage() {
206 206
 		return $this->addContent((new HtmlMessage(""))->setError());
207 207
 	}
208 208
 
@@ -215,22 +215,22 @@  discard block
 block discarded – undo
215 215
 		return $this;
216 216
 	}
217 217
 
218
-	public function submitOn($event,$identifier,$url,$responseElement){
218
+	public function submitOn($event, $identifier, $url, $responseElement) {
219 219
 		$elem=$this->getElementById($identifier, $this->content);
220
-		if(isset($elem)){
220
+		if (isset($elem)) {
221 221
 			$elem->addEvent($event, "$('#".$this->identifier."').form('validate form');");
222
-			$this->_validationParams["_ajaxSubmit"]=new AjaxCall("postForm", ["form"=>$this->identifier,"responseElement"=>$responseElement,"url"=>$url]);
222
+			$this->_validationParams["_ajaxSubmit"]=new AjaxCall("postForm", ["form"=>$this->identifier, "responseElement"=>$responseElement, "url"=>$url]);
223 223
 		}
224 224
 		return $this;
225 225
 	}
226 226
 
227
-	public function submitOnClick($identifier,$url,$responseElement){
227
+	public function submitOnClick($identifier, $url, $responseElement) {
228 228
 		return $this->submitOn("click", $identifier, $url, $responseElement);
229 229
 	}
230 230
 
231
-	public function addSubmit($identifier,$value,$CssStyle=NULL,$url=NULL,$responseElement=NULL){
232
-		$bt=$this->addButton($identifier, $value,$CssStyle);
233
-		if(isset($url) && isset($responseElement))
231
+	public function addSubmit($identifier, $value, $CssStyle=NULL, $url=NULL, $responseElement=NULL) {
232
+		$bt=$this->addButton($identifier, $value, $CssStyle);
233
+		if (isset($url) && isset($responseElement))
234 234
 			$this->submitOnClick($identifier, $url, $responseElement);
235 235
 		return $bt;
236 236
 	}
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	 * @param string $jsCode
241 241
 	 * @return \Ajax\semantic\html\collections\form\HtmlForm
242 242
 	 */
243
-	public function onValid($jsCode){
243
+	public function onValid($jsCode) {
244 244
 		$this->_validationParams["onValid"]="%function(){".$jsCode."}%";
245 245
 		return $this;
246 246
 	}
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 * @param string $jsCode can use event and fields parameters
251 251
 	 * @return HtmlForm
252 252
 	 */
253
-	public function onSuccess($jsCode){
253
+	public function onSuccess($jsCode) {
254 254
 		$this->_validationParams["onSuccess"]="%function(evt,fields){".$jsCode."}%";
255 255
 		return $this;
256 256
 	}
Please login to merge, or discard this patch.
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -47,8 +47,9 @@  discard block
 block discarded – undo
47 47
 	 */
48 48
 	public function addHeader($title, $niveau=1, $dividing=true) {
49 49
 		$header=new HtmlHeader("", $niveau, $title);
50
-		if ($dividing)
51
-			$header->setDividing();
50
+		if ($dividing) {
51
+					$header->setDividing();
52
+		}
52 53
 		return $this->addItem($header);
53 54
 	}
54 55
 
@@ -69,14 +70,16 @@  discard block
 block discarded – undo
69 70
 					if (\is_string($end)) {
70 71
 						$label=$end;
71 72
 						\array_pop($fields);
72
-					} else
73
-						$label=NULL;
73
+					} else {
74
+											$label=NULL;
75
+					}
74 76
 				}
75 77
 				$this->_fields=\array_merge($this->_fields, $fields);
76 78
 				$fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count(), $fields);
77 79
 			}
78
-			if (isset($label))
79
-				$fields=new HtmlFormField("", $fields, $label);
80
+			if (isset($label)) {
81
+							$fields=new HtmlFormField("", $fields, $label);
82
+			}
80 83
 		} else {
81 84
 			$fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count());
82 85
 		}
@@ -145,12 +148,15 @@  discard block
 block discarded – undo
145 148
 	 */
146 149
 	public function addMessage($identifier, $content, $header=NULL, $icon=NULL, $type=NULL) {
147 150
 		$message=new HtmlMessage($identifier, $content);
148
-		if (isset($header))
149
-			$message->addHeader($header);
150
-		if (isset($icon))
151
-			$message->setIcon($icon);
152
-		if (isset($type))
153
-			$message->setStyle($type);
151
+		if (isset($header)) {
152
+					$message->addHeader($header);
153
+		}
154
+		if (isset($icon)) {
155
+					$message->setIcon($icon);
156
+		}
157
+		if (isset($type)) {
158
+					$message->setStyle($type);
159
+		}
154 160
 		return $this->addItem($message);
155 161
 	}
156 162
 
@@ -169,15 +175,17 @@  discard block
 block discarded – undo
169 175
 	public function run(JsUtils $js) {
170 176
 		$compo=NULL;
171 177
 		foreach ($this->_fields as $field){
172
-			if($field instanceof HtmlFormField)
173
-				$compo=$this->addCompoValidation($js, $compo, $field);
178
+			if($field instanceof HtmlFormField) {
179
+							$compo=$this->addCompoValidation($js, $compo, $field);
180
+			}
174 181
 		}
175 182
 		foreach ($this->content as $field){
176 183
 			if($field instanceof HtmlFormFields){
177 184
 				$items=$field->getItems();
178 185
 				foreach ($items as $_field){
179
-					if($_field instanceof HtmlFormField)
180
-						$compo=$this->addCompoValidation($js, $compo, $_field);
186
+					if($_field instanceof HtmlFormField) {
187
+											$compo=$this->addCompoValidation($js, $compo, $_field);
188
+					}
181 189
 				}
182 190
 			}
183 191
 		}
@@ -230,8 +238,9 @@  discard block
 block discarded – undo
230 238
 
231 239
 	public function addSubmit($identifier,$value,$CssStyle=NULL,$url=NULL,$responseElement=NULL){
232 240
 		$bt=$this->addButton($identifier, $value,$CssStyle);
233
-		if(isset($url) && isset($responseElement))
234
-			$this->submitOnClick($identifier, $url, $responseElement);
241
+		if(isset($url) && isset($responseElement)) {
242
+					$this->submitOnClick($identifier, $url, $responseElement);
243
+		}
235 244
 		return $bt;
236 245
 	}
237 246
 
Please login to merge, or discard this patch.