From bb503268117942e5645c3f6c0b8e2ffac371c4a4 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 30 Nov 2018 16:29:00 +0000 Subject: [PATCH] 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 --- app/assets/javascripts/templateFolderForm.js | 36 ++++++++------------ app/templates/views/templates/choose.html | 7 ++-- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/templateFolderForm.js b/app/assets/javascripts/templateFolderForm.js index 8dc6a95eb..fde801504 100644 --- a/app/assets/javascripts/templateFolderForm.js +++ b/app/assets/javascripts/templateFolderForm.js @@ -41,8 +41,6 @@ this.addCancelButton = function($el) { let $cancel = $('') - // .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 ` -
- - -
- `; - }; + this.nothingSelectedButtons = ` +
+ + +
+ `; - this.itemsSelectedButtons = function() { - return ` -
- - -
- `; - }; + this.itemsSelectedButtons = ` +
+ + +
+ `; }; })(window.GOVUK.Modules); diff --git a/app/templates/views/templates/choose.html b/app/templates/views/templates/choose.html index adb6b19c2..8ff03b7b3 100644 --- a/app/templates/views/templates/choose.html +++ b/app/templates/views/templates/choose.html @@ -60,8 +60,9 @@ {% if current_user.has_permissions('manage_templates') %}
+ {% if not can_manage_folders %} Add new template - + {% endif %} {% if can_manage_folders and current_template_folder_id %} Manage {% 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 %}