Improve operation workflow.
This commit is contained in:
parent
4f3c196179
commit
e433aed773
@ -54,13 +54,10 @@ var operationModule = angular.module('accountant.operations', [
|
||||
* Controller for the operations.
|
||||
*/
|
||||
.controller('OperationController', function($rootScope, $scope, $routeParams,
|
||||
$uibModal, Notification, Operation, $log) {
|
||||
$uibModal, Notification, Operation, $log, $q) {
|
||||
|
||||
var vm = this;
|
||||
|
||||
// List of operations.
|
||||
vm.operations = [];
|
||||
|
||||
/*
|
||||
* Add an empty operation.
|
||||
*/
|
||||
@ -70,14 +67,14 @@ var operationModule = angular.module('accountant.operations', [
|
||||
account_id: $routeParams.accountId
|
||||
});
|
||||
|
||||
vm.operations.splice(0, 0, operation);
|
||||
return vm.modify(operation);
|
||||
};
|
||||
|
||||
/*
|
||||
* Load operations.
|
||||
*/
|
||||
vm.load = function(begin, end) {
|
||||
vm.operations = Operation.query({
|
||||
return Operation.query({
|
||||
// eslint-disable-next-line camelcase
|
||||
account_id: $routeParams.accountId,
|
||||
begin: begin.format('YYYY-MM-DD'),
|
||||
@ -91,10 +88,7 @@ var operationModule = angular.module('accountant.operations', [
|
||||
vm.togglePointed = function(operation, rowform) {
|
||||
operation.pointed = !operation.pointed;
|
||||
|
||||
// Save operation if not editing it.
|
||||
if (!rowform.$visible) {
|
||||
vm.save(operation);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -107,32 +101,32 @@ var operationModule = angular.module('accountant.operations', [
|
||||
};
|
||||
|
||||
/*
|
||||
* Save an operation and emit operationSavedEvent.
|
||||
* Save an operation and return a promise.
|
||||
*/
|
||||
vm.save = function($data, $index) {
|
||||
// Check if $data is already a resource.
|
||||
var operation;
|
||||
|
||||
if ($data.$save) {
|
||||
operation = $data;
|
||||
} else {
|
||||
operation = vm.operations[$index];
|
||||
operation = angular.merge(operation, $data);
|
||||
}
|
||||
|
||||
vm.save = function(operation) {
|
||||
operation.confirmed = true;
|
||||
|
||||
return operation.$save().then(function(data) {
|
||||
Notification.success('Operation #' + data.id + ' saved.');
|
||||
return operation.$save().then(function(operation) {
|
||||
Notification.success('Operation #' + operation.id + ' saved.');
|
||||
|
||||
$scope.$emit('operationSavedEvent', data);
|
||||
vm.operations = vm.load(moment().date(1).year(2000), moment());
|
||||
|
||||
return operation;
|
||||
}, function(result){
|
||||
$log.error('Error while saving operation', operation, result);
|
||||
|
||||
Notification.error(
|
||||
'Error while saving operation: ' + result.message
|
||||
);
|
||||
|
||||
return $q.reject(result);
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Delete an operation and emit operationDeletedEvent.
|
||||
* Delete an operation and return a promise.
|
||||
*/
|
||||
vm.delete = function(operation, $index) {
|
||||
vm.delete = function(operation) {
|
||||
var id = operation.id;
|
||||
|
||||
$uibModal.open({
|
||||
@ -143,16 +137,31 @@ var operationModule = angular.module('accountant.operations', [
|
||||
}
|
||||
}
|
||||
}).result.then(function(operation) {
|
||||
// FIXME Alexis Lahouze 2017-06-15 Delete operation and reload data
|
||||
// to update balances.
|
||||
$log.info('Delete operation', operation);
|
||||
return operation.$delete().then(function() {
|
||||
Notification.success('Operation #' + id + ' deleted.');
|
||||
|
||||
vm.operations = vm.load(moment().date(1).year(2000), moment());
|
||||
|
||||
return operation;
|
||||
}, function(result) {
|
||||
Notification.error(
|
||||
'An error occurred while trying to delete operation #' +
|
||||
id + ':<br />' + result
|
||||
);
|
||||
|
||||
return $q.reject(result);
|
||||
});
|
||||
}, function() {
|
||||
$log.info('modal-component dismissed at: ' + new Date());
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
vm.modify = function(operation, $index) {
|
||||
$uibModal.open({
|
||||
/*
|
||||
* Open the popup to modify the operation, save it on confirm.
|
||||
* @returns a promise.
|
||||
*/
|
||||
vm.modify = function(operation) {
|
||||
return $uibModal.open({
|
||||
component: 'operationModifyModalComponent',
|
||||
resolve: {
|
||||
operation: function() {
|
||||
@ -160,11 +169,9 @@ var operationModule = angular.module('accountant.operations', [
|
||||
}
|
||||
}
|
||||
}).result.then(function(operation) {
|
||||
// FIXME Alexis Lahouze 2017-06-15 Save Operation and reload data to
|
||||
// update balances.
|
||||
$log.info('Save operation', operation);
|
||||
return vm.save(operation);
|
||||
}, function() {
|
||||
$log.info('modal-component dismissed at: ' + new Date());
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
@ -179,7 +186,7 @@ var operationModule = angular.module('accountant.operations', [
|
||||
vm.onRangeSelected = angular.noop;
|
||||
});
|
||||
|
||||
vm.load(moment().date(1).year(2000), moment());
|
||||
vm.operations = vm.load(moment().date(1).year(2000), moment());
|
||||
})
|
||||
|
||||
.component('operationModifyModalComponent', {
|
||||
|
@ -68,14 +68,14 @@
|
||||
<!-- Edit operation, for non-canceled operation. -->
|
||||
<button type="button" class="btn btn-default"
|
||||
ng-if="!operation.canceled"
|
||||
ng-click="operationsCtrl.modify(operation, $index)" title="edit">
|
||||
ng-click="operationsCtrl.modify(operation)" title="edit">
|
||||
<span class="fa fa-pencil-square-o"></span>
|
||||
</button>
|
||||
|
||||
<!-- Toggle pointed operation, for non-canceled operations. -->
|
||||
<button type="button" class="btn btn-default"
|
||||
ng-if="!operation.canceled"
|
||||
ng-click="operationsCtrl.togglePointed(operation, rowform)"
|
||||
ng-click="operationsCtrl.togglePointed(operation)"
|
||||
ng-class="{active: operation.pointed}" title="point">
|
||||
<span ng-class="{'fa fa-check-square-o': operation.pointed, 'fa fa-square-o': !operation.pointed}"></span>
|
||||
</button>
|
||||
@ -91,7 +91,7 @@
|
||||
<!-- Delete operation, with confirm. -->
|
||||
<button type="button" class="btn btn-default"
|
||||
ng-if="operation.id && !operation.scheduled_operation_id"
|
||||
ng-click="operationsCtrl.delete(operation, $index)">
|
||||
ng-click="operationsCtrl.delete(operation)">
|
||||
<span class="fa fa-trash-o"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user