I’m trying to add two buttons in the Manage Membership form for Display Groups.
This because we have layouts we would like to schedule on most of the displays, but not all. So instead of having to click every single display we would like to do this all in once.
I created one button to select all the displays, and one to deselect them all.
I added the name ‘member’ to the checkboxes and get them all to select using the following code:
function check_all() {
var checkboxes = document.getElementsByName('member');
checkboxes = [...checkboxes];
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = true;
}
}
When saving the form, the checked items aren’t saved.
I saw further on in the code in displaygroup-page.twig that there is a change function for checkboxes.
control.on("change", ".checkbox", function() {
// Update our global members data with this
var memberId = $(this).data().memberId;
var memberType = $(this).data().memberType;
var value = $(this).is(":checked");
if (memberType == "display")
control.data().members.displays[memberId] = (value) ? 1 : 0;
else if (memberType == "displayGroup")
control.data().members.displayGroups[memberId] = (value) ? 1 : 0;
});
You’d need to trigger the “change” action ie something like $("input.checkbox:checkbox").prop("checked", true).trigger("change");
Perhaps you’ve noticed that there are tabs for Display and Display Group assignment, as such you will want to make the selector only select the checkbox from the page that interest you - you could add additional class to the checkbox input say display and do
For deselect all it can be the same just with false instead of true
the trigger('change') will fire the on change function and with that when you save the form displays should be correctly assigned.
You could also modify your existing code to do the same or do it in many other possible ways.
It’s not something I’ve extensively tested, but hopefully it will be of help to you.
As a side note - it would be good for you to have custom theme with /views folder and the displaygroup-page.twig in it and modify that page instead of making changes to the core code - as it might be problematic on CMS upgrades.
You need to add code to two twig pages. Like Peter mentioned it’s best to make a custom theme.
Copy the pages displaygroup-page.twig and displaygroup-form-members.twig to the /views folder.
On page displaygroup-page.twig do the following:
In function displayGroupMembersFormOpen(dialog) look for var table displaysMemberTable.
At var checkBox add name=“member” to the input.
Below the function displayGroupMembersFormOpen(dialog) add the following:
function check_all() {
var checkboxes = document.getElementsByName('member');
checkboxes = [...checkboxes];
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = true;
$(".checkbox").trigger("change");
}
}
function uncheck_all() {
var uncheckboxes = document.getElementsByName('member');
uncheckboxes = [...uncheckboxes];
for (var i = 0; i < uncheckboxes.length; i++) {
uncheckboxes[i].checked = false;
$(".checkbox").change();
}
}
Add the following in displaygroup-form-members.twig: