From 79bc3d47ac1a61c39dd9e843565d99c7184654d6 Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Sun, 23 Jun 2024 23:03:51 +0200 Subject: [PATCH] #764 - add new input field for account end date --- .../accounts/AccountController.java | 6 ++++ .../resources/languages/base_de.properties | 1 + .../resources/languages/base_en.properties | 1 + .../src/main/resources/static/js/accounts.js | 31 +++++++++++++++++++ .../templates/accounts/newAccount.ftl | 26 ++++++++++++++++ 5 files changed, 65 insertions(+) diff --git a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountController.java b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountController.java index 123d873c2..2467ddf87 100644 --- a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountController.java +++ b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountController.java @@ -19,7 +19,9 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.WebRequest; import jakarta.servlet.http.HttpServletRequest; + import java.text.MessageFormat; +import java.time.LocalDate; import java.util.List; import java.util.Optional; @@ -39,6 +41,7 @@ public class AccountController extends BaseController public static final String FONTAWESOME_ICONS = "fontawesomeIcons"; public static final String ERROR = "error"; public static final String NOTIFICATIONS = "notifications"; + public static final String TODAY = "today"; } private static class ReturnValues @@ -148,6 +151,7 @@ public class AccountController extends BaseController model.addAttribute(ModelAttributes.ONE_ENTITY, emptyAccount); model.addAttribute(ModelAttributes.AVAILABLE_ACCOUNT_STATES, AccountState.values()); model.addAttribute(ModelAttributes.FONTAWESOME_ICONS, FontAwesomeIcons.ICONS); + model.addAttribute(ModelAttributes.TODAY, LocalDate.now()); return ReturnValues.NEW_ENTITY; } @@ -163,6 +167,7 @@ public class AccountController extends BaseController model.addAttribute(ModelAttributes.ONE_ENTITY, accountOptional.get()); model.addAttribute(ModelAttributes.AVAILABLE_ACCOUNT_STATES, AccountState.values()); model.addAttribute(ModelAttributes.FONTAWESOME_ICONS, FontAwesomeIcons.ICONS); + model.addAttribute(ModelAttributes.TODAY, LocalDate.now()); return ReturnValues.NEW_ENTITY; } @@ -211,6 +216,7 @@ public class AccountController extends BaseController model.addAttribute(ModelAttributes.ONE_ENTITY, account); model.addAttribute(ModelAttributes.AVAILABLE_ACCOUNT_STATES, AccountState.values()); model.addAttribute(ModelAttributes.FONTAWESOME_ICONS, FontAwesomeIcons.ICONS); + model.addAttribute(ModelAttributes.TODAY, LocalDate.now()); return ReturnValues.NEW_ENTITY; } diff --git a/BudgetMasterServer/src/main/resources/languages/base_de.properties b/BudgetMasterServer/src/main/resources/languages/base_de.properties index 3566699b8..605429f0e 100644 --- a/BudgetMasterServer/src/main/resources/languages/base_de.properties +++ b/BudgetMasterServer/src/main/resources/languages/base_de.properties @@ -354,6 +354,7 @@ account.new.icon.placeholder=Vorschau anklicken, um ein Icon auszuwählen account.new.icon.upload.choose.file=Datei auswählen account.new.icon.upload=Hochladen account.new.label.state=Sichtbarkeit +account.new.label.endDate=Enddatum account.default.name=Standardkonto account.all=Alle Konten account.tooltip.default=Als Standardkonto festlegen diff --git a/BudgetMasterServer/src/main/resources/languages/base_en.properties b/BudgetMasterServer/src/main/resources/languages/base_en.properties index f99a50312..bf10454f4 100644 --- a/BudgetMasterServer/src/main/resources/languages/base_en.properties +++ b/BudgetMasterServer/src/main/resources/languages/base_en.properties @@ -353,6 +353,7 @@ account.new.icon.placeholder=Click preview to select an icon account.new.icon.upload.choose.file=Choose file account.new.icon.upload=Upload account.new.label.state=Visibility +account.new.label.endDate=End Date account.default.name=Default Account account.all=All Accounts account.tooltip.default=Set as default account diff --git a/BudgetMasterServer/src/main/resources/static/js/accounts.js b/BudgetMasterServer/src/main/resources/static/js/accounts.js index 8f0a92394..9f03f22ec 100644 --- a/BudgetMasterServer/src/main/resources/static/js/accounts.js +++ b/BudgetMasterServer/src/main/resources/static/js/accounts.js @@ -20,4 +20,35 @@ $(document).ready(function() { fetchAndShowModalContent(this.dataset.url, '#deleteModalContainerOnDemand', '#modalConfirmDelete', function(){}); }); + + if($(".datepicker").length) + { + M.Datepicker.init(document.getElementById('account-datepicker'), { + firstDay: 1, + showClearBtn: true, + defaultDate: startDate, + autoClose: true, + + i18n: { + // Strings and translations + months: monthNames, + monthsShort: monthNamesShort, + weekdays: weekDays, + weekdaysShort: weekDaysShort, + weekdaysAbbrev: weekDaysLetters, + + // Buttons + cancel: buttonCancel, + done: buttonClose, + + // Accessibility labels + labelMonthNext: '>', + labelMonthPrev: '<' + }, + + // Formats + format: 'dd.mm.yyyy', + formatSubmit: 'dd.mm.yyyy', + }); + } }); diff --git a/BudgetMasterServer/src/main/resources/templates/accounts/newAccount.ftl b/BudgetMasterServer/src/main/resources/templates/accounts/newAccount.ftl index de9e0354c..c4fa9196b 100644 --- a/BudgetMasterServer/src/main/resources/templates/accounts/newAccount.ftl +++ b/BudgetMasterServer/src/main/resources/templates/accounts/newAccount.ftl @@ -11,6 +11,7 @@ <@header.header "BudgetMaster - ${title}"/> <@header.style "iconSelect"/> + <@header.style "datepicker"/> <#import "/spring.ftl" as s> </head> <@header.body> @@ -77,6 +78,28 @@ </#if> <@customSelectMacros.customAccountStateSelect "account-state-select-wrapper" "accountState" availableAccountStates selectedState "col s12 m12 l8 offset-l2" locale.getString("account.new.label.state") "account-state"/> + <#-- end date --> + <div class="row"> + <div class="input-field col s12 m12 l8 offset-l2"> + <#if account.getEndDate()??> + <#assign startDate = dateService.getLongDateString(account.getEndDate())/> + <#assign accountEndDate = dateService.getLongDateString(account.getEndDate())/> + <#else> + <#assign startDate = dateService.getLongDateString(today)/> + <#assign accountEndDate = ""/> + </#if> + + <i class="material-icons prefix">notifications</i> + <input id="account-datepicker" type="text" class="datepicker" name="endDate" value="${accountEndDate}"> + <label class="input-label" for="account-datepicker">${locale.getString("account.new.label.endDate")}</label> + </div> + </div> + + <script> + startDate = "${startDate}".split("."); + startDate = new Date(startDate[2], startDate[1]-1, startDate[0]); + </script> + <br> <#-- buttons --> @@ -109,6 +132,9 @@ <@iconSelectMacros.modalIconSelect idToFocusOnClose="account-name" item=account/> + <#import "../helpers/globalDatePicker.ftl" as datePicker> + <@datePicker.datePickerLocalization/> + <!-- Scripts--> <#import "../helpers/scripts.ftl" as scripts> <@scripts.scripts/> -- GitLab