Skip to content

Commit

Permalink
#764 - add new input field for account end date
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlocker8 committed Jun 23, 2024
1 parent ba977de commit 79bc3d4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
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;

Expand All @@ -39,6 +41,7 @@ private static class ModelAttributes
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
Expand Down Expand Up @@ -148,6 +151,7 @@ public String newAccount(Model model)
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;
}

Expand All @@ -163,6 +167,7 @@ public String editAccount(Model model, @PathVariable("ID") Integer ID)
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;
}

Expand Down Expand Up @@ -211,6 +216,7 @@ public String post(HttpServletRequest request, WebRequest webRequest, Model mode
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions BudgetMasterServer/src/main/resources/static/js/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<@header.header "BudgetMaster - ${title}"/>
<@header.style "iconSelect"/>
<@header.style "datepicker"/>
<#import "/spring.ftl" as s>
</head>
<@header.body>
Expand Down Expand Up @@ -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 -->
Expand Down Expand Up @@ -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/>
Expand Down

0 comments on commit 79bc3d4

Please sign in to comment.