diff --git a/accountant/frontend/static/js/entries.js b/accountant/frontend/static/js/entries.js index 55b2419..2473ff8 100644 --- a/accountant/frontend/static/js/entries.js +++ b/accountant/frontend/static/js/entries.js @@ -315,11 +315,9 @@ accountantApp // Function to reset the new entry. $scope.addEntry = function() { - if(!$scope.inserted) { - $scope.inserted = new Entries(); - $scope.inserted.account_id = $routeParams.accountId; - $scope.entries.splice(0, 0, $scope.inserted); - } + entry = new Entries(); + entry.account_id = $routeParams.accountId; + $scope.entries.splice(0, 0, entry); }; // Function to load entries from server for a specific account and month. @@ -338,9 +336,9 @@ accountantApp }; // Cancel current editing entry or clears field if a new one. - $scope.cancelEditEntry = function(entry, rowform) { - if(entry == $scope.inserted) { - $scope.entries.splice(0, 1); + $scope.cancelEditEntry = function(entry, rowform, $index) { + if(!entry.id) { + $scope.entries.splice($index, 1); } else { rowform.$cancel(); } @@ -383,17 +381,7 @@ accountantApp entry.confirmed = true; - var promise = entry.$save(); - - if(entry == $scope.inserted) { - promise = promise.then(function(data) { - $scope.inserted = false; - - return data; - }); - } - - return promise.then(function(data) { + return entry.$save().then(function(data) { notificationService.success("Entry #" + data.id + " saved."); $scope.$emit("entrySavedEvent", data); diff --git a/accountant/frontend/static/templates/entries.html b/accountant/frontend/static/templates/entries.html index 5274ef4..818bae0 100644 --- a/accountant/frontend/static/templates/entries.html +++ b/accountant/frontend/static/templates/entries.html @@ -100,7 +100,7 @@
+ shown="!entry.id">