Add support for multiple new scheduled operations.

This commit is contained in:
Alexis Lahouze 2015-08-21 00:12:11 +02:00
parent 8868dd18c2
commit b5a483e8e5
2 changed files with 10 additions and 20 deletions

View File

@ -34,11 +34,9 @@ accountantApp
$scope.categories = [];
$scope.addOperation = function() {
if(! $scope.inserted) {
$scope.inserted = new ScheduledOperations({});
$scope.inserted.account_id = $routeParams.accountId;
$scope.operations.splice(0, 0, $scope.inserted);
}
operation = new ScheduledOperations({});
operation.account_id = $routeParams.accountId;
$scope.operations.splice(0, 0, operation);
};
$scope.loadOperations = function(accountId) {
@ -62,25 +60,16 @@ accountantApp
operation = angular.merge(operation, $data);
}
var promise = operation.$save();
if(operation == $scope.inserted) {
promise = promise.then(function(data) {
$scope.inserted = false;
return data;
});
}
return promise.then(function(data) {
return operation.$save().then(function(data) {
notificationService.success("Operation #" + data.id + " saved.");
return data;
});
};
// Reload operation from server to cancel edition.
$scope.cancelEditOperation = function(operation, rowform) {
if(operation == $scope.inserted) {
$scope.entries.splice(0, 1);
$scope.cancelEditOperation = function(operation, rowform, $index) {
if(!operation.id) {
$scope.operations.splice($index, 1);
} else {
rowform.$cancel();
}

View File

@ -106,7 +106,7 @@
<td>
<form editable-form name="rowform"
onbeforesave="saveOperation($data, $index)"
shown="operation == inserted">
shown="!operation.id">
<div class="btn-group btn-group-xs">
<!-- Save current operation -->
<button type="submit" class="btn btn-success"
@ -124,13 +124,14 @@
<!-- Cancel edit. -->
<button type="button" class="btn btn-default"
ng-if="rowform.$visible"
ng-click="cancelEditOperation(operation, rowform)"
ng-click="cancelEditOperation(operation, rowform, $index)"
title="Cancel">
<span class="fa fa-times"></span>
</button>
<!-- Remove operation. -->
<button type="button" class="btn btn-default"
ng-if="!operation.id"
ng-click="delete(operation, $index)"
title="remove">
<span class="fa fa-trash"></span>