diff --git a/BudgetMasterServer/src/main/resources/static/js/transactions.js b/BudgetMasterServer/src/main/resources/static/js/transactions.js index 46d68433388ffcbbb2c5ea36922d89d1b118761d..ccb8fe3810a71539258b40ef55935f56015412ef 100644 --- a/BudgetMasterServer/src/main/resources/static/js/transactions.js +++ b/BudgetMasterServer/src/main/resources/static/js/transactions.js @@ -381,12 +381,12 @@ function convertDateWithoutDots(dateString) return dateString.substr(0, 2) + '.' + dateString.substr(2, 2) + '.' + dateString.substr(4, yearLength); } -function validateForm(allowEmptyAmount = false, skipKeywordCheck = false) +function validateForm(isSaveAndContinue = false, allowEmptyAmount = false, skipKeywordCheck = false) { // name (keyword check) if(!skipKeywordCheck) { - let nameContainsKeywords = checkNameForKeywords(); + let nameContainsKeywords = checkNameForKeywords(isSaveAndContinue); if(nameContainsKeywords) { return false; @@ -477,7 +477,7 @@ function validateForm(allowEmptyAmount = false, skipKeywordCheck = false) return true; } -function checkNameForKeywords() +function checkNameForKeywords(isSaveAndContinue) { let url = document.getElementById('keywordCheckUrl').dataset.url; let transactionName = document.getElementById('transaction-name').value; @@ -495,7 +495,7 @@ function checkNameForKeywords() { // name contains at least one keyword result = true; - openKeywordWarningModal(data); + openKeywordWarningModal(data, isSaveAndContinue); } else { @@ -511,7 +511,7 @@ function checkNameForKeywords() return result; } -function openKeywordWarningModal(htmlData) +function openKeywordWarningModal(htmlData, isSaveAndContinue) { let modalID = '#modalTransactionNameKeywordWarning'; @@ -524,21 +524,30 @@ function openKeywordWarningModal(htmlData) { $(modalID).modal('close'); + let button; + if(isSaveAndContinue) + { + button = document.getElementById('button-save-transaction-and-continue'); + } + else + { + button = document.getElementById('button-save-transaction'); + } + let allowEmptyAmount = document.getElementById('template-name') !== null; - // rebind onsubmit function to skip keyword check once - document.getElementById('mainForm').onsubmit = function() + // rebind onclick function of button to skip keyword check once + button.onclick = function() { - return validateForm(allowEmptyAmount, true); + return validateForm(isSaveAndContinue, allowEmptyAmount, true); }; - // TODO differentiate between user clicked button "save" or "save and continue" before - document.getElementById('button-save-transaction').click(); + button.click(); - // reset onsubmit function in case user edits transaction name too after fixing validation errors - document.getElementById('mainForm').onsubmit = function() + // reset onsubmit function of button in case user edits transaction name too after fixing validation errors + button.onclick = function() { - return validateForm(allowEmptyAmount, false); + return validateForm(isSaveAndContinue, allowEmptyAmount, false); }; }); } diff --git a/BudgetMasterServer/src/main/resources/templates/helpers/header.ftl b/BudgetMasterServer/src/main/resources/templates/helpers/header.ftl index d25b1bb0a64be6b1c2250ab013b07b0f4cb08356..3b1c9a7be53d068222aeb0d506232d08f0fc5a9e 100644 --- a/BudgetMasterServer/src/main/resources/templates/helpers/header.ftl +++ b/BudgetMasterServer/src/main/resources/templates/helpers/header.ftl @@ -130,8 +130,8 @@ </a> </#macro> -<#macro buttonSubmit name icon localizationKey id="" color="background-blue" classes="" disabled=false formaction="" value=""> - <button id="${id}" class="btn waves-effect waves-light ${color} ${classes}" type="submit" name="${name}" <#if disabled>disabled</#if> <#if formaction?has_content>formaction="<@s.url formaction/>"</#if> <#if value?has_content>value="${value}"</#if>> +<#macro buttonSubmit name icon localizationKey id="" color="background-blue" classes="" disabled=false formaction="" value="" onclick=""> + <button id="${id}" class="btn waves-effect waves-light ${color} ${classes}" type="submit" name="${name}" <#if disabled>disabled</#if> <#if formaction?has_content>formaction="<@s.url formaction/>"</#if> <#if value?has_content>value="${value}"</#if> <#if onclick??>onclick="${onclick}"</#if>> <i class="material-icons left <#if !localizationKey?has_content>no-margin</#if>">${icon}</i><#if localizationKey?has_content>${locale.getString(localizationKey)}</#if> </button> </#macro> diff --git a/BudgetMasterServer/src/main/resources/templates/templates/newTemplate.ftl b/BudgetMasterServer/src/main/resources/templates/templates/newTemplate.ftl index c0d5c73e2763eb5b37a517bca2b040fe0c3b5671..497073d3de65ad22451121f2b3b61916b97143da 100644 --- a/BudgetMasterServer/src/main/resources/templates/templates/newTemplate.ftl +++ b/BudgetMasterServer/src/main/resources/templates/templates/newTemplate.ftl @@ -36,7 +36,7 @@ <@header.content> <div class="container"> <#import "../helpers/validation.ftl" as validation> - <form id="mainForm" name="NewTemplate" action="<@s.url '/templates/newTemplate'/>" method="post" onsubmit="return validateForm(true)"> + <form id="mainForm" name="NewTemplate" action="<@s.url '/templates/newTemplate'/>" method="post"> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <input type="hidden" name="ID" value="<#if template.getID()??>${template.getID()?c}</#if>"> <input type="hidden" name="templateGroup" value="<#if template.getTemplateGroup()??>${template.getTemplateGroup().getID()?c}</#if>"> diff --git a/BudgetMasterServer/src/main/resources/templates/transactions/newTransactionMacros.ftl b/BudgetMasterServer/src/main/resources/templates/transactions/newTransactionMacros.ftl index 0f09255a75bde1a511858b2f5ab4fe57d498ff42..6d871b8912060e83ddaff98ef57bd736c4d998e8 100644 --- a/BudgetMasterServer/src/main/resources/templates/transactions/newTransactionMacros.ftl +++ b/BudgetMasterServer/src/main/resources/templates/transactions/newTransactionMacros.ftl @@ -346,11 +346,11 @@ </#macro> <#macro buttonSave> - <@header.buttonSubmit name='action' icon='save' localizationKey='save' id='button-save-transaction' color='green'/> + <@header.buttonSubmit name='action' icon='save' localizationKey='save' id='button-save-transaction' color='green' onclick='return validateForm(false, false, false)'/> </#macro> <#macro buttonSaveAndContinue> - <@header.buttonSubmit name='action' icon='save' localizationKey='saveAndContinue' id='button-save-transaction-and-continue' value='continue'/> + <@header.buttonSubmit name='action' icon='save' localizationKey='saveAndContinue' id='button-save-transaction-and-continue' value='continue' onclick='return validateForm(true, false, false)'/> </#macro> <#macro buttonTransactionActions canChangeType canCreateTemplate changeTypeInProgress> diff --git a/BudgetMasterServer/src/main/resources/templates/transactions/newTransactionNormal.ftl b/BudgetMasterServer/src/main/resources/templates/transactions/newTransactionNormal.ftl index cf77495d3a8720a20308e7b1e8393646d559e06e..c529aaa42442ccf7b000bf1055981797d2c99919 100644 --- a/BudgetMasterServer/src/main/resources/templates/transactions/newTransactionNormal.ftl +++ b/BudgetMasterServer/src/main/resources/templates/transactions/newTransactionNormal.ftl @@ -33,7 +33,7 @@ <@header.content> <div class="container"> <#import "../helpers/validation.ftl" as validation> - <form id="mainForm" name="NewTransaction" action="<@s.url '/transactions/newTransaction'/>" method="post" onsubmit="return validateForm()"> + <form id="mainForm" name="NewTransaction" action="<@s.url '/transactions/newTransaction'/>" method="post"> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <!-- only set ID for transactions not templates, otherwise the input is filled with the template ID and saving the transaction may then override an existing transactions if the ID is also already used in transactions table -->