remove extra add template button and cleanup of html

only remove the add template button if they have the folder service
permission (thus can see the add button at the bottom).

Also make some unnecessary functions into strings in the js, and
remove some commented out code
This commit is contained in:
Leo Hemsted
2018-11-30 16:29:00 +00:00
parent af8de93c30
commit bb50326811
2 changed files with 18 additions and 25 deletions

View File

@@ -41,8 +41,6 @@
this.addCancelButton = function($el) {
let $cancel = $('<a></a>')
// .addClass('api-key')
// .css('min-height', $component.height())
.html('Cancel')
.click((event) => {
event.preventDefault();
@@ -70,8 +68,10 @@
let numSelected = this.countSelectedCheckboxes();
if (this.currentState === 'nothingSelectedButtons' && numSelected !== 0) {
// user has just selected first item
this.currentState = 'itemsSelectedButtons';
} else if (this.currentState === 'itemsSelectedButtons' && numSelected === 0) {
// user has just deselected last item
this.currentState = 'nothingSelectedButtons';
}
@@ -79,35 +79,29 @@
};
this.countSelectedCheckboxes = function() {
return this.$form.find('input[type=checkbox]:checked').length;
return this.$form.find('input:checkbox:checked').length;
};
this.render = function() {
let numSelected = this.countSelectedCheckboxes();
// detach everything, unless they are the currentState
Object.entries(this.states).forEach(
([state, $el]) => (state === this.currentState ? this.$stickyBottom.append($el) : $el.detach())
);
};
this.nothingSelectedButtons = function() {
return `
<div id="nothing_selected">
<button class="button-secondary" value="addNewTemplateForm">New template</button>
<button class="button-secondary" value="addNewFolderForm">New folder</button>
</div>
`;
};
this.nothingSelectedButtons = `
<div id="nothing_selected">
<button class="button-secondary" value="addNewTemplateForm">New template</button>
<button class="button-secondary" value="addNewFolderForm">New folder</button>
</div>
`;
this.itemsSelectedButtons = function() {
return `
<div id="items_selected">
<button class="button-secondary" value="moveToFolderRadios">Move</button>
<button class="button-secondary" value="moveToNewFolderForm">Add to a new folder</button>
</div>
`;
};
this.itemsSelectedButtons = `
<div id="items_selected">
<button class="button-secondary" value="moveToFolderRadios">Move</button>
<button class="button-secondary" value="moveToNewFolderForm">Add to a new folder</button>
</div>
`;
};
})(window.GOVUK.Modules);

View File

@@ -60,8 +60,9 @@
</div>
{% if current_user.has_permissions('manage_templates') %}
<div class="column-one-third">
{% if not can_manage_folders %}
<a href="{{ url_for('.add_template_by_type', service_id=current_service.id, template_folder_id=current_template_folder_id) }}" class="button align-with-heading">Add new template</a>
{% endif %}
{% if can_manage_folders and current_template_folder_id %}
<a href="{{ url_for('.manage_template_folder', service_id=current_service.id, template_folder_id=current_template_folder_id) }}" class="align-with-heading">Manage</a>
{% endif %}
@@ -80,9 +81,7 @@
{% if can_manage_folders %}
{% call form_wrapper(module='template-folder-form') %}
{% include 'views/templates/_template_list.html' %}
{% with templates=templates, template_folders=template_folders, templates_and_folders_form=templates_and_folders_form %}
{% include 'views/templates/_move_to.html' %}
{% endwith %}
{% include 'views/templates/_move_to.html' %}
{% endcall %}
{% else %}