From b5a483e8e55d168662a5e44e70d0b872f06c0309 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Fri, 21 Aug 2015 00:12:11 +0200 Subject: [PATCH] Add support for multiple new scheduled operations. --- accountant/frontend/static/js/scheduler.js | 25 ++++++------------- .../frontend/static/templates/scheduler.html | 5 ++-- 2 files changed, 10 insertions(+), 20 deletions(-) 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 @@
+ shown="!operation.id">