Add possibilty to add multiple entries.

This commit is contained in:
Alexis Lahouze 2015-08-20 11:43:02 +02:00
parent 156c9a3be2
commit f4f62e6e0c
2 changed files with 8 additions and 20 deletions

View File

@ -315,11 +315,9 @@ accountantApp
// Function to reset the new entry. // Function to reset the new entry.
$scope.addEntry = function() { $scope.addEntry = function() {
if(!$scope.inserted) { entry = new Entries();
$scope.inserted = new Entries(); entry.account_id = $routeParams.accountId;
$scope.inserted.account_id = $routeParams.accountId; $scope.entries.splice(0, 0, entry);
$scope.entries.splice(0, 0, $scope.inserted);
}
}; };
// Function to load entries from server for a specific account and month. // Function to load entries from server for a specific account and month.
@ -338,9 +336,9 @@ 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, rowform) { $scope.cancelEditEntry = function(entry, rowform, $index) {
if(entry == $scope.inserted) { if(!entry.id) {
$scope.entries.splice(0, 1); $scope.entries.splice($index, 1);
} else { } else {
rowform.$cancel(); rowform.$cancel();
} }
@ -383,17 +381,7 @@ accountantApp
entry.confirmed = true; entry.confirmed = true;
var promise = entry.$save(); return entry.$save().then(function(data) {
if(entry == $scope.inserted) {
promise = promise.then(function(data) {
$scope.inserted = false;
return data;
});
}
return promise.then(function(data) {
notificationService.success("Entry #" + data.id + " saved."); notificationService.success("Entry #" + data.id + " saved.");
$scope.$emit("entrySavedEvent", data); $scope.$emit("entrySavedEvent", data);

View File

@ -100,7 +100,7 @@
<td> <td>
<form editable-form name="rowform" <form editable-form name="rowform"
onbeforesave="saveEntry($data, $index)" onbeforesave="saveEntry($data, $index)"
shown="entry == inserted"> shown="!entry.id">
<div class="btn-group btn-group-xs"> <div class="btn-group btn-group-xs">
<!-- Save current entry, for editing and non-confirmed non-canceled entries --> <!-- Save current entry, for editing and non-confirmed non-canceled entries -->
<button type="submit" class="btn btn-success" <button type="submit" class="btn btn-success"