Skip to content

Commit 172c54c

Browse files
committed
dropdown changements
1 parent 2c01a5e commit 172c54c

File tree

3 files changed

+143
-11
lines changed

3 files changed

+143
-11
lines changed

Ajax/semantic/html/content/HtmlDropdownItem.php

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
use Ajax\common\html\html5\HtmlInput;
99
use Ajax\service\JArray;
1010
use Ajax\semantic\html\base\traits\IconTrait;
11+
use Ajax\semantic\html\elements\HtmlLabel;
12+
use Ajax\semantic\html\elements\HtmlIcon;
1113

1214
class HtmlDropdownItem extends HtmlSemDoubleElement {
1315
use IconTrait;
14-
public function __construct($identifier, $content="",$value=NULL,$image=NULL) {
16+
public function __construct($identifier, $content="",$value=NULL,$image=NULL,$description=NULL) {
1517
parent::__construct($identifier, "a");
1618
$this->setClass("item");
1719
$this->setContent($content);
1820
if($value!==NULL)
1921
$this->setData($value);
2022
if($image!==NULL)
2123
$this->asMiniAvatar($image);
24+
if($description!==NULL)
25+
$this->setDescription($description);
2226
}
2327

2428
public function setDescription($description){
@@ -47,7 +51,31 @@ public function asMiniAvatar($image){
4751
$img=new HtmlImg("image-".$this->identifier,$image);
4852
$img->setClass("ui mini avatar image");
4953
$this->addContent($img,true);
50-
return $img;
54+
return $this;
55+
}
56+
57+
/**
58+
* @param string $caption
59+
* @param string $icon
60+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
61+
*/
62+
public function asIcon($caption,$icon){
63+
$this->setContent($caption);
64+
$this->addContent(new HtmlIcon("", $icon),true);
65+
return $this;
66+
}
67+
68+
/**
69+
* Adds a circular label to the item
70+
* @param string $color
71+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
72+
*/
73+
public function asCircularLabel($caption,$color){
74+
$this->setContent($caption);
75+
$lbl=new HtmlLabel("");
76+
$lbl->setCircular()->setColor($color)->setEmpty();
77+
$this->addContent($lbl,true);
78+
return $this;
5179
}
5280

5381
public function asSearchInput($placeholder=NULL,$icon=NULL){
@@ -72,11 +100,20 @@ public function setContent($content){
72100
return $this;
73101
}
74102

103+
/**
104+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
105+
*/
75106
public function asDivider(){
76107
$this->content=NULL;
77108
$this->setClass("divider");
109+
return $this;
78110
}
79111

112+
/**
113+
* @param string $caption
114+
* @param string $icon
115+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
116+
*/
80117
public function asHeader($caption=NULL,$icon=NULL){
81118
$this->setClass("header");
82119
$this->content=$caption;
@@ -85,15 +122,55 @@ public function asHeader($caption=NULL,$icon=NULL){
85122
return $this;
86123
}
87124

125+
/**
126+
* @param string $placeholder
127+
* @param string $icon
128+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
129+
*/
88130
public static function searchInput($placeholder=NULL,$icon=NULL){
89131
return (new HtmlDropdownItem(""))->asSearchInput($placeholder,$icon);
90132
}
91133

92-
public static function divider($placeholder=NULL,$icon=NULL){
134+
/**
135+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
136+
*/
137+
public static function divider(){
93138
return (new HtmlDropdownItem(""))->asDivider();
94139
}
95140

141+
/**
142+
* @param string $caption
143+
* @param string $icon
144+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
145+
*/
96146
public static function header($caption=NULL,$icon=NULL){
97147
return (new HtmlDropdownItem(""))->asHeader($caption,$icon);
98148
}
149+
150+
/**
151+
* @param string $caption
152+
* @param string $color
153+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
154+
*/
155+
public static function circular($caption,$color){
156+
return (new HtmlDropdownItem(""))->asCircularLabel($caption,$color);
157+
}
158+
159+
/**
160+
* @param string $caption
161+
* @param string $icon
162+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
163+
*/
164+
public static function icon($caption,$icon){
165+
return (new HtmlDropdownItem(""))->asIcon($caption,$icon);
166+
}
167+
168+
/**
169+
* @param unknown $caption
170+
* @param unknown $image
171+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
172+
*/
173+
public static function avatar($caption,$image){
174+
return (new HtmlDropdownItem("",$caption))->asMiniAvatar($image);
175+
}
99176
}

Ajax/semantic/html/content/HtmlGridCol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function addDivider($vertical=true, $content=NULL) {
5252
$divider->setVertical();
5353
else
5454
$divider->setHorizontal();
55-
$this->wrap("", $divider);
55+
$this->wrap($divider,"");
5656
return $divider;
5757
}
5858
}

Ajax/semantic/html/modules/HtmlDropdown.php

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function __construct($identifier, $value="", $items=array()) {
3434
$this->addItems($items);
3535
}
3636

37-
public function addItem($item,$value=NULL,$image=NULL){
38-
$itemO=$this->beforeAddItem($item,$value,$image);
37+
public function addItem($item,$value=NULL,$image=NULL,$description=NULL){
38+
$itemO=$this->beforeAddItem($item,$value,$image,$description);
3939
$this->items[]=$itemO;
4040
return $itemO;
4141
}
@@ -44,6 +44,7 @@ public function addIcon($icon,$before=true,$labeled=false){
4444
$this->addIconP($icon,$before,$labeled);
4545
return $this->getElementById("text-".$this->identifier, $this->content)->setWrapAfter("");
4646
}
47+
4748
/**
4849
* Insert an item at a position
4950
* @param mixed $item
@@ -59,15 +60,16 @@ public function insertItem($item,$position=0){
5960
return $itemO;
6061
}
6162

62-
protected function beforeAddItem($item,$value=NULL,$image=NULL){
63+
protected function beforeAddItem($item,$value=NULL,$image=NULL,$description=NULL){
6364
$itemO=$item;
6465
if(\is_array($item)){
66+
$description=JArray::getValue($item, "description", 3);
6567
$value=JArray::getValue($item, "value", 1);
6668
$image=JArray::getValue($item, "image", 2);
6769
$item=JArray::getValue($item, "item", 0);
6870
}
6971
if(!$item instanceof HtmlDropdownItem){
70-
$itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items),$item,$value,$image);
72+
$itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items),$item,$value,$image,$description);
7173
}elseif($itemO instanceof HtmlDropdownItem){
7274
$this->addToProperty("class", "vertical");
7375
}
@@ -88,6 +90,53 @@ public function addInput($name){
8890
$this->input=new HtmlInput($name,"hidden");
8991
}
9092

93+
/**
94+
* Adds a search input item
95+
* @param string $placeHolder
96+
* @param string $icon
97+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
98+
*/
99+
public function addSearchInputItem($placeHolder=NULL,$icon=NULL){
100+
return $this->addItem(HtmlDropdownItem::searchInput($placeHolder,$icon));
101+
}
102+
103+
/**
104+
* Adds a divider item
105+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
106+
*/
107+
public function addDividerItem(){
108+
return $this->addItem(HtmlDropdownItem::divider());
109+
}
110+
111+
/**
112+
* Adds an header item
113+
* @param string $caption
114+
* @param string $icon
115+
* @return \Ajax\semantic\html\content\HtmlDropdownItem|unknown
116+
*/
117+
public function addHeaderItem($caption=NULL,$icon=NULL){
118+
return $this->addItem(HtmlDropdownItem::header($caption,$icon));
119+
}
120+
121+
/**
122+
* Adds an item with a circular label
123+
* @param string $caption
124+
* @param string $color
125+
* @return \Ajax\semantic\html\content\HtmlDropdownItem|unknown
126+
*/
127+
public function addCircularLabelItem($caption,$color){
128+
return $this->addItem(HtmlDropdownItem::circular($caption, $color));
129+
}
130+
131+
/**
132+
* @param string $caption
133+
* @param string $image
134+
* @return \Ajax\semantic\html\content\HtmlDropdownItem
135+
*/
136+
public function addMiniAvatarImageItem($caption,$image){
137+
return $this->addItem(HtmlDropdownItem::avatar($caption, $image));
138+
}
139+
91140
public function addItems($items){
92141
if(JArray::isAssociative($items)){
93142
foreach ($items as $k=>$v){
@@ -100,6 +149,9 @@ public function addItems($items){
100149
}
101150
}
102151

152+
/**
153+
* @return int
154+
*/
103155
public function count(){
104156
return \sizeof($this->items);
105157
}
@@ -128,6 +180,7 @@ public function setSimple(){
128180
public function asButton($floating=false){
129181
if($floating)
130182
$this->addToProperty("class", "floating");
183+
$this->removePropertyValue("class", "selection");
131184
return $this->addToProperty("class", "button");
132185
}
133186

@@ -136,12 +189,14 @@ public function asSelect($name=NULL,$multiple=false,$selection=true){
136189
$this->addInput($name);
137190
if($multiple)
138191
$this->addToProperty("class", "multiple");
139-
if ($selection)
140-
$this->addToPropertyCtrl("class", "selection",array("selection"));
192+
if ($selection){
193+
if($this->propertyContains("class", "button")===false)
194+
$this->addToPropertyCtrl("class", "selection",array("selection"));
195+
}
141196
return $this;
142197
}
143198

144-
public function asSearch($name=NULL,$multiple=false,$selection=false){
199+
public function asSearch($name=NULL,$multiple=false,$selection=true){
145200
$this->asSelect($name,$multiple,$selection);
146201
return $this->addToProperty("class", "search");
147202
}

0 commit comments

Comments
 (0)