mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 11:23:48 -05:00
if state is unknown on load, then work out which action buttons to show
previously, it'd always show nothing-selected-buttons - however, if some items were checked (due to being selected previously, and loading with a form error message), it would be showing the wrong buttons. Now, if the state is unknown, work out which state to show by counting checkboxes, the same as when someone presses the cancel button.
This commit is contained in:
@@ -25,8 +25,10 @@
|
||||
this.states.filter(state => state.cancellable).forEach((x) => this.addCancelButton(x));
|
||||
|
||||
// first off show the new template / new folder buttons
|
||||
let prevState = this.$form.data('prev-state') || 'unknown';
|
||||
this.currentState = (prevState === 'unknown') ? 'nothing-selected-buttons' : prevState;
|
||||
this.currentState = this.$form.data('prev-state') || 'unknown';
|
||||
if (this.currentState === 'unknown') {
|
||||
this.selectActionButtons();
|
||||
}
|
||||
|
||||
this.$form.on('click', 'button.button-secondary', (event) => this.actionButtonClicked(event));
|
||||
this.$form.on('change', 'input[type=checkbox]', () => this.templateFolderCheckboxChanged());
|
||||
@@ -43,15 +45,21 @@
|
||||
state.$el.find('input:radio').prop('checked', false);
|
||||
state.$el.find('input:text').val('');
|
||||
|
||||
// gross hack - pretend we're in the choose actions state, then pretend a checkbox was clicked to work out
|
||||
// whether to show zero or non-zero options. This calls a render at the end
|
||||
this.currentState = 'nothing-selected-buttons';
|
||||
this.templateFolderCheckboxChanged();
|
||||
// go back to action buttons
|
||||
this.selectActionButtons();
|
||||
});
|
||||
|
||||
state.$el.append($cancel);
|
||||
};
|
||||
|
||||
this.selectActionButtons = function () {
|
||||
// If we want to show one of the grey choose actions state, we can pretend we're in the choose actions state,
|
||||
// and then pretend a checkbox was clicked to work out whether to show zero or non-zero options.
|
||||
// This calls a render at the end
|
||||
this.currentState = 'nothing-selected-buttons';
|
||||
this.templateFolderCheckboxChanged();
|
||||
};
|
||||
|
||||
this.actionButtonClicked = function(event) {
|
||||
event.preventDefault();
|
||||
this.currentState = $(event.currentTarget).val();
|
||||
|
||||
Reference in New Issue
Block a user