Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit 86ec66d

Browse files
author
Christoph Möke
committed
Added different sortable types
Added bootstrap list styles to Sortable::TYPE_BS_LIST. #3
1 parent d60099c commit 86ec66d

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

Sortable.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@
4040
*/
4141
class Sortable extends Widget
4242
{
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+
4359
/***
4460
* @inheritDoc
4561
*/
@@ -48,7 +64,7 @@ class Sortable extends Widget
4864
/**
4965
* @var string the tag name for the container element.
5066
*/
51-
public $containerElement = 'ul';
67+
public $containerElement = '';
5268

5369
/**
5470
* @var array the HTML attributes for the container tag.
@@ -60,7 +76,7 @@ class Sortable extends Widget
6076
* @var string the tag name for the item element. This will be overwritten
6177
* by the "element" set in individual [[items]].
6278
*/
63-
public $itemElement = 'li';
79+
public $itemElement = '';
6480

6581
/**
6682
* @var array the HTML attributes for the item tag. This will be overwritten
@@ -182,6 +198,28 @@ protected function initClientOptions()
182198
$this->clientOptions['filter'] = 'rubaxa-sortable-disabled';
183199
}
184200
}
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+
}
185223
}
186224

187225
/**
@@ -250,6 +288,12 @@ private function renderItems()
250288
Html::addCssClass($itemOptions, $this->clientOptions['filter']);
251289
}
252290

291+
switch ($this->type) {
292+
case self::TYPE_BS_LIST:
293+
Html::addCssClass($itemOptions, 'list-group-item');
294+
break;
295+
}
296+
253297
$addHandle = ArrayHelper::getValue($item, 'addHandle', $this->addHandle);
254298

255299
if ($addHandle) {

0 commit comments

Comments
 (0)