Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add master checkbox to Grid #1921

Open
wants to merge 62 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
4794b95
add master checkbox in table header
mhuser Oct 28, 2022
df9f80c
ugly working mastercheckbox
mhuser Oct 29, 2022
cebaf59
Add indeterminate state to master checkbox
mhuser Oct 29, 2022
472db65
Merge branch 'atk4:develop' into add-master-checkbox-to-grid--addSele…
mhuser Nov 4, 2022
2542bfc
add behat test
mhuser Nov 5, 2022
7fd9d4b
Merge branch 'add-master-checkbox-to-grid--addSelection()' of https:/…
mhuser Nov 5, 2022
3574c18
Fix merge git mess
mhuser Nov 5, 2022
f72140d
Toast selection
mhuser Nov 5, 2022
ce62a0a
Behat with selection toast
mhuser Nov 5, 2022
5ed0e7a
syntax
mhuser Nov 5, 2022
6a837c6
make behat happy
mhuser Nov 5, 2022
8ead2ab
syntax
mhuser Nov 5, 2022
761c459
add selector for behat
mhuser Nov 5, 2022
eb5b5ee
account for grid id
mhuser Nov 5, 2022
86be84d
revert selector
mhuser Nov 5, 2022
5900356
use same class as crud menu behat
mhuser Nov 5, 2022
52ad16e
strip end blanks
mhuser Nov 5, 2022
ed8c541
correct row index
mhuser Nov 5, 2022
e942c77
js syntax
mhuser Nov 5, 2022
e4fa197
reduce ipp
mhuser Nov 5, 2022
1b18382
more js syntax
mhuser Nov 5, 2022
31a0f25
const $checkbox
mhuser Nov 5, 2022
404861f
fix EOL and text empty selection reliably
mhuser Nov 5, 2022
a1a1a7a
fix EOL
mhuser Nov 6, 2022
80ac317
make it npm friendly
mhuser Nov 8, 2022
df582bd
npm run build
mhuser Nov 8, 2022
337b5e9
npm build 2nd attempt
mhuser Nov 8, 2022
f413c40
is this missing ?
mhuser Nov 8, 2022
58bfe12
enforce LF against mysterious CRLF
mhuser Nov 8, 2022
98533cf
even '\r\n' moved to '\n'
mhuser Nov 8, 2022
ad89648
some more tweaks
mhuser Nov 8, 2022
5cc92ab
even more \r\n
mhuser Nov 8, 2022
6674fc5
one more
mhuser Nov 9, 2022
9bc4968
git reset --hard on Linux and npm run build
mhuser Nov 9, 2022
3d6dc3f
Merge branch 'atk4:develop' into add-master-checkbox-to-grid--addSele…
mhuser Nov 9, 2022
2b3c2ca
Merge branch 'atk4:develop' into add-master-checkbox-to-grid--addSele…
mhuser Nov 10, 2022
9e018e1
Merge branch 'develop'
mvorisek May 29, 2023
3fdd93a
fix merge
mvorisek May 29, 2023
5a18354
npm run build js
mhuser Aug 7, 2023
7118430
Merge remote-tracking branch 'upstream/develop' into add-master-check…
mhuser Aug 7, 2023
024b5f9
more npm build
mhuser Aug 7, 2023
245d5dc
even more npm build
mhuser Aug 7, 2023
da216b7
make behat happy
mhuser Aug 10, 2023
676f65d
Revert "make behat happy"
mhuser Aug 10, 2023
082ab90
fix slow checkbox on page load
mhuser Aug 10, 2023
8fb3949
checkout lf files and npm run build
mhuser Aug 10, 2023
159cf9b
fix checkbox column witdth
mhuser Aug 10, 2023
7166991
restore js/package-lock.json and js/package.json
mhuser Aug 10, 2023
9536060
npm run build again
mhuser Aug 10, 2023
2e244bb
fix class array
mhuser Aug 10, 2023
4eb182b
Merge branch 'develop'
mvorisek Sep 4, 2023
fe7d4ad
fix CS
mvorisek Sep 4, 2023
390cc22
Merge branch 'develop'
mvorisek Sep 23, 2023
8c4cc48
Merge branch 'develop'
mvorisek Sep 24, 2023
d85362a
Merge branch 'develop'
mvorisek Sep 30, 2023
a00ecac
Merge branch 'develop'
mvorisek Feb 1, 2024
2608a62
Merge branch 'develop'
mvorisek Feb 2, 2024
9469d03
fix performance issue after PR 2146
mvorisek Feb 2, 2024
ea43c69
Merge branch 'develop'
mvorisek Feb 2, 2024
fec1793
Merge branch 'develop'
mvorisek Mar 29, 2024
1b28c35
simplify/fix Behat
mvorisek Mar 29, 2024
ad4909d
Merge branch 'develop'
mvorisek May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions js/src/helpers/grid-checkbox.helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Simple helper to help displaying Fomantic-UI checkbox within an atk grid.
* The master checkbox in the header of the column enable to toggle all
* content checkboxes to check or uncheck. A partially checked master checkbox
* is displayed if appopriate.
*/
function InitGridMasterCheckbox() {
$('.table .master.checkbox').checkbox({
// check all children
onChecked: function() {
var
$childCheckbox = $(this).closest('.table').find('.child.checkbox')
;
$childCheckbox.checkbox('check');
},
// uncheck all children
onUnchecked: function() {
var
$childCheckbox = $(this).closest('.table').find('.child.checkbox')
;
$childCheckbox.checkbox('uncheck');
}
})
;
}

