From cb0ac2acecb266bb624e300384daa565a82a0a11 Mon Sep 17 00:00:00 2001
From: Robert Goldmann <deadlocker@gmx.de>
Date: Mon, 27 Sep 2021 23:08:33 +0200
Subject: [PATCH] #596 - new normal transaction page: addes button to add
 repeating options

---
 .../resources/languages/base_de.properties     |  2 ++
 .../resources/languages/base_en.properties     |  2 ++
 src/main/resources/static/js/transactions.js   |  9 ++++++++-
 .../transactions/newTransactionMacros.ftl      | 18 +++++++++++-------
 .../transactions/newTransactionNormal.ftl      |  9 +++++++++
 5 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/src/main/resources/languages/base_de.properties b/src/main/resources/languages/base_de.properties
index bfe443661..9383131d5 100644
--- a/src/main/resources/languages/base_de.properties
+++ b/src/main/resources/languages/base_de.properties
@@ -305,6 +305,8 @@ transaction.new.label.transfer.account=Zielkonto
 transaction.new.label.repeating=Wiederholung
 transaction.new.label.repeating.all=Alle
 
+repeating.button=Wiederholung hinzufügen
+
 repeating.modifier.days=Tage
 repeating.modifier.months=Monate
 repeating.modifier.years=Jahre
diff --git a/src/main/resources/languages/base_en.properties b/src/main/resources/languages/base_en.properties
index cf7c86c5c..c212409bb 100644
--- a/src/main/resources/languages/base_en.properties
+++ b/src/main/resources/languages/base_en.properties
@@ -306,6 +306,8 @@ transaction.new.label.transfer.account=Destination Account
 transaction.new.label.repeating=Repeating
 transaction.new.label.repeating.all=Every
 
+repeating.button=Add repetition
+
 repeating.modifier.days=Days
 repeating.modifier.months=Months
 repeating.modifier.years=Years
diff --git a/src/main/resources/static/js/transactions.js b/src/main/resources/static/js/transactions.js
index 9a4bc75c8..282bab801 100644
--- a/src/main/resources/static/js/transactions.js
+++ b/src/main/resources/static/js/transactions.js
@@ -263,6 +263,13 @@ $(document).ready(function()
     {
         fetchAndShowModalContent(this.dataset.url, '#deleteModalContainerOnDemand', '#modalConfirmDelete', function(){});
     });
+
+    $('#button-transaction-add-repeating-option').click(function()
+    {
+        document.getElementById('button-transaction-add-repeating-option').classList.toggle('hidden', true);
+        document.getElementsByName('isRepeating')[0].value = 1;
+        document.getElementById('transaction-repeating-option').classList.toggle('hidden', false);
+    });
 });
 
 function isHidden(el)
@@ -403,7 +410,7 @@ function validateForm(allowEmptyAmount = false)
         }
     }
 
-    if($(transactionRepeatingModifierID).length)
+    if(document.getElementsByName('isRepeating')[0].value === '1')
     {
         if(!validateNumber($(transactionRepeatingModifierID).val(), transactionRepeatingModifierID.substr(1), "hidden-" + transactionRepeatingModifierID.substr(1), numberValidationMessage, REGEX_NUMBER))
         {
diff --git a/src/main/resources/templates/transactions/newTransactionMacros.ftl b/src/main/resources/templates/transactions/newTransactionMacros.ftl
index 3931e0b5c..75579718e 100644
--- a/src/main/resources/templates/transactions/newTransactionMacros.ftl
+++ b/src/main/resources/templates/transactions/newTransactionMacros.ftl
@@ -154,16 +154,20 @@
 </#macro>
 
 <#macro transactionRepeating transaction currentDate>
-    <div class="row">
-        <div class="col s12 m12 l8 offset-l2">
-            <i class="material-icons icon-repeating">repeat</i>
-            ${locale.getString("transaction.new.label.repeating")}
+    <div class="hidden" id="transaction-repeating-option">
+        <input type="hidden" name="isRepeating" value="<#if transaction.getRepeatingOption()??>1}</#if>">
+
+        <div class="row">
+            <div class="col s12 m12 l8 offset-l2">
+                <i class="material-icons icon-repeating">repeat</i>
+                ${locale.getString("transaction.new.label.repeating")}
+            </div>
         </div>
-    </div>
 
-    <@newTransactionMacros.repeatingModifier transaction/>
+        <@repeatingModifier transaction/>
 
-    <@newTransactionMacros.repeatingEndOption transaction currentDate/>
+        <@repeatingEndOption transaction currentDate/>
+    </div>
 </#macro>
 
 <#macro repeatingModifier transaction>
diff --git a/src/main/resources/templates/transactions/newTransactionNormal.ftl b/src/main/resources/templates/transactions/newTransactionNormal.ftl
index bc29ed0f4..154f59ae4 100644
--- a/src/main/resources/templates/transactions/newTransactionNormal.ftl
+++ b/src/main/resources/templates/transactions/newTransactionNormal.ftl
@@ -72,6 +72,15 @@
                             </#if>
                             <@customSelectMacros.customAccountSelect "account-select-wrapper" "account" accounts selectedAccount "col s12 m12 l8 offset-l2" locale.getString("transaction.new.label.account") "transaction-account"/>
 
+                            <div class="row">
+                                <div class="col s12 center-align">
+                                    <@header.buttonLink url='' icon='repeat' localizationKey='repeating.button' id='button-transaction-add-repeating-option' color='background-blue-baby' noUrl=true classes="text-black"/>
+                                </div>
+                            </div>
+
+                            <#-- repeating options -->
+                            <@newTransactionMacros.transactionRepeating transaction currentDate/>
+
                             <#-- buttons -->
                             <@newTransactionMacros.buttons "/transactions"/>
                             <@newTransactionMacros.buttonTransactionActions isEdit true previousType??/>
-- 
GitLab