Skip to content

Commit

Permalink
DetailActions: Allow to explicitly enable/disable multiselect
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Aug 28, 2023
1 parent dd6a0c1 commit 05f6a71
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/Common/DetailActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ trait DetailActions
/** @var bool */
protected $detailActionsDisabled = false;

/** @var bool Whether this item list supports multi select */
protected $multiselectSupported = false;

/**
* Set whether this list should be an action-list
*
Expand All @@ -36,6 +39,30 @@ public function getDetailActionsDisabled(): bool
return $this->detailActionsDisabled;
}

/**
* Get whether multi select is supported by this item list
*
* @return bool
*/
public function isMultiselectSupported(): bool
{
return ! $this->getDetailActionsDisabled() && $this->multiselectSupported;
}

/**
* Set whether this item list supports multi select
*
* @param bool $multiselectSupported
*
* @return $this
*/
public function setMultiselectSupport(bool $multiselectSupported = true): self
{
$this->multiselectSupported = $multiselectSupported;

return $this;
}

/**
* Prepare this list as action-list
*
Expand All @@ -48,10 +75,10 @@ public function initializeDetailActions(): self
return $this->getDetailActionsDisabled() ? null : 'action-list';
})
->registerAttributeCallback('data-icinga-multiselect-count-label', function () {
return $this->getDetailActionsDisabled() ? t('%d Item(s) selected') : null;
return $this->isMultiselectSupported() ? t('%d Item(s) selected') : null;
})
->registerAttributeCallback('data-icinga-multiselect-hint-label', function () {
return $this->getDetailActionsDisabled()
return $this->isMultiselectSupported()
? t('Use shift/cmd + click/arrow keys to select multiple items')
: null;
});
Expand All @@ -71,7 +98,7 @@ protected function setMultiselectUrl(Url $url): self
/** @var BaseHtmlElement $this */
$this->getAttributes()
->registerAttributeCallback('data-icinga-multiselect-url', function () use ($url) {
return $this->getDetailActionsDisabled() ? (string) $url : null;
return $this->isMultiselectSupported() ? (string) $url : null;
});

return $this;
Expand Down Expand Up @@ -107,7 +134,7 @@ public function addMultiselectFilterAttribute(BaseHtmlElement $element, Filter\R
{
$element->getAttributes()
->registerAttributeCallback('data-icinga-multiselect-filter', function () use ($filter) {
if (! $this->getDetailActionsDisabled()) {
if (! $this->isMultiselectSupported()) {
return null;
}

Expand Down

0 comments on commit 05f6a71

Please sign in to comment.