diff --git a/accountant/frontend/static/js/scheduler.js b/accountant/frontend/static/js/scheduler.js index 1d935fa..2afd129 100644 --- a/accountant/frontend/static/js/scheduler.js +++ b/accountant/frontend/static/js/scheduler.js @@ -26,23 +26,21 @@ accountantApp .controller( "SchedulerController", [ - "$scope", "$rootScope", "$routeParams", "ScheduledOperations", - function($scope, $rootScope, $routeParams, ScheduledOperations) { + "$scope", "$rootScope", "$routeParams", "notificationService", "ScheduledOperations", + function($scope, $rootScope, $routeParams, notificationService, ScheduledOperations) { // Operations store and selection $scope.operations = []; - $scope.selectedOperation = null; - - // Placeholder for saved value to cancel entry edition - $scope.savedOperation = null; $scope.categories = []; - $scope.resetNewOperation = function() { - $scope.newOperation = new ScheduledOperations({}); + $scope.addOperation = function() { + if(! $scope.inserted) { + $scope.inserted = new ScheduledOperations({}); + $scope.inserted.account_id = $routeParams.accountId; + $scope.operations.splice(0, 0, $scope.inserted); + } }; - $scope.resetNewOperation(); - $scope.loadOperations = function(accountId) { // Clean up selected entry. $scope.selectedOperation = null; @@ -50,95 +48,44 @@ accountantApp $scope.operations = ScheduledOperations.query({ account: $routeParams.accountId - }, function(data) { - $scope.$emit("operationsLoadedEvent", {operations: data}); }); }; - // Returns true if the entry is in editing state. - $scope.isEditing = function(operation) { - return operation.state === 'edit'; - }; - - $scope.isDisplaying = function(operation) { - return !operation.state; - }; - - $scope.createOperation = function(operation) { - operation.account_id = $routeParams.accountId; - - operation.$save(function(data) { - $scope.resetNewOperation(); - - $scope.$emit("operationCreatedEvent", data); - }); - }; - - // Notify on success. - $scope.$on("operationCreatedEvent", function(e, operation) { - new PNotify({ - type: "success", - title: "Save", - text: "Operation #" + operation.id + " created." - }); - }); - // Save operation. - $scope.saveOperation = function(operation) { - operation.$save(function(data) { - $scope.$emit("operationSavedEvent", operation); - }); - }; + $scope.saveOperation = function($data, $index) { + var operation; - // Notify on success. - $scope.$on("operationSavedEvent", function(e, operation) { - new PNotify({ - type: "success", - title: "Save", - text: "Operation #" + operation.id + " saved." + if($data.$save) { + operation = $data; + } else { + operation = $scope.operations[$index]; + operation = angular.merge(operation, $data); + } + + var promise = operation.$save() + + if(operation == $scope.inserted) { + promise = promise.then(function(data) { + $scope.inserted = false; + return data; }); - }); + } - $scope.editOperation = function(operation) { - // Enter edit state. - operation.state='edit'; + return promise.then(function(data) { + notificationService.success("Operation #" + data.id + " saved."); + return data; + }); }; // Reload operation from server to cancel edition. - $scope.cancelEditOperation = function(operation) { - operation.$get(); - }; - - // Remove an operation. - $scope.removeOperation = function(operation, modalScope) { - operation.$delete(function(data) { - new PNotify({ - type: "success", - title: "Delete", - text: "Operation #" + operation.id + " deleted." - }); - - // Send the "entry removed" event. - $scope.$emit("operationRemovedEvent", operation); - - $scope.closeModal(modalScope); - }); - }; - - // Close modal. - $scope.closeModal = function(modalScope) { - // Close the modal dialog - if(modalScope && modalScope.dismiss) { - modalScope.dismiss(); + $scope.cancelEditOperation = function(operation, rowform) { + if(operation == $scope.inserted) { + $scope.entries.splice(0, 1); + } else { + rowform.$cancel(); } }; - // 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); }]); diff --git a/accountant/frontend/static/templates/scheduler.html b/accountant/frontend/static/templates/scheduler.html index 2994a65..3933ada 100644 --- a/accountant/frontend/static/templates/scheduler.html +++ b/accountant/frontend/static/templates/scheduler.html @@ -16,139 +16,129 @@ --> -
- - - - - - - - - - - - - - +
+
+
+ +
+
- -
- - +
+
Date de débutDate de finJourFréq.Libellé de l'opérationMontantCatégorieActions
- -
+ + + + + + + + + + + + + - + + + + - + - + - + - + - + - - - - - + - + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Date de débutDate de finJourFréq.Libellé de l'opérationMontantCatégorieActions
- -
+ + {{ operation.start_date | date: "yyyy-MM-dd" }} + + - - + + {{ operation.stop_date | date: "yyyy-MM-dd" }} + + - - + + {{ operation.day }} + + - - + + {{ operation.frequency }} + + - - + + {{ operation.label }} + + - - + + {{ operation.value }} + + -
- +
+ + {{ operation.category }} + +
+
+
+ + -
{{operation.start_date}}{{operation.stop_date}}{{operation.day}}{{operation.frequency}}{{operation.label}}{{operation.value}}{{operation.category}} -
- - - -
-
- - - - - - - - - - - - - - -
- - - -
-
+ + +
+ + + + + +