This commit is contained in:
Alexis Lahouze 2015-08-21 01:19:51 +02:00
parent 41647324ef
commit 50a192dbec
2 changed files with 15 additions and 13 deletions

View File

@ -19,7 +19,7 @@
// The AccountController. // The AccountController.
accountantApp accountantApp
.factory("Accounts", ["$resource", function($resource) { .factory("Account", ["$resource", function($resource) {
return $resource( return $resource(
"/api/accounts/:id", { "/api/accounts/:id", {
id: "@id" id: "@id"
@ -29,8 +29,8 @@ accountantApp
.controller( .controller(
"AccountController", [ "AccountController", [
"$scope", "Accounts", "notificationService", "$scope", "Account", "notificationService",
function($scope, Accounts, notificationService) { function($scope, Account, notificationService) {
/* /*
* Return the class for an account current value compared to authorized * Return the class for an account current value compared to authorized
@ -66,9 +66,11 @@ accountantApp
/* /*
* Add an empty account if not already added. * Add an empty account if not already added.
*/ */
$scope.addAccount = function() { $scope.add = function() {
var account = new Accounts(); var account = new Account({
account.authorized_overdraft = 0; authorized_overdraft: 0
});
$scope.accounts.splice(0, 0, account); $scope.accounts.splice(0, 0, account);
}; };
@ -86,7 +88,7 @@ accountantApp
/* /*
* Save account. * Save account.
*/ */
$scope.saveAccount = function($data, $index) { $scope.save = function($data, $index) {
var account = $scope.accounts[$index]; var account = $scope.accounts[$index];
account = angular.merge(account, $data); account = angular.merge(account, $data);
@ -120,9 +122,9 @@ accountantApp
}; };
/* /*
* Delete an account and emit accountDeletedEvent. * Delete an account.
*/ */
$scope.deleteAccount = function(account, $index) { $scope.delete = function(account, $index) {
var id = account.id; var id = account.id;
bootbox.confirm( bootbox.confirm(
@ -141,5 +143,5 @@ accountantApp
}; };
// Load accounts. // Load accounts.
$scope.accounts = Accounts.query(); $scope.accounts = Account.query();
}]); }]);

View File

@ -31,7 +31,7 @@
<tr> <tr>
<td colspan="5"> <td colspan="5">
<button class="btn btn-success btn-success" <button class="btn btn-success btn-success"
ng-click="addAccount()">Ajouter</button> ng-click="add()">Ajouter</button>
</td> </td>
</tr> </tr>
@ -70,7 +70,7 @@
<td> <td>
<form editable-form name="rowform" <form editable-form name="rowform"
onbeforesave="saveAccount($data, $index)" shown="!account.id"> onbeforesave="save($data, $index)" shown="!account.id">
<div class="btn-group btn-group-xs"> <div class="btn-group btn-group-xs">
<!-- Edit account. --> <!-- Edit account. -->
<button type="button" class="btn btn-success" <button type="button" class="btn btn-success"
@ -95,7 +95,7 @@
<!-- Delete account, with confirm. --> <!-- Delete account, with confirm. -->
<button type="button" class="btn btn-default" <button type="button" class="btn btn-default"
ng-if="account.id" ng-if="account.id"
ng-click="deleteAccount(account, $index)"> ng-click="delete(account, $index)">
<span class="fa fa-trash-o"></span> <span class="fa fa-trash-o"></span>
</button> </button>