Add account deletion.
This commit is contained in:
parent
a23cb97721
commit
25f43228dd
@ -120,7 +120,7 @@ class AccountResource(Resource):
|
|||||||
|
|
||||||
session.delete(account)
|
session.delete(account)
|
||||||
|
|
||||||
return account
|
return None, 204
|
||||||
|
|
||||||
@session_aware
|
@session_aware
|
||||||
@marshal_with_field(Object(resource_fields))
|
@marshal_with_field(Object(resource_fields))
|
||||||
|
@ -74,21 +74,7 @@ accountantApp
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notify on account created event.
|
* Save account.
|
||||||
*/
|
|
||||||
$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.
|
|
||||||
*/
|
*/
|
||||||
$scope.saveAccount = function($data, $index) {
|
$scope.saveAccount = function($data, $index) {
|
||||||
var account = $scope.accounts[$index];
|
var account = $scope.accounts[$index];
|
||||||
@ -98,68 +84,42 @@ accountantApp
|
|||||||
var promise = account.$save();
|
var promise = account.$save();
|
||||||
|
|
||||||
if(account == $scope.inserted) {
|
if(account == $scope.inserted) {
|
||||||
return promise.then(function(data) {
|
promise = promise.then(function(data) {
|
||||||
$scope.inserted = false;
|
$scope.inserted = false;
|
||||||
$scope.$emit("accountCreatedEvent", data);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
return data;
|
||||||
return promise.then(function(data) {
|
|
||||||
$scope.$emit("accountSavedEvent", data);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
return promise.then(function(data) {
|
||||||
* Notify on account saved event.
|
notificationService.success("Account #" + data.id + " saved.");
|
||||||
*/
|
|
||||||
$rootScope.$on("accountSavedEvent", function(e, account) {
|
return data;
|
||||||
new PNnotify({
|
|
||||||
type: "success",
|
|
||||||
title: "Save",
|
|
||||||
text: "Account #" + account.id + " saved."
|
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete an account and emit accountDeletedEvent.
|
* Delete an account and emit accountDeletedEvent.
|
||||||
*/
|
*/
|
||||||
$scope.deleteAccount = function(account, modalScope) {
|
$scope.deleteAccount = function(account, $index) {
|
||||||
account.$delete(function(data) {
|
var id = account.id;
|
||||||
$scope.$emit("accountDeletedEvent", account);
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
// Load accounts.
|
||||||
* Notify on account deleted event.
|
$scope.accounts = Accounts.query();
|
||||||
*/
|
|
||||||
$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();
|
|
||||||
}]);
|
}]);
|
||||||
|
@ -93,6 +93,11 @@
|
|||||||
<span class="fa fa-pencil-square-o"></span>
|
<span class="fa fa-pencil-square-o"></span>
|
||||||
</button>
|
</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">
|
<a ng-if="!isNew(account)" class="btn btn-xs btn-default" href="account/{{ account.id }}/scheduler">
|
||||||
<span class="fa fa-clock-o"></span>
|
<span class="fa fa-clock-o"></span>
|
||||||
</a>
|
</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user