From 156c9a3be2d7b959633945bc4861d501a9391b06 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Thu, 20 Aug 2015 11:42:17 +0200 Subject: [PATCH] Add entry deletion. --- accountant/frontend/static/js/entries.js | 28 +++++++++++++++++++ .../frontend/static/templates/entries.html | 9 +++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/accountant/frontend/static/js/entries.js b/accountant/frontend/static/js/entries.js index 667a2a8..55b2419 100644 --- a/accountant/frontend/static/js/entries.js +++ b/accountant/frontend/static/js/entries.js @@ -292,6 +292,11 @@ accountantApp $scope.loadSolds(); }); + // Reload solds when an entry is deleted. + $rootScope.$on("entryDeletedEvent", function(e, entry) { + $scope.loadSolds(); + }); + // Update authorized overdraft on account loading. $rootScope.$on("accountLoadedEvent", function(e, account) { $scope.config.yAxis.plotLines[1].value = account.authorized_overdraft; @@ -396,6 +401,29 @@ accountantApp }); }; + /* + * Delete an entry and emit entryDeletedEvent. + */ + $scope.deleteEntry = function(entry, $index) { + var id = entry.id; + + bootbox.confirm( + "Voulez-vous supprimer l'entrĂ©e \"" + entry.label + "\" ?", + function(result) { + if(result) { + entry.$delete().then(function() { + notificationService.success("Entry #" + id + " deleted."); + + // Remove entry from array. + $scope.entries.splice($index, 1); + + $scope.$emit("entryDeletedEvent", entry); + }); + } + } + ); + }; + // Reload entries on range selection. $rootScope.$on("rangeSelectedEvent", function(e, args) { $scope.loadEntries(args.begin, args.end); diff --git a/accountant/frontend/static/templates/entries.html b/accountant/frontend/static/templates/entries.html index bf1ed67..5274ef4 100644 --- a/accountant/frontend/static/templates/entries.html +++ b/accountant/frontend/static/templates/entries.html @@ -40,7 +40,7 @@ Montant Solde Catégorie - Actions + Actions @@ -138,6 +138,13 @@ ng-class="{active: entry.canceled}" title="cancel"> + + +