Skip to content
Snippets Groups Projects
Commit c2551fea authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#583 - show feedback after deleting an account

parent 2ac73048
No related branches found
No related tags found
No related merge requests found
......@@ -4,12 +4,17 @@ import de.deadlocker8.budgetmaster.controller.BaseController;
import de.deadlocker8.budgetmaster.settings.SettingsService;
import de.deadlocker8.budgetmaster.utils.Mappings;
import de.deadlocker8.budgetmaster.utils.ResourceNotFoundException;
import de.deadlocker8.budgetmaster.utils.WebRequestUtils;
import de.deadlocker8.budgetmaster.utils.notification.Notification;
import de.deadlocker8.budgetmaster.utils.notification.NotificationType;
import de.thecodelabs.utils.util.Localization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.WebRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
......@@ -97,17 +102,21 @@ public class AccountController extends BaseController
}
@GetMapping("/{ID}/delete")
public String deleteAccountAndReferringTransactions(Model model, @PathVariable("ID") Integer ID)
public String deleteAccountAndReferringTransactions(WebRequest request, Model model, @PathVariable("ID") Integer ID)
{
// at least one account is required (to delete a sole account another one has to be created first)
final Account accountToDelete = accountService.getRepository().getOne(ID);
if(accountService.getRepository().findAllByType(AccountType.CUSTOM).size() > 1)
{
accountService.deleteAccount(ID);
WebRequestUtils.putNotification(request, new Notification(Localization.getString("notification.account.delete.success", accountToDelete.getName()), NotificationType.SUCCESS));
return "redirect:/accounts";
}
model.addAttribute("accounts", accountService.getAllAccountsAsc());
model.addAttribute("currentAccount", accountService.getRepository().getOne(ID));
model.addAttribute("currentAccount", accountToDelete);
model.addAttribute("accountNotDeletable", true);
model.addAttribute("settings", settingsService.getSettings());
return "accounts/accounts";
......
......@@ -105,6 +105,7 @@ notification.category.delete.not.deletable=Die Kategorie mit der ID "{0}" ist ni
info.title.account.delete=Konto löschen
info.text.account.delete=Möchtest du das Konto "{0}" wirklich unwiderruflich löschen?<br>Hinweis: Diesem Konto sind {1} Buchungen zugeordnet. Beim Löschen des Kontos werden diese ebenfalls gelöscht!
info.button.account.delete=Konto und Buchungen löschen
notification.account.delete.success=Das Konto "{0}" wurde erfolgreich gelöscht.
info.title.transaction.delete=Buchung löschen
info.text.transaction.delete=Möchtest du die Buchung "{0}" wirklich unwiderruflich löschen?
......
......@@ -105,6 +105,7 @@ notification.category.delete.not.deletable=The category with id "{0}" is undelet
info.title.account.delete=Delete Account
info.text.account.delete=Do you really want to delete the account "{0}"? This can''t be undone.<br>Note: There are {1} transactions associated with this account. Deleting this account will delete all releated transactions too!
info.button.account.delete=Delete Account and Transactions
notification.account.delete.success=Successfully deleted account "{0}".
info.title.transaction.delete=Delete Entry
info.text.transaction.delete=Do you really want to delete the entry "{0}"? This can''t be undone.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment