diff --git a/accountant/frontend/static/js/entries.js b/accountant/frontend/static/js/entries.js index 812c0de..bd1381c 100644 --- a/accountant/frontend/static/js/entries.js +++ b/accountant/frontend/static/js/entries.js @@ -37,12 +37,8 @@ accountantApp $scope.categories = []; - $scope.selectedItem = null; - $scope.account = null; - // Placeholder for saved value to cancel entry edition - $scope.savedItem = null; // Function to reset the new entry. $scope.resetNewEntry = function() { @@ -369,18 +365,8 @@ accountantApp // Starts editing an entry $scope.editEntry = function(entry) { - // Cancel previous editing. - if($scope.selectedItem) { - $scope.cancelEditEntry($scope.selectedItem); - } - - // Save current entry values. - if(!entry.id) { - $scope.savedItem = angular.copy(entry); - $scope.selectedItem = entry; - } - // Enter edit state. + entry.confirmed=true; entry.state='edit'; }; @@ -401,27 +387,10 @@ accountantApp // Cancel current editing entry or clears field if a new one. $scope.cancelEditEntry = function(entry) { - if (entry.id) { - entry.$get(); - } else { - // Reset selected item fields to saved item ones. - entry.id = $scope.savedItem.id; // id should not change, but just in case... - entry.pointed = $scope.savedItem.pointed; - entry.operation_date = $scope.savedItem.operation_date; - entry.label = $scope.savedItem.label; - entry.value = $scope.savedItem.value; - entry.account_id = $scope.savedItem.account_id; // account_id should not change, but just in case... - entry.category = $scope.savedItem.category; - entry.canceled = $scope.savedItem.canceled; - entry.scheduled_operation_id = $scope.savedItem.scheduled_operation_id; - - // Reset saved and selected items to null. - $scope.savedItem = null; - $scope.selectedItem = null; - - // Enter display state. - entry.state = 'display'; - } + sold = entry.sold; + entry.$get(function(entry) { + entry.sold = sold; + }); }; // Points an entry. @@ -468,13 +437,21 @@ accountantApp entry.account_id = $scope.account.id; } + sold = entry.sold; + // Ajax call to save an entry entry.$save(function(data) { + data.sold = sold; + // Send the "entry saved" event. $scope.$emit("entrySavedEvent", entry); }); }; + $rootScope.$on("entrySavedEvent", function(e, entry) { + $scope.getAccountStatus($routeParams.accountId); + }); + $rootScope.$on("entrySavedEvent", function(e, entry) { new PNotify({ type: "success",