diff --git a/accountant/frontend/static/js/entries.js b/accountant/frontend/static/js/entries.js index 529064c..1aae133 100644 --- a/accountant/frontend/static/js/entries.js +++ b/accountant/frontend/static/js/entries.js @@ -26,8 +26,8 @@ accountantApp .controller( "EntryController", [ - "$scope", "$http", "$rootScope", "$filter", "$routeParams", "Entries", - function($scope, $http, $rootScope, $filter, $routeParams, Entries) { + "$scope", "$http", "$rootScope", "$filter", "$routeParams", "notificationService", "Entries", + function($scope, $http, $rootScope, $filter, $routeParams, notificationService, Entries) { // Range for entries. $scope.begin = moment.utc().startOf('month'); $scope.end = moment.utc().endOf('month'); @@ -39,15 +39,15 @@ accountantApp $scope.account = null; - // Function to reset the new entry. - $scope.resetNewEntry = function() { - // The new entry. - $scope.newEntry = new Entries({}); + $scope.addEntry = function() { + if(!$scope.inserted) { + $scope.inserted = new Entries(); + $scope.inserted.account_id = $routeParams.accountId; + $scope.entries.splice(0, 0, $scope.inserted); + } }; - $scope.resetNewEntry(); - $scope.setExtremes = function(e) { begin = moment.utc(e.min); end = moment.utc(e.max); @@ -279,6 +279,9 @@ accountantApp $scope.getAccountStatus($routeParams.accountId); }); + /* + * Get account status. + */ $scope.getAccountStatus = function(accountId) { $scope.categoriesChartConfig.loading = true; @@ -335,94 +338,72 @@ accountantApp }); }; - // Starts editing an entry - $scope.editEntry = function(entry) { - // Enter edit state. - entry.confirmed=true; - entry.editing=true; - }; - // Cancel current editing entry or clears field if a new one. - $scope.cancelEditEntry = function(entry) { - sold = entry.sold; - entry.$get(function(entry) { - entry.sold = sold; - }); + $scope.cancelEditEntry = function(entry, rowform) { + if(entry == $scope.inserted) { + $scope.entries.splice(0, 1); + } else { + rowform.$cancel(); + } }; - // Points an entry. - $scope.togglePointedEntry = function(entry) { - entry.confirmed = true; + /* + * Toggle pointed indicator for an entry. + */ + $scope.togglePointedEntry = function(entry, rowform) { entry.pointed = !entry.pointed; - $scope.saveEntry(entry); + // Save entry if not editing it. + if(!rowform.$visible) { + $scope.saveEntry(entry); + } }; - // Confirm an entry. - $scope.confirmEntry = function(entry) { - entry.confirmed = true; - - $scope.saveEntry(entry); - }; - - // Confirm an entry. + /* + * Toggle cancel indicator for an entry. + */ $scope.toggleCanceledEntry = function(entry) { entry.canceled = !entry.canceled; $scope.saveEntry(entry); }; - // Create an new entry. - $scope.createEntry = function(entry) { - entry.account_id = $scope.account.id; + /* + * Save an entry and emit entrySavedEvent, or entryCreatedEvent. + */ + $scope.saveEntry = function($data, $index) { + // Check if $data is already a resource. + var entry; - // Ajax call to create an entry - $scope.newEntry.$save(function(data) { - $scope.resetNewEntry(); - - // Send the "entry saved" event. - $scope.$emit("entryCreatedEvent", entry); - }); - }; - - $rootScope.$on("entryCreatedEvent", function(e, entry) { - new PNotify({ - type: "success", - title: "Save", - text: "Entry #" + entry.id + " created." - }); - - }); - - // Saves an existing entry. - $scope.saveEntry = function(entry) { - - if(!entry.account_id) { - entry.account_id = $scope.account.id; + if($data.$save) { + entry = $data; + } else { + entry = $scope.entries[$index]; + entry = angular.merge(entry, $data); } - sold = entry.sold; + entry.confirmed = true; - // Ajax call to save an entry - entry.$save(function(data) { - data.sold = sold; + var promise = entry.$save(); - // Send the "entry saved" event. - $scope.$emit("entrySavedEvent", entry); - }); - }; + if(entry == $scope.inserted) { + promise = promise.then(function(data) { + $scope.inserted = false; - $rootScope.$on("entrySavedEvent", function(e, entry) { - $scope.getAccountStatus($routeParams.accountId); - }); - - $rootScope.$on("entrySavedEvent", function(e, entry) { - new PNotify({ - type: "success", - title: "Save", - text: "Entry #" + entry.id + " saved." + notificationService.success("Entry #" + data.id + " created."); }); - }); + } else { + promise = promise.then(function(data) { + notificationService.success("Entry #" + data.id + " saved."); + }); + } + + promise = promise.then(function(data) { + $scope.getAccountStatus($routeParams.accountId); + }); + + return promise; + }; $scope.removeEntry = function(entry) { $scope.removingEntry = entry; diff --git a/accountant/frontend/static/templates/entries.html b/accountant/frontend/static/templates/entries.html index 0bb77f0..09afc86 100644 --- a/accountant/frontend/static/templates/entries.html +++ b/accountant/frontend/static/templates/entries.html @@ -16,162 +16,115 @@ --> -
- - +
+
+ + - - -
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Date d'op.Libellé de l'opérationMontantSoldeCatégorieActions
- - - - - - - - - - -
- - - - - -
-
- - - - - - - {{entry.sold}} - - - -
- - - - - -
-
- {{entry.operation_date | date:"yyyy-MM-dd"}} - - {{entry.label}} - - {{entry.value}} - - {{entry.sold}} - - {{entry.category}} - - -
- - - - - - - -
-
+ + +
+ +
+
+ +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Date d'op.Libellé de l'opérationMontantSoldeCatégorieActions
+ + {{ entry.operation_date | date:"yyyy-MM-dd" }} + + + + {{ entry.label }} + + + + {{ entry.value }} + + + {{ entry.sold }} + + + {{ entry.category }} + + +
+ +
+ + + + + + + + + + + + + + +
+
+
+