Improve operation edition workflow.

This commit is contained in:
Alexis Lahouze 2015-07-18 10:03:43 +02:00
parent 2b443e2826
commit c4e262e255

View File

@ -37,12 +37,8 @@ accountantApp
$scope.categories = []; $scope.categories = [];
$scope.selectedItem = null;
$scope.account = null; $scope.account = null;
// Placeholder for saved value to cancel entry edition
$scope.savedItem = null;
// Function to reset the new entry. // Function to reset the new entry.
$scope.resetNewEntry = function() { $scope.resetNewEntry = function() {
@ -369,18 +365,8 @@ accountantApp
// Starts editing an entry // Starts editing an entry
$scope.editEntry = function(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. // Enter edit state.
entry.confirmed=true;
entry.state='edit'; entry.state='edit';
}; };
@ -401,27 +387,10 @@ accountantApp
// Cancel current editing entry or clears field if a new one. // Cancel current editing entry or clears field if a new one.
$scope.cancelEditEntry = function(entry) { $scope.cancelEditEntry = function(entry) {
if (entry.id) { sold = entry.sold;
entry.$get(); entry.$get(function(entry) {
} else { entry.sold = sold;
// 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';
}
}; };
// Points an entry. // Points an entry.
@ -468,13 +437,21 @@ accountantApp
entry.account_id = $scope.account.id; entry.account_id = $scope.account.id;
} }
sold = entry.sold;
// Ajax call to save an entry // Ajax call to save an entry
entry.$save(function(data) { entry.$save(function(data) {
data.sold = sold;
// Send the "entry saved" event. // Send the "entry saved" event.
$scope.$emit("entrySavedEvent", entry); $scope.$emit("entrySavedEvent", entry);
}); });
}; };
$rootScope.$on("entrySavedEvent", function(e, entry) {
$scope.getAccountStatus($routeParams.accountId);
});
$rootScope.$on("entrySavedEvent", function(e, entry) { $rootScope.$on("entrySavedEvent", function(e, entry) {
new PNotify({ new PNotify({
type: "success", type: "success",