@@ -13,53 +13,53 @@ discard block |
||
| 13 | 13 | use Ajax\semantic\html\collections\form\traits\FieldTrait; |
| 14 | 14 | |
| 15 | 15 | class HtmlDropdown extends HtmlSemDoubleElement { |
| 16 | - use FieldTrait,LabeledIconTrait { |
|
| 16 | + use FieldTrait, LabeledIconTrait { |
|
| 17 | 17 | addIcon as addIconP; |
| 18 | 18 | } |
| 19 | 19 | protected $mClass="menu"; |
| 20 | 20 | protected $mTagName="div"; |
| 21 | - protected $items=array (); |
|
| 22 | - protected $_params=array("action"=>"nothing","on"=>"hover"); |
|
| 21 | + protected $items=array(); |
|
| 22 | + protected $_params=array("action"=>"nothing", "on"=>"hover"); |
|
| 23 | 23 | protected $input; |
| 24 | 24 | protected $value; |
| 25 | 25 | protected $_associative; |
| 26 | 26 | |
| 27 | - public function __construct($identifier, $value="", $items=array(),$associative=true) { |
|
| 27 | + public function __construct($identifier, $value="", $items=array(), $associative=true) { |
|
| 28 | 28 | parent::__construct($identifier, "div"); |
| 29 | 29 | $this->_template=include dirname(__FILE__).'/../templates/tplDropdown.php'; |
| 30 | 30 | $this->setProperty("class", "ui dropdown"); |
| 31 | - $content=new HtmlSemDoubleElement("text-".$this->identifier,"div"); |
|
| 31 | + $content=new HtmlSemDoubleElement("text-".$this->identifier, "div"); |
|
| 32 | 32 | $content->setClass("text"); |
| 33 | 33 | $this->setValue($value); |
| 34 | - $content->wrap("",new HtmlIcon("", "dropdown")); |
|
| 34 | + $content->wrap("", new HtmlIcon("", "dropdown")); |
|
| 35 | 35 | $this->content=array($content); |
| 36 | 36 | $this->tagName="div"; |
| 37 | 37 | $this->_associative=$associative; |
| 38 | 38 | $this->addItems($items); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function getField(){ |
|
| 41 | + public function getField() { |
|
| 42 | 42 | return $this->input; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function getDataField(){ |
|
| 45 | + public function getDataField() { |
|
| 46 | 46 | return $this->input; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - public function addItem($item,$value=NULL,$image=NULL,$description=NULL){ |
|
| 50 | - $itemO=$this->beforeAddItem($item,$value,$image,$description); |
|
| 49 | + public function addItem($item, $value=NULL, $image=NULL, $description=NULL) { |
|
| 50 | + $itemO=$this->beforeAddItem($item, $value, $image, $description); |
|
| 51 | 51 | $this->items[]=$itemO; |
| 52 | 52 | return $itemO; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public function addIcon($icon,$before=true,$labeled=false){ |
|
| 56 | - $this->addIconP($icon,$before,$labeled); |
|
| 55 | + public function addIcon($icon, $before=true, $labeled=false) { |
|
| 56 | + $this->addIconP($icon, $before, $labeled); |
|
| 57 | 57 | return $this->getElementById("text-".$this->identifier, $this->content)->setWrapAfter(""); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public function addIcons($icons){ |
|
| 60 | + public function addIcons($icons) { |
|
| 61 | 61 | $count=$this->count(); |
| 62 | - for ($i=0;$i<\sizeof($icons) && $i<$count;$i++){ |
|
| 62 | + for ($i=0; $i<\sizeof($icons) && $i<$count; $i++) { |
|
| 63 | 63 | $this->getItem($i)->addIcon($icons[$i]); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -70,26 +70,26 @@ discard block |
||
| 70 | 70 | * @param number $position |
| 71 | 71 | * @return \Ajax\semantic\html\content\HtmlDropdownItem|unknown |
| 72 | 72 | */ |
| 73 | - public function insertItem($item,$position=0){ |
|
| 73 | + public function insertItem($item, $position=0) { |
|
| 74 | 74 | $itemO=$this->beforeAddItem($item); |
| 75 | - $start = array_slice($this->items, 0, $position); |
|
| 76 | - $end = array_slice($this->items, $position); |
|
| 77 | - $start[] = $item; |
|
| 75 | + $start=array_slice($this->items, 0, $position); |
|
| 76 | + $end=array_slice($this->items, $position); |
|
| 77 | + $start[]=$item; |
|
| 78 | 78 | $this->items=array_merge($start, $end); |
| 79 | 79 | return $itemO; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - protected function beforeAddItem($item,$value=NULL,$image=NULL,$description=NULL){ |
|
| 82 | + protected function beforeAddItem($item, $value=NULL, $image=NULL, $description=NULL) { |
|
| 83 | 83 | $itemO=$item; |
| 84 | - if(\is_array($item)){ |
|
| 84 | + if (\is_array($item)) { |
|
| 85 | 85 | $description=JArray::getValue($item, "description", 3); |
| 86 | 86 | $value=JArray::getValue($item, "value", 1); |
| 87 | 87 | $image=JArray::getValue($item, "image", 2); |
| 88 | 88 | $item=JArray::getValue($item, "item", 0); |
| 89 | 89 | } |
| 90 | - if(!$item instanceof HtmlDropdownItem){ |
|
| 91 | - $itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items),$item,$value,$image,$description); |
|
| 92 | - }elseif($itemO instanceof HtmlDropdownItem){ |
|
| 90 | + if (!$item instanceof HtmlDropdownItem) { |
|
| 91 | + $itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items), $item, $value, $image, $description); |
|
| 92 | + }elseif ($itemO instanceof HtmlDropdownItem) { |
|
| 93 | 93 | $this->addToProperty("class", "vertical"); |
| 94 | 94 | } |
| 95 | 95 | return $itemO; |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | $this->addItem($function($object)); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - public function addInput($name){ |
|
| 106 | - if(!isset($name)) |
|
| 105 | + public function addInput($name) { |
|
| 106 | + if (!isset($name)) |
|
| 107 | 107 | $name="input-".$this->identifier; |
| 108 | 108 | $this->setAction("activate"); |
| 109 | - $this->input=new HtmlInput($name,"hidden"); |
|
| 109 | + $this->input=new HtmlInput($name, "hidden"); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -115,15 +115,15 @@ discard block |
||
| 115 | 115 | * @param string $icon |
| 116 | 116 | * @return \Ajax\semantic\html\content\HtmlDropdownItem |
| 117 | 117 | */ |
| 118 | - public function addSearchInputItem($placeHolder=NULL,$icon=NULL){ |
|
| 119 | - return $this->addItem(HtmlDropdownItem::searchInput($placeHolder,$icon)); |
|
| 118 | + public function addSearchInputItem($placeHolder=NULL, $icon=NULL) { |
|
| 119 | + return $this->addItem(HtmlDropdownItem::searchInput($placeHolder, $icon)); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * Adds a divider item |
| 124 | 124 | * @return \Ajax\semantic\html\content\HtmlDropdownItem |
| 125 | 125 | */ |
| 126 | - public function addDividerItem(){ |
|
| 126 | + public function addDividerItem() { |
|
| 127 | 127 | return $this->addItem(HtmlDropdownItem::divider()); |
| 128 | 128 | } |
| 129 | 129 | |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | * @param string $icon |
| 134 | 134 | * @return \Ajax\semantic\html\content\HtmlDropdownItem|unknown |
| 135 | 135 | */ |
| 136 | - public function addHeaderItem($caption=NULL,$icon=NULL){ |
|
| 137 | - return $this->addItem(HtmlDropdownItem::header($caption,$icon)); |
|
| 136 | + public function addHeaderItem($caption=NULL, $icon=NULL) { |
|
| 137 | + return $this->addItem(HtmlDropdownItem::header($caption, $icon)); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @param string $color |
| 144 | 144 | * @return \Ajax\semantic\html\content\HtmlDropdownItem|unknown |
| 145 | 145 | */ |
| 146 | - public function addCircularLabelItem($caption,$color){ |
|
| 146 | + public function addCircularLabelItem($caption, $color) { |
|
| 147 | 147 | return $this->addItem(HtmlDropdownItem::circular($caption, $color)); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -152,87 +152,87 @@ discard block |
||
| 152 | 152 | * @param string $image |
| 153 | 153 | * @return \Ajax\semantic\html\content\HtmlDropdownItem |
| 154 | 154 | */ |
| 155 | - public function addMiniAvatarImageItem($caption,$image){ |
|
| 155 | + public function addMiniAvatarImageItem($caption, $image) { |
|
| 156 | 156 | return $this->addItem(HtmlDropdownItem::avatar($caption, $image)); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - public function addItems($items){ |
|
| 160 | - if(\is_array($items) && $this->_associative){ |
|
| 161 | - foreach ($items as $k=>$v){ |
|
| 159 | + public function addItems($items) { |
|
| 160 | + if (\is_array($items) && $this->_associative) { |
|
| 161 | + foreach ($items as $k=>$v) { |
|
| 162 | 162 | $this->addItem($v)->setData($k); |
| 163 | 163 | } |
| 164 | - }else{ |
|
| 165 | - foreach ($items as $item){ |
|
| 164 | + } else { |
|
| 165 | + foreach ($items as $item) { |
|
| 166 | 166 | $this->addItem($item); |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - public function getItem($index){ |
|
| 171 | + public function getItem($index) { |
|
| 172 | 172 | return $this->items[$index]; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | 176 | * @return int |
| 177 | 177 | */ |
| 178 | - public function count(){ |
|
| 178 | + public function count() { |
|
| 179 | 179 | return \sizeof($this->items); |
| 180 | 180 | } |
| 181 | 181 | /** |
| 182 | 182 | * @param boolean $dropdown |
| 183 | 183 | */ |
| 184 | - public function asDropdown($dropdown){ |
|
| 185 | - if($dropdown===false){ |
|
| 184 | + public function asDropdown($dropdown) { |
|
| 185 | + if ($dropdown===false) { |
|
| 186 | 186 | $this->_template=include dirname(__FILE__).'/../templates/tplDropdownMenu.php'; |
| 187 | 187 | $dropdown="menu"; |
| 188 | - }else{ |
|
| 188 | + } else { |
|
| 189 | 189 | $dropdown="dropdown"; |
| 190 | 190 | $this->mClass="menu"; |
| 191 | 191 | } |
| 192 | - return $this->addToPropertyCtrl("class", $dropdown,array("menu","dropdown")); |
|
| 192 | + return $this->addToPropertyCtrl("class", $dropdown, array("menu", "dropdown")); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - public function setVertical(){ |
|
| 196 | - return $this->addToPropertyCtrl("class", "vertical",array("vertical")); |
|
| 195 | + public function setVertical() { |
|
| 196 | + return $this->addToPropertyCtrl("class", "vertical", array("vertical")); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - public function setInline(){ |
|
| 200 | - return $this->addToPropertyCtrl("class", "inline",["inline"]); |
|
| 199 | + public function setInline() { |
|
| 200 | + return $this->addToPropertyCtrl("class", "inline", ["inline"]); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - public function setSimple(){ |
|
| 204 | - return $this->addToPropertyCtrl("class", "simple",array("simple")); |
|
| 203 | + public function setSimple() { |
|
| 204 | + return $this->addToPropertyCtrl("class", "simple", array("simple")); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - public function asButton($floating=false){ |
|
| 208 | - if($floating) |
|
| 207 | + public function asButton($floating=false) { |
|
| 208 | + if ($floating) |
|
| 209 | 209 | $this->addToProperty("class", "floating"); |
| 210 | 210 | $this->removePropertyValue("class", "selection"); |
| 211 | 211 | return $this->addToProperty("class", "button"); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - public function asSelect($name=NULL,$multiple=false,$selection=true){ |
|
| 215 | - if(isset($name)) |
|
| 214 | + public function asSelect($name=NULL, $multiple=false, $selection=true) { |
|
| 215 | + if (isset($name)) |
|
| 216 | 216 | $this->addInput($name); |
| 217 | - if($multiple) |
|
| 217 | + if ($multiple) |
|
| 218 | 218 | $this->addToProperty("class", "multiple"); |
| 219 | - if ($selection){ |
|
| 220 | - if($this->propertyContains("class", "button")===false) |
|
| 221 | - $this->addToPropertyCtrl("class", "selection",array("selection")); |
|
| 219 | + if ($selection) { |
|
| 220 | + if ($this->propertyContains("class", "button")===false) |
|
| 221 | + $this->addToPropertyCtrl("class", "selection", array("selection")); |
|
| 222 | 222 | } |
| 223 | 223 | return $this; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - public function asSearch($name=NULL,$multiple=false,$selection=true){ |
|
| 227 | - $this->asSelect($name,$multiple,$selection); |
|
| 226 | + public function asSearch($name=NULL, $multiple=false, $selection=true) { |
|
| 227 | + $this->asSelect($name, $multiple, $selection); |
|
| 228 | 228 | return $this->addToProperty("class", "search"); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - public function setSelect($name=NULL,$multiple=false){ |
|
| 232 | - if(!isset($name)) |
|
| 231 | + public function setSelect($name=NULL, $multiple=false) { |
|
| 232 | + if (!isset($name)) |
|
| 233 | 233 | $name="select-".$this->identifier; |
| 234 | 234 | $this->input=null; |
| 235 | - if($multiple){ |
|
| 235 | + if ($multiple) { |
|
| 236 | 236 | $this->setProperty("multiple", true); |
| 237 | 237 | $this->addToProperty("class", "multiple"); |
| 238 | 238 | } |
@@ -240,37 +240,37 @@ discard block |
||
| 240 | 240 | $this->tagName="select"; |
| 241 | 241 | $this->setProperty("name", $name); |
| 242 | 242 | $this->content=null; |
| 243 | - foreach ($this->items as $item){ |
|
| 243 | + foreach ($this->items as $item) { |
|
| 244 | 244 | $item->asOption(); |
| 245 | 245 | } |
| 246 | 246 | return $this; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - public function asSubmenu($pointing=NULL){ |
|
| 249 | + public function asSubmenu($pointing=NULL) { |
|
| 250 | 250 | $this->setClass("ui dropdown link item"); |
| 251 | - if(isset($pointing)){ |
|
| 251 | + if (isset($pointing)) { |
|
| 252 | 252 | $this->setPointing($pointing); |
| 253 | 253 | } |
| 254 | 254 | return $this; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - public function setPointing($value=Direction::NONE){ |
|
| 258 | - return $this->addToPropertyCtrl("class", $value." pointing",Direction::getConstantValues("pointing")); |
|
| 257 | + public function setPointing($value=Direction::NONE) { |
|
| 258 | + return $this->addToPropertyCtrl("class", $value." pointing", Direction::getConstantValues("pointing")); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - public function setValue($value){ |
|
| 261 | + public function setValue($value) { |
|
| 262 | 262 | $this->value=$value; |
| 263 | 263 | return $this; |
| 264 | 264 | } |
| 265 | - private function applyValue(){ |
|
| 265 | + private function applyValue() { |
|
| 266 | 266 | $value=$this->value; |
| 267 | - if(isset($this->input) && isset($value)){ |
|
| 267 | + if (isset($this->input) && isset($value)) { |
|
| 268 | 268 | $this->input->setProperty("value", $value); |
| 269 | - }else{ |
|
| 269 | + } else { |
|
| 270 | 270 | $this->setProperty("value", $value); |
| 271 | 271 | } |
| 272 | 272 | $textElement=$this->getElementById("text-".$this->identifier, $this->content); |
| 273 | - if(isset($textElement)) |
|
| 273 | + if (isset($textElement)) |
|
| 274 | 274 | $textElement->setContent($value); |
| 275 | 275 | return $this; |
| 276 | 276 | } |
@@ -280,29 +280,29 @@ discard block |
||
| 280 | 280 | * @see BaseHtml::run() |
| 281 | 281 | */ |
| 282 | 282 | public function run(JsUtils $js) { |
| 283 | - if($this->propertyContains("class", "simple")===false){ |
|
| 284 | - if(isset($this->_bsComponent)===false) |
|
| 285 | - $this->_bsComponent=$js->semantic()->dropdown("#".$this->identifier,$this->_params); |
|
| 283 | + if ($this->propertyContains("class", "simple")===false) { |
|
| 284 | + if (isset($this->_bsComponent)===false) |
|
| 285 | + $this->_bsComponent=$js->semantic()->dropdown("#".$this->identifier, $this->_params); |
|
| 286 | 286 | $this->addEventsOnRun($js); |
| 287 | 287 | return $this->_bsComponent; |
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - public function setCompact(){ |
|
| 291 | + public function setCompact() { |
|
| 292 | 292 | return $this->addToPropertyCtrl("class", "compact", array("compact")); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - public function setAction($action){ |
|
| 295 | + public function setAction($action) { |
|
| 296 | 296 | $this->_params["action"]=$action; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - public function setFullTextSearch($value){ |
|
| 299 | + public function setFullTextSearch($value) { |
|
| 300 | 300 | $this->_params["fullTextSearch"]=$value; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 304 | 304 | $this->applyValue(); |
| 305 | - return parent::compile($js,$view); |
|
| 305 | + return parent::compile($js, $view); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | public function getInput() { |