Add account deletion.

This commit is contained in:
Alexis Lahouze 2015-08-19 15:51:04 +02:00
parent a23cb97721
commit 25f43228dd
3 changed files with 33 additions and 68 deletions

View File

@ -120,7 +120,7 @@ class AccountResource(Resource):
session.delete(account)
return account
return None, 204
@session_aware
@marshal_with_field(Object(resource_fields))

View File

@ -74,21 +74,7 @@ accountantApp
};
/*
* Notify on account created event.
*/
$rootScope.$on("accountCreatedEvent", function(e, account) {
notificationService.success("Account #" + account.id + " created.");
});
/*
* Reload accounts on account created event.
*/
$rootScope.$on("accountCreatedEvent", function(e, account) {
$scope.loadAccounts();
});
/*
* Save account and emit accountSavedEvent.
* Save account.
*/
$scope.saveAccount = function($data, $index) {
var account = $scope.accounts[$index];
@ -98,68 +84,42 @@ accountantApp
var promise = account.$save();
if(account == $scope.inserted) {
return promise.then(function(data) {
promise = promise.then(function(data) {
$scope.inserted = false;
$scope.$emit("accountCreatedEvent", data);
});
} else {
return promise.then(function(data) {
$scope.$emit("accountSavedEvent", data);
return data;
});
}
};
/*
* Notify on account saved event.
*/
$rootScope.$on("accountSavedEvent", function(e, account) {
new PNnotify({
type: "success",
title: "Save",
text: "Account #" + account.id + " saved."
});
return promise.then(function(data) {
notificationService.success("Account #" + data.id + " saved.");
return data;
});
};
/*
* Delete an account and emit accountDeletedEvent.
*/
$scope.deleteAccount = function(account, modalScope) {
account.$delete(function(data) {
$scope.$emit("accountDeletedEvent", account);
$scope.deleteAccount = function(account, $index) {
var id = account.id;
var index = $index;
bootbox.confirm(
"Voulez-vous supprimer le compte \"" + account.name + "\" ?",
function(result) {
if(result) {
account.$delete().then(function() {
notificationService.success("Account #" + id + " deleted.");
// Remove account from array.
$scope.accounts.splice(index, 1);
});
}
}
);
};
/*
* Notify on account deleted event.
*/
$rootScope.$on("accountDeletedEvent", function(e, account) {
new PNotify({
type: "success",
title: "Save",
text: "Account #" + account.id + " deleted."
});
});
/*
* Reload acounts when an account is deleted.
*/
$rootScope.$on("accountDeletedEvent", function(e, account) {
$scope.loadAccounts();
});
/*
* Reload accounts and emit accountsLoadedEvent.
*/
$scope.loadAccounts = function() {
// Reset the new account.
$scope.newAccount = new Accounts();
// Load accounts using the resource.
$scope.accounts = Accounts.query(function (data) {
$scope.$emit("accountsLoadedEvent", $scope.accounts);
});
};
$scope.loadAccounts();
// Load accounts.
$scope.accounts = Accounts.query();
}]);

View File

@ -93,6 +93,11 @@
<span class="fa fa-pencil-square-o"></span>
</button>
<button type="button" class="btn btn-xs btn-default"
ng-click="deleteAccount(account, $index)">
<span class="fa fa-trash-o"></span>
</button>
<a ng-if="!isNew(account)" class="btn btn-xs btn-default" href="account/{{ account.id }}/scheduler">
<span class="fa fa-clock-o"></span>
</a>