diff --git a/accountant/api/views/accounts.py b/accountant/api/views/accounts.py
index 12d7a0f..f37dce6 100644
--- a/accountant/api/views/accounts.py
+++ b/accountant/api/views/accounts.py
@@ -120,7 +120,7 @@ class AccountResource(Resource):
session.delete(account)
- return account
+ return None, 204
@session_aware
@marshal_with_field(Object(resource_fields))
diff --git a/accountant/frontend/static/js/accounts.js b/accountant/frontend/static/js/accounts.js
index c8233fd..b82fc07 100644
--- a/accountant/frontend/static/js/accounts.js
+++ b/accountant/frontend/static/js/accounts.js
@@ -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();
}]);
diff --git a/accountant/frontend/static/templates/accounts.html b/accountant/frontend/static/templates/accounts.html
index b8bf171..f6071f5 100644
--- a/accountant/frontend/static/templates/accounts.html
+++ b/accountant/frontend/static/templates/accounts.html
@@ -93,6 +93,11 @@
+
+