@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param string $onClick |
| 46 | 46 | * @return HtmlButton |
| 47 | 47 | */ |
| 48 | - public function htmlButton($identifier, $value = null, $cssStyle = null, $onClick = null) { |
|
| 48 | + public function htmlButton($identifier, $value=null, $cssStyle=null, $onClick=null) { |
|
| 49 | 49 | return $this->addHtmlComponent(new HtmlButton($identifier, $value, $cssStyle, $onClick)); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param boolean $asIcons |
| 60 | 60 | * @return HtmlButtonGroups |
| 61 | 61 | */ |
| 62 | - public function htmlButtonGroups($identifier, $elements = array(), $asIcons = false) { |
|
| 62 | + public function htmlButtonGroups($identifier, $elements=array(), $asIcons=false) { |
|
| 63 | 63 | return $this->addHtmlComponent(new HtmlButtonGroups($identifier, $elements, $asIcons)); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param string $content |
| 73 | 73 | * @return HtmlContainer |
| 74 | 74 | */ |
| 75 | - public function htmlContainer($identifier, $content = "") { |
|
| 75 | + public function htmlContainer($identifier, $content="") { |
|
| 76 | 76 | return $this->addHtmlComponent(new HtmlContainer($identifier, $content)); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param string $content |
| 86 | 86 | * @return HtmlDivider |
| 87 | 87 | */ |
| 88 | - public function htmlDivider($identifier, $content = "", $tagName = "div") { |
|
| 88 | + public function htmlDivider($identifier, $content="", $tagName="div") { |
|
| 89 | 89 | return $this->addHtmlComponent(new HtmlDivider($identifier, $content, $tagName)); |
| 90 | 90 | } |
| 91 | 91 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @param string $type |
| 101 | 101 | * @return HtmlHeader |
| 102 | 102 | */ |
| 103 | - public function htmlHeader($identifier, $niveau = 1, $content = NULL, $type = "page") { |
|
| 103 | + public function htmlHeader($identifier, $niveau=1, $content=NULL, $type="page") { |
|
| 104 | 104 | return $this->addHtmlComponent(new HtmlHeader($identifier, $niveau, $content, $type)); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @param string $size |
| 129 | 129 | * @return HtmlImage |
| 130 | 130 | */ |
| 131 | - public function htmlImage($identifier, $src = "", $alt = "", $size = NULL) { |
|
| 131 | + public function htmlImage($identifier, $src="", $alt="", $size=NULL) { |
|
| 132 | 132 | return $this->addHtmlComponent(new HtmlImage($identifier, $src, $alt, $size)); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param string $size |
| 143 | 143 | * @return HtmlIconGroups |
| 144 | 144 | */ |
| 145 | - public function htmlIconGroups($identifier, $icons = array(), $size = "") { |
|
| 145 | + public function htmlIconGroups($identifier, $icons=array(), $size="") { |
|
| 146 | 146 | return $this->addHtmlComponent(new HtmlIconGroups($identifier, $icons, $size)); |
| 147 | 147 | } |
| 148 | 148 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param string $placeholder |
| 158 | 158 | * @return HtmlInput |
| 159 | 159 | */ |
| 160 | - public function htmlInput($identifier, $type = "text", $value = "", $placeholder = "") { |
|
| 160 | + public function htmlInput($identifier, $type="text", $value="", $placeholder="") { |
|
| 161 | 161 | return $this->addHtmlComponent(new HtmlInput($identifier, $type, $value, $placeholder)); |
| 162 | 162 | } |
| 163 | 163 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * @param string $tagName |
| 172 | 172 | * @return HtmlLabel |
| 173 | 173 | */ |
| 174 | - public function htmlLabel($identifier, $content = "", $icon = NULL, $tagName = "div") { |
|
| 174 | + public function htmlLabel($identifier, $content="", $icon=NULL, $tagName="div") { |
|
| 175 | 175 | return $this->addHtmlComponent(new HtmlLabel($identifier, $content, $icon, $tagName)); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @param array $attributes |
| 183 | 183 | * @return HtmlLabelGroups |
| 184 | 184 | */ |
| 185 | - public function htmlLabelGroups($identifier, $labels = array(), $attributes = array()) { |
|
| 185 | + public function htmlLabelGroups($identifier, $labels=array(), $attributes=array()) { |
|
| 186 | 186 | return $this->addHtmlComponent(new HtmlLabelGroups($identifier, $labels, $attributes)); |
| 187 | 187 | } |
| 188 | 188 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @param array $items |
| 194 | 194 | * @return HtmlList |
| 195 | 195 | */ |
| 196 | - public function htmlList($identifier, $items = array()) { |
|
| 196 | + public function htmlList($identifier, $items=array()) { |
|
| 197 | 197 | return $this->addHtmlComponent(new HtmlList($identifier, $items)); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @param string $content |
| 205 | 205 | * @return HtmlSegment |
| 206 | 206 | */ |
| 207 | - public function htmlSegment($identifier, $content = "") { |
|
| 207 | + public function htmlSegment($identifier, $content="") { |
|
| 208 | 208 | return $this->addHtmlComponent(new HtmlSegment($identifier, $content)); |
| 209 | 209 | } |
| 210 | 210 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * the segments |
| 217 | 217 | * @return HtmlSegmentGroups |
| 218 | 218 | */ |
| 219 | - public function htmlSegmentGroups($identifier, $items = array()) { |
|
| 219 | + public function htmlSegmentGroups($identifier, $items=array()) { |
|
| 220 | 220 | return $this->addHtmlComponent(new HtmlSegmentGroups($identifier, $items)); |
| 221 | 221 | } |
| 222 | 222 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * @param Direction|string $attributeType |
| 231 | 231 | * @return HtmlReveal |
| 232 | 232 | */ |
| 233 | - public function htmlReveal($identifier, $visibleContent, $hiddenContent, $type = RevealType::FADE, $attributeType = NULL) { |
|
| 233 | + public function htmlReveal($identifier, $visibleContent, $hiddenContent, $type=RevealType::FADE, $attributeType=NULL) { |
|
| 234 | 234 | return $this->addHtmlComponent(new HtmlReveal($identifier, $visibleContent, $hiddenContent, $type, $attributeType)); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * @param array $steps |
| 242 | 242 | * @return HtmlStep |
| 243 | 243 | */ |
| 244 | - public function htmlStep($identifier, $steps = array()) { |
|
| 244 | + public function htmlStep($identifier, $steps=array()) { |
|
| 245 | 245 | return $this->addHtmlComponent(new HtmlStep($identifier, $steps)); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @param mixed $content |
| 276 | 276 | * @return HtmlRail |
| 277 | 277 | */ |
| 278 | - public function htmlRail($identifier, $content = null) { |
|
| 278 | + public function htmlRail($identifier, $content=null) { |
|
| 279 | 279 | return $this->addHtmlComponent(new HtmlRail($identifier, $content)); |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -13,19 +13,19 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | protected $content; |
| 15 | 15 | |
| 16 | - protected $wrapContentBefore = ""; |
|
| 16 | + protected $wrapContentBefore=""; |
|
| 17 | 17 | |
| 18 | - protected $wrapContentAfter = ""; |
|
| 18 | + protected $wrapContentAfter=""; |
|
| 19 | 19 | |
| 20 | 20 | protected $_editableContent; |
| 21 | 21 | |
| 22 | - public function __construct($identifier, $tagName = "p") { |
|
| 22 | + public function __construct($identifier, $tagName="p") { |
|
| 23 | 23 | parent::__construct($identifier, $tagName); |
| 24 | - $this->_template = '<%tagName% id="%identifier%" %properties%>%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>'; |
|
| 24 | + $this->_template='<%tagName% id="%identifier%" %properties%>%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>'; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function setContent($content) { |
| 28 | - $this->content = $content; |
|
| 28 | + $this->content=$content; |
|
| 29 | 29 | return $this; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -33,19 +33,19 @@ discard block |
||
| 33 | 33 | return $this->content; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function addContent($content, $before = false) { |
|
| 37 | - if (! \is_array($this->content)) { |
|
| 36 | + public function addContent($content, $before=false) { |
|
| 37 | + if (!\is_array($this->content)) { |
|
| 38 | 38 | if (isset($this->content)) |
| 39 | - $this->content = array( |
|
| 39 | + $this->content=array( |
|
| 40 | 40 | $this->content |
| 41 | 41 | ); |
| 42 | 42 | else |
| 43 | - $this->content = array(); |
|
| 43 | + $this->content=array(); |
|
| 44 | 44 | } |
| 45 | 45 | if ($before) |
| 46 | 46 | \array_unshift($this->content, $content); |
| 47 | 47 | else |
| 48 | - $this->content[] = $content; |
|
| 48 | + $this->content[]=$content; |
|
| 49 | 49 | return $this; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public function setValue($value) {} |
| 70 | 70 | |
| 71 | - public function wrapContent($before, $after = "") { |
|
| 72 | - $this->wrapContentBefore .= $before; |
|
| 73 | - $this->wrapContentAfter = $after . $this->wrapContentAfter; |
|
| 71 | + public function wrapContent($before, $after="") { |
|
| 72 | + $this->wrapContentBefore.=$before; |
|
| 73 | + $this->wrapContentAfter=$after.$this->wrapContentAfter; |
|
| 74 | 74 | return $this; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | protected function _getContentInstances($class, $content) { |
| 92 | - $instances = []; |
|
| 92 | + $instances=[]; |
|
| 93 | 93 | if ($content instanceof $class) { |
| 94 | - $instances[] = $content; |
|
| 94 | + $instances[]=$content; |
|
| 95 | 95 | } elseif ($content instanceof HtmlDoubleElement) { |
| 96 | - $instances = \array_merge($instances, $content->getContentInstances($class)); |
|
| 96 | + $instances=\array_merge($instances, $content->getContentInstances($class)); |
|
| 97 | 97 | } elseif (\is_array($content)) { |
| 98 | 98 | foreach ($content as $element) { |
| 99 | - $instances = \array_merge($instances, $this->_getContentInstances($class, $element)); |
|
| 99 | + $instances=\array_merge($instances, $this->_getContentInstances($class, $element)); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | return $instances; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @return HtmlDoubleElement |
| 109 | 109 | */ |
| 110 | - public function asLink($href = NULL, $target = NULL) { |
|
| 110 | + public function asLink($href=NULL, $target=NULL) { |
|
| 111 | 111 | if (isset($href)) |
| 112 | 112 | $this->setProperty("href", $href); |
| 113 | 113 | if (isset($target)) |
@@ -122,28 +122,28 @@ discard block |
||
| 122 | 122 | return \strip_tags($this->content); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - public function asEditable(HtmlFormField $field, $asForm = false, $setValueProperty = "val()") { |
|
| 126 | - $idF = $field->getIdentifier(); |
|
| 127 | - $idE = $idF; |
|
| 125 | + public function asEditable(HtmlFormField $field, $asForm=false, $setValueProperty="val()") { |
|
| 126 | + $idF=$field->getIdentifier(); |
|
| 127 | + $idE=$idF; |
|
| 128 | 128 | if ($asForm) { |
| 129 | - $frm = new HtmlForm("frm-" . $field->getIdentifier()); |
|
| 129 | + $frm=new HtmlForm("frm-".$field->getIdentifier()); |
|
| 130 | 130 | $frm->setProperty("onsubmit", "return false;"); |
| 131 | - $fields = $frm->addFields(); |
|
| 132 | - $idE = $frm->getIdentifier(); |
|
| 131 | + $fields=$frm->addFields(); |
|
| 132 | + $idE=$frm->getIdentifier(); |
|
| 133 | 133 | $fields->addItem($field); |
| 134 | - $fields->addButtonIcon("bt-okay", "check", "green mini", "\$('#" . $idE . "').trigger('validate',{value: $('#'+idF+' input').val()});"); |
|
| 135 | - $fields->addButtonIcon("bt-cancel", "close", "mini", "\$('#" . $idE . "').trigger('endEdit');"); |
|
| 136 | - $this->_editableContent = $frm; |
|
| 137 | - $keypress = ""; |
|
| 138 | - $focusOut = ""; |
|
| 134 | + $fields->addButtonIcon("bt-okay", "check", "green mini", "\$('#".$idE."').trigger('validate',{value: $('#'+idF+' input').val()});"); |
|
| 135 | + $fields->addButtonIcon("bt-cancel", "close", "mini", "\$('#".$idE."').trigger('endEdit');"); |
|
| 136 | + $this->_editableContent=$frm; |
|
| 137 | + $keypress=""; |
|
| 138 | + $focusOut=""; |
|
| 139 | 139 | } else { |
| 140 | - $focusOut = "if(e.relatedTarget==null)elm.trigger('endEdit');"; |
|
| 141 | - $this->_editableContent = $field; |
|
| 142 | - $keypress = "$('#" . $idF . "').keyup(function(e){if(e.which == 13) {\$('#" . $idE . "').trigger('validate',{value: $('#'+idF+' input').val()});}if(e.keyCode===27) {\$('#" . $idE . "').trigger('endEdit');}});"; |
|
| 140 | + $focusOut="if(e.relatedTarget==null)elm.trigger('endEdit');"; |
|
| 141 | + $this->_editableContent=$field; |
|
| 142 | + $keypress="$('#".$idF."').keyup(function(e){if(e.which == 13) {\$('#".$idE."').trigger('validate',{value: $('#'+idF+' input').val()});}if(e.keyCode===27) {\$('#".$idE."').trigger('endEdit');}});"; |
|
| 143 | 143 | } |
| 144 | 144 | $this->_editableContent->setProperty("style", "display:none;"); |
| 145 | - $this->onCreate("let idF='" . $idF . "';let idE='" . $idE . "';let elm=$('#'+idE);let self=$('#" . $this->getIdentifier() . "');" . $keypress . "elm.on('validate',function(){self.html($('#'+idE+' input')." . $setValueProperty . ");elm.trigger('endEdit');});elm.on('endEdit',function(){self.show();$(this).hide();});elm.focusout(function(e){" . $focusOut . "});"); |
|
| 146 | - $this->onClick("let self=$(this);self.hide();" . $field->setJsContent("self.html()") . ";$('#" . $idF . " input').trigger('change');elm.show();$('#'+idE+' input').focus();"); |
|
| 145 | + $this->onCreate("let idF='".$idF."';let idE='".$idE."';let elm=$('#'+idE);let self=$('#".$this->getIdentifier()."');".$keypress."elm.on('validate',function(){self.html($('#'+idE+' input').".$setValueProperty.");elm.trigger('endEdit');});elm.on('endEdit',function(){self.show();$(this).hide();});elm.focusout(function(e){".$focusOut."});"); |
|
| 146 | + $this->onClick("let self=$(this);self.hide();".$field->setJsContent("self.html()").";$('#".$idF." input').trigger('change');elm.show();$('#'+idE+' input').focus();"); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | * {@inheritdoc} |
| 152 | 152 | * @see \Ajax\common\html\BaseHtml::compile_once() |
| 153 | 153 | */ |
| 154 | - protected function compile_once(\Ajax\JsUtils $js = NULL, &$view = NULL) { |
|
| 155 | - if (! $this->_compiled && isset($this->_editableContent)) { |
|
| 154 | + protected function compile_once(\Ajax\JsUtils $js=NULL, &$view=NULL) { |
|
| 155 | + if (!$this->_compiled && isset($this->_editableContent)) { |
|
| 156 | 156 | $this->wrap("", $this->_editableContent); |
| 157 | 157 | } |
| 158 | 158 | parent::compile_once($js, $view); |
@@ -35,17 +35,19 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function addContent($content, $before = false) { |
| 37 | 37 | if (! \is_array($this->content)) { |
| 38 | - if (isset($this->content)) |
|
| 39 | - $this->content = array( |
|
| 38 | + if (isset($this->content)) { |
|
| 39 | + $this->content = array( |
|
| 40 | 40 | $this->content |
| 41 | 41 | ); |
| 42 | - else |
|
| 43 | - $this->content = array(); |
|
| 42 | + } else { |
|
| 43 | + $this->content = array(); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + if ($before) { |
|
| 47 | + \array_unshift($this->content, $content); |
|
| 48 | + } else { |
|
| 49 | + $this->content[] = $content; |
|
| 44 | 50 | } |
| 45 | - if ($before) |
|
| 46 | - \array_unshift($this->content, $content); |
|
| 47 | - else |
|
| 48 | - $this->content[] = $content; |
|
| 49 | 51 | return $this; |
| 50 | 52 | } |
| 51 | 53 | |
@@ -108,10 +110,12 @@ discard block |
||
| 108 | 110 | * @return HtmlDoubleElement |
| 109 | 111 | */ |
| 110 | 112 | public function asLink($href = NULL, $target = NULL) { |
| 111 | - if (isset($href)) |
|
| 112 | - $this->setProperty("href", $href); |
|
| 113 | - if (isset($target)) |
|
| 114 | - $this->setProperty("target", $target); |
|
| 113 | + if (isset($href)) { |
|
| 114 | + $this->setProperty("href", $href); |
|
| 115 | + } |
|
| 116 | + if (isset($target)) { |
|
| 117 | + $this->setProperty("target", $target); |
|
| 118 | + } |
|
| 115 | 119 | return $this->setTagName("a"); |
| 116 | 120 | } |
| 117 | 121 | |
@@ -73,8 +73,9 @@ discard block |
||
| 73 | 73 | $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
| 74 | 74 | |
| 75 | 75 | $retour = $this->_addJsCondition($jsCondition, $retour); |
| 76 | - if ($immediatly) |
|
| 77 | - $this->jquery_code_for_compile[] = $retour; |
|
| 76 | + if ($immediatly) { |
|
| 77 | + $this->jquery_code_for_compile[] = $retour; |
|
| 78 | + } |
|
| 78 | 79 | return $retour; |
| 79 | 80 | } |
| 80 | 81 | |
@@ -157,10 +158,11 @@ discard block |
||
| 157 | 158 | } elseif (isset($this->ajaxTransition)) { |
| 158 | 159 | $call = $this->ajaxTransition; |
| 159 | 160 | } |
| 160 | - if (\is_callable($call)) |
|
| 161 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 162 | - else |
|
| 163 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 161 | + if (\is_callable($call)) { |
|
| 162 | + $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 163 | + } else { |
|
| 164 | + $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 165 | + } |
|
| 164 | 166 | } |
| 165 | 167 | if (isset($history)) { |
| 166 | 168 | if ($this->params["autoActiveLinks"]) { |
@@ -194,8 +196,9 @@ discard block |
||
| 194 | 196 | } |
| 195 | 197 | |
| 196 | 198 | protected function _correctAjaxUrl($url) { |
| 197 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 198 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 199 | + if ($url !== "/" && JString::endsWith($url, "/") === true) { |
|
| 200 | + $url = substr($url, 0, strlen($url) - 1); |
|
| 201 | + } |
|
| 199 | 202 | if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
| 200 | 203 | $url = $this->getUrl($url); |
| 201 | 204 | } |
@@ -219,8 +222,9 @@ discard block |
||
| 219 | 222 | public static function _implodeParams($parameters) { |
| 220 | 223 | $allParameters = []; |
| 221 | 224 | foreach ($parameters as $params) { |
| 222 | - if (isset($params)) |
|
| 223 | - $allParameters[] = self::_correctParams($params); |
|
| 225 | + if (isset($params)) { |
|
| 226 | + $allParameters[] = self::_correctParams($params); |
|
| 227 | + } |
|
| 224 | 228 | } |
| 225 | 229 | return \implode("+'&'+", $allParameters); |
| 226 | 230 | } |
@@ -254,8 +258,9 @@ discard block |
||
| 254 | 258 | |
| 255 | 259 | protected function setDefaultParameters(&$parameters, $default) { |
| 256 | 260 | foreach ($default as $k => $v) { |
| 257 | - if (! isset($parameters[$k])) |
|
| 258 | - $parameters[$k] = $v; |
|
| 261 | + if (! isset($parameters[$k])) { |
|
| 262 | + $parameters[$k] = $v; |
|
| 263 | + } |
|
| 259 | 264 | } |
| 260 | 265 | } |
| 261 | 266 | |
@@ -820,8 +825,9 @@ discard block |
||
| 820 | 825 | $retour .= "$('#'+" . $form . ").submit();\n"; |
| 821 | 826 | } |
| 822 | 827 | $retour = $this->_addJsCondition($jsCondition, $retour); |
| 823 | - if ($immediatly) |
|
| 824 | - $this->jquery_code_for_compile[] = $retour; |
|
| 828 | + if ($immediatly) { |
|
| 829 | + $this->jquery_code_for_compile[] = $retour; |
|
| 830 | + } |
|
| 825 | 831 | return $retour; |
| 826 | 832 | } |
| 827 | 833 | |
@@ -15,71 +15,71 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | protected $ajaxTransition; |
| 17 | 17 | |
| 18 | - protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 18 | + protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 19 | 19 | |
| 20 | 20 | abstract public function getUrl($url); |
| 21 | 21 | |
| 22 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn = false); |
|
| 22 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
| 23 | 23 | |
| 24 | - abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true); |
|
| 24 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
| 25 | 25 | |
| 26 | - protected function _ajax($method, $url, $responseElement = '', $parameters = []) { |
|
| 26 | + protected function _ajax($method, $url, $responseElement='', $parameters=[]) { |
|
| 27 | 27 | if (isset($this->params['ajax'])) { |
| 28 | 28 | extract($this->params['ajax']); |
| 29 | 29 | } |
| 30 | 30 | extract($parameters); |
| 31 | 31 | |
| 32 | - $jsCallback = isset($jsCallback) ? $jsCallback : ''; |
|
| 33 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 34 | - $originalSelector = $responseElement; |
|
| 35 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 36 | - $retour .= "var self=this;\n"; |
|
| 37 | - $before = isset($before) ? $before : ""; |
|
| 38 | - $retour .= $before; |
|
| 39 | - if ($hasLoader === true && JString::isNotNull($responseElement)) { |
|
| 32 | + $jsCallback=isset($jsCallback) ? $jsCallback : ''; |
|
| 33 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 34 | + $originalSelector=$responseElement; |
|
| 35 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 36 | + $retour.="var self=this;\n"; |
|
| 37 | + $before=isset($before) ? $before : ""; |
|
| 38 | + $retour.=$before; |
|
| 39 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
| 40 | 40 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 41 | - } elseif ($hasLoader === 'response') { |
|
| 41 | + } elseif ($hasLoader==='response') { |
|
| 42 | 42 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
| 43 | - } elseif ($hasLoader === 'internal-x') { |
|
| 43 | + } elseif ($hasLoader==='internal-x') { |
|
| 44 | 44 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
| 45 | - } elseif ($hasLoader === 'internal') { |
|
| 46 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 45 | + } elseif ($hasLoader==='internal') { |
|
| 46 | + $retour.="\n$(this).addClass('loading');"; |
|
| 47 | 47 | } elseif (\is_string($hasLoader)) { |
| 48 | 48 | $this->addLoading($retour, $hasLoader, $ajaxLoader); |
| 49 | 49 | } |
| 50 | - $ajaxParameters = [ |
|
| 50 | + $ajaxParameters=[ |
|
| 51 | 51 | "url" => "url", |
| 52 | - "method" => "'" . \strtoupper($method) . "'" |
|
| 52 | + "method" => "'".\strtoupper($method)."'" |
|
| 53 | 53 | ]; |
| 54 | 54 | |
| 55 | - $ajaxParameters["async"] = ($async ? "true" : "false"); |
|
| 55 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
| 56 | 56 | |
| 57 | 57 | if (isset($params)) { |
| 58 | - $ajaxParameters["data"] = self::_correctParams($params, $parameters); |
|
| 58 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
| 59 | 59 | } |
| 60 | 60 | if (isset($headers)) { |
| 61 | - $ajaxParameters["headers"] = $headers; |
|
| 61 | + $ajaxParameters["headers"]=$headers; |
|
| 62 | 62 | } |
| 63 | 63 | if ($csrf) { |
| 64 | - $csrf = (is_string($csrf)) ? $csrf : 'csrf-token'; |
|
| 65 | - $parameters["beforeSend"] = "jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 64 | + $csrf=(is_string($csrf)) ? $csrf : 'csrf-token'; |
|
| 65 | + $parameters["beforeSend"]="jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 66 | 66 | } |
| 67 | 67 | if (isset($partial)) { |
| 68 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 69 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 68 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 69 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 70 | 70 | } |
| 71 | 71 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 72 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 73 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
|
| 72 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 73 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
| 74 | 74 | |
| 75 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 75 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 76 | 76 | if ($immediatly) |
| 77 | - $this->jquery_code_for_compile[] = $retour; |
|
| 77 | + $this->jquery_code_for_compile[]=$retour; |
|
| 78 | 78 | return $retour; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | protected function createAjaxParameters(&$original, $parameters) { |
| 82 | - $validParameters = [ |
|
| 82 | + $validParameters=[ |
|
| 83 | 83 | "contentType" => "%value%", |
| 84 | 84 | "dataType" => "'%value%'", |
| 85 | 85 | "beforeSend" => "function(jqXHR,settings){%value%}", |
@@ -88,21 +88,21 @@ discard block |
||
| 88 | 88 | ]; |
| 89 | 89 | foreach ($validParameters as $param => $mask) { |
| 90 | 90 | if (isset($parameters[$param])) { |
| 91 | - $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
| 91 | + $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | protected function implodeAjaxParameters($ajaxParameters) { |
| 97 | - $s = ''; |
|
| 97 | + $s=''; |
|
| 98 | 98 | foreach ($ajaxParameters as $k => $v) { |
| 99 | - if ($s !== '') { |
|
| 100 | - $s .= ','; |
|
| 99 | + if ($s!=='') { |
|
| 100 | + $s.=','; |
|
| 101 | 101 | } |
| 102 | 102 | if (is_array($v)) { |
| 103 | - $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
| 103 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 104 | 104 | } else { |
| 105 | - $s .= "'{$k}':{$v}"; |
|
| 105 | + $s.="'{$k}':{$v}"; |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | return $s; |
@@ -110,29 +110,29 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | protected function _addJsCondition($jsCondition, $jsSource) { |
| 112 | 112 | if (isset($jsCondition)) { |
| 113 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
| 113 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
| 114 | 114 | } |
| 115 | 115 | return $jsSource; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | protected function _getAjaxUrl($url, $attr) { |
| 119 | - $url = $this->_correctAjaxUrl($url); |
|
| 120 | - $retour = "url='" . $url . "';"; |
|
| 121 | - $slash = "/"; |
|
| 122 | - if (JString::endswith($url, "/") === true) { |
|
| 123 | - $slash = ""; |
|
| 119 | + $url=$this->_correctAjaxUrl($url); |
|
| 120 | + $retour="url='".$url."';"; |
|
| 121 | + $slash="/"; |
|
| 122 | + if (JString::endswith($url, "/")===true) { |
|
| 123 | + $slash=""; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (JString::isNotNull($attr)) { |
| 127 | - if ($attr === "value") { |
|
| 128 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
| 129 | - } elseif ($attr === "html") { |
|
| 130 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
| 131 | - } elseif (\substr($attr, 0, 3) === "js:") { |
|
| 132 | - $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
|
| 133 | - } elseif ($attr !== null && $attr !== "") { |
|
| 134 | - $retour .= "let elmUrl=$(this).attr('" . $attr . "')||'';"; |
|
| 135 | - $retour .= "url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'" . $slash . "'+elmUrl:elmUrl;\n"; |
|
| 127 | + if ($attr==="value") { |
|
| 128 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 129 | + } elseif ($attr==="html") { |
|
| 130 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
| 131 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
| 132 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
| 133 | + } elseif ($attr!==null && $attr!=="") { |
|
| 134 | + $retour.="let elmUrl=$(this).attr('".$attr."')||'';"; |
|
| 135 | + $retour.="url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'".$slash."'+elmUrl:elmUrl;\n"; |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | return $retour; |
@@ -142,110 +142,110 @@ discard block |
||
| 142 | 142 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
| 146 | - $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 147 | - $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 145 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 146 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 147 | + $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 148 | 148 | return $result; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
| 152 | - $retour = ""; |
|
| 153 | - $call = null; |
|
| 151 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
| 152 | + $retour=""; |
|
| 153 | + $call=null; |
|
| 154 | 154 | if (JString::isNotNull($responseElement)) { |
| 155 | 155 | if (isset($ajaxTransition)) { |
| 156 | - $call = $this->setAjaxDataCall($ajaxTransition); |
|
| 156 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
| 157 | 157 | } elseif (isset($this->ajaxTransition)) { |
| 158 | - $call = $this->ajaxTransition; |
|
| 158 | + $call=$this->ajaxTransition; |
|
| 159 | 159 | } |
| 160 | 160 | if (\is_callable($call)) |
| 161 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 161 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 162 | 162 | else |
| 163 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 163 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 164 | 164 | } |
| 165 | 165 | if (isset($history)) { |
| 166 | 166 | if ($this->params["autoActiveLinks"]) { |
| 167 | - $retour .= $this->autoActiveLinks("url"); |
|
| 167 | + $retour.=$this->autoActiveLinks("url"); |
|
| 168 | 168 | } |
| 169 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 169 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 170 | 170 | } |
| 171 | - if ($hasLoader === 'internal') { |
|
| 172 | - $retour .= "\n$(self).removeClass('loading');"; |
|
| 173 | - } elseif ($hasLoader === 'internal-x') { |
|
| 174 | - $retour .= "\n$(self).children('.ajax-loader').remove();"; |
|
| 171 | + if ($hasLoader==='internal') { |
|
| 172 | + $retour.="\n$(self).removeClass('loading');"; |
|
| 173 | + } elseif ($hasLoader==='internal-x') { |
|
| 174 | + $retour.="\n$(self).children('.ajax-loader').remove();"; |
|
| 175 | 175 | } else { |
| 176 | - $retour .= "\n$(self).find('.loading').removeClass('loading');"; |
|
| 176 | + $retour.="\n$(self).find('.loading').removeClass('loading');"; |
|
| 177 | 177 | } |
| 178 | - $retour .= "\t" . $jsCallback . "\n"; |
|
| 178 | + $retour.="\t".$jsCallback."\n"; |
|
| 179 | 179 | return $retour; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | protected function _getResponseElement($responseElement) { |
| 183 | 183 | if (JString::isNotNull($responseElement)) { |
| 184 | - $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
| 184 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
| 185 | 185 | } |
| 186 | 186 | return $responseElement; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | protected function _getFormElement($formElement) { |
| 190 | 190 | if (JString::isNotNull($formElement)) { |
| 191 | - $formElement = Javascript::prep_value($formElement); |
|
| 191 | + $formElement=Javascript::prep_value($formElement); |
|
| 192 | 192 | } |
| 193 | 193 | return $formElement; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | protected function _correctAjaxUrl($url) { |
| 197 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 198 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 199 | - if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
|
| 200 | - $url = $this->getUrl($url); |
|
| 197 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 198 | + $url=substr($url, 0, strlen($url)-1); |
|
| 199 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 200 | + $url=$this->getUrl($url); |
|
| 201 | 201 | } |
| 202 | 202 | return $url; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - public static function _correctParams($params, $ajaxParameters = []) { |
|
| 205 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
| 206 | 206 | if (JString::isNull($params)) { |
| 207 | 207 | return ""; |
| 208 | 208 | } |
| 209 | 209 | if (\preg_match("@^\{.*?\}$@", $params)) { |
| 210 | - if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 211 | - return '$.param(' . $params . ')'; |
|
| 210 | + if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 211 | + return '$.param('.$params.')'; |
|
| 212 | 212 | } else { |
| 213 | - return 'JSON.stringify(' . $params . ')'; |
|
| 213 | + return 'JSON.stringify('.$params.')'; |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | return $params; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | public static function _implodeParams($parameters) { |
| 220 | - $allParameters = []; |
|
| 220 | + $allParameters=[]; |
|
| 221 | 221 | foreach ($parameters as $params) { |
| 222 | 222 | if (isset($params)) |
| 223 | - $allParameters[] = self::_correctParams($params); |
|
| 223 | + $allParameters[]=self::_correctParams($params); |
|
| 224 | 224 | } |
| 225 | 225 | return \implode("+'&'+", $allParameters); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 229 | - if (! isset($ajaxLoader)) { |
|
| 230 | - $ajaxLoader = $this->ajaxLoader; |
|
| 228 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 229 | + if (!isset($ajaxLoader)) { |
|
| 230 | + $ajaxLoader=$this->ajaxLoader; |
|
| 231 | 231 | } |
| 232 | - $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
| 233 | - $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 232 | + $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
| 233 | + $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 237 | - if (! isset($ajaxLoader)) { |
|
| 238 | - $ajaxLoader = $this->ajaxLoader; |
|
| 236 | + protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 237 | + if (!isset($ajaxLoader)) { |
|
| 238 | + $ajaxLoader=$this->ajaxLoader; |
|
| 239 | 239 | } |
| 240 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
| 241 | - $retour .= "{$responseElement}.empty();\n"; |
|
| 242 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 240 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
| 241 | + $retour.="{$responseElement}.empty();\n"; |
|
| 242 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | protected function setAjaxDataCall($params) { |
| 246 | - $result = null; |
|
| 247 | - if (! \is_callable($params)) { |
|
| 248 | - $result = function ($responseElement, $jqueryDone = 'html') use ($params) { |
|
| 246 | + $result=null; |
|
| 247 | + if (!\is_callable($params)) { |
|
| 248 | + $result=function($responseElement, $jqueryDone='html') use ($params) { |
|
| 249 | 249 | return AjaxTransition::{$params}($responseElement, $jqueryDone); |
| 250 | 250 | }; |
| 251 | 251 | } |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | protected function setDefaultParameters(&$parameters, $default) { |
| 256 | 256 | foreach ($default as $k => $v) { |
| 257 | - if (! isset($parameters[$k])) |
|
| 258 | - $parameters[$k] = $v; |
|
| 257 | + if (!isset($parameters[$k])) |
|
| 258 | + $parameters[$k]=$v; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | public function setAjaxLoader($loader) { |
| 263 | - $this->ajaxLoader = $loader; |
|
| 263 | + $this->ajaxLoader=$loader; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @param string $responseElement |
| 272 | 272 | * selector of the HTML element displaying the answer |
| 273 | 273 | */ |
| 274 | - private function _get($url, $responseElement = '', $parameters = []) { |
|
| 274 | + private function _get($url, $responseElement='', $parameters=[]) { |
|
| 275 | 275 | return $this->_ajax('get', $url, $responseElement, $parameters); |
| 276 | 276 | } |
| 277 | 277 | |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | * @param array $parameters |
| 286 | 286 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 287 | 287 | */ |
| 288 | - public function get($url, $responseElement = '', $parameters = []) { |
|
| 289 | - $parameters['immediatly'] = true; |
|
| 288 | + public function get($url, $responseElement='', $parameters=[]) { |
|
| 289 | + $parameters['immediatly']=true; |
|
| 290 | 290 | return $this->_get($url, $responseElement, $parameters); |
| 291 | 291 | } |
| 292 | 292 | |
@@ -302,8 +302,8 @@ discard block |
||
| 302 | 302 | * @param array $parameters |
| 303 | 303 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 304 | 304 | */ |
| 305 | - public function ajax($method, $url, $responseElement = '', $parameters = []) { |
|
| 306 | - $parameters['immediatly'] = true; |
|
| 305 | + public function ajax($method, $url, $responseElement='', $parameters=[]) { |
|
| 306 | + $parameters['immediatly']=true; |
|
| 307 | 307 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 308 | 308 | } |
| 309 | 309 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | * $immediatly |
| 326 | 326 | * @return string |
| 327 | 327 | */ |
| 328 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = '', $parameters = [], $immediatly = true) { |
|
| 328 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement='', $parameters=[], $immediatly=true) { |
|
| 329 | 329 | return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
| 330 | 330 | } |
| 331 | 331 | |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | * @param array $parameters |
| 342 | 342 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 343 | 343 | */ |
| 344 | - public function ajaxDeferred($method, $url, $responseElement = '', $parameters = []) { |
|
| 345 | - $parameters['immediatly'] = false; |
|
| 344 | + public function ajaxDeferred($method, $url, $responseElement='', $parameters=[]) { |
|
| 345 | + $parameters['immediatly']=false; |
|
| 346 | 346 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 347 | 347 | } |
| 348 | 348 | |
@@ -356,15 +356,15 @@ discard block |
||
| 356 | 356 | * @param array $parameters |
| 357 | 357 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 358 | 358 | */ |
| 359 | - private function _json($url, $method = "get", $parameters = []) { |
|
| 360 | - $parameters = \array_merge($parameters, [ |
|
| 359 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 360 | + $parameters=\array_merge($parameters, [ |
|
| 361 | 361 | "hasLoader" => false |
| 362 | 362 | ]); |
| 363 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 364 | - $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 365 | - $retour = "\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t" . $jsCallback . ";" . "\n\tfor(var key in data){" . "if($('#'+key," . $context . ").length){ if($('#'+key," . $context . ").is('[value]')) { $('#'+key," . $context . ").val(data[key]);} else { $('#'+key," . $context . ").html(data[key]); }}};\n"; |
|
| 366 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 367 | - $parameters["jsCallback"] = $retour; |
|
| 363 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 364 | + $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 365 | + $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";"."\n\tfor(var key in data){"."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
|
| 366 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 367 | + $parameters["jsCallback"]=$retour; |
|
| 368 | 368 | return $this->_ajax($method, $url, null, $parameters); |
| 369 | 369 | } |
| 370 | 370 | |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | * @param array $parameters |
| 379 | 379 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 380 | 380 | */ |
| 381 | - public function json($url, $method = "get", $parameters = []) { |
|
| 381 | + public function json($url, $method="get", $parameters=[]) { |
|
| 382 | 382 | return $this->_json($url, $method, $parameters); |
| 383 | 383 | } |
| 384 | 384 | |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | * @param array $parameters |
| 395 | 395 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 396 | 396 | */ |
| 397 | - public function jsonOn($event, $element, $url, $method = 'get', $parameters = array()) { |
|
| 397 | + public function jsonOn($event, $element, $url, $method='get', $parameters=array()) { |
|
| 398 | 398 | $this->setDefaultParameters($parameters, [ |
| 399 | 399 | 'preventDefault' => true, |
| 400 | 400 | 'stopPropagation' => true, |
@@ -414,8 +414,8 @@ discard block |
||
| 414 | 414 | * @param array $parameters |
| 415 | 415 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 416 | 416 | */ |
| 417 | - public function jsonDeferred($url, $method = 'get', $parameters = []) { |
|
| 418 | - $parameters['immediatly'] = false; |
|
| 417 | + public function jsonDeferred($url, $method='get', $parameters=[]) { |
|
| 418 | + $parameters['immediatly']=false; |
|
| 419 | 419 | return $this->_json($url, $method, $parameters); |
| 420 | 420 | } |
| 421 | 421 | |
@@ -430,29 +430,29 @@ discard block |
||
| 430 | 430 | * @param array $parameters |
| 431 | 431 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 432 | 432 | */ |
| 433 | - private function _jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 434 | - $parameters = \array_merge($parameters, [ |
|
| 433 | + private function _jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 434 | + $parameters=\array_merge($parameters, [ |
|
| 435 | 435 | "hasLoader" => false |
| 436 | 436 | ]); |
| 437 | - $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 438 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 439 | - $context = isset($parameters['context']) ? $parameters['context'] : null; |
|
| 440 | - if ($context === null) { |
|
| 441 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
| 442 | - $newElm = "$('#'+newId)"; |
|
| 437 | + $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 438 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 439 | + $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
| 440 | + if ($context===null) { |
|
| 441 | + $parent="$('".$maskSelector."').parent()"; |
|
| 442 | + $newElm="$('#'+newId)"; |
|
| 443 | 443 | } else { |
| 444 | - $parent = $context; |
|
| 445 | - $newElm = $context . ".find('#'+newId)"; |
|
| 444 | + $parent=$context; |
|
| 445 | + $newElm=$context.".find('#'+newId)"; |
|
| 446 | 446 | } |
| 447 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
| 448 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
| 449 | - $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(); |
|
| 447 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
| 448 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
| 449 | + $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(); |
|
| 450 | 450 | 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"; |
| 451 | - $retour .= $appendTo; |
|
| 452 | - $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"; |
|
| 453 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 454 | - $retour .= "\t" . $jsCallback; |
|
| 455 | - $parameters["jsCallback"] = $retour; |
|
| 451 | + $retour.=$appendTo; |
|
| 452 | + $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"; |
|
| 453 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 454 | + $retour.="\t".$jsCallback; |
|
| 455 | + $parameters["jsCallback"]=$retour; |
|
| 456 | 456 | return $this->_ajax($method, $url, null, $parameters); |
| 457 | 457 | } |
| 458 | 458 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | * @param array $parameters |
| 468 | 468 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 469 | 469 | */ |
| 470 | - public function jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 470 | + public function jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 471 | 471 | return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
| 472 | 472 | } |
| 473 | 473 | |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @param array $parameters |
| 483 | 483 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
| 484 | 484 | */ |
| 485 | - public function jsonArrayDeferred($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 486 | - $parameters['immediatly'] = false; |
|
| 485 | + public function jsonArrayDeferred($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 486 | + $parameters['immediatly']=false; |
|
| 487 | 487 | return $this->jsonArray($maskSelector, $url, $method, $parameters); |
| 488 | 488 | } |
| 489 | 489 | |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | * @param array $parameters |
| 500 | 500 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 501 | 501 | */ |
| 502 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = 'get', $parameters = array()) { |
|
| 502 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method='get', $parameters=array()) { |
|
| 503 | 503 | $this->setDefaultParameters($parameters, [ |
| 504 | 504 | 'preventDefault' => true, |
| 505 | 505 | 'stopPropagation' => true, |
@@ -520,8 +520,8 @@ discard block |
||
| 520 | 520 | * @param array $parameters |
| 521 | 521 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 522 | 522 | */ |
| 523 | - public function getDeferred($url, $responseElement = "", $parameters = []) { |
|
| 524 | - $parameters['immediatly'] = false; |
|
| 523 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
| 524 | + $parameters['immediatly']=false; |
|
| 525 | 525 | return $this->_get($url, $responseElement, $parameters); |
| 526 | 526 | } |
| 527 | 527 | |
@@ -540,8 +540,8 @@ discard block |
||
| 540 | 540 | * @param array $parameters |
| 541 | 541 | * 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,"before"=>null,"listenerOn"=>false) |
| 542 | 542 | */ |
| 543 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
| 544 | - $parameters['method'] = 'get'; |
|
| 543 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 544 | + $parameters['method']='get'; |
|
| 545 | 545 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
| 546 | 546 | } |
| 547 | 547 | |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | * @param array $parameters |
| 561 | 561 | * 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,"before"=>null,"listenerOn"=>false) |
| 562 | 562 | */ |
| 563 | - public function ajaxOn($event, $element, $url, $responseElement = '', $parameters = array()) { |
|
| 563 | + public function ajaxOn($event, $element, $url, $responseElement='', $parameters=array()) { |
|
| 564 | 564 | $this->setDefaultParameters($parameters, [ |
| 565 | 565 | 'preventDefault' => true, |
| 566 | 566 | 'stopPropagation' => true, |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | * @param array $parameters |
| 585 | 585 | * 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,"before"=>null,"listenerOn"=>false) |
| 586 | 586 | */ |
| 587 | - public function ajaxOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
| 587 | + public function ajaxOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 588 | 588 | return $this->ajaxOn('click', $element, $url, $responseElement, $parameters); |
| 589 | 589 | } |
| 590 | 590 | |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | * @param array $parameters |
| 602 | 602 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 603 | 603 | */ |
| 604 | - public function getOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
| 604 | + public function getOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 605 | 605 | return $this->getOn('click', $element, $url, $responseElement, $parameters); |
| 606 | 606 | } |
| 607 | 607 | |
@@ -616,18 +616,18 @@ discard block |
||
| 616 | 616 | * 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,"before"=>null,"listenerOn"=>false) |
| 617 | 617 | * @return $this |
| 618 | 618 | */ |
| 619 | - public function getHref($element, $responseElement = "", $parameters = array()) { |
|
| 620 | - $parameters['attr'] = 'href'; |
|
| 619 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 620 | + $parameters['attr']='href'; |
|
| 621 | 621 | if (JString::isNull($responseElement)) { |
| 622 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 622 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 623 | 623 | } else { |
| 624 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 624 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 625 | 625 | } |
| 626 | - if (! isset($parameters['historize'])) { |
|
| 627 | - $parameters['historize'] = true; |
|
| 626 | + if (!isset($parameters['historize'])) { |
|
| 627 | + $parameters['historize']=true; |
|
| 628 | 628 | } |
| 629 | - if (! isset($parameters['jsCallback'])) { |
|
| 630 | - $parameters['jsCallback'] = 'var event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
|
| 629 | + if (!isset($parameters['jsCallback'])) { |
|
| 630 | + $parameters['jsCallback']='var event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
|
| 631 | 631 | } |
| 632 | 632 | return $this->getOnClick($element, "", $responseElement, $parameters); |
| 633 | 633 | } |
@@ -643,15 +643,15 @@ discard block |
||
| 643 | 643 | * 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,"before"=>null,"listenerOn"=>false) |
| 644 | 644 | * @return $this |
| 645 | 645 | */ |
| 646 | - public function postHref($element, $responseElement = "", $parameters = array()) { |
|
| 647 | - $parameters['attr'] = 'href'; |
|
| 646 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 647 | + $parameters['attr']='href'; |
|
| 648 | 648 | if (JString::isNull($responseElement)) { |
| 649 | - $responseElement = '%$(this).attr("data-target")%'; |
|
| 649 | + $responseElement='%$(this).attr("data-target")%'; |
|
| 650 | 650 | } else { |
| 651 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 651 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 652 | 652 | } |
| 653 | - if (! isset($parameters['historize'])) { |
|
| 654 | - $parameters['historize'] = true; |
|
| 653 | + if (!isset($parameters['historize'])) { |
|
| 654 | + $parameters['historize']=true; |
|
| 655 | 655 | } |
| 656 | 656 | return $this->postOnClick($element, '', '{}', $responseElement, $parameters); |
| 657 | 657 | } |
@@ -667,29 +667,29 @@ discard block |
||
| 667 | 667 | * 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,"before"=>null,"listenerOn"=>false) |
| 668 | 668 | * @return $this |
| 669 | 669 | */ |
| 670 | - public function postFormAction($element, $responseElement = "", $parameters = array()) { |
|
| 671 | - $parameters['attr'] = 'action'; |
|
| 670 | + public function postFormAction($element, $responseElement="", $parameters=array()) { |
|
| 671 | + $parameters['attr']='action'; |
|
| 672 | 672 | if (JString::isNull($responseElement)) { |
| 673 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 673 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 674 | 674 | } else { |
| 675 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 675 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 676 | 676 | } |
| 677 | - $formId = '%$(this).attr("id")%'; |
|
| 678 | - if (! isset($parameters['historize'])) { |
|
| 679 | - $parameters['historize'] = true; |
|
| 677 | + $formId='%$(this).attr("id")%'; |
|
| 678 | + if (!isset($parameters['historize'])) { |
|
| 679 | + $parameters['historize']=true; |
|
| 680 | 680 | } |
| 681 | - $parameters['preventDefault'] = true; |
|
| 682 | - if (! isset($parameters['hasLoader'])) { |
|
| 683 | - $parameters['hasLoader'] = '$(self).find("button, input[type=submit], input[type=button]")'; |
|
| 681 | + $parameters['preventDefault']=true; |
|
| 682 | + if (!isset($parameters['hasLoader'])) { |
|
| 683 | + $parameters['hasLoader']='$(self).find("button, input[type=submit], input[type=button]")'; |
|
| 684 | 684 | } |
| 685 | - if (! isset($parameters['jsCallback'])) { |
|
| 686 | - $parameters['jsCallback'] = 'var event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
|
| 685 | + if (!isset($parameters['jsCallback'])) { |
|
| 686 | + $parameters['jsCallback']='var event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
|
| 687 | 687 | } |
| 688 | 688 | return $this->postFormOn('submit', $element, '', $formId, $responseElement, $parameters); |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - private function _post($url, $params = '{}', $responseElement = '', $parameters = []) { |
|
| 692 | - $parameters['params'] = $params; |
|
| 691 | + private function _post($url, $params='{}', $responseElement='', $parameters=[]) { |
|
| 692 | + $parameters['params']=$params; |
|
| 693 | 693 | return $this->_ajax('POST', $url, $responseElement, $parameters); |
| 694 | 694 | } |
| 695 | 695 | |
@@ -705,8 +705,8 @@ discard block |
||
| 705 | 705 | * @param array $parameters |
| 706 | 706 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 707 | 707 | */ |
| 708 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 709 | - $parameters['immediatly'] = true; |
|
| 708 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 709 | + $parameters['immediatly']=true; |
|
| 710 | 710 | return $this->_post($url, $params, $responseElement, $parameters); |
| 711 | 711 | } |
| 712 | 712 | |
@@ -723,8 +723,8 @@ discard block |
||
| 723 | 723 | * @param array $parameters |
| 724 | 724 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 725 | 725 | */ |
| 726 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 727 | - $parameters['immediatly'] = false; |
|
| 726 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 727 | + $parameters['immediatly']=false; |
|
| 728 | 728 | return $this->_post($url, $params, $responseElement, $parameters); |
| 729 | 729 | } |
| 730 | 730 | |
@@ -743,9 +743,9 @@ discard block |
||
| 743 | 743 | * @param array $parameters |
| 744 | 744 | * 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,"before"=>null,"listenerOn"=>false) |
| 745 | 745 | */ |
| 746 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
| 747 | - $parameters['method'] = 'post'; |
|
| 748 | - $parameters['params'] = $params; |
|
| 746 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 747 | + $parameters['method']='post'; |
|
| 748 | + $parameters['params']=$params; |
|
| 749 | 749 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
| 750 | 750 | } |
| 751 | 751 | |
@@ -763,71 +763,71 @@ discard block |
||
| 763 | 763 | * @param array $parameters |
| 764 | 764 | * 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,"before"=>null,"before"=>null,"listenerOn"=>false) |
| 765 | 765 | */ |
| 766 | - public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array()) { |
|
| 766 | + public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
|
| 767 | 767 | return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
| 770 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 771 | 771 | if (isset($this->params['ajax'])) { |
| 772 | 772 | extract($this->params['ajax']); |
| 773 | 773 | } |
| 774 | - $params = '{}'; |
|
| 775 | - $validation = false; |
|
| 774 | + $params='{}'; |
|
| 775 | + $validation=false; |
|
| 776 | 776 | \extract($parameters); |
| 777 | - $async = ($async) ? 'true' : 'false'; |
|
| 778 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
| 779 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 780 | - $form = $this->_getFormElement($form); |
|
| 781 | - $retour .= "\n$('#'+" . $form . ").trigger('ajaxSubmit');"; |
|
| 782 | - if (! isset($contentType) || $contentType != 'false') { |
|
| 783 | - $retour .= "\nvar params=$('#'+" . $form . ").serialize();\n"; |
|
| 777 | + $async=($async) ? 'true' : 'false'; |
|
| 778 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
| 779 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 780 | + $form=$this->_getFormElement($form); |
|
| 781 | + $retour.="\n$('#'+".$form.").trigger('ajaxSubmit');"; |
|
| 782 | + if (!isset($contentType) || $contentType!='false') { |
|
| 783 | + $retour.="\nvar params=$('#'+".$form.").serialize();\n"; |
|
| 784 | 784 | if (isset($params)) { |
| 785 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
| 785 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
| 786 | 786 | } |
| 787 | 787 | } else { |
| 788 | - $retour .= "\nvar params=new FormData($('#'+" . $form . ")[0]);\n"; |
|
| 788 | + $retour.="\nvar params=new FormData($('#'+".$form.")[0]);\n"; |
|
| 789 | 789 | } |
| 790 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 791 | - $retour .= "var self=this;\n"; |
|
| 792 | - $before = isset($before) ? $before : ""; |
|
| 793 | - $retour .= $before; |
|
| 794 | - if ($hasLoader === true) { |
|
| 790 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 791 | + $retour.="var self=this;\n"; |
|
| 792 | + $before=isset($before) ? $before : ""; |
|
| 793 | + $retour.=$before; |
|
| 794 | + if ($hasLoader===true) { |
|
| 795 | 795 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 796 | - } elseif ($hasLoader === 'response') { |
|
| 796 | + } elseif ($hasLoader==='response') { |
|
| 797 | 797 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
| 798 | - } elseif ($hasLoader === 'internal-x') { |
|
| 798 | + } elseif ($hasLoader==='internal-x') { |
|
| 799 | 799 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
| 800 | - } elseif ($hasLoader === 'internal') { |
|
| 801 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 800 | + } elseif ($hasLoader==='internal') { |
|
| 801 | + $retour.="\n$(this).addClass('loading');"; |
|
| 802 | 802 | } elseif (\is_string($hasLoader)) { |
| 803 | - $retour .= "\n$hasLoader.addClass('loading');"; |
|
| 803 | + $retour.="\n$hasLoader.addClass('loading');"; |
|
| 804 | 804 | } |
| 805 | - $ajaxParameters = [ |
|
| 805 | + $ajaxParameters=[ |
|
| 806 | 806 | "url" => "url", |
| 807 | 807 | "method" => "'POST'", |
| 808 | 808 | "data" => "params", |
| 809 | 809 | "async" => $async |
| 810 | 810 | ]; |
| 811 | 811 | if (isset($headers)) { |
| 812 | - $ajaxParameters["headers"] = $headers; |
|
| 812 | + $ajaxParameters["headers"]=$headers; |
|
| 813 | 813 | } |
| 814 | 814 | if (isset($partial)) { |
| 815 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 816 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 815 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 816 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 817 | 817 | } |
| 818 | 818 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 819 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
| 820 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader) . "});\n"; |
|
| 819 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
| 820 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
| 821 | 821 | |
| 822 | 822 | if ($validation) { |
| 823 | - $retour = "$('#'+" . $form . ").validate({submitHandler: function(form) { |
|
| 824 | - " . $retour . " |
|
| 823 | + $retour="$('#'+".$form.").validate({submitHandler: function(form) { |
|
| 824 | + " . $retour." |
|
| 825 | 825 | }});\n"; |
| 826 | - $retour .= "$('#'+" . $form . ").submit();\n"; |
|
| 826 | + $retour.="$('#'+".$form.").submit();\n"; |
|
| 827 | 827 | } |
| 828 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 828 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 829 | 829 | if ($immediatly) |
| 830 | - $this->jquery_code_for_compile[] = $retour; |
|
| 830 | + $this->jquery_code_for_compile[]=$retour; |
|
| 831 | 831 | return $retour; |
| 832 | 832 | } |
| 833 | 833 | |
@@ -843,8 +843,8 @@ discard block |
||
| 843 | 843 | * @param array $parameters |
| 844 | 844 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 845 | 845 | */ |
| 846 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
| 847 | - $parameters['immediatly'] = true; |
|
| 846 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 847 | + $parameters['immediatly']=true; |
|
| 848 | 848 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 849 | 849 | } |
| 850 | 850 | |
@@ -861,8 +861,8 @@ discard block |
||
| 861 | 861 | * @param array $parameters |
| 862 | 862 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 863 | 863 | */ |
| 864 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
| 865 | - $parameters['immediatly'] = false; |
|
| 864 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
| 865 | + $parameters['immediatly']=false; |
|
| 866 | 866 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 867 | 867 | } |
| 868 | 868 | |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | * @param array $parameters |
| 880 | 880 | * 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,"before"=>null,"listenerOn"=>false) |
| 881 | 881 | */ |
| 882 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 882 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 883 | 883 | $this->setDefaultParameters($parameters, [ |
| 884 | 884 | 'preventDefault' => true, |
| 885 | 885 | 'stopPropagation' => true, |
@@ -901,11 +901,11 @@ discard block |
||
| 901 | 901 | * @param array $parameters |
| 902 | 902 | * 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,"before"=>null,"listenerOn"=>false) |
| 903 | 903 | */ |
| 904 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 904 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 905 | 905 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | - public function addCsrf($name = 'csrf-token') { |
|
| 908 | + public function addCsrf($name='csrf-token') { |
|
| 909 | 909 | return " |
| 910 | 910 | $.ajaxSetup({ |
| 911 | 911 | beforeSend: function(xhr, settings) { |
@@ -24,39 +24,39 @@ discard block |
||
| 24 | 24 | private $_inverted; |
| 25 | 25 | |
| 26 | 26 | public function __construct($identifier, $modelInstance=NULL) { |
| 27 | - parent::__construct($identifier, null,$modelInstance); |
|
| 27 | + parent::__construct($identifier, null, $modelInstance); |
|
| 28 | 28 | $this->_form=new HtmlForm($identifier); |
| 29 | 29 | $this->_init(new FormInstanceViewer($identifier), 'form', $this->_form, true); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - protected function _getFieldIdentifier($prefix,$name=''){ |
|
| 32 | + protected function _getFieldIdentifier($prefix, $name='') { |
|
| 33 | 33 | return $this->identifier."-{$name}-".$this->_instanceViewer->getIdentifier(); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 37 | - if(!$this->_generated){ |
|
| 36 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 37 | + if (!$this->_generated) { |
|
| 38 | 38 | $this->_instanceViewer->setInstance($this->_modelInstance); |
| 39 | 39 | |
| 40 | 40 | $form=$this->content['form']; |
| 41 | 41 | $this->_generateContent($form); |
| 42 | 42 | |
| 43 | - if(isset($this->_toolbar)){ |
|
| 43 | + if (isset($this->_toolbar)) { |
|
| 44 | 44 | $this->_setToolbarPosition($form); |
| 45 | 45 | } |
| 46 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,'form',PositionInTable::AFTERTABLE]); |
|
| 47 | - if($this->_inverted){ |
|
| 46 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, 'form', PositionInTable::AFTERTABLE]); |
|
| 47 | + if ($this->_inverted) { |
|
| 48 | 48 | $this->content['form']->setInverted(true); |
| 49 | 49 | } |
| 50 | 50 | $this->_generated=true; |
| 51 | 51 | } |
| 52 | - return parent::compile($js,$view); |
|
| 52 | + return parent::compile($js, $view); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * @param HtmlForm $form |
| 57 | 57 | */ |
| 58 | - protected function _generateContent($form){ |
|
| 59 | - $values= $this->_instanceViewer->getValues(); |
|
| 58 | + protected function _generateContent($form) { |
|
| 59 | + $values=$this->_instanceViewer->getValues(); |
|
| 60 | 60 | $count=$this->_instanceViewer->count(); |
| 61 | 61 | $separators=$this->_instanceViewer->getSeparators(); |
| 62 | 62 | $headers=$this->_instanceViewer->getHeaders(); |
@@ -65,42 +65,42 @@ discard block |
||
| 65 | 65 | \sort($separators); |
| 66 | 66 | $size=\count($separators); |
| 67 | 67 | $nb=0; |
| 68 | - if($size===1){ |
|
| 68 | + if ($size===1) { |
|
| 69 | 69 | $i=-1; |
| 70 | - foreach ($values as $k=>$v){ |
|
| 71 | - $this->_generateFields($form, [$v], $headers, $i, $wrappers,$nb++,$names[$k]??''); |
|
| 70 | + foreach ($values as $k=>$v) { |
|
| 71 | + $this->_generateFields($form, [$v], $headers, $i, $wrappers, $nb++, $names[$k] ?? ''); |
|
| 72 | 72 | $i++; |
| 73 | 73 | } |
| 74 | - }else{ |
|
| 74 | + } else { |
|
| 75 | 75 | $separators[]=$count; |
| 76 | - for($i=0;$i<$size;$i++){ |
|
| 77 | - $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
|
| 78 | - $this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers,$nb++,$names[$i]??''); |
|
| 76 | + for ($i=0; $i<$size; $i++) { |
|
| 77 | + $fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]); |
|
| 78 | + $this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers, $nb++, $names[$i] ?? ''); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | - if($this->_hasRules && !$this->getForm()->hasValidationParams()){ |
|
| 81 | + if ($this->_hasRules && !$this->getForm()->hasValidationParams()) { |
|
| 82 | 82 | $this->setValidationParams(['inline'=>true]); |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - protected function _generateFields($form, $values, $headers, $sepFirst, $wrappers, $nb, $name){ |
|
| 86 | + protected function _generateFields($form, $values, $headers, $sepFirst, $wrappers, $nb, $name) { |
|
| 87 | 87 | $wrapper=null; |
| 88 | - if(isset($headers[$sepFirst+1])) |
|
| 89 | - $form->addHeader($headers[$sepFirst+1],4,true); |
|
| 90 | - if(isset($wrappers[$sepFirst+1])){ |
|
| 88 | + if (isset($headers[$sepFirst+1])) |
|
| 89 | + $form->addHeader($headers[$sepFirst+1], 4, true); |
|
| 90 | + if (isset($wrappers[$sepFirst+1])) { |
|
| 91 | 91 | $wrapper=$wrappers[$sepFirst+1]; |
| 92 | 92 | } |
| 93 | 93 | $count=\count($values); |
| 94 | - if($count===1){ |
|
| 94 | + if ($count===1) { |
|
| 95 | 95 | $added=$form->addField($values[0]); |
| 96 | - }elseif($count>1){ |
|
| 96 | + }elseif ($count>1) { |
|
| 97 | 97 | $added=$form->addFields($values); |
| 98 | - }else |
|
| 98 | + } else |
|
| 99 | 99 | return; |
| 100 | - if(isset($wrapper)){ |
|
| 101 | - $added->wrap($wrapper[0],$wrapper[1]); |
|
| 100 | + if (isset($wrapper)) { |
|
| 101 | + $added->wrap($wrapper[0], $wrapper[1]); |
|
| 102 | 102 | } |
| 103 | - $this->execHook('onGenerateFields',$added,$nb,$name); |
|
| 103 | + $this->execHook('onGenerateFields', $added, $nb, $name); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -108,18 +108,18 @@ discard block |
||
| 108 | 108 | * the generated field is the first parameter |
| 109 | 109 | * @param callable $callback the fonction to call when a field is generated |
| 110 | 110 | */ |
| 111 | - public function onGenerateField($callback){ |
|
| 112 | - $this->addHook('onGenerateFields',$callback); |
|
| 111 | + public function onGenerateField($callback) { |
|
| 112 | + $this->addHook('onGenerateFields', $callback); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * @return HtmlForm |
| 117 | 117 | */ |
| 118 | - public function getForm(){ |
|
| 118 | + public function getForm() { |
|
| 119 | 119 | return $this->content['form']; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public function addSeparatorAfter($fieldNum){ |
|
| 122 | + public function addSeparatorAfter($fieldNum) { |
|
| 123 | 123 | $fieldNum=$this->_getIndex($fieldNum); |
| 124 | 124 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
| 125 | 125 | return $this; |
@@ -134,12 +134,12 @@ discard block |
||
| 134 | 134 | return $this; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
| 138 | - return $this->_fieldAs(function($id,$name,$value) use ($cssStyle){ |
|
| 139 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 137 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
| 138 | + return $this->_fieldAs(function($id, $name, $value) use ($cssStyle){ |
|
| 139 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 140 | 140 | $button->setProperty('type', 'reset'); |
| 141 | 141 | return $button; |
| 142 | - }, $index,$attributes); |
|
| 142 | + }, $index, $attributes); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -158,19 +158,19 @@ discard block |
||
| 158 | 158 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - public function addDividerBefore($index,$title){ |
|
| 161 | + public function addDividerBefore($index, $title) { |
|
| 162 | 162 | $index=$this->_getIndex($index); |
| 163 | 163 | $this->_instanceViewer->addHeaderDividerBefore($index, $title); |
| 164 | 164 | return $this; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - public function addWrapper($index,$contentBefore,$contentAfter=null){ |
|
| 167 | + public function addWrapper($index, $contentBefore, $contentAfter=null) { |
|
| 168 | 168 | $index=$this->_getIndex($index); |
| 169 | - $this->_instanceViewer->addWrapper($index, $contentBefore,$contentAfter); |
|
| 169 | + $this->_instanceViewer->addWrapper($index, $contentBefore, $contentAfter); |
|
| 170 | 170 | return $this; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - public function run(JsUtils $js){ |
|
| 173 | + public function run(JsUtils $js) { |
|
| 174 | 174 | parent::run($js); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | $this->_generateFields($form, [$v], $headers, $i, $wrappers,$nb++,$names[$k]??''); |
| 72 | 72 | $i++; |
| 73 | 73 | } |
| 74 | - }else{ |
|
| 74 | + } else{ |
|
| 75 | 75 | $separators[]=$count; |
| 76 | 76 | for($i=0;$i<$size;$i++){ |
| 77 | 77 | $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
@@ -85,18 +85,20 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | protected function _generateFields($form, $values, $headers, $sepFirst, $wrappers, $nb, $name){ |
| 87 | 87 | $wrapper=null; |
| 88 | - if(isset($headers[$sepFirst+1])) |
|
| 89 | - $form->addHeader($headers[$sepFirst+1],4,true); |
|
| 88 | + if(isset($headers[$sepFirst+1])) { |
|
| 89 | + $form->addHeader($headers[$sepFirst+1],4,true); |
|
| 90 | + } |
|
| 90 | 91 | if(isset($wrappers[$sepFirst+1])){ |
| 91 | 92 | $wrapper=$wrappers[$sepFirst+1]; |
| 92 | 93 | } |
| 93 | 94 | $count=\count($values); |
| 94 | 95 | if($count===1){ |
| 95 | 96 | $added=$form->addField($values[0]); |
| 96 | - }elseif($count>1){ |
|
| 97 | + } elseif($count>1){ |
|
| 97 | 98 | $added=$form->addFields($values); |
| 98 | - }else |
|
| 99 | - return; |
|
| 99 | + } else { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 100 | 102 | if(isset($wrapper)){ |
| 101 | 103 | $added->wrap($wrapper[0],$wrapper[1]); |
| 102 | 104 | } |