Completed
Push — master ( 24138a...0b3773 )
by Jean-Christophe
05:10
created
Ajax/common/html/traits/BaseHtmlEventsTrait.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
  * @property SimpleExtComponent $_bsComponent
12 12
  * @property string identifier
13 13
  */
14
-trait BaseHtmlEventsTrait{
14
+trait BaseHtmlEventsTrait {
15 15
 
16
-	protected $_events=array ();
16
+	protected $_events=array();
17 17
 
18 18
 	/**
19 19
 	 * @param string $event
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
 	 * @return \Ajax\common\html\BaseHtml
24 24
 	 */
25 25
 	public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false) {
26
-		if ($stopPropagation === true) {
27
-			$jsCode=Javascript::$stopPropagation . $jsCode;
26
+		if ($stopPropagation===true) {
27
+			$jsCode=Javascript::$stopPropagation.$jsCode;
28 28
 		}
29
-		if ($preventDefault === true) {
30
-			$jsCode=Javascript::$preventDefault . $jsCode;
29
+		if ($preventDefault===true) {
30
+			$jsCode=Javascript::$preventDefault.$jsCode;
31 31
 		}
32 32
 		return $this->_addEvent($event, $jsCode);
33 33
 	}
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 			if (\is_array($this->_events[$event])) {
43 43
 				$this->_events[$event][]=$jsCode;
44 44
 			} else {
45
-				$this->_events[$event]=array ($this->_events[$event],$jsCode );
45
+				$this->_events[$event]=array($this->_events[$event], $jsCode);
46 46
 			}
47 47
 		} else {
48 48
 			$this->_events[$event]=$jsCode;
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
 		return $this->onClick($jsCode);
70 70
 	}
71 71
 
72
-	public function onCreate($jsCode){
73
-		if(isset($this->_events["_create"])){
72
+	public function onCreate($jsCode) {
73
+		if (isset($this->_events["_create"])) {
74 74
 			$this->_events["_create"][]=$jsCode;
75
-		}else{
75
+		} else {
76 76
 			$this->_events["_create"]=[$jsCode];
77 77
 		}
78 78
 		return $this;
@@ -81,15 +81,15 @@  discard block
 block discarded – undo
81 81
 	public function addEventsOnRun(JsUtils $js=NULL) {
82 82
 		$this->_eventsOnCreate($js);
83 83
 		if (isset($this->_bsComponent)) {
84
-			foreach ( $this->_events as $event => $jsCode ) {
84
+			foreach ($this->_events as $event => $jsCode) {
85 85
 				$code=$jsCode;
86 86
 				if (\is_array($jsCode)) {
87 87
 					$code="";
88
-					foreach ( $jsCode as $jsC ) {
88
+					foreach ($jsCode as $jsC) {
89 89
 						if ($jsC instanceof AjaxCall) {
90
-							$code.="\n" . $jsC->compile($js);
90
+							$code.="\n".$jsC->compile($js);
91 91
 						} else {
92
-							$code.="\n" . $jsC;
92
+							$code.="\n".$jsC;
93 93
 						}
94 94
 					}
95 95
 				} elseif ($jsCode instanceof AjaxCall) {
@@ -97,18 +97,18 @@  discard block
 block discarded – undo
97 97
 				}
98 98
 				$this->_bsComponent->addEvent($event, $code);
99 99
 			}
100
-			$this->_events=array ();
100
+			$this->_events=array();
101 101
 		}
102 102
 	}
103 103
 
104
-	protected function _eventsOnCreate(JsUtils $js=NULL){
105
-		if(isset($this->_events["_create"])){
104
+	protected function _eventsOnCreate(JsUtils $js=NULL) {
105
+		if (isset($this->_events["_create"])) {
106 106
 			$create=$this->_events["_create"];
107
-			if(\is_array($create)){
107
+			if (\is_array($create)) {
108 108
 				$create=\implode("", $create);
109 109
 			}
110
-			if(isset($js) && $create!=="")
111
-				$js->exec($create,true);
110
+			if (isset($js) && $create!=="")
111
+				$js->exec($create, true);
112 112
 			unset($this->_events["_create"]);
113 113
 		}
114 114
 	}
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * @return BaseHtml
123 123
 	 */
124 124
 	public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) {
125
-		$params=array ("url" => $url,"responseElement" => $responseElement );
125
+		$params=array("url" => $url, "responseElement" => $responseElement);
126 126
 		$params=array_merge($params, $parameters);
127 127
 		$this->_addEvent($event, new AjaxCall($operation, $params));
128 128
 		return $this;
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	}
156 156
 
157 157
 	public function jsDoJquery($jqueryCall, $param="") {
158
-		return "$('#" . $this->identifier . "')." . $jqueryCall . "(" . Javascript::prep_value($param) . ");";
158
+		return "$('#".$this->identifier."').".$jqueryCall."(".Javascript::prep_value($param).");";
159 159
 	}
160 160
 
161 161
 	public function executeOnRun($jsCode) {
Please login to merge, or discard this patch.
Ajax/service/Javascript.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,8 @@
 block discarded – undo
6 6
 	public static $preventDefault="\nif(event && event.preventDefault) event.preventDefault();\n";
7 7
 	public static $stopPropagation="\nif(event && event.stopPropagation) event.stopPropagation();\n";
8 8
 
9
-	public static function containsCode($expression){
10
-		return strrpos($expression, 'this')!==false||strrpos($expression, 'event')!==false||strrpos($expression, 'self')!==false;
9
+	public static function containsCode($expression) {
10
+		return strrpos($expression, 'this')!==false || strrpos($expression, 'event')!==false || strrpos($expression, 'self')!==false;
11 11
 	}
12 12
 
13 13
 	/**
Please login to merge, or discard this patch.
Ajax/service/AjaxCall.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,15 +32,15 @@
 block discarded – undo
32 32
 		if ($stopPropagation===true) {
33 33
 			$result.=Javascript::$stopPropagation;
34 34
 		}
35
-		switch($this->method) {
35
+		switch ($this->method) {
36 36
 			case "get":
37
-				$result.=$js->getDeferred($url, $responseElement, $params, $callback, $attr,$jqueryDone);
37
+				$result.=$js->getDeferred($url, $responseElement, $params, $callback, $attr, $jqueryDone);
38 38
 				break;
39 39
 			case "post":
40
-				$result.=$js->postDeferred($url, $responseElement, $params, $callback, $attr,$hasLoader,$jqueryDone);
40
+				$result.=$js->postDeferred($url, $responseElement, $params, $callback, $attr, $hasLoader, $jqueryDone);
41 41
 				break;
42 42
 			case "postForm":
43
-				$result.=$js->postFormDeferred($url, $form, $responseElement, $validation, $callback, $attr,$hasLoader,$jqueryDone);
43
+				$result.=$js->postFormDeferred($url, $form, $responseElement, $validation, $callback, $attr, $hasLoader, $jqueryDone);
44 44
 				break;
45 45
 		}
46 46
 		return $result;
Please login to merge, or discard this patch.
Ajax/Jquery.php 1 patch
Braces   +20 added lines, -13 removed lines patch added patch discarded remove patch
@@ -136,10 +136,12 @@  discard block
 block discarded – undo
136 136
 		if (isset($param)) {
137 137
 			$param=Javascript::prep_value($param);
138 138
 			$str="$({$element}).{$jQueryCall}({$param});";
139
-		} else
140
-			$str="$({$element}).{$jQueryCall}();";
141
-			if ($immediatly)
142
-				$this->jquery_code_for_compile[]=$str;
139
+		} else {
140
+					$str="$({$element}).{$jQueryCall}();";
141
+		}
142
+			if ($immediatly) {
143
+							$this->jquery_code_for_compile[]=$str;
144
+			}
143 145
 			return $str;
144 146
 	}
145 147
 	/**
@@ -154,8 +156,9 @@  discard block
 block discarded – undo
154 156
 		$to=Javascript::prep_element($to);
155 157
 		$element=Javascript::prep_element($element);
156 158
 		$str="$({$to}).{$jQueryCall}({$element});";
157
-		if ($immediatly)
158
-			$this->jquery_code_for_compile[]=$str;
159
+		if ($immediatly) {
160
+					$this->jquery_code_for_compile[]=$str;
161
+		}
159 162
 			return $str;
160 163
 	}
161 164
 
@@ -211,12 +214,14 @@  discard block
 block discarded – undo
211 214
 		if ($stopPropagation===true) {
212 215
 			$js=Javascript::$stopPropagation.$js;
213 216
 		}
214
-		if (array_search($event, $this->jquery_events)===false)
215
-			$event="\n\t$(".Javascript::prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n";
216
-		else
217
-			$event="\n\t$(".Javascript::prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n";
218
-		if($immediatly)
219
-			$this->jquery_code_for_compile[]=$event;
217
+		if (array_search($event, $this->jquery_events)===false) {
218
+					$event="\n\t$(".Javascript::prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n";
219
+		} else {
220
+					$event="\n\t$(".Javascript::prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n";
221
+		}
222
+		if($immediatly) {
223
+					$this->jquery_code_for_compile[]=$event;
224
+		}
220 225
 		return $event;
221 226
 	}
222 227
 
@@ -301,7 +306,9 @@  discard block
 block discarded – undo
301 306
 	}
302 307
 
303 308
 	private function minify($input) {
304
-	if(trim($input) === "") return $input;
309
+	if(trim($input) === "") {
310
+		return $input;
311
+	}
305 312
 	return preg_replace(
306 313
 			array(
307 314
 					// Remove comment(s)
Please login to merge, or discard this patch.
Ajax/semantic/html/collections/form/traits/FormTrait.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -6,28 +6,28 @@  discard block
 block discarded – undo
6 6
 use Ajax\service\AjaxCall;
7 7
 use Ajax\JsUtils;
8 8
 
9
-trait FormTrait{
9
+trait FormTrait {
10 10
 
11 11
 	/**
12 12
 	 * @return HtmlForm
13 13
 	 */
14 14
 	abstract protected function getForm();
15 15
 
16
-	protected function addCompoValidation($compo,$field){
16
+	protected function addCompoValidation($compo, $field) {
17 17
 		$validation=$field->getValidation();
18
-		if(isset($validation)){
18
+		if (isset($validation)) {
19 19
 			$validation->setIdentifier($field->getDataField()->getIdentifier());
20 20
 			$compo->addFieldValidation($validation);
21 21
 		}
22 22
 		return $compo;
23 23
 	}
24 24
 
25
-	protected function _runValidationParams(&$compo,JsUtils $js=NULL){
25
+	protected function _runValidationParams(&$compo, JsUtils $js=NULL) {
26 26
 		$form=$this->getForm();
27 27
 		$params=$form->getValidationParams();
28
-		if(isset($params["_ajaxSubmit"]) && $params["_ajaxSubmit"] instanceof AjaxCall){
28
+		if (isset($params["_ajaxSubmit"]) && $params["_ajaxSubmit"] instanceof AjaxCall) {
29 29
 			$compilation=$params["_ajaxSubmit"]->compile($js);
30
-			$compilation=str_ireplace("\"","%quote%", $compilation);
30
+			$compilation=str_ireplace("\"", "%quote%", $compilation);
31 31
 			$this->onSuccess($compilation);
32 32
 			$form->removeValidationParam("_ajaxSubmit");
33 33
 		}
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
 		return $this->getForm()->addToProperty("class", "loading");
41 41
 	}
42 42
 
43
-	public function setAttached($value=true){
43
+	public function setAttached($value=true) {
44 44
 		$form=$this->getForm();
45
-		if($value)
46
-			$form->addToPropertyCtrl("class", "attached", array ("attached" ));
45
+		if ($value)
46
+			$form->addToPropertyCtrl("class", "attached", array("attached"));
47 47
 		return $form;
48 48
 	}
49 49
 
50
-	public function addErrorMessage(){
50
+	public function addErrorMessage() {
51 51
 		return $this->getForm()->addContent((new HtmlMessage(""))->setError());
52 52
 	}
53 53
 
@@ -62,38 +62,38 @@  discard block
 block discarded – undo
62 62
 	 * @param string $responseElement
63 63
 	 * @return \Ajax\semantic\html\collections\form\HtmlForm
64 64
 	 */
65
-	public function submitOn($event,$identifier,$url,$responseElement){
65
+	public function submitOn($event, $identifier, $url, $responseElement) {
66 66
 		$form=$this->getForm();
67 67
 		$elem=$form->getElementById($identifier, $form->getContent());
68
-		if(isset($elem)){
69
-			$this->_buttonAsSubmit($elem, $event,$url,$responseElement);
68
+		if (isset($elem)) {
69
+			$this->_buttonAsSubmit($elem, $event, $url, $responseElement);
70 70
 		}
71 71
 		return $form;
72 72
 	}
73 73
 
74
-	public function submitOnClick($identifier,$url,$responseElement){
74
+	public function submitOnClick($identifier, $url, $responseElement) {
75 75
 		return $this->submitOn("click", $identifier, $url, $responseElement);
76 76
 	}
77 77
 
78
-	public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL){
79
-		$bt=$this->getForm()->addButton($identifier, $value,$cssStyle);
80
-		return $this->_buttonAsSubmit($bt, "click",$url,$responseElement);
78
+	public function addSubmit($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL) {
79
+		$bt=$this->getForm()->addButton($identifier, $value, $cssStyle);
80
+		return $this->_buttonAsSubmit($bt, "click", $url, $responseElement);
81 81
 	}
82 82
 
83
-	protected function _buttonAsSubmit(&$button,$event,$url,$responseElement=NULL,$parameters=NULL){
83
+	protected function _buttonAsSubmit(&$button, $event, $url, $responseElement=NULL, $parameters=NULL) {
84 84
 		$form=$this->getForm();
85
-		if(isset($url) && isset($responseElement)){
85
+		if (isset($url) && isset($responseElement)) {
86 86
 			$button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');");
87
-			$params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url];
88
-			if(\is_array($parameters))
89
-				$params=\array_merge($params,$parameters);
87
+			$params=["form"=>$form->getIdentifier(), "responseElement"=>$responseElement, "url"=>$url];
88
+			if (\is_array($parameters))
89
+				$params=\array_merge($params, $parameters);
90 90
 			$form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params));
91 91
 		}
92 92
 		return $button;
93 93
 	}
94 94
 
95
-	public function addReset($identifier,$value,$cssStyle=NULL){
96
-		$bt=$this->getForm()->addButton($identifier, $value,$cssStyle);
95
+	public function addReset($identifier, $value, $cssStyle=NULL) {
96
+		$bt=$this->getForm()->addButton($identifier, $value, $cssStyle);
97 97
 		$bt->setProperty("type", "reset");
98 98
 		return $bt;
99 99
 	}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 * @param string $jsCode
104 104
 	 * @return \Ajax\semantic\html\collections\form\HtmlForm
105 105
 	 */
106
-	public function onValid($jsCode){
106
+	public function onValid($jsCode) {
107 107
 		$form=$this->getForm();
108 108
 		$form->addValidationParam("onValid", "%function(){".$jsCode."}%");
109 109
 		return $form;
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @param string $jsCode can use event and fields parameters
115 115
 	 * @return HtmlForm
116 116
 	 */
117
-	public function onSuccess($jsCode){
117
+	public function onSuccess($jsCode) {
118 118
 		$form=$this->getForm();
119 119
 		$form->addValidationParam("onSuccess", "%function(event,fields){console.log(fields);".$jsCode."}%");
120 120
 		return $form;
Please login to merge, or discard this patch.