From a25b95f4022919e661367ce0317e9235cbd0e0b5 Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Sat, 21 Nov 2020 19:36:11 +0100 Subject: [PATCH] #533 - confirm selection and redirect to new transaction form template page --- src/main/resources/static/js/templates.js | 26 +++++++++++++++++++ .../templates/templates/templateFunctions.ftl | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/resources/static/js/templates.js b/src/main/resources/static/js/templates.js index 602a682cd..258afb984 100644 --- a/src/main/resources/static/js/templates.js +++ b/src/main/resources/static/js/templates.js @@ -120,6 +120,11 @@ function enableHotKeys() { handleKeyUpOrDown(false); }); + + Mousetrap.bind('enter', function() + { + confirmTemplateSelection(false); + }); } function handleKeyUpOrDown(isUp) @@ -214,4 +219,25 @@ function selectNextItemOnUp(templateItems, previousIndex) { selectItem(templateItems, previousIndex - 1); } +} + +function confirmTemplateSelection() +{ + let templateItems = document.querySelectorAll('.template-item:not(.hidden)'); + if(templateItems.length === 0) + { + selectedTemplateName = null; + return; + } + + let index = getIndexOfTemplateName(templateItems, selectedTemplateName); + let indexItemNoLongerInList = index === null; + let noItemSelected = selectedTemplateName === null; + + if(noItemSelected || indexItemNoLongerInList) + { + return; + } + + templateItems[index].getElementsByClassName('button-select-template')[0].click(); } \ No newline at end of file diff --git a/src/main/resources/templates/templates/templateFunctions.ftl b/src/main/resources/templates/templates/templateFunctions.ftl index 93b9c609e..2f15b605a 100644 --- a/src/main/resources/templates/templates/templateFunctions.ftl +++ b/src/main/resources/templates/templates/templateFunctions.ftl @@ -26,7 +26,7 @@ <div class="collapsible-header-button"> <a href="<@s.url '/templates/${template.ID?c}/edit'/>" class="btn-flat no-padding text-color"><i class="material-icons left no-margin">edit</i></a> <a href="<@s.url '/templates/${template.ID?c}/requestDelete'/>" class="btn-flat no-padding text-color"><i class="material-icons left no-margin">delete</i></a> - <a href="<@s.url '/templates/${template.ID?c}/select'/>" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left no-margin">note_add</i></a> + <a href="<@s.url '/templates/${template.ID?c}/select'/>" class="waves-effect waves-light btn budgetmaster-blue button-select-template"><i class="material-icons left no-margin">note_add</i></a> </div> </div> <div class="collapsible-body"> -- GitLab