start js for template folder form

have a bunch of separate elements within the sticky_template_forms div
that we hide or show based on button presses and such. This commit just
sets up the class - it doesn't actually deal with button presses or
checkboxes etc yet.
This commit is contained in:
Leo Hemsted
2018-11-28 17:40:54 +00:00
parent 1a5ebb3e62
commit 370f2527ff
4 changed files with 62 additions and 1 deletions

View File

@@ -0,0 +1,58 @@
(function(Modules) {
"use strict";
Modules.TemplateFolderForm = function() {
this.start = function(templateFolderForm) {
this.$form = $(templateFolderForm);
this.$stickyBottom = this.$form.find('#sticky_template_forms');
this.$stickyBottom.append(this.nothingSelectedButtons);
this.$stickyBottom.append(this.itemsSelectedButtons);
// all the diff states that we want to show or hide
this.states = {
nothingSelectedButtons: this.$form.find('#nothing_selected'),
itemsSelectedButtons: this.$form.find('#items_selected'),
moveToFolderRadios: this.$form.find('#move_to_folder_radios'),
addNewFolderName: this.$form.find('#add_new_folder_form'),
moveToNewFolderName: this.$form.find('#move_to_new_folder_form'),
};
this.render();
};
this.countSelectedCheckboxes = function() {
return this.$form.find('input[type=checkbox]:checked').length;
};
this.render = function() {
let numSelected = this.countSelectedCheckboxes();
// hide everything
Object.values(this.states).forEach($el => $el.hide());
this.states.nothingSelectedButtons.show();
};
this.nothingSelectedButtons = function() {
return `
<div id="nothing_selected">
<button class="button-secondary" value="new_template">New template</button>
<button class="button-secondary" value="new_folder">New folder</button>
</div>
`;
};
this.itemsSelectedButtons = function() {
return `
<div id="items_selected">
<button class="button-secondary" value="move_to_folder">Move</button>
<button class="button-secondary" value="add_to_new_folder">Add to a new folder</button>
</div>
`;
};
};
})(window.GOVUK.Modules);