From af8de93c301eab51c939dd0be9881a3e5e467947 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 30 Nov 2018 12:02:51 +0000 Subject: [PATCH] add cancel buttons to template folder flow when cancelled, clears any data inputted into the sub-form action, and then uses an icky hack to go back to the buttons, by changing the state to "nothingSelectedButtons", and then pretending a checkbox was clicked so it works out which actions to show and re-renders. --- app/assets/javascripts/templateFolderForm.js | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/assets/javascripts/templateFolderForm.js b/app/assets/javascripts/templateFolderForm.js index 961fcdfcc..8dc6a95eb 100644 --- a/app/assets/javascripts/templateFolderForm.js +++ b/app/assets/javascripts/templateFolderForm.js @@ -24,6 +24,12 @@ }; + // cancel buttons only relevant if JS enabled, so + this.addCancelButton(this.states.moveToFolderRadios); + this.addCancelButton(this.states.moveToNewFolderForm); + this.addCancelButton(this.states.addNewFolderForm); + this.addCancelButton(this.states.addNewTemplateForm); + // first off show the new template / new folder buttons this.currentState = 'nothingSelectedButtons'; @@ -33,6 +39,26 @@ this.render(); }; + this.addCancelButton = function($el) { + let $cancel = $('') + // .addClass('api-key') + // .css('min-height', $component.height()) + .html('Cancel') + .click((event) => { + event.preventDefault(); + // clear existing data + $el.find('input:radio').prop('checked', false); + $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 = 'nothingSelectedButtons'; + this.templateFolderCheckboxChanged(); + }); + + $el.append($cancel); + }; + this.actionButtonClicked = function(event) { event.preventDefault(); this.currentState = $(event.currentTarget).val();