1
1
<?php
2
-
3
2
namespace Ajax \semantic \html \elements ;
4
3
5
4
use Ajax \semantic \html \base \HtmlSemDoubleElement ;
10
9
11
10
/**
12
11
* Semantic Button component
12
+ *
13
13
* @see http://phpmv-ui.kobject.net/index/direct/main/31
14
14
* @see http://semantic-ui.com/elements/button.html
15
15
* @author jc
@@ -20,14 +20,19 @@ class HtmlButton extends HtmlSemDoubleElement {
20
20
21
21
/**
22
22
* 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
27
32
*/
28
- public function __construct ($ identifier , $ value= null , $ cssStyle= null , $ onClick= null ) {
33
+ public function __construct ($ identifier , $ value = null , $ cssStyle = null , $ onClick = null ) {
29
34
parent ::__construct ($ identifier , "button " , "ui button " );
30
- $ this ->content = $ value ;
35
+ $ this ->content = $ value ;
31
36
if (isset ($ cssStyle )) {
32
37
$ this ->setStyle ($ cssStyle );
33
38
}
@@ -38,32 +43,34 @@ public function __construct($identifier, $value=null, $cssStyle=null, $onClick=n
38
43
39
44
/**
40
45
* Set the button value
46
+ *
41
47
* @param string $value
42
48
* @return HtmlButton
43
49
*/
44
50
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 ;
49
55
return $ this ;
50
56
}
51
57
}
52
58
}
53
- $ this ->content = $ value ;
59
+ $ this ->content = $ value ;
54
60
return $ this ;
55
61
}
56
62
57
63
/**
58
64
* define the button style
65
+ *
59
66
* @param string|int $cssStyle
60
67
* @return HtmlButton default : ""
61
68
*/
62
69
public function setStyle ($ cssStyle ) {
63
70
return $ this ->addToProperty ("class " , $ cssStyle );
64
71
}
65
72
66
- public function setFocusable ($ value= true ) {
73
+ public function setFocusable ($ value = true ) {
67
74
if ($ value === true )
68
75
$ this ->setProperty ("tabindex " , "0 " );
69
76
else {
@@ -72,16 +79,19 @@ public function setFocusable($value=true) {
72
79
return $ this ;
73
80
}
74
81
75
- public function setAnimated ($ content , $ animation= "" ) {
82
+ public function setAnimated ($ content , $ animation = "" ) {
76
83
$ this ->setTagName ("div " );
77
84
$ this ->addToProperty ("class " , "animated " . $ animation );
78
- $ visible= new HtmlSemDoubleElement ("visible- " . $ this ->identifier , "div " );
85
+ $ visible = new HtmlSemDoubleElement ("visible- " . $ this ->identifier , "div " );
79
86
$ visible ->setClass ("visible content " );
80
87
$ visible ->setContent ($ this ->content );
81
- $ hidden= new HtmlSemDoubleElement ("hidden- " . $ this ->identifier , "div " );
88
+ $ hidden = new HtmlSemDoubleElement ("hidden- " . $ this ->identifier , "div " );
82
89
$ hidden ->setClass ("hidden content " );
83
90
$ hidden ->setContent ($ content );
84
- $ this ->content =array ($ visible ,$ hidden );
91
+ $ this ->content = array (
92
+ $ visible ,
93
+ $ hidden
94
+ );
85
95
return $ hidden ;
86
96
}
87
97
@@ -91,12 +101,12 @@ public function setAnimated($content, $animation="") {
91
101
* @return HtmlButton
92
102
*/
93
103
public function asIcon ($ icon ) {
94
- $ iconO= $ icon ;
104
+ $ iconO = $ icon ;
95
105
if (\is_string ($ icon )) {
96
- $ iconO= new HtmlIcon ("icon- " . $ this ->identifier , $ icon );
106
+ $ iconO = new HtmlIcon ("icon- " . $ this ->identifier , $ icon );
97
107
}
98
108
$ this ->addToProperty ("class " , "icon " );
99
- $ this ->content = $ iconO ;
109
+ $ this ->content = $ iconO ;
100
110
return $ this ;
101
111
}
102
112
@@ -107,23 +117,25 @@ public function asSubmit() {
107
117
108
118
/**
109
119
* Add and return a button label
120
+ *
110
121
* @param string $label
111
122
* @param boolean $before
112
123
* @param string $icon
113
124
* @return HtmlLabel
114
125
*/
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 ) {
123
135
$ this ->content ->addClass ("icon " );
124
136
}
125
137
$ this ->content ->setTagName ("div " );
126
- $ label= new HtmlLabel ("label- " . $ this ->identifier , $ label , $ icon ,"a " );
138
+ $ label = new HtmlLabel ("label- " . $ this ->identifier , $ label , $ icon , "a " );
127
139
$ label ->setBasic ();
128
140
$ this ->addContent ($ label , $ before );
129
141
return $ label ;
@@ -134,35 +146,36 @@ public function addLabel($label, $before=false, $icon=NULL) {
134
146
* @see \Ajax\common\html\BaseHtml::fromArray()
135
147
*/
136
148
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 ) {
139
151
$ this ->setProperty ($ key , $ value );
140
152
}
141
153
return $ array ;
142
154
}
143
155
144
156
/**
145
157
* hint towards a positive consequence
158
+ *
146
159
* @return HtmlButton
147
160
*/
148
161
public function setPositive () {
149
162
return $ this ->addToProperty ("class " , "positive " );
150
163
}
151
164
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)
156
169
$ content ->setColor ($ color );
157
170
}
158
- }
159
- else
171
+ } else
160
172
parent ::setColor ($ color );
161
173
return $ this ;
162
174
}
163
175
164
176
/**
165
177
* hint towards a negative consequence
178
+ *
166
179
* @return HtmlButton
167
180
*/
168
181
public function setNegative () {
@@ -171,11 +184,12 @@ public function setNegative() {
171
184
172
185
/**
173
186
* formatted to toggle on/off
187
+ *
174
188
* @return HtmlButton
175
189
*/
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 );
179
193
}
180
194
181
195
/**
@@ -188,6 +202,7 @@ public function setCircular() {
188
202
189
203
/**
190
204
* button is less pronounced
205
+ *
191
206
* @return HtmlButton
192
207
*/
193
208
public function setBasic () {
@@ -204,68 +219,86 @@ public function setLoading() {
204
219
205
220
/**
206
221
* Returns a new social Button
222
+ *
207
223
* @param string $identifier
208
224
* @param string $social
209
225
* @param string $value
210
226
* @return HtmlButton
211
227
*/
212
- public static function social ($ identifier , $ social , $ value= NULL ) {
228
+ public static function social ($ identifier , $ social , $ value = NULL ) {
213
229
if ($ value === NULL )
214
- $ value= \ucfirst ($ social );
215
- $ return= new HtmlButton ($ identifier , $ value );
230
+ $ value = \ucfirst ($ social );
231
+ $ return = new HtmlButton ($ identifier , $ value );
216
232
$ return ->addIcon ($ social );
217
233
return $ return ->addToPropertyCtrl ("class " , $ social , Social::getConstants ());
218
234
}
219
235
220
236
/**
221
237
* Returns a new labeled Button
238
+ *
222
239
* @param string $identifier
223
240
* @param string $value
224
241
* @param string $icon
225
242
* @param boolean $before
226
243
* @return \Ajax\semantic\html\elements\HtmlButton
227
244
*/
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 );
230
247
$ result ->addIcon ($ icon , $ before , true );
231
248
return $ result ;
232
249
}
233
250
234
251
/**
235
252
* Returns a new icon Button
253
+ *
236
254
* @param string $identifier
237
255
* @param string $icon
238
256
* @return HtmlButton
239
257
*/
240
258
public static function icon ($ identifier , $ icon ) {
241
- $ result= new HtmlButton ($ identifier );
259
+ $ result = new HtmlButton ($ identifier );
242
260
$ result ->asIcon ($ icon );
243
261
return $ result ;
244
262
}
245
263
246
264
/**
247
- * {@inheritDoc}
265
+ *
266
+ * {@inheritdoc}
248
267
* @see HtmlSemDoubleElement::asLink()
249
268
*/
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 );
252
271
return $ this ;
253
272
}
254
273
255
274
/**
256
275
* Returns a button with a dropdown button
276
+ *
257
277
* @param string $identifier
258
278
* @param string $value
259
279
* @param array $items
260
280
* @param boolean $asCombo
261
281
* @param string $icon
262
282
* @return HtmlButtonGroups
263
283
*/
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)
268
290
$ dd ->setIcon ($ icon );
269
291
return $ result ;
270
292
}
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
+ }
271
304
}
0 commit comments