Skip to content

Commit

Permalink
Change "isDisabled" to "isEnabled" for actions everywhere (#2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Nov 25, 2024
1 parent de0e11c commit 8d7a9e2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 45 deletions.
4 changes: 2 additions & 2 deletions demos/collection/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/** @var App $app */
require_once __DIR__ . '/../init-app.php';

if ($app->tryGetRequestQueryParam('id')) {
if ($app->tryGetRequestQueryParam('person_id') || $app->tryGetRequestQueryParam('person_surname')) {
$app->layout->js(true, new JsToast('Details link is in simulation mode.'));
}

Expand Down Expand Up @@ -78,7 +78,7 @@
$table->setSource($myArray, ['name']);

// $table->addColumn('name');
$table->addColumn('surname', [Table\Column\Link::class, 'url' => 'table.php?id={$surname}']);
$table->addColumn('surname', [Table\Column\Link::class, 'url' => 'table.php?person_surname={$surname}']);
$table->addColumn('birthdate', [], ['type' => 'date']);
$table->addColumn('cv', [Table\Column\Html::class]);

Expand Down
32 changes: 13 additions & 19 deletions src/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,15 @@ public function jsReload($args = [], $afterSuccess = null, array $apiConfig = []
* Adds a new button into the action column on the right. For Crud this
* column will already contain "delete" and "edit" buttons.
*
* @param string|array<mixed>|View $button Label text, object or seed for the Button
* @param string|array<mixed>|View $button Label text, object or seed for the Button
* @param JsExpressionable|JsCallbackSetWithRowIdClosure $action
* @param bool|\Closure<T of Model>(T): bool $isDisabled
* @param bool|\Closure<T of Model>(T): bool $isEnabled
*
* @return View
*/
public function addActionButton($button, $action = null, string $confirmMsg = '', $isDisabled = false)
public function addActionButton($button, $action = null, string $confirmMsg = '', $isEnabled = true)
{
return $this->getActionButtons()->addButton($button, $action, $confirmMsg, $isDisabled);
return $this->getActionButtons()->addButton($button, $action, $confirmMsg, $isEnabled);
}

/**
Expand All @@ -374,11 +374,8 @@ public function addExecutorButton(ExecutorInterface $executor, ?Button $button =
if (!$confirmation) {
$confirmation = '';
}
$disabled = is_bool($executor->getAction()->enabled)
? !$executor->getAction()->enabled
: $executor->getAction()->enabled;

return $this->getActionButtons()->addButton($button, $executor, $confirmation, $disabled);
return $this->getActionButtons()->addButton($button, $executor, $confirmation, $executor->getAction()->enabled);
}

private function getActionButtons(): Table\Column\ActionButtons
Expand All @@ -396,13 +393,13 @@ private function getActionButtons(): Table\Column\ActionButtons
*
* @param View|string $view
* @param JsExpressionable|JsCallbackSetWithRowIdClosure $action
* @param bool|\Closure<T of Model>(T): bool $isDisabled
* @param bool|\Closure<T of Model>(T): bool $isEnabled
*
* @return View
*/
public function addActionMenuItem($view, $action = null, string $confirmMsg = '', $isDisabled = false)
public function addActionMenuItem($view, $action = null, string $confirmMsg = '', $isEnabled = true)
{
return $this->getActionMenu()->addActionMenuItem($view, $action, $confirmMsg, $isDisabled);
return $this->getActionMenu()->addActionMenuItem($view, $action, $confirmMsg, $isEnabled);
}

/**
Expand All @@ -417,11 +414,8 @@ public function addExecutorMenuItem(ExecutorInterface $executor)
if (!$confirmation) {
$confirmation = '';
}
$disabled = is_bool($executor->getAction()->enabled)
? !$executor->getAction()->enabled
: $executor->getAction()->enabled;

return $this->getActionMenu()->addActionMenuItem($item, $executor, $confirmation, $disabled);
return $this->getActionMenu()->addActionMenuItem($item, $executor, $confirmation, $executor->getAction()->enabled);
}

/**
Expand Down Expand Up @@ -500,14 +494,14 @@ public function addPopup($columnName, $popup = null, $icon = 'caret square down'
* @param string|array<mixed>|View $button
* @param string $title
* @param \Closure(View, mixed): void $callback
* @param array<string, string> $args extra URL argument for callback
* @param bool|\Closure<T of Model>(T): bool $isDisabled
* @param array<string, string> $args extra URL argument for callback
* @param bool|\Closure<T of Model>(T): bool $isEnabled
*
* @return View
*/
public function addModalAction($button, $title, \Closure $callback, $args = [], $isDisabled = false)
public function addModalAction($button, $title, \Closure $callback, $args = [], $isEnabled = true)
{
return $this->getActionButtons()->addModal($button, $title, $callback, $this, $args, $isDisabled);
return $this->getActionButtons()->addModal($button, $title, $callback, $this, $args, $isEnabled);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/Table/Column/ActionButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ protected function init(): void
*
* @param string|array<mixed>|View $button
* @param JsExpressionable|JsCallbackSetWithRowIdClosure|ExecutorInterface $action
* @param bool|\Closure<T of Model>(T): bool $isDisabled
* @param bool|\Closure<T of Model>(T): bool $isEnabled
*
* @return View
*/
public function addButton($button, $action = null, string $confirmMsg = '', $isDisabled = false)
public function addButton($button, $action = null, string $confirmMsg = '', $isEnabled = true)
{
$name = $this->name . '_button_' . (count($this->buttons) + 1);

Expand All @@ -60,10 +60,10 @@ public function addButton($button, $action = null, string $confirmMsg = '', $isD

$this->assertColumnViewNotInitialized($button);

if ($isDisabled === true) {
if ($isEnabled === false) {
$button->addClass('disabled');
} elseif ($isDisabled !== false) {
$this->isEnabledFxs[$name] = $isDisabled;
} elseif ($isEnabled !== true) {
$this->isEnabledFxs[$name] = $isEnabled;
}

$button->setApp($this->table->getApp());
Expand All @@ -88,15 +88,15 @@ public function addButton($button, $action = null, string $confirmMsg = '', $isD
* load contents through $callback. Will pass a virtual page.
*
* @param string|array<mixed>|View $button
* @param string|array<mixed> $defaults modal title or modal defaults array
* @param string|array<mixed> $defaults modal title or modal defaults array
* @param \Closure(View, mixed): void $callback
* @param View $owner
* @param array<string, string> $args
* @param bool|\Closure<T of Model>(T): bool $isDisabled
* @param bool|\Closure<T of Model>(T): bool $isEnabled
*
* @return View
*/
public function addModal($button, $defaults, \Closure $callback, $owner = null, $args = [], $isDisabled = false)
public function addModal($button, $defaults, \Closure $callback, $owner = null, $args = [], $isEnabled = true)
{
if ($owner === null) { // TODO explicit owner should not be needed
$owner = $this->getOwner()->getOwner();
Expand All @@ -113,7 +113,7 @@ public function addModal($button, $defaults, \Closure $callback, $owner = null,
$callback($t, $id);
});

return $this->addButton($button, $modal->jsShow(array_merge([$this->name => $this->getOwner()->jsRow()->data('id')], $args)), '', $isDisabled);
return $this->addButton($button, $modal->jsShow(array_merge([$this->name => $this->getOwner()->jsRow()->data('id')], $args)), '', $isEnabled);
}

#[\Override]
Expand Down
10 changes: 5 additions & 5 deletions src/Table/Column/ActionMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public function getTag(string $position, $attr, $value): string
*
* @param View|string $item
* @param JsExpressionable|JsCallbackSetWithRowIdClosure|ExecutorInterface $action
* @param bool|\Closure<T of Model>(T): bool $isDisabled
* @param bool|\Closure<T of Model>(T): bool $isEnabled
*
* @return View
*/
public function addActionMenuItem($item, $action = null, string $confirmMsg = '', $isDisabled = false)
public function addActionMenuItem($item, $action = null, string $confirmMsg = '', $isEnabled = true)
{
$name = $this->name . '_action_' . (count($this->items) + 1);

Expand All @@ -75,10 +75,10 @@ public function addActionMenuItem($item, $action = null, string $confirmMsg = ''

$item->addClass('{$_' . $name . '_disabled} i_' . $name);

if ($isDisabled === true) {
if ($isEnabled === false) {
$item->addClass('disabled');
} elseif ($isDisabled !== false) {
$this->isEnabledFxs[$name] = $isDisabled;
} elseif ($isEnabled !== true) {
$this->isEnabledFxs[$name] = $isEnabled;
}

if ($action !== null) {
Expand Down
20 changes: 10 additions & 10 deletions src/Table/Column/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ class Checkbox extends Table\Column
/** @var string */
public $class;

/**
* Return action which will calculate and return array of all checkbox IDs, e.g. [3, 5, 20].
*/
public function jsChecked(): JsExpressionable
{
return (new Jquery($this->table))->find('.checked.' . $this->class)->closest('tr')
->map(new JsFunction([], [new JsExpression('return $(this).data(\'id\')')]))
->get()->join(',');
}

#[\Override]
protected function init(): void
{
Expand Down Expand Up @@ -58,4 +48,14 @@ public function getDataCellTemplate(?Field $field = null): string
{
return $this->getApp()->getTag('div', ['class' => 'ui child fitted checkbox ' . $this->class], [['input/', ['type' => 'checkbox']]]);
}

/**
* Return action which will calculate and return array of all checkbox IDs, e.g. [3, 5, 20].
*/
public function jsChecked(): JsExpressionable
{
return (new Jquery($this->table))->find('.checked.' . $this->class)->closest('tr')
->map(new JsFunction([], [new JsExpression('return $(this).data(\'id\')')]))
->get()->join(',');
}
}

0 comments on commit 8d7a9e2

Please sign in to comment.