40
40
*/
41
41
class Sortable extends Widget
42
42
{
43
+ /**
44
+ * Option to display the sortable widget with custom elements and styles
45
+ */
46
+ const TYPE_CUSTOM = 0 ;
47
+
48
+ /**
49
+ * Option to display the sortable widget as bootstrap list-group.
50
+ */
51
+ const TYPE_BS_LIST = 1 ;
52
+
53
+ /**
54
+ * @var int the display type of the sortable widget.
55
+ * Should be set with on of the [[Sortable::TYPE]] constants.
56
+ */
57
+ public $ type = self ::TYPE_BS_LIST ;
58
+
43
59
/***
44
60
* @inheritDoc
45
61
*/
@@ -48,7 +64,7 @@ class Sortable extends Widget
48
64
/**
49
65
* @var string the tag name for the container element.
50
66
*/
51
- public $ containerElement = 'ul ' ;
67
+ public $ containerElement = '' ;
52
68
53
69
/**
54
70
* @var array the HTML attributes for the container tag.
@@ -60,7 +76,7 @@ class Sortable extends Widget
60
76
* @var string the tag name for the item element. This will be overwritten
61
77
* by the "element" set in individual [[items]].
62
78
*/
63
- public $ itemElement = 'li ' ;
79
+ public $ itemElement = '' ;
64
80
65
81
/**
66
82
* @var array the HTML attributes for the item tag. This will be overwritten
@@ -182,6 +198,28 @@ protected function initClientOptions()
182
198
$ this ->clientOptions ['filter ' ] = 'rubaxa-sortable-disabled ' ;
183
199
}
184
200
}
201
+
202
+ switch ($ this ->type ) {
203
+ case self ::TYPE_BS_LIST :
204
+ Html::addCssClass ($ this ->containerOptions , 'list-group ' );
205
+
206
+ if (empty ($ this ->containerElement )) {
207
+ $ this ->containerElement = 'ul ' ;
208
+ }
209
+
210
+ if (empty ($ this ->itemElement )) {
211
+ $ this ->itemElement = 'li ' ;
212
+ }
213
+ break ;
214
+ }
215
+
216
+ if (empty ($ this ->containerElement )) {
217
+ $ this ->containerElement = 'div ' ;
218
+ }
219
+
220
+ if (empty ($ this ->itemElement )) {
221
+ $ this ->itemElement = 'div ' ;
222
+ }
185
223
}
186
224
187
225
/**
@@ -250,6 +288,12 @@ private function renderItems()
250
288
Html::addCssClass ($ itemOptions , $ this ->clientOptions ['filter ' ]);
251
289
}
252
290
291
+ switch ($ this ->type ) {
292
+ case self ::TYPE_BS_LIST :
293
+ Html::addCssClass ($ itemOptions , 'list-group-item ' );
294
+ break ;
295
+ }
296
+
253
297
$ addHandle = ArrayHelper::getValue ($ item , 'addHandle ' , $ this ->addHandle );
254
298
255
299
if ($ addHandle ) {
0 commit comments