11<?php
2-
32namespace Ajax \semantic \html \elements ;
43
54use Ajax \semantic \html \base \HtmlSemDoubleElement ;
109
1110/**
1211 * Semantic Button component
12+ *
1313 * @see http://phpmv-ui.kobject.net/index/direct/main/31
1414 * @see http://semantic-ui.com/elements/button.html
1515 * @author jc
@@ -20,14 +20,19 @@ class HtmlButton extends HtmlSemDoubleElement {
2020
2121 /**
2222 * Constructs an HTML Semantic button
23- * @param string $identifier HTML id
24- * @param string $value value of the Button
25- * @param string $cssStyle btn-default, btn-primary...
26- * @param string $onClick JS Code for click event
23+ *
24+ * @param string $identifier
25+ * HTML id
26+ * @param string $value
27+ * value of the Button
28+ * @param string $cssStyle
29+ * btn-default, btn-primary...
30+ * @param string $onClick
31+ * JS Code for click event
2732 */
28- public function __construct ($ identifier , $ value= null , $ cssStyle= null , $ onClick= null ) {
33+ public function __construct ($ identifier , $ value = null , $ cssStyle = null , $ onClick = null ) {
2934 parent ::__construct ($ identifier , "button " , "ui button " );
30- $ this ->content = $ value ;
35+ $ this ->content = $ value ;
3136 if (isset ($ cssStyle )) {
3237 $ this ->setStyle ($ cssStyle );
3338 }
@@ -38,32 +43,34 @@ public function __construct($identifier, $value=null, $cssStyle=null, $onClick=n
3843
3944 /**
4045 * Set the button value
46+ *
4147 * @param string $value
4248 * @return HtmlButton
4349 */
4450 public function setValue ($ value ) {
45- if (is_array ($ this ->content )){
46- foreach ($ this ->content as $ i=> $ content ){
47- if (is_string ($ content )){
48- $ this ->content [$ i ]= $ value ;
51+ if (is_array ($ this ->content )) {
52+ foreach ($ this ->content as $ i => $ content ) {
53+ if (is_string ($ content )) {
54+ $ this ->content [$ i ] = $ value ;
4955 return $ this ;
5056 }
5157 }
5258 }
53- $ this ->content = $ value ;
59+ $ this ->content = $ value ;
5460 return $ this ;
5561 }
5662
5763 /**
5864 * define the button style
65+ *
5966 * @param string|int $cssStyle
6067 * @return HtmlButton default : ""
6168 */
6269 public function setStyle ($ cssStyle ) {
6370 return $ this ->addToProperty ("class " , $ cssStyle );
6471 }
6572
66- public function setFocusable ($ value= true ) {
73+ public function setFocusable ($ value = true ) {
6774 if ($ value === true )
6875 $ this ->setProperty ("tabindex " , "0 " );
6976 else {
@@ -72,16 +79,19 @@ public function setFocusable($value=true) {
7279 return $ this ;
7380 }
7481
75- public function setAnimated ($ content , $ animation= "" ) {
82+ public function setAnimated ($ content , $ animation = "" ) {
7683 $ this ->setTagName ("div " );
7784 $ this ->addToProperty ("class " , "animated " . $ animation );
78- $ visible= new HtmlSemDoubleElement ("visible- " . $ this ->identifier , "div " );
85+ $ visible = new HtmlSemDoubleElement ("visible- " . $ this ->identifier , "div " );
7986 $ visible ->setClass ("visible content " );
8087 $ visible ->setContent ($ this ->content );
81- $ hidden= new HtmlSemDoubleElement ("hidden- " . $ this ->identifier , "div " );
88+ $ hidden = new HtmlSemDoubleElement ("hidden- " . $ this ->identifier , "div " );
8289 $ hidden ->setClass ("hidden content " );
8390 $ hidden ->setContent ($ content );
84- $ this ->content =array ($ visible ,$ hidden );
91+ $ this ->content = array (
92+ $ visible ,
93+ $ hidden
94+ );
8595 return $ hidden ;
8696 }
8797
@@ -91,12 +101,12 @@ public function setAnimated($content, $animation="") {
91101 * @return HtmlButton
92102 */
93103 public function asIcon ($ icon ) {
94- $ iconO= $ icon ;
104+ $ iconO = $ icon ;
95105 if (\is_string ($ icon )) {
96- $ iconO= new HtmlIcon ("icon- " . $ this ->identifier , $ icon );
106+ $ iconO = new HtmlIcon ("icon- " . $ this ->identifier , $ icon );
97107 }
98108 $ this ->addToProperty ("class " , "icon " );
99- $ this ->content = $ iconO ;
109+ $ this ->content = $ iconO ;
100110 return $ this ;
101111 }
102112
@@ -107,23 +117,25 @@ public function asSubmit() {
107117
108118 /**
109119 * Add and return a button label
120+ *
110121 * @param string $label
111122 * @param boolean $before
112123 * @param string $icon
113124 * @return HtmlLabel
114125 */
115- public function addLabel ($ label , $ before =false , $ icon =NULL ) {
116- $ this ->tagName ="div " ;$ prefix ="" ;
117- if ($ before )
118- $ prefix ="left " ;
119- $ this ->addToProperty ("class " , $ prefix ."labeled " );
120- $ isIcon =(isset ($ this ->content [0 ]) && $ this ->content [0 ] instanceof HtmlIcon);
121- $ this ->content =new HtmlButton ("button- " . $ this ->identifier , $ this ->content );
122- if ($ isIcon ){
126+ public function addLabel ($ label , $ before = false , $ icon = NULL ) {
127+ $ this ->tagName = "div " ;
128+ $ prefix = "" ;
129+ if ($ before )
130+ $ prefix = "left " ;
131+ $ this ->addToProperty ("class " , $ prefix . "labeled " );
132+ $ isIcon = (isset ($ this ->content [0 ]) && $ this ->content [0 ] instanceof HtmlIcon);
133+ $ this ->content = new HtmlButton ("button- " . $ this ->identifier , $ this ->content );
134+ if ($ isIcon ) {
123135 $ this ->content ->addClass ("icon " );
124136 }
125137 $ this ->content ->setTagName ("div " );
126- $ label= new HtmlLabel ("label- " . $ this ->identifier , $ label , $ icon ,"a " );
138+ $ label = new HtmlLabel ("label- " . $ this ->identifier , $ label , $ icon , "a " );
127139 $ label ->setBasic ();
128140 $ this ->addContent ($ label , $ before );
129141 return $ label ;
@@ -134,35 +146,36 @@ public function addLabel($label, $before=false, $icon=NULL) {
134146 * @see \Ajax\common\html\BaseHtml::fromArray()
135147 */
136148 public function fromArray ($ array ) {
137- $ array= parent ::fromArray ($ array );
138- foreach ( $ array as $ key => $ value ) {
149+ $ array = parent ::fromArray ($ array );
150+ foreach ($ array as $ key => $ value ) {
139151 $ this ->setProperty ($ key , $ value );
140152 }
141153 return $ array ;
142154 }
143155
144156 /**
145157 * hint towards a positive consequence
158+ *
146159 * @return HtmlButton
147160 */
148161 public function setPositive () {
149162 return $ this ->addToProperty ("class " , "positive " );
150163 }
151164
152- public function setColor ($ color ){
153- if (\is_array ($ this ->content )){
154- foreach ($ this ->content as $ content ){
155- if ($ content instanceof HtmlButton)
165+ public function setColor ($ color ) {
166+ if (\is_array ($ this ->content )) {
167+ foreach ($ this ->content as $ content ) {
168+ if ($ content instanceof HtmlButton)
156169 $ content ->setColor ($ color );
157170 }
158- }
159- else
171+ } else
160172 parent ::setColor ($ color );
161173 return $ this ;
162174 }
163175
164176 /**
165177 * hint towards a negative consequence
178+ *
166179 * @return HtmlButton
167180 */
168181 public function setNegative () {
@@ -171,11 +184,12 @@ public function setNegative() {
171184
172185 /**
173186 * formatted to toggle on/off
187+ *
174188 * @return HtmlButton
175189 */
176- public function setToggle ($ active= "" ) {
177- $ this ->onCreate ("$('# " . $ this ->identifier . "').state(); " );
178- return $ this ->addToProperty ("class " , "toggle " . $ active );
190+ public function setToggle ($ active = "" ) {
191+ $ this ->onCreate ("$('# " . $ this ->identifier . "').state(); " );
192+ return $ this ->addToProperty ("class " , "toggle " . $ active );
179193 }
180194
181195 /**
@@ -188,6 +202,7 @@ public function setCircular() {
188202
189203 /**
190204 * button is less pronounced
205+ *
191206 * @return HtmlButton
192207 */
193208 public function setBasic () {
@@ -204,68 +219,86 @@ public function setLoading() {
204219
205220 /**
206221 * Returns a new social Button
222+ *
207223 * @param string $identifier
208224 * @param string $social
209225 * @param string $value
210226 * @return HtmlButton
211227 */
212- public static function social ($ identifier , $ social , $ value= NULL ) {
228+ public static function social ($ identifier , $ social , $ value = NULL ) {
213229 if ($ value === NULL )
214- $ value= \ucfirst ($ social );
215- $ return= new HtmlButton ($ identifier , $ value );
230+ $ value = \ucfirst ($ social );
231+ $ return = new HtmlButton ($ identifier , $ value );
216232 $ return ->addIcon ($ social );
217233 return $ return ->addToPropertyCtrl ("class " , $ social , Social::getConstants ());
218234 }
219235
220236 /**
221237 * Returns a new labeled Button
238+ *
222239 * @param string $identifier
223240 * @param string $value
224241 * @param string $icon
225242 * @param boolean $before
226243 * @return \Ajax\semantic\html\elements\HtmlButton
227244 */
228- public static function labeled ($ identifier , $ value , $ icon , $ before= true ) {
229- $ result= new HtmlButton ($ identifier , $ value );
245+ public static function labeled ($ identifier , $ value , $ icon , $ before = true ) {
246+ $ result = new HtmlButton ($ identifier , $ value );
230247 $ result ->addIcon ($ icon , $ before , true );
231248 return $ result ;
232249 }
233250
234251 /**
235252 * Returns a new icon Button
253+ *
236254 * @param string $identifier
237255 * @param string $icon
238256 * @return HtmlButton
239257 */
240258 public static function icon ($ identifier , $ icon ) {
241- $ result= new HtmlButton ($ identifier );
259+ $ result = new HtmlButton ($ identifier );
242260 $ result ->asIcon ($ icon );
243261 return $ result ;
244262 }
245263
246264 /**
247- * {@inheritDoc}
265+ *
266+ * {@inheritdoc}
248267 * @see HtmlSemDoubleElement::asLink()
249268 */
250- public function asLink ($ href= NULL ,$ target= NULL ) {
251- parent ::asLink ($ href ,$ target );
269+ public function asLink ($ href = NULL , $ target = NULL ) {
270+ parent ::asLink ($ href , $ target );
252271 return $ this ;
253272 }
254273
255274 /**
256275 * Returns a button with a dropdown button
276+ *
257277 * @param string $identifier
258278 * @param string $value
259279 * @param array $items
260280 * @param boolean $asCombo
261281 * @param string $icon
262282 * @return HtmlButtonGroups
263283 */
264- public static function dropdown ($ identifier ,$ value ,$ items =[],$ asCombo =false ,$ icon =null ){
265- $ result =new HtmlButtonGroups ($ identifier ,[$ value ]);
266- $ dd =$ result ->addDropdown ($ items ,$ asCombo );
267- if (isset ($ icon ) && $ dd instanceof HtmlDropdown)
284+ public static function dropdown ($ identifier , $ value , $ items = [], $ asCombo = false , $ icon = null ) {
285+ $ result = new HtmlButtonGroups ($ identifier , [
286+ $ value
287+ ]);
288+ $ dd = $ result ->addDropdown ($ items , $ asCombo );
289+ if (isset ($ icon ) && $ dd instanceof HtmlDropdown)
268290 $ dd ->setIcon ($ icon );
269291 return $ result ;
270292 }
293+
294+ public function addPopupConfirmation ($ message , $ buttons = ["Okay " ,"Cancel " ]) {
295+ $ elm = new HtmlSemDoubleElement ('popup-confirm- ' . $ this ->_identifier );
296+ $ elm ->setContent ([
297+ 'message ' => new HtmlSemDoubleElement ('popup-confirm-message- ' . $ this ->_identifier , 'p ' , '' , $ message )
298+ ]);
299+ $ this ->addPopupHtml ($ elm , null , [
300+ 'on ' => 'click '
301+ ]);
302+ return $ elm ;
303+ }
271304}
0 commit comments