From 4bd8bb3819de4cffb839876107ae33737c03253c Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Wed, 19 Aug 2015 17:13:31 +0200 Subject: [PATCH] Cleanup, sort accounts after saving. --- accountant/frontend/static/js/accounts.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/accountant/frontend/static/js/accounts.js b/accountant/frontend/static/js/accounts.js index b82fc07..28029ba 100644 --- a/accountant/frontend/static/js/accounts.js +++ b/accountant/frontend/static/js/accounts.js @@ -92,6 +92,17 @@ accountantApp } return promise.then(function(data) { + // Sort accounts by name. + $scope.accounts.sort(function(a, b) { + if(a.name < b.name) { + return -1; + } else if(a.name > b.name) { + return 1; + } else { + return a.id - b.id; + } + }); + notificationService.success("Account #" + data.id + " saved."); return data; @@ -103,7 +114,6 @@ accountantApp */ $scope.deleteAccount = function(account, $index) { var id = account.id; - var index = $index; bootbox.confirm( "Voulez-vous supprimer le compte \"" + account.name + "\" ?", @@ -113,7 +123,7 @@ accountantApp notificationService.success("Account #" + id + " deleted."); // Remove account from array. - $scope.accounts.splice(index, 1); + $scope.accounts.splice($index, 1); }); } }