@@ -12,19 +12,19 @@ discard block |
||
12 | 12 | * @property boolean $_visibleHover |
13 | 13 | * @property InstanceViewer $_instanceViewer |
14 | 14 | */ |
15 | -trait DataTableFieldAsTrait{ |
|
15 | +trait DataTableFieldAsTrait { |
|
16 | 16 | abstract public function addField($field); |
17 | - abstract public function insertField($index,$field); |
|
18 | - abstract public function insertInField($index,$field); |
|
19 | - abstract public function fieldAs($index,$type,$attributes=NULL); |
|
17 | + abstract public function insertField($index, $field); |
|
18 | + abstract public function insertInField($index, $field); |
|
19 | + abstract public function fieldAs($index, $type, $attributes=NULL); |
|
20 | 20 | /** |
21 | 21 | * @param string $caption |
22 | 22 | * @param callable $callback |
23 | 23 | * @param boolean $visibleHover |
24 | 24 | * @return callable |
25 | 25 | */ |
26 | - private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
|
27 | - return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
|
26 | + private function getFieldButtonCallable($caption, $visibleHover=true, $callback=null) { |
|
27 | + return $this->getCallable("getFieldButton", [$caption, $visibleHover], $callback); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | * @param callable $callback |
34 | 34 | * @return callable |
35 | 35 | */ |
36 | - private function getCallable($thisCallback,$parameters,$callback=null){ |
|
37 | - $result=function($instance) use($thisCallback,$parameters,$callback){ |
|
38 | - $object=call_user_func_array(array($this,$thisCallback), $parameters); |
|
39 | - if(isset($callback)){ |
|
40 | - if(\is_callable($callback)){ |
|
41 | - $callback($object,$instance); |
|
36 | + private function getCallable($thisCallback, $parameters, $callback=null) { |
|
37 | + $result=function($instance) use($thisCallback, $parameters, $callback){ |
|
38 | + $object=call_user_func_array(array($this, $thisCallback), $parameters); |
|
39 | + if (isset($callback)) { |
|
40 | + if (\is_callable($callback)) { |
|
41 | + $callback($object, $instance); |
|
42 | 42 | } |
43 | 43 | } |
44 | - if($object instanceof HtmlSemDoubleElement){ |
|
45 | - $object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
|
46 | - if($object->propertyContains("class","visibleover")){ |
|
44 | + if ($object instanceof HtmlSemDoubleElement) { |
|
45 | + $object->setProperty("data-ajax", $this->_instanceViewer->getIdentifier()); |
|
46 | + if ($object->propertyContains("class", "visibleover")) { |
|
47 | 47 | $this->_visibleHover=true; |
48 | - $object->setProperty("style","visibility:hidden;"); |
|
48 | + $object->setProperty("style", "visibility:hidden;"); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | return $object; |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * @param string $caption |
58 | 58 | * @return HtmlButton |
59 | 59 | */ |
60 | - private function getFieldButton($caption,$visibleHover=true){ |
|
61 | - $bt= new HtmlButton("",$caption); |
|
62 | - if($visibleHover) |
|
60 | + private function getFieldButton($caption, $visibleHover=true) { |
|
61 | + $bt=new HtmlButton("", $caption); |
|
62 | + if ($visibleHover) |
|
63 | 63 | $this->_visibleOver($bt); |
64 | 64 | return $bt; |
65 | 65 | } |
@@ -73,19 +73,19 @@ discard block |
||
73 | 73 | * @param array $attributes associative array (<b>ajax</b> key is for ajax post) |
74 | 74 | * @return \Ajax\semantic\widgets\datatable\DataTable |
75 | 75 | */ |
76 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
77 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index,$attributes){ |
|
78 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
79 | - $button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]); |
|
80 | - if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
76 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
77 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $index, $attributes){ |
|
78 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
79 | + $button->postOnClick($url, "$(event.target).closest('tr').find(':input').serialize()", $responseElement, $attributes["ajax"]); |
|
80 | + if (!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
81 | 81 | $this->_visibleOver($button); |
82 | 82 | return $button; |
83 | - }, $index,$attributes); |
|
83 | + }, $index, $attributes); |
|
84 | 84 | } |
85 | 85 | |
86 | - protected function _visibleOver($element){ |
|
86 | + protected function _visibleOver($element) { |
|
87 | 87 | $this->_visibleHover=true; |
88 | - return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
|
88 | + return $element->addToProperty("class", "visibleover")->setProperty("style", "visibility:hidden;"); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | * @param boolean $visibleHover |
96 | 96 | * @return \Ajax\semantic\widgets\datatable\DataTable |
97 | 97 | */ |
98 | - public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
|
99 | - $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
|
98 | + public function addFieldButton($caption, $visibleHover=true, $callback=null) { |
|
99 | + $this->addField($this->getCallable("getFieldButton", [$caption, $visibleHover], $callback)); |
|
100 | 100 | return $this; |
101 | 101 | } |
102 | 102 | |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | * @param callable $callback |
108 | 108 | * @return \Ajax\semantic\widgets\datatable\DataTable |
109 | 109 | */ |
110 | - public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
111 | - $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
110 | + public function insertFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
111 | + $this->insertField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
112 | 112 | return $this; |
113 | 113 | } |
114 | 114 | |
@@ -119,25 +119,25 @@ discard block |
||
119 | 119 | * @param callable $callback |
120 | 120 | * @return \Ajax\semantic\widgets\datatable\DataTable |
121 | 121 | */ |
122 | - public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
123 | - $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
122 | + public function insertInFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
123 | + $this->insertInField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
124 | 124 | return $this; |
125 | 125 | } |
126 | 126 | |
127 | - private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
|
128 | - $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
127 | + private function addDefaultButton($icon, $class=null, $visibleHover=true, $callback=null) { |
|
128 | + $this->addField($this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
129 | 129 | return $this; |
130 | 130 | } |
131 | 131 | |
132 | - private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
|
133 | - $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
132 | + private function insertDefaultButtonIn($index, $icon, $class=null, $visibleHover=true, $callback=null) { |
|
133 | + $this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
134 | 134 | return $this; |
135 | 135 | } |
136 | 136 | |
137 | - private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
|
138 | - $bt=$this->getFieldButton("",$visibleHover); |
|
137 | + private function getDefaultButton($icon, $class=null, $visibleHover=true) { |
|
138 | + $bt=$this->getFieldButton("", $visibleHover); |
|
139 | 139 | $bt->asIcon($icon); |
140 | - if(isset($class)) |
|
140 | + if (isset($class)) |
|
141 | 141 | $bt->addClass($class); |
142 | 142 | return $bt; |
143 | 143 | } |
@@ -148,30 +148,30 @@ discard block |
||
148 | 148 | * @param callable $callback |
149 | 149 | * @return DataTable |
150 | 150 | */ |
151 | - public function addDeleteButton($visibleHover=true,$deleteBehavior=[],$callback=null){ |
|
151 | + public function addDeleteButton($visibleHover=true, $deleteBehavior=[], $callback=null) { |
|
152 | 152 | $this->_deleteBehavior=$deleteBehavior; |
153 | - return $this->addDefaultButton("remove","_delete red basic",$visibleHover,$callback); |
|
153 | + return $this->addDefaultButton("remove", "_delete red basic", $visibleHover, $callback); |
|
154 | 154 | } |
155 | 155 | |
156 | - public function addEditButton($visibleHover=true,$editBehavior=[],$callback=null){ |
|
156 | + public function addEditButton($visibleHover=true, $editBehavior=[], $callback=null) { |
|
157 | 157 | $this->_editBehavior=$editBehavior; |
158 | - return $this->addDefaultButton("edit","_edit basic",$visibleHover,$callback); |
|
158 | + return $this->addDefaultButton("edit", "_edit basic", $visibleHover, $callback); |
|
159 | 159 | } |
160 | 160 | |
161 | - public function addEditDeleteButtons($visibleHover=true,$behavior=[],$callbackEdit=null,$callbackDelete=null){ |
|
162 | - $this->addEditButton($visibleHover,$behavior,$callbackEdit); |
|
161 | + public function addEditDeleteButtons($visibleHover=true, $behavior=[], $callbackEdit=null, $callbackDelete=null) { |
|
162 | + $this->addEditButton($visibleHover, $behavior, $callbackEdit); |
|
163 | 163 | $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
164 | - $this->insertDeleteButtonIn($index,$visibleHover,$behavior,$callbackDelete); |
|
164 | + $this->insertDeleteButtonIn($index, $visibleHover, $behavior, $callbackDelete); |
|
165 | 165 | return $this; |
166 | 166 | } |
167 | 167 | |
168 | - public function insertDeleteButtonIn($index,$visibleHover=true,$deleteBehavior=[],$callback=null){ |
|
168 | + public function insertDeleteButtonIn($index, $visibleHover=true, $deleteBehavior=[], $callback=null) { |
|
169 | 169 | $this->_deleteBehavior=$deleteBehavior; |
170 | - return $this->insertDefaultButtonIn($index,"remove","_delete red basic",$visibleHover,$callback); |
|
170 | + return $this->insertDefaultButtonIn($index, "remove", "_delete red basic", $visibleHover, $callback); |
|
171 | 171 | } |
172 | 172 | |
173 | - public function insertEditButtonIn($index,$visibleHover=true,$editBehavior=[],$callback=null){ |
|
173 | + public function insertEditButtonIn($index, $visibleHover=true, $editBehavior=[], $callback=null) { |
|
174 | 174 | $this->_editBehavior=$editBehavior; |
175 | - return $this->insertDefaultButtonIn($index,"edit","_edit basic",$visibleHover,$callback); |
|
175 | + return $this->insertDefaultButtonIn($index, "edit", "_edit basic", $visibleHover, $callback); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | \ No newline at end of file |
@@ -16,24 +16,24 @@ discard block |
||
16 | 16 | |
17 | 17 | public function __construct($identifier, $elements=array(), $asIcons=false) { |
18 | 18 | parent::__construct($identifier, "div", "ui buttons"); |
19 | - if ($asIcons === true) |
|
19 | + if ($asIcons===true) |
|
20 | 20 | $this->asIcons(); |
21 | 21 | $this->addElements($elements, $asIcons); |
22 | 22 | } |
23 | - protected function createItem($value){ |
|
23 | + protected function createItem($value) { |
|
24 | 24 | return new HtmlButton("", $value); |
25 | 25 | } |
26 | 26 | |
27 | 27 | |
28 | 28 | public function addElement($element, $asIcon=false) { |
29 | 29 | $item=$this->addItem($element); |
30 | - if($asIcon) |
|
30 | + if ($asIcon) |
|
31 | 31 | $item->asIcon($element); |
32 | 32 | return $item; |
33 | 33 | } |
34 | 34 | |
35 | 35 | public function addElements($elements, $asIcons=false) { |
36 | - foreach ( $elements as $element ) { |
|
36 | + foreach ($elements as $element) { |
|
37 | 37 | $this->addElement($element, $asIcons); |
38 | 38 | } |
39 | 39 | return $this; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function insertOr($aferIndex=0, $or="or") { |
43 | 43 | $orElement=new HtmlSemDoubleElement("", "div", "or"); |
44 | 44 | $orElement->setProperty("data-text", $or); |
45 | - array_splice($this->content, $aferIndex + 1, 0, array ($orElement )); |
|
45 | + array_splice($this->content, $aferIndex+1, 0, array($orElement)); |
|
46 | 46 | return $this; |
47 | 47 | } |
48 | 48 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | public function asIcons() { |
58 | - foreach ( $this->content as $item ) { |
|
59 | - if($item instanceof HtmlButton) |
|
58 | + foreach ($this->content as $item) { |
|
59 | + if ($item instanceof HtmlButton) |
|
60 | 60 | $item->asIcon($item->getContent()); |
61 | 61 | } |
62 | 62 | return $this->addToProperty("class", "icons"); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @see \Ajax\bootstrap\html\base\BaseHtml::on() |
90 | 90 | */ |
91 | 91 | public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
92 | - foreach ( $this->content as $element ) { |
|
92 | + foreach ($this->content as $element) { |
|
93 | 93 | $element->on($event, $jsCode, $stopPropagation, $preventDefault); |
94 | 94 | } |
95 | 95 | return $this; |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | |
102 | 102 | public function addClasses($classes=array()) { |
103 | 103 | $i=0; |
104 | - if(!\is_array($classes)){ |
|
105 | - $classes=array_fill (0,$this->count(),$classes); |
|
104 | + if (!\is_array($classes)) { |
|
105 | + $classes=array_fill(0, $this->count(), $classes); |
|
106 | 106 | } |
107 | - foreach ( $this->content as $button ) { |
|
107 | + foreach ($this->content as $button) { |
|
108 | 108 | $button->addToProperty("class", $classes[$i++]); |
109 | 109 | } |
110 | 110 | return $this; |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | $this->addElement($function($object)); |
119 | 119 | } |
120 | 120 | |
121 | - public function run(JsUtils $js){ |
|
122 | - $result= parent::run($js); |
|
121 | + public function run(JsUtils $js) { |
|
122 | + $result=parent::run($js); |
|
123 | 123 | return $result->setItemSelector(".ui.button"); |
124 | 124 | } |
125 | 125 | } |
126 | 126 | \ No newline at end of file |
@@ -10,17 +10,17 @@ discard block |
||
10 | 10 | * @author jc |
11 | 11 | * @property string identifier |
12 | 12 | */ |
13 | -trait HasCheckboxesTrait{ |
|
13 | +trait HasCheckboxesTrait { |
|
14 | 14 | protected $_hasCheckboxes; |
15 | 15 | protected $_hasCheckedMessage=false; |
16 | 16 | protected $_checkedMessage; |
17 | 17 | protected $_checkedClass; |
18 | 18 | |
19 | - abstract public function addInToolbar($element,$callback=NULL); |
|
19 | + abstract public function addInToolbar($element, $callback=NULL); |
|
20 | 20 | |
21 | - protected function _runCheckboxes(JsUtils $js){ |
|
21 | + protected function _runCheckboxes(JsUtils $js) { |
|
22 | 22 | $checkedMessageCall=""; |
23 | - if($this->_hasCheckedMessage){ |
|
23 | + if ($this->_hasCheckedMessage) { |
|
24 | 24 | $msg=$this->getCheckedMessage(); |
25 | 25 | $checkedMessageFunction="function updateChecked(){var msg='".$msg[0]."',count=\$('#{$this->identifier} [name=\"selection[]\"]:checked').length,all=\$('#{$this->identifier} [name=\"selection[]\"]').length; |
26 | 26 | if(count==1) msg='".$msg[1]."'; |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | \$('#checked-count-".$this->identifier."').contents().filter(function() {return this.nodeType == 3;}).each(function(){this.textContent = msg.replace('{count}',count);}); |
29 | 29 | \$('#toolbar-{$this->identifier} .visibleOnChecked').toggle(count>0);}\$('#toolbar-".$this->identifier." .visibleOnChecked').hide();"; |
30 | 30 | $checkedMessageCall="updateChecked();"; |
31 | - if(isset($this->_checkedClass)){ |
|
31 | + if (isset($this->_checkedClass)) { |
|
32 | 32 | $checkedMessageCall.="$(this).closest('tr').toggleClass('".$this->_checkedClass."',$(this).prop('checked'));"; |
33 | 33 | } |
34 | - $js->exec($checkedMessageFunction,true); |
|
34 | + $js->exec($checkedMessageFunction, true); |
|
35 | 35 | } |
36 | 36 | $js->execOn("change", "#".$this->identifier." [name='selection[]']", " |
37 | 37 | var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true; |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$checkedMessageCall); |
40 | 40 | } |
41 | 41 | |
42 | - protected function _generateMainCheckbox(&$captions){ |
|
43 | - $ck=new HtmlCheckbox("main-ck-".$this->identifier,""); |
|
42 | + protected function _generateMainCheckbox(&$captions) { |
|
43 | + $ck=new HtmlCheckbox("main-ck-".$this->identifier, ""); |
|
44 | 44 | $checkedMessageCall=""; |
45 | - if($this->_hasCheckedMessage) |
|
45 | + if ($this->_hasCheckedMessage) |
|
46 | 46 | $checkedMessageCall="updateChecked();"; |
47 | 47 | |
48 | 48 | $ck->setOnChecked($this->_setAllChecked("true").$checkedMessageCall); |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | \array_unshift($captions, $ck); |
51 | 51 | } |
52 | 52 | |
53 | - protected function _setAllChecked($checked){ |
|
53 | + protected function _setAllChecked($checked) { |
|
54 | 54 | $result="$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',".$checked.");"; |
55 | - if(isset($this->_checkedClass)){ |
|
55 | + if (isset($this->_checkedClass)) { |
|
56 | 56 | $result.="$('#".$this->identifier." tr').toggleClass('".$this->_checkedClass."',".$checked.");"; |
57 | 57 | } |
58 | 58 | return $result; |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | protected function getCheckedMessage() { |
71 | - $result= $this->_checkedMessage; |
|
72 | - if(!isset($result)){ |
|
73 | - $result=[0=>"none selected",1=>"one item selected","other"=>"{count} items selected"]; |
|
71 | + $result=$this->_checkedMessage; |
|
72 | + if (!isset($result)) { |
|
73 | + $result=[0=>"none selected", 1=>"one item selected", "other"=>"{count} items selected"]; |
|
74 | 74 | } |
75 | 75 | return $result; |
76 | 76 | } |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | * @param array $checkedMessage |
91 | 91 | * @param callable $callback |
92 | 92 | */ |
93 | - public function addCountCheckedInToolbar(array $checkedMessage=null,$callback=null){ |
|
94 | - if(isset($checkedMessage)) |
|
93 | + public function addCountCheckedInToolbar(array $checkedMessage=null, $callback=null) { |
|
94 | + if (isset($checkedMessage)) |
|
95 | 95 | $this->_checkedMessage=$checkedMessage; |
96 | 96 | $checkedMessage=$this->getCheckedMessage(); |
97 | 97 | $this->_hasCheckboxes=true; |
98 | 98 | $this->_hasCheckedMessage=true; |
99 | - $element=new HtmlLabel("checked-count-".$this->identifier,$checkedMessage[0]); |
|
100 | - $this->addInToolbar($element,$callback); |
|
99 | + $element=new HtmlLabel("checked-count-".$this->identifier, $checkedMessage[0]); |
|
100 | + $this->addInToolbar($element, $callback); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | public function setCheckedClass($_checkedClass) { |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | */ |
23 | 23 | class DataTable extends Widget { |
24 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait; |
|
24 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait; |
|
25 | 25 | protected $_searchField; |
26 | 26 | protected $_urls; |
27 | 27 | protected $_pagination; |
@@ -32,33 +32,33 @@ discard block |
||
32 | 32 | protected $_targetSelector; |
33 | 33 | |
34 | 34 | |
35 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
36 | - parent::__construct($identifier, $model,$modelInstance); |
|
37 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
35 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
36 | + parent::__construct($identifier, $model, $modelInstance); |
|
37 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
38 | 38 | $this->_urls=[]; |
39 | 39 | } |
40 | 40 | |
41 | - public function run(JsUtils $js){ |
|
42 | - if($this->_hasCheckboxes && isset($js)){ |
|
41 | + public function run(JsUtils $js) { |
|
42 | + if ($this->_hasCheckboxes && isset($js)) { |
|
43 | 43 | $this->_runCheckboxes($js); |
44 | 44 | } |
45 | - if($this->_visibleHover){ |
|
46 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
47 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
45 | + if ($this->_visibleHover) { |
|
46 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
47 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
48 | 48 | } |
49 | - if(\is_array($this->_deleteBehavior)) |
|
50 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
51 | - if(\is_array($this->_editBehavior)) |
|
52 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
49 | + if (\is_array($this->_deleteBehavior)) |
|
50 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
51 | + if (\is_array($this->_editBehavior)) |
|
52 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
53 | 53 | return parent::run($js); |
54 | 54 | } |
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
59 | - if(isset($this->_urls[$op])){ |
|
60 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
61 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params); |
|
58 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
59 | + if (isset($this->_urls[$op])) { |
|
60 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
61 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
@@ -71,62 +71,62 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | |
74 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
75 | - if(!$this->_generated){ |
|
74 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
75 | + if (!$this->_generated) { |
|
76 | 76 | $this->_instanceViewer->setInstance($this->_model); |
77 | 77 | $captions=$this->_instanceViewer->getCaptions(); |
78 | 78 | |
79 | 79 | $table=$this->content["table"]; |
80 | 80 | |
81 | - if($this->_hasCheckboxes){ |
|
81 | + if ($this->_hasCheckboxes) { |
|
82 | 82 | $this->_generateMainCheckbox($captions); |
83 | 83 | } |
84 | 84 | |
85 | 85 | $table->setRowCount(0, \sizeof($captions)); |
86 | 86 | $table->setHeaderValues($captions); |
87 | - if(isset($this->_compileParts)) |
|
87 | + if (isset($this->_compileParts)) |
|
88 | 88 | $table->setCompileParts($this->_compileParts); |
89 | 89 | |
90 | - if(isset($this->_searchField) && isset($js)){ |
|
91 | - if(isset($this->_urls["refresh"])) |
|
92 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
90 | + if (isset($this->_searchField) && isset($js)) { |
|
91 | + if (isset($this->_urls["refresh"])) |
|
92 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $this->_generateContent($table); |
96 | 96 | |
97 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
97 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
98 | 98 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
99 | 99 | } |
100 | 100 | |
101 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
101 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
102 | 102 | $this->_generatePagination($table); |
103 | 103 | } |
104 | - if(isset($this->_toolbar)){ |
|
104 | + if (isset($this->_toolbar)) { |
|
105 | 105 | $this->_setToolbarPosition($table, $captions); |
106 | 106 | } |
107 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
107 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
108 | 108 | $this->_compileForm(); |
109 | 109 | $this->_generated=true; |
110 | 110 | } |
111 | - return parent::compile($js,$view); |
|
111 | + return parent::compile($js, $view); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | |
115 | 115 | |
116 | - protected function _generateContent($table){ |
|
116 | + protected function _generateContent($table) { |
|
117 | 117 | $objects=$this->_modelInstance; |
118 | - if(isset($this->_pagination)){ |
|
118 | + if (isset($this->_pagination)) { |
|
119 | 119 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
120 | 120 | } |
121 | 121 | InstanceViewer::setIndex(0); |
122 | 122 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
123 | 123 | $this->_instanceViewer->setInstance($instance); |
124 | 124 | InstanceViewer::$index++; |
125 | - $values= $this->_instanceViewer->getValues(); |
|
126 | - if($this->_hasCheckboxes){ |
|
127 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
125 | + $values=$this->_instanceViewer->getValues(); |
|
126 | + if ($this->_hasCheckboxes) { |
|
127 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
128 | 128 | $field=$ck->getField(); |
129 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
129 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
130 | 130 | $field->setProperty("name", "selection[]"); |
131 | 131 | \array_unshift($values, $ck); |
132 | 132 | } |
@@ -137,37 +137,37 @@ discard block |
||
137 | 137 | }); |
138 | 138 | } |
139 | 139 | |
140 | - private function _generatePagination($table){ |
|
140 | + private function _generatePagination($table) { |
|
141 | 141 | $footer=$table->getFooter(); |
142 | 142 | $footer->mergeCol(); |
143 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
143 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
144 | 144 | $menu->floatRight(); |
145 | 145 | $menu->setActiveItem($this->_pagination->getPage()-1); |
146 | 146 | $footer->setValues($menu); |
147 | - if(isset($this->_urls["refresh"])) |
|
148 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
147 | + if (isset($this->_urls["refresh"])) |
|
148 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
149 | 149 | } |
150 | 150 | |
151 | - protected function _getFieldName($index){ |
|
151 | + protected function _getFieldName($index) { |
|
152 | 152 | return parent::_getFieldName($index)."[]"; |
153 | 153 | } |
154 | 154 | |
155 | - protected function _getFieldCaption($index){ |
|
155 | + protected function _getFieldCaption($index) { |
|
156 | 156 | return null; |
157 | 157 | } |
158 | 158 | |
159 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
160 | - switch ($this->_toolbarPosition){ |
|
159 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
160 | + switch ($this->_toolbarPosition) { |
|
161 | 161 | case PositionInTable::BEFORETABLE: |
162 | 162 | case PositionInTable::AFTERTABLE: |
163 | - if(isset($this->_compileParts)===false){ |
|
163 | + if (isset($this->_compileParts)===false) { |
|
164 | 164 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
165 | 165 | } |
166 | 166 | break; |
167 | 167 | case PositionInTable::HEADER: |
168 | 168 | case PositionInTable::FOOTER: |
169 | 169 | case PositionInTable::BODY: |
170 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
170 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
171 | 171 | break; |
172 | 172 | } |
173 | 173 | } |
@@ -179,23 +179,23 @@ discard block |
||
179 | 179 | * @param callable $callback function called after the field compilation |
180 | 180 | * @return \Ajax\semantic\widgets\datatable\DataTable |
181 | 181 | */ |
182 | - public function afterCompile($index,$callback){ |
|
183 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
182 | + public function afterCompile($index, $callback) { |
|
183 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
184 | 184 | return $this; |
185 | 185 | } |
186 | 186 | |
187 | - private function addToolbarRow($part,$table,$captions){ |
|
187 | + private function addToolbarRow($part, $table, $captions) { |
|
188 | 188 | $hasPart=$table->hasPart($part); |
189 | - if($hasPart){ |
|
189 | + if ($hasPart) { |
|
190 | 190 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
191 | - }else{ |
|
191 | + } else { |
|
192 | 192 | $row=$table->getPart($part)->getRow(0); |
193 | 193 | } |
194 | 194 | $row->mergeCol(); |
195 | 195 | $row->setValues([$this->_toolbar]); |
196 | 196 | } |
197 | 197 | |
198 | - public function getHtmlComponent(){ |
|
198 | + public function getHtmlComponent() { |
|
199 | 199 | return $this->content["table"]; |
200 | 200 | } |
201 | 201 | |
@@ -209,36 +209,36 @@ discard block |
||
209 | 209 | * @return \Ajax\semantic\widgets\datatable\DataTable |
210 | 210 | */ |
211 | 211 | public function setUrls($urls) { |
212 | - if(\is_array($urls)){ |
|
213 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
214 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
215 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
216 | - }else{ |
|
217 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
212 | + if (\is_array($urls)) { |
|
213 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
214 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
215 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
216 | + } else { |
|
217 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
218 | 218 | } |
219 | 219 | return $this; |
220 | 220 | } |
221 | 221 | |
222 | - public function paginate($items_per_page=10,$page=1){ |
|
223 | - $this->_pagination=new Pagination($items_per_page,4,$page); |
|
222 | + public function paginate($items_per_page=10, $page=1) { |
|
223 | + $this->_pagination=new Pagination($items_per_page, 4, $page); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
227 | 227 | |
228 | - public function refresh($compileParts=["tbody"]){ |
|
228 | + public function refresh($compileParts=["tbody"]) { |
|
229 | 229 | $this->_compileParts=$compileParts; |
230 | 230 | return $this; |
231 | 231 | } |
232 | 232 | |
233 | 233 | |
234 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
234 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
235 | 235 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
236 | 236 | } |
237 | 237 | |
238 | - public function getSearchField(){ |
|
239 | - if(isset($this->_searchField)===false){ |
|
240 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
241 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
238 | + public function getSearchField() { |
|
239 | + if (isset($this->_searchField)===false) { |
|
240 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
241 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
242 | 242 | } |
243 | 243 | return $this->_searchField; |
244 | 244 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | return $this; |
255 | 255 | } |
256 | 256 | |
257 | - public function asForm(){ |
|
257 | + public function asForm() { |
|
258 | 258 | return $this->getForm(); |
259 | 259 | } |
260 | 260 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | protected function getTargetSelector() { |
264 | 264 | $result=$this->_targetSelector; |
265 | - if(!isset($result)) |
|
265 | + if (!isset($result)) |
|
266 | 266 | $result="#".$this->identifier; |
267 | 267 | return $result; |
268 | 268 | } |
@@ -18,207 +18,207 @@ discard block |
||
18 | 18 | |
19 | 19 | public static $index=0; |
20 | 20 | |
21 | - public function __construct($identifier,$instance=NULL,$captions=NULL){ |
|
21 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
22 | 22 | $this->widgetIdentifier=$identifier; |
23 | 23 | $this->values=[]; |
24 | 24 | $this->afterCompile=[]; |
25 | - if(isset($instance)) |
|
25 | + if (isset($instance)) |
|
26 | 26 | $this->setInstance($instance); |
27 | 27 | $this->setCaptions($captions); |
28 | 28 | $this->captionCallback=NULL; |
29 | - $this->defaultValueFunction=function($name,$value){return $value;}; |
|
29 | + $this->defaultValueFunction=function($name, $value) {return $value; }; |
|
30 | 30 | } |
31 | 31 | |
32 | - public function moveFieldTo($from,$to){ |
|
33 | - if(JArray::moveElementTo($this->visibleProperties, $from, $to)){ |
|
32 | + public function moveFieldTo($from, $to) { |
|
33 | + if (JArray::moveElementTo($this->visibleProperties, $from, $to)) { |
|
34 | 34 | return JArray::moveElementTo($this->values, $from, $to); |
35 | 35 | } |
36 | 36 | return false; |
37 | 37 | } |
38 | 38 | |
39 | - public function swapFields($index1,$index2){ |
|
40 | - if(JArray::swapElements($this->visibleProperties, $index1, $index2)){ |
|
39 | + public function swapFields($index1, $index2) { |
|
40 | + if (JArray::swapElements($this->visibleProperties, $index1, $index2)) { |
|
41 | 41 | return JArray::swapElements($this->values, $index1, $index2); |
42 | 42 | } |
43 | 43 | return false; |
44 | 44 | } |
45 | 45 | |
46 | - public function removeField($index){ |
|
47 | - \array_splice($this->visibleProperties,$index,1); |
|
48 | - \array_splice($this->values,$index,1); |
|
49 | - \array_splice($this->captions,$index,1); |
|
46 | + public function removeField($index) { |
|
47 | + \array_splice($this->visibleProperties, $index, 1); |
|
48 | + \array_splice($this->values, $index, 1); |
|
49 | + \array_splice($this->captions, $index, 1); |
|
50 | 50 | return $this; |
51 | 51 | } |
52 | 52 | |
53 | - public function getValues(){ |
|
53 | + public function getValues() { |
|
54 | 54 | $values=[]; |
55 | 55 | $index=0; |
56 | 56 | $count=$this->count(); |
57 | - while($index<$count){ |
|
57 | + while ($index<$count) { |
|
58 | 58 | $values[]=$this->getValue($index++); |
59 | 59 | } |
60 | 60 | return $values; |
61 | 61 | } |
62 | 62 | |
63 | - public function getIdentifier($index=NULL){ |
|
64 | - if(!isset($index)) |
|
63 | + public function getIdentifier($index=NULL) { |
|
64 | + if (!isset($index)) |
|
65 | 65 | $index=self::$index; |
66 | 66 | $value=$index; |
67 | - if(isset($this->values["identifier"])) |
|
68 | - $value=$this->values["identifier"]($index,$this->instance); |
|
67 | + if (isset($this->values["identifier"])) |
|
68 | + $value=$this->values["identifier"]($index, $this->instance); |
|
69 | 69 | return $value; |
70 | 70 | } |
71 | 71 | |
72 | - public function getValue($index){ |
|
72 | + public function getValue($index) { |
|
73 | 73 | $property=$this->properties[$index]; |
74 | 74 | return $this->_getValue($property, $index); |
75 | 75 | } |
76 | 76 | |
77 | - protected function _beforeAddProperty($index,&$field){ |
|
77 | + protected function _beforeAddProperty($index, &$field) { |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
81 | - protected function _getDefaultValue($name,$value,$index){ |
|
81 | + protected function _getDefaultValue($name, $value, $index) { |
|
82 | 82 | $func=$this->defaultValueFunction; |
83 | - return $func($name,$value,$index,$this->instance); |
|
83 | + return $func($name, $value, $index, $this->instance); |
|
84 | 84 | } |
85 | 85 | |
86 | - protected function _getPropertyValue(\ReflectionProperty $property,$index){ |
|
86 | + protected function _getPropertyValue(\ReflectionProperty $property, $index) { |
|
87 | 87 | $property->setAccessible(true); |
88 | 88 | $value=$property->getValue($this->instance); |
89 | - if(isset($this->values[$index])){ |
|
90 | - $value= $this->values[$index]($value,$this->instance,$index); |
|
91 | - }else{ |
|
92 | - $value=$this->_getDefaultValue($property->getName(),$value, $index); |
|
89 | + if (isset($this->values[$index])) { |
|
90 | + $value=$this->values[$index]($value, $this->instance, $index); |
|
91 | + } else { |
|
92 | + $value=$this->_getDefaultValue($property->getName(), $value, $index); |
|
93 | 93 | } |
94 | 94 | return $value; |
95 | 95 | } |
96 | 96 | |
97 | - protected function _getValue($property,$index){ |
|
97 | + protected function _getValue($property, $index) { |
|
98 | 98 | $value=null; |
99 | - if($property instanceof \ReflectionProperty){ |
|
99 | + if ($property instanceof \ReflectionProperty) { |
|
100 | 100 | $value=$this->_getPropertyValue($property, $index); |
101 | - }else{ |
|
102 | - if(\is_callable($property)) |
|
101 | + } else { |
|
102 | + if (\is_callable($property)) |
|
103 | 103 | $value=$property($this->instance); |
104 | - elseif(\is_array($property)){ |
|
105 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
104 | + elseif (\is_array($property)) { |
|
105 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
106 | 106 | $value=\implode("", $values); |
107 | - }else{ |
|
108 | - if(isset($this->values[$index])){ |
|
109 | - $value= $this->values[$index]($property,$this->instance,$index); |
|
110 | - }elseif(isset($this->instance->{$property})){ |
|
107 | + } else { |
|
108 | + if (isset($this->values[$index])) { |
|
109 | + $value=$this->values[$index]($property, $this->instance, $index); |
|
110 | + }elseif (isset($this->instance->{$property})) { |
|
111 | 111 | $value=$this->instance->{$property}; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
115 | - if(isset($this->afterCompile[$index])){ |
|
116 | - if(\is_callable($this->afterCompile[$index])){ |
|
117 | - $this->afterCompile[$index]($value,$this->instance,$index); |
|
115 | + if (isset($this->afterCompile[$index])) { |
|
116 | + if (\is_callable($this->afterCompile[$index])) { |
|
117 | + $this->afterCompile[$index]($value, $this->instance, $index); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | return $value; |
121 | 121 | } |
122 | 122 | |
123 | - public function insertField($index,$field){ |
|
124 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
123 | + public function insertField($index, $field) { |
|
124 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
125 | 125 | return $this; |
126 | 126 | } |
127 | 127 | |
128 | - public function insertInField($index,$field){ |
|
128 | + public function insertInField($index, $field) { |
|
129 | 129 | $vb=$this->visibleProperties; |
130 | - if(isset($vb[$index])){ |
|
131 | - if(\is_array($vb[$index])){ |
|
130 | + if (isset($vb[$index])) { |
|
131 | + if (\is_array($vb[$index])) { |
|
132 | 132 | $this->visibleProperties[$index][]=$field; |
133 | - }else{ |
|
134 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
133 | + } else { |
|
134 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
135 | 135 | } |
136 | - }else{ |
|
136 | + } else { |
|
137 | 137 | return $this->insertField($index, $field); |
138 | 138 | } |
139 | 139 | return $this; |
140 | 140 | } |
141 | 141 | |
142 | - public function addField($field){ |
|
142 | + public function addField($field) { |
|
143 | 143 | $this->visibleProperties[]=$field; |
144 | 144 | return $this; |
145 | 145 | } |
146 | 146 | |
147 | - public function count(){ |
|
147 | + public function count() { |
|
148 | 148 | return \sizeof($this->properties); |
149 | 149 | } |
150 | 150 | |
151 | - public function visiblePropertiesCount(){ |
|
151 | + public function visiblePropertiesCount() { |
|
152 | 152 | return \sizeof($this->visibleProperties); |
153 | 153 | } |
154 | 154 | |
155 | - public function getProperty($index){ |
|
155 | + public function getProperty($index) { |
|
156 | 156 | return $this->properties[$index]; |
157 | 157 | } |
158 | 158 | |
159 | - public function getFieldName($index){ |
|
159 | + public function getFieldName($index) { |
|
160 | 160 | $property=$this->getProperty($index); |
161 | - if($property instanceof \ReflectionProperty){ |
|
161 | + if ($property instanceof \ReflectionProperty) { |
|
162 | 162 | $result=$property->getName(); |
163 | - }elseif(\is_callable($property)){ |
|
163 | + }elseif (\is_callable($property)) { |
|
164 | 164 | $result=$this->visibleProperties[$index]; |
165 | - }else{ |
|
165 | + } else { |
|
166 | 166 | $result=$property; |
167 | 167 | } |
168 | 168 | return $result; |
169 | 169 | } |
170 | 170 | |
171 | 171 | |
172 | - protected function showableProperty(\ReflectionProperty $rProperty){ |
|
173 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
172 | + protected function showableProperty(\ReflectionProperty $rProperty) { |
|
173 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | public function setInstance($instance) { |
177 | - if(\is_string($instance)){ |
|
177 | + if (\is_string($instance)) { |
|
178 | 178 | $instance=new $instance(); |
179 | 179 | } |
180 | 180 | $this->instance=$instance; |
181 | 181 | $this->properties=[]; |
182 | 182 | $this->reflect=new \ReflectionClass($instance); |
183 | - if(\sizeof($this->visibleProperties)===0){ |
|
183 | + if (\sizeof($this->visibleProperties)===0) { |
|
184 | 184 | $this->properties=$this->getDefaultProperties(); |
185 | - }else{ |
|
186 | - foreach ($this->visibleProperties as $property){ |
|
185 | + } else { |
|
186 | + foreach ($this->visibleProperties as $property) { |
|
187 | 187 | $this->setInstanceProperty($property); |
188 | 188 | } |
189 | 189 | } |
190 | 190 | return $this; |
191 | 191 | } |
192 | 192 | |
193 | - private function setInstanceProperty($property){ |
|
194 | - if(\is_callable($property)){ |
|
193 | + private function setInstanceProperty($property) { |
|
194 | + if (\is_callable($property)) { |
|
195 | 195 | $this->properties[]=$property; |
196 | - }elseif(\is_string($property)){ |
|
197 | - try{ |
|
196 | + }elseif (\is_string($property)) { |
|
197 | + try { |
|
198 | 198 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
199 | 199 | $rProperty=$this->reflect->getProperty($property); |
200 | 200 | $this->properties[]=$rProperty; |
201 | - }catch(\Exception $e){ |
|
201 | + }catch (\Exception $e) { |
|
202 | 202 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
203 | 203 | $this->properties[]=$property; |
204 | 204 | } |
205 | - }elseif(\is_int($property)){ |
|
205 | + }elseif (\is_int($property)) { |
|
206 | 206 | $props=$this->getDefaultProperties(); |
207 | - if(isset($props[$property])) |
|
207 | + if (isset($props[$property])) |
|
208 | 208 | $this->properties[]=$props[$property]; |
209 | 209 | else |
210 | 210 | $this->properties[]=$property; |
211 | - }else{ |
|
211 | + } else { |
|
212 | 212 | $this->properties[]=$property; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - protected function getDefaultProperties(){ |
|
216 | + protected function getDefaultProperties() { |
|
217 | 217 | $result=[]; |
218 | 218 | $properties=$this->reflect->getProperties(); |
219 | - foreach ($properties as $property){ |
|
219 | + foreach ($properties as $property) { |
|
220 | 220 | $showable=$this->showableProperty($property); |
221 | - if($showable!==false){ |
|
221 | + if ($showable!==false) { |
|
222 | 222 | $result[]=$property; |
223 | 223 | } |
224 | 224 | } |
@@ -230,12 +230,12 @@ discard block |
||
230 | 230 | return $this; |
231 | 231 | } |
232 | 232 | |
233 | - public function setValueFunction($index,$callback){ |
|
233 | + public function setValueFunction($index, $callback) { |
|
234 | 234 | $this->values[$index]=$callback; |
235 | 235 | return $this; |
236 | 236 | } |
237 | 237 | |
238 | - public function setIdentifierFunction($callback){ |
|
238 | + public function setIdentifierFunction($callback) { |
|
239 | 239 | $this->values["identifier"]=$callback; |
240 | 240 | return $this; |
241 | 241 | } |
@@ -248,41 +248,41 @@ discard block |
||
248 | 248 | return $this->properties; |
249 | 249 | } |
250 | 250 | |
251 | - public function getCaption($index){ |
|
252 | - if(isset($this->captions[$index])){ |
|
251 | + public function getCaption($index) { |
|
252 | + if (isset($this->captions[$index])) { |
|
253 | 253 | return $this->captions[$index]; |
254 | 254 | } |
255 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
255 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
256 | 256 | return $this->properties[$index]->getName(); |
257 | - elseif(\is_callable($this->properties[$index])) |
|
257 | + elseif (\is_callable($this->properties[$index])) |
|
258 | 258 | return ""; |
259 | 259 | else |
260 | 260 | return $this->properties[$index]; |
261 | 261 | } |
262 | 262 | |
263 | - public function getCaptions(){ |
|
264 | - if(isset($this->captions)){ |
|
265 | - $captions= \array_values($this->captions); |
|
266 | - for($i=\sizeof($captions);$i<$this->count();$i++){ |
|
263 | + public function getCaptions() { |
|
264 | + if (isset($this->captions)) { |
|
265 | + $captions=\array_values($this->captions); |
|
266 | + for ($i=\sizeof($captions); $i<$this->count(); $i++) { |
|
267 | 267 | $captions[]=""; |
268 | 268 | } |
269 | - }else{ |
|
269 | + } else { |
|
270 | 270 | $captions=[]; |
271 | 271 | $index=0; |
272 | 272 | $count=$this->count(); |
273 | - while($index<$count){ |
|
273 | + while ($index<$count) { |
|
274 | 274 | $captions[]=$this->getCaption($index++); |
275 | 275 | } |
276 | 276 | } |
277 | - if(isset($this->captionCallback) && \is_callable($this->captionCallback)){ |
|
277 | + if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
|
278 | 278 | $callback=$this->captionCallback; |
279 | - $callback($captions,$this->instance); |
|
279 | + $callback($captions, $this->instance); |
|
280 | 280 | } |
281 | 281 | return $captions; |
282 | 282 | } |
283 | 283 | |
284 | - public function setCaption($index,$caption){ |
|
285 | - if(isset($this->captions)===false) |
|
284 | + public function setCaption($index, $caption) { |
|
285 | + if (isset($this->captions)===false) |
|
286 | 286 | $this->captions=[]; |
287 | 287 | $this->captions[$index]=$caption; |
288 | 288 | return $this; |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * @param callable $callback function called after the field compilation |
301 | 301 | * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
302 | 302 | */ |
303 | - public function afterCompile($index,$callback){ |
|
303 | + public function afterCompile($index, $callback) { |
|
304 | 304 | $this->afterCompile[$index]=$callback; |
305 | 305 | return $this; |
306 | 306 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | parent::__construct($identifier, $instance, $captions); |
13 | 13 | } |
14 | 14 | |
15 | - public function getValue($index){ |
|
15 | + public function getValue($index) { |
|
16 | 16 | $result=parent::getValue($index); |
17 | - if($result instanceof HtmlFormField){ |
|
18 | - $lbl=new HtmlSemDoubleElement("lbl-".$this->widgetIdentifier."-".$index,"label","",$this->getCaption($index)); |
|
17 | + if ($result instanceof HtmlFormField) { |
|
18 | + $lbl=new HtmlSemDoubleElement("lbl-".$this->widgetIdentifier."-".$index, "label", "", $this->getCaption($index)); |
|
19 | 19 | $lbl->setProperty("for", $result->getDataField()->getIdentifier()); |
20 | 20 | $this->captions[$index]=$lbl; |
21 | 21 | } |
@@ -18,49 +18,49 @@ discard block |
||
18 | 18 | class DataElement extends Widget { |
19 | 19 | |
20 | 20 | public function __construct($identifier, $modelInstance=NULL) { |
21 | - parent::__construct($identifier, null,$modelInstance); |
|
22 | - $this->_init(new DeInstanceViewer($identifier), "table", new HtmlTable($identifier, 0,2), false); |
|
21 | + parent::__construct($identifier, null, $modelInstance); |
|
22 | + $this->_init(new DeInstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 2), false); |
|
23 | 23 | $this->content["table"]->setDefinition(); |
24 | 24 | } |
25 | 25 | |
26 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
27 | - if(!$this->_generated){ |
|
26 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
27 | + if (!$this->_generated) { |
|
28 | 28 | $this->_instanceViewer->setInstance($this->_modelInstance); |
29 | 29 | |
30 | 30 | $table=$this->content["table"]; |
31 | 31 | $this->_generateContent($table); |
32 | 32 | |
33 | - if(isset($this->_toolbar)){ |
|
33 | + if (isset($this->_toolbar)) { |
|
34 | 34 | $this->_setToolbarPosition($table); |
35 | 35 | } |
36 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
36 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
37 | 37 | $this->_compileForm(); |
38 | 38 | $this->_generated=true; |
39 | 39 | } |
40 | - return parent::compile($js,$view); |
|
40 | + return parent::compile($js, $view); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @param HtmlTable $table |
45 | 45 | */ |
46 | - protected function _generateContent($table){ |
|
47 | - $values= $this->_instanceViewer->getValues(); |
|
46 | + protected function _generateContent($table) { |
|
47 | + $values=$this->_instanceViewer->getValues(); |
|
48 | 48 | $captions=$this->_instanceViewer->getCaptions(); |
49 | 49 | $count=$this->_instanceViewer->count(); |
50 | - for($i=0;$i<$count;$i++){ |
|
51 | - $table->addRow([$captions[$i],$values[$i]]); |
|
50 | + for ($i=0; $i<$count; $i++) { |
|
51 | + $table->addRow([$captions[$i], $values[$i]]); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - protected function _getFieldName($index){ |
|
55 | + protected function _getFieldName($index) { |
|
56 | 56 | return $this->_instanceViewer->getFieldName($index); |
57 | 57 | } |
58 | 58 | |
59 | - protected function _getFieldCaption($index){ |
|
59 | + protected function _getFieldCaption($index) { |
|
60 | 60 | return null; |
61 | 61 | } |
62 | 62 | |
63 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
63 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
64 | 64 | return $this->identifier."-{$prefix}-".$name; |
65 | 65 | } |
66 | 66 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | return $this; |
93 | 93 | } |
94 | 94 | |
95 | - public function asForm(){ |
|
95 | + public function asForm() { |
|
96 | 96 | return $this->getForm(); |
97 | 97 | } |
98 | 98 | } |
99 | 99 | \ No newline at end of file |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | class JArray { |
6 | 6 | |
7 | 7 | public static function isAssociative($array) { |
8 | - return (array_values($array) !== $array); |
|
8 | + return (array_values($array)!==$array); |
|
9 | 9 | // return (array_keys($array)!==range(0, count($array)-1)); |
10 | 10 | } |
11 | 11 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | return $array[$key]; |
15 | 15 | } |
16 | 16 | $values=array_values($array); |
17 | - if ($pos < sizeof($values)) |
|
17 | + if ($pos<sizeof($values)) |
|
18 | 18 | return $values[$pos]; |
19 | 19 | } |
20 | 20 | |
@@ -22,12 +22,12 @@ discard block |
||
22 | 22 | $result=NULL; |
23 | 23 | if (array_key_exists($key, $array)) { |
24 | 24 | $result=$array[$key]; |
25 | - if ($condition($result) === true) |
|
25 | + if ($condition($result)===true) |
|
26 | 26 | return $result; |
27 | 27 | } |
28 | 28 | $values=array_values($array); |
29 | - foreach ( $values as $val ) { |
|
30 | - if ($condition($val) === true) |
|
29 | + foreach ($values as $val) { |
|
30 | + if ($condition($val)===true) |
|
31 | 31 | return $val; |
32 | 32 | } |
33 | 33 | return $result; |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | $result=""; |
45 | 45 | if (\is_array($glue)) { |
46 | 46 | $size=\sizeof($pieces); |
47 | - if ($size > 0) { |
|
48 | - for($i=0; $i < $size - 1; $i++) { |
|
49 | - $result.=$pieces[$i] . @$glue[$i]; |
|
47 | + if ($size>0) { |
|
48 | + for ($i=0; $i<$size-1; $i++) { |
|
49 | + $result.=$pieces[$i].@$glue[$i]; |
|
50 | 50 | } |
51 | - $result.=$pieces[$size - 1]; |
|
51 | + $result.=$pieces[$size-1]; |
|
52 | 52 | } |
53 | 53 | } else { |
54 | 54 | $result=\implode($glue, $pieces); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | public static function dimension($array) { |
60 | 60 | if (\is_array(reset($array))) { |
61 | - $return=self::dimension(reset($array)) + 1; |
|
61 | + $return=self::dimension(reset($array))+1; |
|
62 | 62 | } else { |
63 | 63 | $return=1; |
64 | 64 | } |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | public static function sortAssociative($array, $sortedKeys=array()) { |
69 | - $newArray=array (); |
|
70 | - foreach ( $sortedKeys as $key ) { |
|
69 | + $newArray=array(); |
|
70 | + foreach ($sortedKeys as $key) { |
|
71 | 71 | if (\array_key_exists($key, $array)) { |
72 | 72 | $newArray[$key]=$array[$key]; |
73 | 73 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | |
78 | 78 | public static function moveElementTo(&$array, $from, $to) { |
79 | 79 | $result=false; |
80 | - if(isset($array)){ |
|
81 | - if(isset($array[$from])){ |
|
82 | - $out = array_splice($array, $from, 1); |
|
80 | + if (isset($array)) { |
|
81 | + if (isset($array[$from])) { |
|
82 | + $out=array_splice($array, $from, 1); |
|
83 | 83 | array_splice($array, $to, 0, $out); |
84 | 84 | $result=true; |
85 | 85 | } |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | return $result; |
88 | 88 | } |
89 | 89 | |
90 | - public static function swapElements(&$array,$index1,$index2){ |
|
90 | + public static function swapElements(&$array, $index1, $index2) { |
|
91 | 91 | $result=false; |
92 | - if(isset($array)){ |
|
93 | - if(isset($array[$index1])&& isset($array[$index2])){ |
|
92 | + if (isset($array)) { |
|
93 | + if (isset($array[$index1]) && isset($array[$index2])) { |
|
94 | 94 | $tmp=$array[$index1]; |
95 | 95 | $array[$index1]=$array[$index2]; |
96 | 96 | $array[$index2]=$tmp; |
@@ -101,27 +101,27 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | |
104 | - public static function modelArray($objects,$identifierFunction=NULL,$modelFunction=NULL){ |
|
104 | + public static function modelArray($objects, $identifierFunction=NULL, $modelFunction=NULL) { |
|
105 | 105 | $result=[]; |
106 | - if(isset($modelFunction)===false){ |
|
106 | + if (isset($modelFunction)===false) { |
|
107 | 107 | $modelFunction="__toString"; |
108 | 108 | } |
109 | - if(isset($identifierFunction)===false){ |
|
110 | - foreach ($objects as $object){ |
|
109 | + if (isset($identifierFunction)===false) { |
|
110 | + foreach ($objects as $object) { |
|
111 | 111 | $result[]=self::callFunction($object, $modelFunction); |
112 | 112 | } |
113 | - }else{ |
|
114 | - foreach ($objects as $object){ |
|
113 | + } else { |
|
114 | + foreach ($objects as $object) { |
|
115 | 115 | $result[self::callFunction($object, $identifierFunction)]=self::callFunction($object, $modelFunction); |
116 | 116 | } |
117 | 117 | } |
118 | 118 | return $result; |
119 | 119 | } |
120 | 120 | |
121 | - private static function callFunction($object,$callback){ |
|
122 | - if(\is_string($callback)) |
|
123 | - return \call_user_func(array($object, $callback),[]); |
|
124 | - else if (\is_callable($callback)){ |
|
121 | + private static function callFunction($object, $callback) { |
|
122 | + if (\is_string($callback)) |
|
123 | + return \call_user_func(array($object, $callback), []); |
|
124 | + else if (\is_callable($callback)) { |
|
125 | 125 | return $callback($object); |
126 | 126 | } |
127 | 127 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | use Ajax\semantic\html\modules\HtmlModal; |
21 | 21 | |
22 | 22 | abstract class Widget extends HtmlDoubleElement { |
23 | - use FieldAsTrait,FormTrait; |
|
23 | + use FieldAsTrait, FormTrait; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @var string classname |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | protected $_generated; |
54 | 54 | |
55 | 55 | |
56 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
56 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
57 | 57 | parent::__construct($identifier); |
58 | 58 | $this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
59 | 59 | $this->setModel($model); |
60 | - if(isset($modelInstance)){ |
|
61 | - if(\is_array($modelInstance)){ |
|
60 | + if (isset($modelInstance)) { |
|
61 | + if (\is_array($modelInstance)) { |
|
62 | 62 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
63 | 63 | } |
64 | 64 | $this->show($modelInstance); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->_generated=false; |
67 | 67 | } |
68 | 68 | |
69 | - protected function _init($instanceViewer,$contentKey,$content,$edition){ |
|
69 | + protected function _init($instanceViewer, $contentKey, $content, $edition) { |
|
70 | 70 | $this->_instanceViewer=$instanceViewer; |
71 | 71 | $this->content=[$contentKey=>$content]; |
72 | 72 | $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
@@ -77,25 +77,25 @@ discard block |
||
77 | 77 | * @param int|string $fieldName |
78 | 78 | * @return int|string |
79 | 79 | */ |
80 | - protected function _getIndex($fieldName){ |
|
80 | + protected function _getIndex($fieldName) { |
|
81 | 81 | return $fieldName; |
82 | 82 | } |
83 | 83 | |
84 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
84 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
85 | 85 | return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
86 | 86 | } |
87 | 87 | |
88 | - protected function _getFieldName($index){ |
|
88 | + protected function _getFieldName($index) { |
|
89 | 89 | return $this->_instanceViewer->getFieldName($index); |
90 | 90 | } |
91 | 91 | |
92 | - protected function _getFieldCaption($index){ |
|
92 | + protected function _getFieldCaption($index) { |
|
93 | 93 | return $this->_instanceViewer->getCaption($index); |
94 | 94 | } |
95 | 95 | |
96 | - abstract protected function _setToolbarPosition($table,$captions=NULL); |
|
96 | + abstract protected function _setToolbarPosition($table, $captions=NULL); |
|
97 | 97 | |
98 | - public function show($modelInstance){ |
|
98 | + public function show($modelInstance) { |
|
99 | 99 | $this->_modelInstance=$modelInstance; |
100 | 100 | } |
101 | 101 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | abstract public function getHtmlComponent(); |
121 | 121 | |
122 | - public function setAttached($value=true){ |
|
122 | + public function setAttached($value=true) { |
|
123 | 123 | return $this->getHtmlComponent()->setAttached($value); |
124 | 124 | } |
125 | 125 | |
@@ -130,66 +130,66 @@ discard block |
||
130 | 130 | * @param callable $callback function called after the field compilation |
131 | 131 | * @return Widget |
132 | 132 | */ |
133 | - public function afterCompile($index,$callback){ |
|
133 | + public function afterCompile($index, $callback) { |
|
134 | 134 | $index=$this->_getIndex($index); |
135 | 135 | $this->_instanceViewer->afterCompile($index, $callback); |
136 | 136 | return $this; |
137 | 137 | } |
138 | 138 | |
139 | - public function setColor($color){ |
|
139 | + public function setColor($color) { |
|
140 | 140 | return $this->getHtmlComponent()->setColor($color); |
141 | 141 | } |
142 | 142 | |
143 | 143 | |
144 | - public function setCaptions($captions){ |
|
144 | + public function setCaptions($captions) { |
|
145 | 145 | $this->_instanceViewer->setCaptions($captions); |
146 | 146 | return $this; |
147 | 147 | } |
148 | 148 | |
149 | - public function setCaption($index,$caption){ |
|
149 | + public function setCaption($index, $caption) { |
|
150 | 150 | $this->_instanceViewer->setCaption($this->_getIndex($index), $caption); |
151 | 151 | return $this; |
152 | 152 | } |
153 | 153 | |
154 | - public function setFields($fields){ |
|
154 | + public function setFields($fields) { |
|
155 | 155 | $this->_instanceViewer->setVisibleProperties($fields); |
156 | 156 | return $this; |
157 | 157 | } |
158 | 158 | |
159 | - public function addField($field){ |
|
159 | + public function addField($field) { |
|
160 | 160 | $this->_instanceViewer->addField($field); |
161 | 161 | return $this; |
162 | 162 | } |
163 | 163 | |
164 | - public function addMessage($attributes=NULL,$fieldName="message"){ |
|
164 | + public function addMessage($attributes=NULL, $fieldName="message") { |
|
165 | 165 | $this->_instanceViewer->addField($fieldName); |
166 | 166 | $count=$this->_instanceViewer->visiblePropertiesCount(); |
167 | - return $this->fieldAsMessage($count-1,$attributes); |
|
167 | + return $this->fieldAsMessage($count-1, $attributes); |
|
168 | 168 | } |
169 | 169 | |
170 | - public function addErrorMessage(){ |
|
171 | - return $this->addMessage(["error"=>true],"message"); |
|
170 | + public function addErrorMessage() { |
|
171 | + return $this->addMessage(["error"=>true], "message"); |
|
172 | 172 | } |
173 | 173 | |
174 | - public function insertField($index,$field){ |
|
174 | + public function insertField($index, $field) { |
|
175 | 175 | $index=$this->_getIndex($index); |
176 | 176 | $this->_instanceViewer->insertField($index, $field); |
177 | 177 | return $this; |
178 | 178 | } |
179 | 179 | |
180 | - public function insertInField($index,$field){ |
|
180 | + public function insertInField($index, $field) { |
|
181 | 181 | $index=$this->_getIndex($index); |
182 | 182 | $this->_instanceViewer->insertInField($index, $field); |
183 | 183 | return $this; |
184 | 184 | } |
185 | 185 | |
186 | - public function setValueFunction($index,$callback){ |
|
186 | + public function setValueFunction($index, $callback) { |
|
187 | 187 | $index=$this->_getIndex($index); |
188 | 188 | $this->_instanceViewer->setValueFunction($index, $callback); |
189 | 189 | return $this; |
190 | 190 | } |
191 | 191 | |
192 | - public function setIdentifierFunction($callback){ |
|
192 | + public function setIdentifierFunction($callback) { |
|
193 | 193 | $this->_instanceViewer->setIdentifierFunction($callback); |
194 | 194 | return $this; |
195 | 195 | } |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | /** |
198 | 198 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
199 | 199 | */ |
200 | - public function getToolbar(){ |
|
201 | - if(isset($this->_toolbar)===false){ |
|
200 | + public function getToolbar() { |
|
201 | + if (isset($this->_toolbar)===false) { |
|
202 | 202 | $this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
203 | 203 | } |
204 | 204 | return $this->_toolbar; |
@@ -210,15 +210,15 @@ discard block |
||
210 | 210 | * @param callable $callback function to call on $element |
211 | 211 | * @return \Ajax\common\html\HtmlDoubleElement |
212 | 212 | */ |
213 | - public function addInToolbar($element,$callback=NULL){ |
|
213 | + public function addInToolbar($element, $callback=NULL) { |
|
214 | 214 | $tb=$this->getToolbar(); |
215 | - if($element instanceof BaseWidget){ |
|
216 | - if($element->getIdentifier()===""){ |
|
215 | + if ($element instanceof BaseWidget) { |
|
216 | + if ($element->getIdentifier()==="") { |
|
217 | 217 | $element->setIdentifier("tb-item-".$this->identifier."-".$tb->count()); |
218 | 218 | } |
219 | 219 | } |
220 | - if(isset($callback)){ |
|
221 | - if(\is_callable($callback)){ |
|
220 | + if (isset($callback)) { |
|
221 | + if (\is_callable($callback)) { |
|
222 | 222 | $callback($element); |
223 | 223 | } |
224 | 224 | } |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | * @param callable $callback function($element) |
232 | 232 | * @return \Ajax\common\html\HtmlDoubleElement |
233 | 233 | */ |
234 | - public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){ |
|
235 | - $result=$this->addInToolbar($caption,$callback); |
|
236 | - if(isset($icon)) |
|
234 | + public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) { |
|
235 | + $result=$this->addInToolbar($caption, $callback); |
|
236 | + if (isset($icon)) |
|
237 | 237 | $result->addIcon($icon); |
238 | 238 | return $result; |
239 | 239 | } |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | * @param callable $callback function($element) |
244 | 244 | * @return \Ajax\common\Widget |
245 | 245 | */ |
246 | - public function addItemsInToolbar(array $items,$callback=NULL){ |
|
247 | - if(JArray::isAssociative($items)){ |
|
248 | - foreach ($items as $icon=>$item){ |
|
249 | - $this->addItemInToolbar($item,$icon,$callback); |
|
246 | + public function addItemsInToolbar(array $items, $callback=NULL) { |
|
247 | + if (JArray::isAssociative($items)) { |
|
248 | + foreach ($items as $icon=>$item) { |
|
249 | + $this->addItemInToolbar($item, $icon, $callback); |
|
250 | 250 | } |
251 | - }else{ |
|
252 | - foreach ($items as $item){ |
|
253 | - $this->addItemInToolbar($item,null,$callback); |
|
251 | + } else { |
|
252 | + foreach ($items as $item) { |
|
253 | + $this->addItemInToolbar($item, null, $callback); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | return $this; |
@@ -262,12 +262,12 @@ discard block |
||
262 | 262 | * @param callable $callback function($element) |
263 | 263 | * @return \Ajax\common\html\HtmlDoubleElement |
264 | 264 | */ |
265 | - public function addDropdownInToolbar($value,$items,$callback=NULL){ |
|
265 | + public function addDropdownInToolbar($value, $items, $callback=NULL) { |
|
266 | 266 | $dd=$value; |
267 | 267 | if (\is_string($value)) { |
268 | - $dd=new HtmlDropdown("dropdown-". $this->identifier."-".$value, $value, $items); |
|
268 | + $dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items); |
|
269 | 269 | } |
270 | - return $this->addInToolbar($dd,$callback); |
|
270 | + return $this->addInToolbar($dd, $callback); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | * @param callable $callback function($element) |
277 | 277 | * @return \Ajax\common\html\HtmlDoubleElement |
278 | 278 | */ |
279 | - public function addButtonInToolbar($caption,$cssStyle=null,$callback=NULL){ |
|
280 | - $bt=new HtmlButton("bt-".$caption,$caption,$cssStyle); |
|
281 | - return $this->addInToolbar($bt,$callback); |
|
279 | + public function addButtonInToolbar($caption, $cssStyle=null, $callback=NULL) { |
|
280 | + $bt=new HtmlButton("bt-".$caption, $caption, $cssStyle); |
|
281 | + return $this->addInToolbar($bt, $callback); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | * @param callable $callback function($element) |
288 | 288 | * @return \Ajax\common\html\HtmlDoubleElement |
289 | 289 | */ |
290 | - public function addButtonsInToolbar(array $captions,$asIcon=false,$callback=NULL){ |
|
291 | - $bts=new HtmlButtonGroups("",$captions,$asIcon); |
|
292 | - return $this->addInToolbar($bts,$callback); |
|
290 | + public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) { |
|
291 | + $bts=new HtmlButtonGroups("", $captions, $asIcon); |
|
292 | + return $this->addInToolbar($bts, $callback); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -299,15 +299,15 @@ discard block |
||
299 | 299 | * @param boolean $labeled |
300 | 300 | * @return \Ajax\common\html\HtmlDoubleElement |
301 | 301 | */ |
302 | - public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
|
303 | - $bt=new HtmlButton("",$caption); |
|
304 | - $bt->addIcon($icon,$before,$labeled); |
|
302 | + public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) { |
|
303 | + $bt=new HtmlButton("", $caption); |
|
304 | + $bt->addIcon($icon, $before, $labeled); |
|
305 | 305 | return $this->addInToolbar($bt); |
306 | 306 | } |
307 | 307 | |
308 | - public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){ |
|
309 | - $button=new HtmlButton($identifier,$value,$cssStyle); |
|
310 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,$parameters); |
|
308 | + public function addSubmitInToolbar($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
309 | + $button=new HtmlButton($identifier, $value, $cssStyle); |
|
310 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, $parameters); |
|
311 | 311 | return $this->addInToolbar($button); |
312 | 312 | } |
313 | 313 | |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | * @param callable $defaultValueFunction function parameters are : $name : the field name, $value : the field value ,$index : the field index, $instance : the active instance of model |
338 | 338 | * @return \Ajax\common\Widget |
339 | 339 | */ |
340 | - public function setDefaultValueFunction($defaultValueFunction){ |
|
340 | + public function setDefaultValueFunction($defaultValueFunction) { |
|
341 | 341 | $this->_instanceViewer->setDefaultValueFunction($defaultValueFunction); |
342 | 342 | return $this; |
343 | 343 | } |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @param string|boolean $disable |
347 | 347 | * @return string |
348 | 348 | */ |
349 | - public function jsDisabled($disable=true){ |
|
349 | + public function jsDisabled($disable=true) { |
|
350 | 350 | return "$('#".$this->identifier." .ui.input,#".$this->identifier." .ui.dropdown,#".$this->identifier." .ui.checkbox').toggleClass('disabled',".$disable.");"; |
351 | 351 | } |
352 | 352 | |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | * @param callable $callback function($element) |
356 | 356 | * @return \Ajax\common\html\HtmlDoubleElement |
357 | 357 | */ |
358 | - public function addEditButtonInToolbar($caption,$callback=NULL){ |
|
359 | - $bt=new HtmlButton($this->identifier."-editBtn",$caption); |
|
358 | + public function addEditButtonInToolbar($caption, $callback=NULL) { |
|
359 | + $bt=new HtmlButton($this->identifier."-editBtn", $caption); |
|
360 | 360 | $bt->setToggle(); |
361 | 361 | $bt->setActive($this->_edition); |
362 | 362 | $bt->onClick($this->jsDisabled(Javascript::prep_value("!$(event.target).hasClass('active')"))); |
363 | - return $this->addInToolbar($bt,$callback); |
|
363 | + return $this->addInToolbar($bt, $callback); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | public function setToolbar(HtmlMenu $_toolbar) { |
@@ -374,35 +374,35 @@ discard block |
||
374 | 374 | } |
375 | 375 | |
376 | 376 | public function getForm() { |
377 | - if(!isset($this->_form)){ |
|
377 | + if (!isset($this->_form)) { |
|
378 | 378 | $this->_form=new HtmlForm("frm-".$this->identifier); |
379 | 379 | $this->setEdition(true); |
380 | 380 | } |
381 | 381 | return $this->_form; |
382 | 382 | } |
383 | 383 | |
384 | - public function run(JsUtils $js){ |
|
384 | + public function run(JsUtils $js) { |
|
385 | 385 | $result=parent::run($js); |
386 | - if(isset($this->_form)){ |
|
386 | + if (isset($this->_form)) { |
|
387 | 387 | $result=$this->runForm($js); |
388 | 388 | } |
389 | 389 | return $result; |
390 | 390 | } |
391 | 391 | |
392 | - protected function runForm(JsUtils $js){ |
|
392 | + protected function runForm(JsUtils $js) { |
|
393 | 393 | $fields=$this->getContentInstances(HtmlFormField::class); |
394 | - foreach ($fields as $field){ |
|
394 | + foreach ($fields as $field) { |
|
395 | 395 | $this->_form->addField($field); |
396 | 396 | } |
397 | 397 | return $this->_form->run($js); |
398 | 398 | } |
399 | 399 | |
400 | - protected function _compileForm(){ |
|
401 | - if(isset($this->_form)){ |
|
400 | + protected function _compileForm() { |
|
401 | + if (isset($this->_form)) { |
|
402 | 402 | $noValidate=""; |
403 | - if(\sizeof($this->_form->getValidationParams())>0) |
|
403 | + if (\sizeof($this->_form->getValidationParams())>0) |
|
404 | 404 | $noValidate="novalidate"; |
405 | - $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">","</form>"); |
|
405 | + $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">", "</form>"); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
@@ -411,26 +411,26 @@ discard block |
||
411 | 411 | return $this; |
412 | 412 | } |
413 | 413 | |
414 | - public function moveFieldTo($from,$to){ |
|
414 | + public function moveFieldTo($from, $to) { |
|
415 | 415 | return $this->_instanceViewer->moveFieldTo($from, $to); |
416 | 416 | } |
417 | 417 | |
418 | - public function swapFields($index1,$index2){ |
|
418 | + public function swapFields($index1, $index2) { |
|
419 | 419 | $index1=$this->_getIndex($index1); |
420 | 420 | $index2=$this->_getIndex($index2); |
421 | 421 | return $this->_instanceViewer->swapFields($index1, $index2); |
422 | 422 | } |
423 | 423 | |
424 | - public function removeField($index){ |
|
424 | + public function removeField($index) { |
|
425 | 425 | $index=$this->_getIndex($index); |
426 | 426 | $this->_instanceViewer->removeField($index); |
427 | 427 | return $this; |
428 | 428 | } |
429 | 429 | |
430 | - public function asModal($header){ |
|
431 | - $modal=new HtmlModal("modal-".$this->identifier,$header); |
|
430 | + public function asModal($header) { |
|
431 | + $modal=new HtmlModal("modal-".$this->identifier, $header); |
|
432 | 432 | $modal->setContent($this); |
433 | - if(isset($this->_form)){ |
|
433 | + if (isset($this->_form)) { |
|
434 | 434 | $this->_form->onSuccess($modal->jsHide()); |
435 | 435 | } |
436 | 436 | return $modal; |