Add entry deletion.

This commit is contained in:
Alexis Lahouze 2015-08-20 11:42:17 +02:00
parent ad60e19617
commit 156c9a3be2
2 changed files with 36 additions and 1 deletions

View File

@ -292,6 +292,11 @@ accountantApp
$scope.loadSolds(); $scope.loadSolds();
}); });
// Reload solds when an entry is deleted.
$rootScope.$on("entryDeletedEvent", function(e, entry) {
$scope.loadSolds();
});
// Update authorized overdraft on account loading. // Update authorized overdraft on account loading.
$rootScope.$on("accountLoadedEvent", function(e, account) { $rootScope.$on("accountLoadedEvent", function(e, account) {
$scope.config.yAxis.plotLines[1].value = account.authorized_overdraft; $scope.config.yAxis.plotLines[1].value = account.authorized_overdraft;
@ -396,6 +401,29 @@ accountantApp
}); });
}; };
/*
* Delete an entry and emit entryDeletedEvent.
*/
$scope.deleteEntry = function(entry, $index) {
var id = entry.id;
bootbox.confirm(
"Voulez-vous supprimer l'entrée \"" + entry.label + "\" ?",
function(result) {
if(result) {
entry.$delete().then(function() {
notificationService.success("Entry #" + id + " deleted.");
// Remove entry from array.
$scope.entries.splice($index, 1);
$scope.$emit("entryDeletedEvent", entry);
});
}
}
);
};
// Reload entries on range selection. // Reload entries on range selection.
$rootScope.$on("rangeSelectedEvent", function(e, args) { $rootScope.$on("rangeSelectedEvent", function(e, args) {
$scope.loadEntries(args.begin, args.end); $scope.loadEntries(args.begin, args.end);

View File

@ -40,7 +40,7 @@
<th class="col-md-1">Montant</th> <th class="col-md-1">Montant</th>
<th class="col-md-1">Solde</th> <th class="col-md-1">Solde</th>
<th class="col-md-2">Cat&eacute;gorie</th> <th class="col-md-2">Cat&eacute;gorie</th>
<th class="col-md-1">Actions</th> <th class="col-md-2">Actions</th>
</tr> </tr>
</thead> </thead>
@ -138,6 +138,13 @@
ng-class="{active: entry.canceled}" title="cancel"> ng-class="{active: entry.canceled}" title="cancel">
<span class="fa fa-remove"></span> <span class="fa fa-remove"></span>
</button> </button>
<!-- Delete entry, with confirm. -->
<button type="button" class="btn btn-default"
ng-if="entry.id"
ng-click="deleteEntry(entry, $index)">
<span class="fa fa-trash-o"></span>
</button>
</div> </div>
</form> </form>
</td> </td>