-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
238 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atk4\Ui\Demos; | ||
|
||
use Atk4\Ui\App; | ||
use Atk4\Ui\Grid; | ||
use Atk4\Ui\Js\Jquery; | ||
use Atk4\Ui\Js\JsToast; | ||
|
||
/** @var App $app */ | ||
require_once __DIR__ . '/../init-app.php'; | ||
|
||
$model = new Country($app->db); | ||
$grid = Grid::addTo($app, ['ipp' => 5]); | ||
$grid->setModel($model); | ||
|
||
$grid->addSelection(); | ||
|
||
$grid->addBulkAction('Show selected', static function (Jquery $j, array $ids) use ($grid) { | ||
return new JsToast('Selected: ' . implode(', ', array_map(static fn ($id) => $grid->getApp()->uiPersistence->typecastSaveField($grid->model->getIdField(), $id), $ids)) . '#'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import $ from 'external/jquery'; | ||
|
||
function recomputeMasterCheckbox($table) { | ||
const $masterCheckbox = $table.find('.master.checkbox'); | ||
const $childCheckbox = $table.find('.child.checkbox'); | ||
|
||
const checkedCount = $childCheckbox.filter('.checked').length; | ||
const allChecked = checkedCount === $childCheckbox.length; | ||
const allUnchecked = checkedCount === 0; | ||
|
||
if (allChecked) { | ||
$masterCheckbox.checkbox('set checked'); | ||
} else if (allUnchecked) { | ||
$masterCheckbox.checkbox('set unchecked'); | ||
} else { | ||
$masterCheckbox.checkbox('set indeterminate'); | ||
} | ||
} | ||
|
||
export default { | ||
/** | ||
* Simple helper for master and child checkboxes connection. | ||
*/ | ||
setupMasterCheckbox: function (tableSelector) { | ||
const $table = $(tableSelector); | ||
let skipRecomputeMasterCheckbox = false; | ||
|
||
$table.find('.master.checkbox').checkbox({ | ||
onChecked: function () { | ||
const $childCheckbox = $table.find('.child.checkbox'); | ||
|
||
skipRecomputeMasterCheckbox = true; | ||
try { | ||
$childCheckbox.checkbox('check'); | ||
} finally { | ||
skipRecomputeMasterCheckbox = false; | ||
} | ||
}, | ||
|
||
onUnchecked: function () { | ||
const $childCheckbox = $table.find('.child.checkbox'); | ||
|
||
skipRecomputeMasterCheckbox = true; | ||
try { | ||
$childCheckbox.checkbox('uncheck'); | ||
} finally { | ||
skipRecomputeMasterCheckbox = false; | ||
} | ||
}, | ||
}); | ||
|
||
$table.find('.child.checkbox').checkbox({ | ||
onChange: function () { | ||
if (skipRecomputeMasterCheckbox) { | ||
return; | ||
} | ||
|
||
recomputeMasterCheckbox($table); | ||
}, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters