From ce3181537db56f85fd6739f1b69f9121c46e51bf Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Fri, 21 Aug 2015 00:25:10 +0200 Subject: [PATCH] Naming, comments. --- accountant/frontend/static/js/scheduler.js | 44 ++++++++++++------- .../frontend/static/templates/scheduler.html | 6 +-- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/accountant/frontend/static/js/scheduler.js b/accountant/frontend/static/js/scheduler.js index 6e21383..80e843f 100644 --- a/accountant/frontend/static/js/scheduler.js +++ b/accountant/frontend/static/js/scheduler.js @@ -16,7 +16,7 @@ */ accountantApp -.factory("ScheduledOperations", ["$resource", function($resource) { +.factory("ScheduledOperation", ["$resource", function($resource) { return $resource( "/api/scheduled_operations/:id", { id: "@id" @@ -26,31 +26,40 @@ accountantApp .controller( "SchedulerController", [ - "$scope", "$rootScope", "$routeParams", "notificationService", "ScheduledOperations", - function($scope, $rootScope, $routeParams, notificationService, ScheduledOperations) { - // Operations store and selection + "$scope", "$rootScope", "$routeParams", "notificationService", "ScheduledOperation", + function($scope, $rootScope, $routeParams, notificationService, ScheduledOperation) { + // Operation store. $scope.operations = []; - $scope.categories = []; + /* + * Add a new operation at the beginning of th array. + */ + $scope.add = function() { + var operation = new ScheduledOperation({ + account_id: $routeParams.accountId + }); - $scope.addOperation = function() { - operation = new ScheduledOperations({}); - operation.account_id = $routeParams.accountId; + // Insert new operation at the beginning of the array. $scope.operations.splice(0, 0, operation); }; - $scope.loadOperations = function(accountId) { + /* + * Load operations. + */ + $scope.load = function() { // Clean up selected entry. $scope.selectedOperation = null; $scope.savedOperation = null; - $scope.operations = ScheduledOperations.query({ + $scope.operations = ScheduledOperation.query({ account: $routeParams.accountId }); }; - // Save operation. - $scope.saveOperation = function($data, $index) { + /* + * Save operation. + */ + $scope.save = function($data, $index) { var operation; if($data.$save) { @@ -62,12 +71,13 @@ accountantApp 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, $index) { + /* + * Cancel operation edition. Delete if new. + */ + $scope.cancelEdit = function(operation, rowform, $index) { if(!operation.id) { $scope.operations.splice($index, 1); } else { @@ -76,7 +86,7 @@ accountantApp }; /* - * Delete a scheduled operation. + * Delete operation. */ $scope.delete = function(operation, $index) { var id = operation.id; @@ -97,5 +107,5 @@ accountantApp }; // Load operations on controller initialization. - $scope.loadOperations($routeParams.accountId); + $scope.load(); }]); diff --git a/accountant/frontend/static/templates/scheduler.html b/accountant/frontend/static/templates/scheduler.html index 7b6eb97..f651142 100644 --- a/accountant/frontend/static/templates/scheduler.html +++ b/accountant/frontend/static/templates/scheduler.html @@ -36,7 +36,7 @@ - @@ -105,7 +105,7 @@
@@ -124,7 +124,7 @@