function InitGridChildCheckbox() {
$('.table .child.checkbox').checkbox({
// Fire on load to set parent value
fireOnInit : true,

// Change parent state on each child checkbox change
onChange : function() {
var
$listGroup = $(this).closest('.table'),
$parentCheckbox = $listGroup.find('.master.checkbox'),
$checkbox = $listGroup.find('.child.checkbox'),
allChecked = true,
allUnchecked = true
;
// check to see if all other siblings are checked or unchecked
$checkbox.each(function() {
if( $(this).checkbox('is checked') ) {
allUnchecked = false;
}
else {
allChecked = false;
}
});
// set parent checkbox state, but don't trigger its onChange callback
if(allChecked) {
$parentCheckbox.checkbox('set checked');
}
else if(allUnchecked) {
$parentCheckbox.checkbox('set unchecked');
}
else {
$parentCheckbox.checkbox('set indeterminate');
}
}
})
;
}
8 changes: 6 additions & 2 deletions src/Table/Column/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected function init(): void
if (!$this->class) {
$this->class = 'cb_' . $this->shortName;
}
$this->getApp()->requireJs($this->getApp()->cdn['atk'] . '/../js/src/helpers/grid-checkbox.helper.js');
mvorisek marked this conversation as resolved.
Show resolved Hide resolved
}

public function getHeaderCellHtml(Field $field = null, $value = null): string
Expand All @@ -46,12 +47,15 @@ public function getHeaderCellHtml(Field $field = null, $value = null): string
->addMoreInfo('field', $field);
}
$this->table->js(true)->find('.' . $this->class)->checkbox();
$this->table->js(true, new JsExpression('InitGridMasterCheckbox();'));

return parent::getHeaderCellHtml($field);
return $this->getTag('head', [['div', ['class' => 'ui master checkbox ' . $this->class], [['input/', ['type' => 'checkbox']]]]], []);
mvorisek marked this conversation as resolved.
Show resolved Hide resolved
}

public function getDataCellTemplate(Field $field = null): string
{
return $this->getApp()->getTag('div', ['class' => 'ui checkbox ' . $this->class], [['input/', ['type' => 'checkbox']]]);
$this->table->js(true, new JsExpression('InitGridChildCheckbox();'));

return $this->getApp()->getTag('div', ['class' => 'ui child checkbox ' . $this->class], [['input/', ['type' => 'checkbox']]]);
}
}
28 changes: 28 additions & 0 deletions tests-behat/grid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,31 @@ Feature: Grid
When I click using selector "xpath(//div[@id='grid']//tr[2]//a)"
Then No toast should be displayed
Then PATCH MINK the url should match "~_unit-test/grid-rowclick.php#test~"

Scenario: master checkbox
Given I am on "_unit-test/grid-rowclick.php"
When I click using selector "xpath(//div[@id='grid']//tr[2]//div.ui.child.checkbox)"
Then No toast should be displayed
mhuser marked this conversation as resolved.
Show resolved Hide resolved
When I click using selector "xpath(//div[@id='grid']//tr[1]//div.ui.master.checkbox)"
Then No toast should be displayed
When I click using selector "xpath(//div[@id='grid']//tr[1]//div.ui.master.checkbox)"
Then No toast should be displayed

Scenario: dynamic scroll
mhuser marked this conversation as resolved.
Show resolved Hide resolved
Given I am on "interactive/scroll-lister.php"
Then I should see "Argentina"
Then I should not see "Denmark"
When I scroll to bottom
Then I should see "Denmark"
When I scroll to bottom
When I scroll to bottom
When I scroll to bottom
When I scroll to bottom
When I scroll to bottom
When I scroll to bottom
Then I should not see "South Sudan"
When I scroll to bottom
Then I should see "South Sudan"
When I scroll to bottom
Then I should see "South Sudan"
Then I should see "Denmark"