mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-24 11:11:15 -04:00
change actions based on which checkboxes are selected
if action buttons are shown (either the nothing selected actions or the stuff selected actions), when a checkbox is selected or deselected, count how many checkboxes are selected. If it's zero, then show the new template/folder buttons, if it's non-zero, then show the move options. Under the hood, we set the `currentState` variable, then the render fn shows that element and hides all others.
This commit is contained in:
@@ -19,6 +19,22 @@
|
||||
addNewFolderName: this.$form.find('#add_new_folder_form'),
|
||||
moveToNewFolderName: this.$form.find('#move_to_new_folder_form'),
|
||||
};
|
||||
// first off show the new template / new folder buttons
|
||||
this.currentState = 'nothingSelectedButtons';
|
||||
|
||||
this.$form.on('change', 'input[type=checkbox]', () => this.templateFolderCheckboxChanged());
|
||||
|
||||
this.render();
|
||||
};
|
||||
|
||||
this.templateFolderCheckboxChanged = function(event) {
|
||||
let numSelected = this.countSelectedCheckboxes();
|
||||
|
||||
if (this.currentState === 'nothingSelectedButtons' && numSelected !== 0) {
|
||||
this.currentState = 'itemsSelectedButtons';
|
||||
} else if (this.currentState === 'itemsSelectedButtons' && numSelected === 0) {
|
||||
this.currentState = 'nothingSelectedButtons';
|
||||
}
|
||||
|
||||
this.render();
|
||||
};
|
||||
@@ -30,10 +46,8 @@
|
||||
this.render = function() {
|
||||
let numSelected = this.countSelectedCheckboxes();
|
||||
|
||||
// hide everything
|
||||
Object.values(this.states).forEach($el => $el.hide());
|
||||
|
||||
this.states.nothingSelectedButtons.show();
|
||||
// hide everything, unless they are the currentState
|
||||
Object.entries(this.states).forEach(([state, $el]) => (state === this.currentState ? $el.show() : $el.hide()));
|
||||
};
|
||||
|
||||
this.nothingSelectedButtons = function() {
|
||||
|
||||
Reference in New Issue
Block a user