diff --git a/accountant/frontend/static/js/scheduler.js b/accountant/frontend/static/js/scheduler.js index 94a31fb..6e21383 100644 --- a/accountant/frontend/static/js/scheduler.js +++ b/accountant/frontend/static/js/scheduler.js @@ -34,11 +34,9 @@ accountantApp $scope.categories = []; $scope.addOperation = function() { - if(! $scope.inserted) { - $scope.inserted = new ScheduledOperations({}); - $scope.inserted.account_id = $routeParams.accountId; - $scope.operations.splice(0, 0, $scope.inserted); - } + operation = new ScheduledOperations({}); + operation.account_id = $routeParams.accountId; + $scope.operations.splice(0, 0, operation); }; $scope.loadOperations = function(accountId) { @@ -62,25 +60,16 @@ accountantApp operation = angular.merge(operation, $data); } - var promise = operation.$save(); - - if(operation == $scope.inserted) { - promise = promise.then(function(data) { - $scope.inserted = false; - return data; - }); - } - - return promise.then(function(data) { + return operation.$save().then(function(data) { notificationService.success("Operation #" + data.id + " saved."); return data; }); }; // Reload operation from server to cancel edition. - $scope.cancelEditOperation = function(operation, rowform) { - if(operation == $scope.inserted) { - $scope.entries.splice(0, 1); + $scope.cancelEditOperation = function(operation, rowform, $index) { + if(!operation.id) { + $scope.operations.splice($index, 1); } else { rowform.$cancel(); } diff --git a/accountant/frontend/static/templates/scheduler.html b/accountant/frontend/static/templates/scheduler.html index a18d898..7b6eb97 100644 --- a/accountant/frontend/static/templates/scheduler.html +++ b/accountant/frontend/static/templates/scheduler.html @@ -106,7 +106,7 @@