diff --git a/src/main/resources/static/js/templates.js b/src/main/resources/static/js/templates.js index 602a682cd8c125f4d06901683b427c0927b48814..258afb984f1fbcf651e8a7c6dd841d29f1dae2ab 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 93b9c609eb1daa4400893c4443d7a3c8fe139439..2f15b605a847382241a069e39f257ce40cff13d5 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">