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

Commit dc02c2d

Browse files
author
Christoph Möke
committed
Added variable to disable all items at once and fixed filter of disabled items
bug #6 enhancement #5
1 parent 86ec66d commit dc02c2d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Sortable.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ class Sortable extends Widget
110110
*/
111111
public $items = [];
112112

113+
/**
114+
* @var bool disable items by default. This will be overwritten
115+
* by the "disabled" set in individual [[items]].
116+
*/
117+
public $disabled = false;
118+
119+
/**
120+
* @var string css class to style disabled items.
121+
*/
122+
public $disabledClass = 'disabled';
123+
113124
/**
114125
* @var string the handle label, this is not HTML encoded. This will be overwritten
115126
* by the "handleLabel" set in individual [[items]].
@@ -189,13 +200,13 @@ protected function initClientOptions()
189200
{
190201
if ($this->addHandle || $this->itemHasEnabledOption('addHandle')) {
191202
if (empty($this->clientOptions['handle'])) {
192-
$this->clientOptions['handle'] = 'rubaxa-sortable-handle';
203+
$this->clientOptions['handle'] = '.rubaxa-sortable-handle';
193204
}
194205
}
195206

196-
if ($this->itemHasEnabledOption('disabled')) {
207+
if ($this->disabled || $this->itemHasEnabledOption('disabled')) {
197208
if (empty($this->clientOptions['filter'])) {
198-
$this->clientOptions['filter'] = 'rubaxa-sortable-disabled';
209+
$this->clientOptions['filter'] = '.rubaxa-sortable-disabled';
199210
}
200211
}
201212

@@ -284,8 +295,8 @@ private function renderItems()
284295
foreach ($this->items as $item) {
285296
$itemOptions = ArrayHelper::merge($this->itemOptions, ArrayHelper::getValue($item, 'options', []));
286297

287-
if (ArrayHelper::getValue($item, 'disabled', false)) {
288-
Html::addCssClass($itemOptions, $this->clientOptions['filter']);
298+
if (ArrayHelper::getValue($item, 'disabled', $this->disabled)) {
299+
Html::addCssClass($itemOptions, [substr($this->clientOptions['filter'], 1), $this->disabledClass]);
289300
}
290301

291302
switch ($this->type) {
@@ -299,7 +310,7 @@ private function renderItems()
299310
if ($addHandle) {
300311
$handleOptions = ArrayHelper::merge($this->handleOptions, ArrayHelper::getValue($item, 'handleOptions', []));
301312

302-
Html::addCssClass($handleOptions, $this->clientOptions['handle']);
313+
Html::addCssClass($handleOptions, substr($this->clientOptions['handle'], 1));
303314

304315
$handleElement = ArrayHelper::getValue($item, 'handleElement', $this->handleElement);
305316
$handleLabel = ArrayHelper::getValue($item, 'handleLabel', $this->handleLabel);

0 commit comments

Comments
 (0)