From 6821d8d0c602ab910cc9a712735366c424d0e594 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Wed, 15 Jul 2015 17:00:18 +0200 Subject: [PATCH] Comments. --- accountant/api/views/scheduled_operations.py | 9 +++++++ accountant/frontend/static/js/scheduler.js | 26 +++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/accountant/api/views/scheduled_operations.py b/accountant/api/views/scheduled_operations.py index 5acaae4..4c288a1 100644 --- a/accountant/api/views/scheduled_operations.py +++ b/accountant/api/views/scheduled_operations.py @@ -61,6 +61,9 @@ class ScheduledOperationListResource(Resource): @session_aware @marshal_with_field(fields.List(Object(resource_fields))) def get(self, session): + """ + Get all scheduled operation for the account. + """ kwargs = get_parser.parse_args() return ScheduledOperation.get_scheduled_operations_for_account( @@ -97,6 +100,9 @@ class ScheduledOperationResource(Resource): @session_aware @marshal_with_field(Object(resource_fields)) def delete(self, scheduled_operation_id, session): + """ + Delete a scheduled operation. + """ try: scheduled_operation = ScheduledOperation.get( session, scheduled_operation_id) @@ -110,6 +116,9 @@ class ScheduledOperationResource(Resource): @session_aware @marshal_with_field(Object(resource_fields)) def post(self, scheduled_operation_id, session): + """ + Update a scheduled operation. + """ kwargs = parser.parse_args() assert (id not in kwargs or kwargs.id is None diff --git a/accountant/frontend/static/js/scheduler.js b/accountant/frontend/static/js/scheduler.js index a9072cb..3101639 100644 --- a/accountant/frontend/static/js/scheduler.js +++ b/accountant/frontend/static/js/scheduler.js @@ -74,6 +74,7 @@ accountantApp }); }; + // Notify on success. $scope.$on("operationCreatedEvent", function(e, operation) { new PNotify({ type: "success", @@ -82,12 +83,14 @@ accountantApp }); }); + // Save operation. $scope.saveOperation = function(operation) { operation.$save(function(data) { $scope.$emit("operationSavedEvent", operation); }); }; + // Notify on success. $scope.$on("operationSavedEvent", function(e, operation) { new PNotify({ type: "success", @@ -101,36 +104,28 @@ accountantApp operation.state='edit'; }; + // Reload operation from server to cancel edition. $scope.cancelEditOperation = function(operation) { operation.$get(); }; + // Remove an operation. $scope.removeOperation = function(operation, modalScope) { - // Cancel current editing. - if (!$scope.isNew(operation)) { - $http.delete("/api/scheduled_operations/" + operation.id).success(function (result) { - $.pnotify({ + operation.$delete(function(data) { + new PNotify({ type: "success", title: "Delete", - text: result + text: "Operation #" + operation.id + " deleted." }); // Send the "entry removed" event. $scope.$emit("operationRemovedEvent", operation); - $scope.closeModal(modalScope); - }).error(function (data) { - $.pnotify({ - type: "error", - title: "Delete", - text: data - }); - $scope.closeModal(modalScope); }); - } }; + // Close modal. $scope.closeModal = function(modalScope) { // Close the modal dialog if(modalScope && modalScope.dismiss) { @@ -138,9 +133,12 @@ accountantApp } }; + // Load operations on account selection. + // FIXME Alexis Lahouze 2015-07-15 Deprecated. $rootScope.$on("accountSelectedEvent", function(event, args){ $scope.loadOperations(args.account.id); }); + // Load operations on controller initialization. $scope.loadOperations($routeParams.accountId); }]);