@@ -12,15 +12,28 @@ discard block |
||
| 12 | 12 | * @property InstanceViewer $_instanceViewer |
| 13 | 13 | */ |
| 14 | 14 | trait DataTableFieldAsTrait{ |
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @param \Closure $field |
|
| 18 | + */ |
|
| 15 | 19 | abstract public function addField($field); |
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param integer $index |
|
| 23 | + * @param \Closure $field |
|
| 24 | + */ |
|
| 16 | 25 | abstract public function insertField($index,$field); |
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @param \Closure $field |
|
| 29 | + */ |
|
| 17 | 30 | abstract public function insertInField($index,$field); |
| 18 | 31 | abstract public function fieldAs($index,$type,$attributes=NULL); |
| 19 | 32 | /** |
| 20 | 33 | * @param string $caption |
| 21 | 34 | * @param callable $callback |
| 22 | 35 | * @param boolean $visibleHover |
| 23 | - * @return callable |
|
| 36 | + * @return \Closure |
|
| 24 | 37 | */ |
| 25 | 38 | private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
| 26 | 39 | return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
@@ -30,7 +43,7 @@ discard block |
||
| 30 | 43 | * @param callable $thisCallback |
| 31 | 44 | * @param array $parameters |
| 32 | 45 | * @param callable $callback |
| 33 | - * @return callable |
|
| 46 | + * @return \Closure |
|
| 34 | 47 | */ |
| 35 | 48 | private function getCallable($thisCallback,$parameters,$callback=null){ |
| 36 | 49 | $result=function($instance) use($thisCallback,$parameters,$callback){ |
@@ -82,6 +95,9 @@ discard block |
||
| 82 | 95 | }, $index,$attributes); |
| 83 | 96 | } |
| 84 | 97 | |
| 98 | + /** |
|
| 99 | + * @param HtmlButton $element |
|
| 100 | + */ |
|
| 85 | 101 | protected function _visibleOver($element){ |
| 86 | 102 | $this->_visibleHover=true; |
| 87 | 103 | return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
@@ -92,7 +108,7 @@ discard block |
||
| 92 | 108 | * @param string $caption |
| 93 | 109 | * @param callable $callback |
| 94 | 110 | * @param boolean $visibleHover |
| 95 | - * @return \Ajax\semantic\widgets\datatable\DataTable |
|
| 111 | + * @return DataTableFieldAsTrait |
|
| 96 | 112 | */ |
| 97 | 113 | public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
| 98 | 114 | $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
@@ -104,7 +120,7 @@ discard block |
||
| 104 | 120 | * @param int $index |
| 105 | 121 | * @param string $caption |
| 106 | 122 | * @param callable $callback |
| 107 | - * @return \Ajax\semantic\widgets\datatable\DataTable |
|
| 123 | + * @return DataTableFieldAsTrait |
|
| 108 | 124 | */ |
| 109 | 125 | public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
| 110 | 126 | $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
@@ -116,18 +132,26 @@ discard block |
||
| 116 | 132 | * @param int $index |
| 117 | 133 | * @param string $caption |
| 118 | 134 | * @param callable $callback |
| 119 | - * @return \Ajax\semantic\widgets\datatable\DataTable |
|
| 135 | + * @return DataTableFieldAsTrait |
|
| 120 | 136 | */ |
| 121 | 137 | public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
| 122 | 138 | $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
| 123 | 139 | return $this; |
| 124 | 140 | } |
| 125 | 141 | |
| 142 | + /** |
|
| 143 | + * @param string $icon |
|
| 144 | + * @param string $class |
|
| 145 | + */ |
|
| 126 | 146 | private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
| 127 | 147 | $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
| 128 | 148 | return $this; |
| 129 | 149 | } |
| 130 | 150 | |
| 151 | + /** |
|
| 152 | + * @param string $icon |
|
| 153 | + * @param string $class |
|
| 154 | + */ |
|
| 131 | 155 | private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
| 132 | 156 | $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
| 133 | 157 | return $this; |
@@ -11,19 +11,19 @@ discard block |
||
| 11 | 11 | * @property boolean $_visibleHover |
| 12 | 12 | * @property InstanceViewer $_instanceViewer |
| 13 | 13 | */ |
| 14 | -trait DataTableFieldAsTrait{ |
|
| 14 | +trait DataTableFieldAsTrait { |
|
| 15 | 15 | abstract public function addField($field); |
| 16 | - abstract public function insertField($index,$field); |
|
| 17 | - abstract public function insertInField($index,$field); |
|
| 18 | - abstract public function fieldAs($index,$type,$attributes=NULL); |
|
| 16 | + abstract public function insertField($index, $field); |
|
| 17 | + abstract public function insertInField($index, $field); |
|
| 18 | + abstract public function fieldAs($index, $type, $attributes=NULL); |
|
| 19 | 19 | /** |
| 20 | 20 | * @param string $caption |
| 21 | 21 | * @param callable $callback |
| 22 | 22 | * @param boolean $visibleHover |
| 23 | 23 | * @return callable |
| 24 | 24 | */ |
| 25 | - private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
|
| 26 | - return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
|
| 25 | + private function getFieldButtonCallable($caption, $visibleHover=true, $callback=null) { |
|
| 26 | + return $this->getCallable("getFieldButton", [$caption, $visibleHover], $callback); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -32,19 +32,19 @@ discard block |
||
| 32 | 32 | * @param callable $callback |
| 33 | 33 | * @return callable |
| 34 | 34 | */ |
| 35 | - private function getCallable($thisCallback,$parameters,$callback=null){ |
|
| 36 | - $result=function($instance) use($thisCallback,$parameters,$callback){ |
|
| 37 | - $object=call_user_func_array(array($this,$thisCallback), $parameters); |
|
| 38 | - if(isset($callback)){ |
|
| 39 | - if(\is_callable($callback)){ |
|
| 40 | - $callback($object,$instance); |
|
| 35 | + private function getCallable($thisCallback, $parameters, $callback=null) { |
|
| 36 | + $result=function($instance) use($thisCallback, $parameters, $callback){ |
|
| 37 | + $object=call_user_func_array(array($this, $thisCallback), $parameters); |
|
| 38 | + if (isset($callback)) { |
|
| 39 | + if (\is_callable($callback)) { |
|
| 40 | + $callback($object, $instance); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | - if($object instanceof HtmlSemDoubleElement){ |
|
| 44 | - $object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
|
| 45 | - if($object->propertyContains("class","visibleover")){ |
|
| 43 | + if ($object instanceof HtmlSemDoubleElement) { |
|
| 44 | + $object->setProperty("data-ajax", $this->_instanceViewer->getIdentifier()); |
|
| 45 | + if ($object->propertyContains("class", "visibleover")) { |
|
| 46 | 46 | $this->_visibleHover=true; |
| 47 | - $object->setProperty("style","visibility:hidden;"); |
|
| 47 | + $object->setProperty("style", "visibility:hidden;"); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | return $object; |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | * @param string $caption |
| 57 | 57 | * @return HtmlButton |
| 58 | 58 | */ |
| 59 | - private function getFieldButton($caption,$visibleHover=true){ |
|
| 60 | - $bt= new HtmlButton("",$caption); |
|
| 61 | - if($visibleHover) |
|
| 59 | + private function getFieldButton($caption, $visibleHover=true) { |
|
| 60 | + $bt=new HtmlButton("", $caption); |
|
| 61 | + if ($visibleHover) |
|
| 62 | 62 | $this->_visibleOver($bt); |
| 63 | 63 | return $bt; |
| 64 | 64 | } |
@@ -72,19 +72,19 @@ discard block |
||
| 72 | 72 | * @param array $attributes associative array (<b>ajax</b> key is for ajax post) |
| 73 | 73 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 74 | 74 | */ |
| 75 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
| 76 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index,$attributes){ |
|
| 77 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 78 | - $button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]); |
|
| 79 | - if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
| 75 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
| 76 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $index, $attributes){ |
|
| 77 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 78 | + $button->postOnClick($url, "$(event.target).closest('tr').find(':input').serialize()", $responseElement, $attributes["ajax"]); |
|
| 79 | + if (!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
| 80 | 80 | $this->_visibleOver($button); |
| 81 | 81 | return $button; |
| 82 | - }, $index,$attributes); |
|
| 82 | + }, $index, $attributes); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - protected function _visibleOver($element){ |
|
| 85 | + protected function _visibleOver($element) { |
|
| 86 | 86 | $this->_visibleHover=true; |
| 87 | - return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
|
| 87 | + return $element->addToProperty("class", "visibleover")->setProperty("style", "visibility:hidden;"); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | * @param boolean $visibleHover |
| 95 | 95 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 96 | 96 | */ |
| 97 | - public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
|
| 98 | - $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
|
| 97 | + public function addFieldButton($caption, $visibleHover=true, $callback=null) { |
|
| 98 | + $this->addField($this->getCallable("getFieldButton", [$caption, $visibleHover], $callback)); |
|
| 99 | 99 | return $this; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | * @param callable $callback |
| 107 | 107 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 108 | 108 | */ |
| 109 | - public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
| 110 | - $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
| 109 | + public function insertFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
| 110 | + $this->insertField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
| 111 | 111 | return $this; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -118,25 +118,25 @@ discard block |
||
| 118 | 118 | * @param callable $callback |
| 119 | 119 | * @return \Ajax\semantic\widgets\datatable\DataTable |
| 120 | 120 | */ |
| 121 | - public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
| 122 | - $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
| 121 | + public function insertInFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
| 122 | + $this->insertInField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
| 123 | 123 | return $this; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
|
| 127 | - $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
| 126 | + private function addDefaultButton($icon, $class=null, $visibleHover=true, $callback=null) { |
|
| 127 | + $this->addField($this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
| 128 | 128 | return $this; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
|
| 132 | - $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
| 131 | + private function insertDefaultButtonIn($index, $icon, $class=null, $visibleHover=true, $callback=null) { |
|
| 132 | + $this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
| 133 | 133 | return $this; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
|
| 137 | - $bt=$this->getFieldButton("",$visibleHover); |
|
| 136 | + private function getDefaultButton($icon, $class=null, $visibleHover=true) { |
|
| 137 | + $bt=$this->getFieldButton("", $visibleHover); |
|
| 138 | 138 | $bt->asIcon($icon); |
| 139 | - if(isset($class)) |
|
| 139 | + if (isset($class)) |
|
| 140 | 140 | $bt->addClass($class); |
| 141 | 141 | return $bt; |
| 142 | 142 | } |
@@ -147,30 +147,30 @@ discard block |
||
| 147 | 147 | * @param callable $callback |
| 148 | 148 | * @return \Ajax\semantic\widgets\datatable\DataTableFieldAsTrait |
| 149 | 149 | */ |
| 150 | - public function addDeleteButton($visibleHover=true,$deleteBehavior=[],$callback=null){ |
|
| 150 | + public function addDeleteButton($visibleHover=true, $deleteBehavior=[], $callback=null) { |
|
| 151 | 151 | $this->_deleteBehavior=$deleteBehavior; |
| 152 | - return $this->addDefaultButton("remove","_delete red basic",$visibleHover,$callback); |
|
| 152 | + return $this->addDefaultButton("remove", "_delete red basic", $visibleHover, $callback); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - public function addEditButton($visibleHover=true,$editBehavior=[],$callback=null){ |
|
| 155 | + public function addEditButton($visibleHover=true, $editBehavior=[], $callback=null) { |
|
| 156 | 156 | $this->_editBehavior=$editBehavior; |
| 157 | - return $this->addDefaultButton("edit","_edit basic",$visibleHover,$callback); |
|
| 157 | + return $this->addDefaultButton("edit", "_edit basic", $visibleHover, $callback); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public function addEditDeleteButtons($visibleHover=true,$behavior=[],$callbackEdit=null,$callbackDelete=null){ |
|
| 161 | - $this->addEditButton($visibleHover,$behavior,$callbackEdit); |
|
| 160 | + public function addEditDeleteButtons($visibleHover=true, $behavior=[], $callbackEdit=null, $callbackDelete=null) { |
|
| 161 | + $this->addEditButton($visibleHover, $behavior, $callbackEdit); |
|
| 162 | 162 | $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
| 163 | - $this->insertDeleteButtonIn($index,$visibleHover,$behavior,$callbackDelete); |
|
| 163 | + $this->insertDeleteButtonIn($index, $visibleHover, $behavior, $callbackDelete); |
|
| 164 | 164 | return $this; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - public function insertDeleteButtonIn($index,$visibleHover=true,$deleteBehavior=[],$callback=null){ |
|
| 167 | + public function insertDeleteButtonIn($index, $visibleHover=true, $deleteBehavior=[], $callback=null) { |
|
| 168 | 168 | $this->_deleteBehavior=$deleteBehavior; |
| 169 | - return $this->insertDefaultButtonIn($index,"remove","_delete red basic",$visibleHover,$callback); |
|
| 169 | + return $this->insertDefaultButtonIn($index, "remove", "_delete red basic", $visibleHover, $callback); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - public function insertEditButtonIn($index,$visibleHover=true,$editBehavior=[],$callback=null){ |
|
| 172 | + public function insertEditButtonIn($index, $visibleHover=true, $editBehavior=[], $callback=null) { |
|
| 173 | 173 | $this->_editBehavior=$editBehavior; |
| 174 | - return $this->insertDefaultButtonIn($index,"edit","_edit basic",$visibleHover,$callback); |
|
| 174 | + return $this->insertDefaultButtonIn($index, "edit", "_edit basic", $visibleHover, $callback); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | \ No newline at end of file |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | protected $ajaxTransition; |
| 18 | 18 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
| 19 | 19 | |
| 20 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
| 20 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 21 | 21 | protected function addLoading(&$retour, $responseElement) { |
| 22 | 22 | $loading_notifier='<div class="ajax-loader">'; |
| 23 | 23 | if ($this->ajaxLoader=='') { |
@@ -30,66 +30,66 @@ discard block |
||
| 30 | 30 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 34 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
| 33 | + public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 34 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
| 35 | 35 | } |
| 36 | - public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 37 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
| 36 | + public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 37 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 41 | - if(JString::isNull($params)){$params="{}";} |
|
| 40 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 41 | + if (JString::isNull($params)) {$params="{}"; } |
|
| 42 | 42 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 43 | 43 | $retour=$this->_getAjaxUrl($url, $attr); |
| 44 | 44 | $responseElement=$this->_getResponseElement($responseElement); |
| 45 | 45 | $retour.="var self=this;\n"; |
| 46 | - if($hasLoader===true){ |
|
| 46 | + if ($hasLoader===true) { |
|
| 47 | 47 | $this->addLoading($retour, $responseElement); |
| 48 | 48 | } |
| 49 | 49 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
| 50 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
| 50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
| 51 | 51 | if ($immediatly) |
| 52 | 52 | $this->jquery_code_for_compile[]=$retour; |
| 53 | 53 | return $retour; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - protected function setAjaxDataCall($params){ |
|
| 56 | + protected function setAjaxDataCall($params) { |
|
| 57 | 57 | $result=null; |
| 58 | - if(!\is_callable($params)){ |
|
| 59 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
| 60 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
| 58 | + if (!\is_callable($params)) { |
|
| 59 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
| 60 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
| 61 | 61 | }; |
| 62 | 62 | } |
| 63 | 63 | return $result; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - protected function _getAjaxUrl($url,$attr){ |
|
| 66 | + protected function _getAjaxUrl($url, $attr) { |
|
| 67 | 67 | $url=$this->_correctAjaxUrl($url); |
| 68 | 68 | $retour="url='".$url."';"; |
| 69 | 69 | $slash="/"; |
| 70 | - if(JString::endswith($url, "/")===true) |
|
| 70 | + if (JString::endswith($url, "/")===true) |
|
| 71 | 71 | $slash=""; |
| 72 | - if(JString::isNotNull($attr)){ |
|
| 72 | + if (JString::isNotNull($attr)) { |
|
| 73 | 73 | if ($attr==="value") |
| 74 | 74 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
| 75 | 75 | elseif ($attr==="html") |
| 76 | 76 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
| 77 | - elseif($attr!=null && $attr!=="") |
|
| 77 | + elseif ($attr!=null && $attr!=="") |
|
| 78 | 78 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
| 79 | 79 | } |
| 80 | 80 | return $retour; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
| 84 | - $retour="";$call=null; |
|
| 83 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
| 84 | + $retour=""; $call=null; |
|
| 85 | 85 | if ($responseElement!=="") { |
| 86 | - if(isset($ajaxTransition)){ |
|
| 86 | + if (isset($ajaxTransition)) { |
|
| 87 | 87 | $call=$this->setAjaxDataCall($ajaxTransition); |
| 88 | - }elseif(isset($this->ajaxTransition)){ |
|
| 88 | + }elseif (isset($this->ajaxTransition)) { |
|
| 89 | 89 | $call=$this->ajaxTransition; |
| 90 | 90 | } |
| 91 | - if(\is_callable($call)) |
|
| 92 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 91 | + if (\is_callable($call)) |
|
| 92 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 93 | 93 | else |
| 94 | 94 | $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
| 95 | 95 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | return $retour; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - protected function _getResponseElement($responseElement){ |
|
| 100 | + protected function _getResponseElement($responseElement) { |
|
| 101 | 101 | if ($responseElement!=="") { |
| 102 | 102 | $responseElement=Javascript::prep_value($responseElement); |
| 103 | 103 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | protected function _correctAjaxUrl($url) { |
| 108 | 108 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
| 109 | 109 | $url=substr($url, 0, strlen($url)-1); |
| 110 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
| 110 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 111 | 111 | $url=$this->jsUtils->getUrl($url); |
| 112 | 112 | } |
| 113 | 113 | return $url; |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param string $jsCallback javascript code to execute after the request |
| 122 | 122 | * @param boolean $immediatly |
| 123 | 123 | */ |
| 124 | - public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
| 124 | + public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
| 125 | 125 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 126 | 126 | $retour=$this->_getAjaxUrl($url, $attr); |
| 127 | 127 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param string $url the request address |
| 143 | 143 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
| 144 | 144 | */ |
| 145 | - public function _jsonOn($event,$element, $url,$parameters=array()) { |
|
| 145 | + public function _jsonOn($event, $element, $url, $parameters=array()) { |
|
| 146 | 146 | $preventDefault=true; |
| 147 | 147 | $stopPropagation=true; |
| 148 | 148 | $jsCallback=null; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $params="{}"; |
| 153 | 153 | $immediatly=true; |
| 154 | 154 | extract($parameters); |
| 155 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 155 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -164,19 +164,19 @@ discard block |
||
| 164 | 164 | * @param string $context jquery DOM element, array container. |
| 165 | 165 | * @param boolean $immediatly |
| 166 | 166 | */ |
| 167 | - public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null,$immediatly=false) { |
|
| 167 | + public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null, $immediatly=false) { |
|
| 168 | 168 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 169 | 169 | $retour=$this->_getAjaxUrl($url, $attr); |
| 170 | - if($context===null){ |
|
| 170 | + if ($context===null) { |
|
| 171 | 171 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
| 172 | - $newElm = "$('#'+newId)"; |
|
| 173 | - }else{ |
|
| 172 | + $newElm="$('#'+newId)"; |
|
| 173 | + } else { |
|
| 174 | 174 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
| 175 | - $newElm = $context.".find('#'+newId)"; |
|
| 175 | + $newElm=$context.".find('#'+newId)"; |
|
| 176 | 176 | } |
| 177 | 177 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
| 178 | 178 | $retour.="\tdata=$.parseJSON(data);$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone();newElm.attr('id',newId);\n"; |
| 179 | - $retour.= $appendTo; |
|
| 179 | + $retour.=$appendTo; |
|
| 180 | 180 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('[['+key+']]')>-1){\n"."\t\t\t\tcontent=$(html.split('[['+key+']]').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
| 181 | 181 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 182 | 182 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -191,30 +191,30 @@ discard block |
||
| 191 | 191 | * @param string $url the request address |
| 192 | 192 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get", "context"=>null) |
| 193 | 193 | */ |
| 194 | - public function _jsonArrayOn($event,$element, $maskSelector,$url,$parameters=array()) { |
|
| 194 | + public function _jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
| 195 | 195 | $preventDefault=true; |
| 196 | 196 | $stopPropagation=true; |
| 197 | 197 | $jsCallback=null; |
| 198 | 198 | $attr="id"; |
| 199 | 199 | $method="get"; |
| 200 | - $context = null; |
|
| 200 | + $context=null; |
|
| 201 | 201 | $params="{}"; |
| 202 | 202 | $immediatly=true; |
| 203 | 203 | extract($parameters); |
| 204 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 204 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 207 | + public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 208 | 208 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 209 | 209 | $retour=$this->_getAjaxUrl($url, $attr); |
| 210 | 210 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
| 211 | 211 | $responseElement=$this->_getResponseElement($responseElement); |
| 212 | 212 | $retour.="var self=this;\n"; |
| 213 | - if($hasLoader===true){ |
|
| 213 | + if ($hasLoader===true) { |
|
| 214 | 214 | $this->addLoading($retour, $responseElement); |
| 215 | 215 | } |
| 216 | 216 | $retour.="$.post(url,params).done(function( data ) {\n"; |
| 217 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
| 217 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
| 218 | 218 | |
| 219 | 219 | if ($validation) { |
| 220 | 220 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * @param string $responseElement |
| 238 | 238 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null,"jqueryDone"=>"html") |
| 239 | 239 | */ |
| 240 | - public function _getOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 240 | + public function _getOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 241 | 241 | $preventDefault=true; |
| 242 | 242 | $stopPropagation=true; |
| 243 | 243 | $jsCallback=null; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $jqueryDone="html"; |
| 248 | 248 | $ajaxTransition=null; |
| 249 | 249 | extract($parameters); |
| 250 | - return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 250 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @param string $responseElement |
| 261 | 261 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null) |
| 262 | 262 | */ |
| 263 | - public function _postOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 263 | + public function _postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 264 | 264 | $preventDefault=true; |
| 265 | 265 | $stopPropagation=true; |
| 266 | 266 | $jsCallback=null; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $jqueryDone="html"; |
| 271 | 271 | $ajaxTransition=null; |
| 272 | 272 | extract($parameters); |
| 273 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 273 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @param string $responseElement |
| 284 | 284 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null,"immediatly"=>true) |
| 285 | 285 | */ |
| 286 | - public function _postFormOn($event,$element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 286 | + public function _postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 287 | 287 | $preventDefault=true; |
| 288 | 288 | $stopPropagation=true; |
| 289 | 289 | $validation=false; |
@@ -294,6 +294,6 @@ discard block |
||
| 294 | 294 | $jqueryDone="html"; |
| 295 | 295 | $ajaxTransition=null; |
| 296 | 296 | extract($parameters); |
| 297 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 297 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | \ No newline at end of file |
@@ -2,37 +2,37 @@ |
||
| 2 | 2 | namespace Ajax\service; |
| 3 | 3 | class JString { |
| 4 | 4 | |
| 5 | - public static function contains($hay,$needle){ |
|
| 6 | - return strpos($hay, $needle) !== false; |
|
| 5 | + public static function contains($hay, $needle) { |
|
| 6 | + return strpos($hay, $needle)!==false; |
|
| 7 | 7 | } |
| 8 | 8 | public static function startswith($hay, $needle) { |
| 9 | - return substr($hay, 0, strlen($needle)) === $needle; |
|
| 9 | + return substr($hay, 0, strlen($needle))===$needle; |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | public static function endswith($hay, $needle) { |
| 13 | - return substr($hay, -strlen($needle)) === $needle; |
|
| 13 | + return substr($hay, -strlen($needle))===$needle; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - public static function isNull($s){ |
|
| 16 | + public static function isNull($s) { |
|
| 17 | 17 | return (!isset($s) || NULL===$s || ""===$s); |
| 18 | 18 | } |
| 19 | - public static function isNotNull($s){ |
|
| 19 | + public static function isNotNull($s) { |
|
| 20 | 20 | return (isset($s) && NULL!==$s && ""!==$s); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public static function isBoolean($value){ |
|
| 23 | + public static function isBoolean($value) { |
|
| 24 | 24 | return \is_bool($value) || $value==1 || $value==0; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public static function isBooleanTrue($value){ |
|
| 27 | + public static function isBooleanTrue($value) { |
|
| 28 | 28 | return $value==1 || $value; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public static function isBooleanFalse($value){ |
|
| 31 | + public static function isBooleanFalse($value) { |
|
| 32 | 32 | return $value==0 || !$value; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public static function camelCaseToSeparated($input,$separator=" "){ |
|
| 35 | + public static function camelCaseToSeparated($input, $separator=" ") { |
|
| 36 | 36 | return strtolower(preg_replace('/(?<!^)[A-Z]/', $separator.'$0', $input)); |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -3,26 +3,26 @@ |
||
| 3 | 3 | use Ajax\semantic\html\base\constants\Transition; |
| 4 | 4 | |
| 5 | 5 | class AjaxTransition { |
| 6 | - public static function none($responseElement,$jqueryDone="html"){ |
|
| 6 | + public static function none($responseElement, $jqueryDone="html") { |
|
| 7 | 7 | return "$({$responseElement}).{$jqueryDone}( data )"; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | - public static function jqFade($responseElement,$jqueryDone="html"){ |
|
| 10 | + public static function jqFade($responseElement, $jqueryDone="html") { |
|
| 11 | 11 | return "$({$responseElement}).hide().{$jqueryDone}( data ).fadeIn()"; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public static function jqSlide($responseElement,$jqueryDone="html"){ |
|
| 14 | + public static function jqSlide($responseElement, $jqueryDone="html") { |
|
| 15 | 15 | return "$({$responseElement}).hide().{$jqueryDone}( data ).slideDown()"; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public static function random($responseElement,$jqueryDone="html"){ |
|
| 18 | + public static function random($responseElement, $jqueryDone="html") { |
|
| 19 | 19 | $transitions=Transition::getConstantValues(); |
| 20 | - $transition=$transitions[\rand(0,\sizeof($transitions)-1)]; |
|
| 21 | - return self::__callStatic($transition, [$responseElement,$jqueryDone]); |
|
| 20 | + $transition=$transitions[\rand(0, \sizeof($transitions)-1)]; |
|
| 21 | + return self::__callStatic($transition, [$responseElement, $jqueryDone]); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public static function __callStatic($name, $arguments){ |
|
| 25 | - if(\sizeof($arguments)==2){ |
|
| 24 | + public static function __callStatic($name, $arguments) { |
|
| 25 | + if (\sizeof($arguments)==2) { |
|
| 26 | 26 | $responseElement=$arguments[0]; |
| 27 | 27 | $jqueryDone=$arguments[1]; |
| 28 | 28 | $name=JString::camelCaseToSeparated($name); |
@@ -3,12 +3,12 @@ |
||
| 3 | 3 | use Ajax\common\BaseEnum; |
| 4 | 4 | abstract class Transition extends BaseEnum { |
| 5 | 5 | const SCALE="scale", |
| 6 | - FADE="fade",FADE_UP="fadeUp",FADE_DOWN="fadeDown",FADE_LEFT="fadeLeft",FADE_RIGHT="fadeRight", |
|
| 7 | - HORIZONTAL_FLIP="horizontalFlip",VERTICAL_FLIP="verticalFlip", |
|
| 6 | + FADE="fade", FADE_UP="fadeUp", FADE_DOWN="fadeDown", FADE_LEFT="fadeLeft", FADE_RIGHT="fadeRight", |
|
| 7 | + HORIZONTAL_FLIP="horizontalFlip", VERTICAL_FLIP="verticalFlip", |
|
| 8 | 8 | DROP="drop", |
| 9 | - FLY_LEFT="flyLeft",FLY_RIGHT="flyRight",FLY_UP="flyUp",FLY_DOWN="flyDown", |
|
| 10 | - SWING_LEFT="swingLeft",SWING_RIGHT="swingRight",SWING_UP="swingUp",SWING_DOWN="swingDown", |
|
| 11 | - BROWSE="browse",BROWSE_RIGHT="browseRight", |
|
| 12 | - SLIDE_LEFT="slideLeft",SLIDE_RIGHT="slideRight",SLIDE_UP="slideUp",SLIDE_DOWN="slideDown", |
|
| 13 | - JIGGLE="jiggle",FLASH="flash",SHAKE="shake",PULSE="pulse",TADA="tada",BOUNCE="bounce"; |
|
| 9 | + FLY_LEFT="flyLeft", FLY_RIGHT="flyRight", FLY_UP="flyUp", FLY_DOWN="flyDown", |
|
| 10 | + SWING_LEFT="swingLeft", SWING_RIGHT="swingRight", SWING_UP="swingUp", SWING_DOWN="swingDown", |
|
| 11 | + BROWSE="browse", BROWSE_RIGHT="browseRight", |
|
| 12 | + SLIDE_LEFT="slideLeft", SLIDE_RIGHT="slideRight", SLIDE_UP="slideUp", SLIDE_DOWN="slideDown", |
|
| 13 | + JIGGLE="jiggle", FLASH="flash", SHAKE="shake", PULSE="pulse", TADA="tada", BOUNCE="bounce"; |
|
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |