Rewrote account management.
This commit is contained in:
parent
d26f086a43
commit
caa68a7385
@ -29,8 +29,20 @@ accountantApp
|
|||||||
|
|
||||||
.controller(
|
.controller(
|
||||||
"AccountController", [
|
"AccountController", [
|
||||||
"$scope", "$rootScope", "$routeParams", "Accounts",
|
"$scope", "$rootScope", "$routeParams", "Accounts", "notificationService",
|
||||||
function($scope, $rootScope, $routeParams, Accounts) {
|
function($scope, $rootScope, $routeParams, Accounts, notificationService) {
|
||||||
|
|
||||||
|
$scope.rowClass = function(account) {
|
||||||
|
if(!account || !account.authorized_overdraft || !account.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(account.current <account.authorized_overdraft) {
|
||||||
|
return "danger";
|
||||||
|
} else if(account.current < 0) {
|
||||||
|
return "warning";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$scope.valueClass = function(account, value) {
|
$scope.valueClass = function(account, value) {
|
||||||
if(!account || !value) {
|
if(!account || !value) {
|
||||||
@ -38,33 +50,34 @@ accountantApp
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(value < account.authorized_overdraft) {
|
if(value < account.authorized_overdraft) {
|
||||||
return "text-error";
|
return "text-danger";
|
||||||
} else if(value < 0) {
|
} else if(value < 0) {
|
||||||
return "text-warning";
|
return "text-warning";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
$scope.addAccount = function() {
|
||||||
* Create a new account and emit accountCreatedEvent.
|
if(!$scope.inserted) {
|
||||||
*/
|
$scope.inserted = new Accounts();
|
||||||
$scope.createAccount = function(account) {
|
$scope.inserted.authorized_overdraft = 0;
|
||||||
account.$save(function(account) {
|
$scope.accounts.splice(0,0, $scope.inserted);
|
||||||
// Reset new account.
|
}
|
||||||
$scope.cancelEditAccount(account);
|
};
|
||||||
|
|
||||||
$scope.$emit("accountCreatedEvent", account);
|
$scope.cancelEdit = function(rowform, account) {
|
||||||
});
|
if(account == $scope.inserted) {
|
||||||
|
$scope.inserted=false;
|
||||||
|
$scope.accounts.splice(0,1);
|
||||||
|
} else {
|
||||||
|
rowform.$cancel();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notify on account created event.
|
* Notify on account created event.
|
||||||
*/
|
*/
|
||||||
$rootScope.$on("accountCreatedEvent", function(e, account) {
|
$rootScope.$on("accountCreatedEvent", function(e, account) {
|
||||||
new PNnotify({
|
notificationService.success("Account #" + account.id + " created.");
|
||||||
type: "success",
|
|
||||||
title: "Save",
|
|
||||||
text: "Account #" + account.id + " created."
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -74,33 +87,27 @@ accountantApp
|
|||||||
$scope.loadAccounts();
|
$scope.loadAccounts();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
* Start account edition.
|
|
||||||
*/
|
|
||||||
$scope.editAccount = function(account) {
|
|
||||||
account.editing = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Cancel account edition.
|
|
||||||
*/
|
|
||||||
$scope.cancelEditAccount = function(account) {
|
|
||||||
if(account.id) {
|
|
||||||
// Reload account if it is a saved one.
|
|
||||||
account.$get();
|
|
||||||
} else {
|
|
||||||
// Reset the new account.
|
|
||||||
$scope.newAccount = new Accounts();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save account and emit accountSavedEvent.
|
* Save account and emit accountSavedEvent.
|
||||||
*/
|
*/
|
||||||
$scope.saveAccount = function(account, modalScope) {
|
$scope.saveAccount = function($data, $index) {
|
||||||
account.$save(function(data) {
|
var account = $scope.accounts[$index];
|
||||||
$scope.$emit("accountSavedEvent", account);
|
|
||||||
});
|
account = angular.merge(account, $data);
|
||||||
|
|
||||||
|
var promise = account.$save();
|
||||||
|
|
||||||
|
if(account == $scope.inserted) {
|
||||||
|
return promise.then(function(data) {
|
||||||
|
$scope.inserted = false;
|
||||||
|
$scope.$emit("accountCreatedEvent", data);
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return promise.then(function(data) {
|
||||||
|
$scope.$emit("accountSavedEvent", data);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -115,7 +122,7 @@ accountantApp
|
|||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete an account and emut accountDeletedEvent.
|
* Delete an account and emit accountDeletedEvent.
|
||||||
*/
|
*/
|
||||||
$scope.deleteAccount = function(account, modalScope) {
|
$scope.deleteAccount = function(account, modalScope) {
|
||||||
account.$delete(function(data) {
|
account.$delete(function(data) {
|
||||||
|
@ -17,11 +17,13 @@
|
|||||||
var accountantApp = angular.module("accountantApp", [
|
var accountantApp = angular.module("accountantApp", [
|
||||||
'ngResource', 'ngRoute',
|
'ngResource', 'ngRoute',
|
||||||
"mgcrea.ngStrap",
|
"mgcrea.ngStrap",
|
||||||
"highcharts-ng"
|
"highcharts-ng",
|
||||||
|
"jlareau.pnotify",
|
||||||
|
"xeditable"
|
||||||
])
|
])
|
||||||
|
|
||||||
.config(function($httpProvider, $routeProvider, $locationProvider) {
|
.config(function($httpProvider, $routeProvider, $locationProvider) {
|
||||||
$httpProvider.interceptors.push(function($q) {
|
$httpProvider.interceptors.push(function($q, notificationService) {
|
||||||
return {
|
return {
|
||||||
"response": function(response) {
|
"response": function(response) {
|
||||||
if(response.data.ok === false) {
|
if(response.data.ok === false) {
|
||||||
@ -33,13 +35,7 @@ var accountantApp = angular.module("accountantApp", [
|
|||||||
|
|
||||||
"responseError": function(response) {
|
"responseError": function(response) {
|
||||||
// TODO Intercept Authentication Required error
|
// TODO Intercept Authentication Required error
|
||||||
new PNotify({
|
notificationService.error(response.data.text);
|
||||||
type: "error",
|
|
||||||
title: response.data.title,
|
|
||||||
text: response.data.text,
|
|
||||||
width: 300
|
|
||||||
});
|
|
||||||
|
|
||||||
return $q.reject(response);
|
return $q.reject(response);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -60,4 +56,8 @@ var accountantApp = angular.module("accountantApp", [
|
|||||||
|
|
||||||
$locationProvider.html5Mode(true);
|
$locationProvider.html5Mode(true);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
.run(function(editableOptions) {
|
||||||
|
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
|
||||||
|
})
|
||||||
;
|
;
|
||||||
|
@ -16,102 +16,85 @@
|
|||||||
-->
|
-->
|
||||||
<!-- vim: set tw=80 ts=2 sw=2 sts=2: -->
|
<!-- vim: set tw=80 ts=2 sw=2 sts=2: -->
|
||||||
<!-- Row with entry table -->
|
<!-- Row with entry table -->
|
||||||
<div class="row">
|
<div>
|
||||||
<table class="table table-striped table-condensed table-hover">
|
<div class="row">
|
||||||
<!-- Head of the table containing column headers and size -->
|
<div class="col-md-3 col-md-offset-1">
|
||||||
<thead>
|
<button class="btn btn-success" ng-click="addAccount()">Ajouter</button>
|
||||||
<tr>
|
</div>
|
||||||
<th class="">Nom du compte</th>
|
</div>
|
||||||
<th class="col-md-1">Solde courant</th>
|
|
||||||
<th class="col-md-1">Solde pointé</th>
|
|
||||||
<th class="col-md-1">Découvert autorisé</th>
|
|
||||||
<th class="col-md-1">Actions</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<!-- Body of the table containing the entries -->
|
<div class="row">
|
||||||
<tbody>
|
<table class="table table-striped table-condensed table-hover">
|
||||||
<tr class=form-inline">
|
<!-- Head of the table containing column headers and size -->
|
||||||
<td>
|
<thead>
|
||||||
<input type="text" class="form-control" ng-model="newAccount.name" />
|
<tr>
|
||||||
</td>
|
<th class="">Nom du compte</th>
|
||||||
|
<th class="col-md-1">Solde courant</th>
|
||||||
|
<th class="col-md-1">Solde pointé</th>
|
||||||
|
<th class="col-md-1">Découvert autorisé</th>
|
||||||
|
<th class="col-md-1">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
<td></td>
|
<!-- Body of the table containing the entries -->
|
||||||
|
<tbody>
|
||||||
|
<tr id="{{ account.id }}" class="form-inline" ng-class="rowClass(account)" ng-repeat="account in accounts">
|
||||||
|
<td>
|
||||||
|
<span editable-text="account.name" e-placeholder="Nom du compte" e-name="name" e-form="rowform" e-required>
|
||||||
|
<a href="account/{{ account.id }}/entries">{{ account.name }}</a>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
|
||||||
<td></td>
|
<td>
|
||||||
|
<span ng-class="valueClass(account, account.current)">
|
||||||
|
{{ account.current }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<input type="text" class="form-control"
|
<span ng-class="valueClass(account, account.pointed)">
|
||||||
ng-model="newAccount.authorized_overdraft" />
|
{{ account.pointed }}
|
||||||
</td>
|
</span>
|
||||||
|
</td>
|
||||||
<td>
|
|
||||||
<div class="btn-group">
|
|
||||||
<button class="btn btn-xs btn-success"
|
|
||||||
ng-click="createAccount(newAccount)">
|
|
||||||
<span class="fa fa-plus"></span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="btn btn-xs btn-default"
|
<td>
|
||||||
ng-click="resetAccount(newAccount)">
|
<span editable-number="account.authorized_overdraft" e-max="0" e-name="authorized_overdraft" e-form="rowform">
|
||||||
<span class="fa fa-times"></span>
|
{{ account.authorized_overdraft }}
|
||||||
</button>
|
</span>
|
||||||
</div>
|
</td>
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr id="account_{{account.id}}" class="form-inline" ng-if="!account.editing" ng-repeat-start="account in accounts">
|
<td>
|
||||||
<td><a href="account/{{ account.id }}/entries">{{ account.name }}</a></td>
|
<form editable-form name="rowform" onbeforesave="saveAccount($data, $index)" shown="inserted == account">
|
||||||
<td><span ng-class="valueClass(account, account.current)">{{ account.current }}</span></td>
|
<div class="btn-group">
|
||||||
<td><span ng-class="valueClass(account, account.pointed)">{{ account.pointed }}</span></td>
|
<button type="submit" class="btn btn-xs btn-success"
|
||||||
<td>{{ account.authorized_overdraft }}</td>
|
ng-if="rowform.$visible">
|
||||||
<td>
|
<span class="fa fa-floppy-o"></span>
|
||||||
<div class="btn-group">
|
</button>
|
||||||
<button class="btn btn-xs btn-success"
|
|
||||||
ng-click="editAccount(account)">
|
|
||||||
<span class="fa fa-pencil-square-o"></span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="btn btn-xs btn-default"
|
<button class="btn btn-xs btn-default"
|
||||||
ng-click="deleteAccount(account)">
|
ng-if="rowform.$visible && inserted == account"
|
||||||
<span class="fa fa-trash"></span>
|
ng-click="accounts.splice(0,1)">
|
||||||
</button>
|
<span class="fa fa-times"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
<a class="btn btn-xs btn-default"
|
<button class="btn btn-xs btn-default"
|
||||||
href="account/{{ account.id }}/scheduler">
|
ng-if="rowform.$visible && inserted != account" ng-click="rowform.$cancel()">
|
||||||
<span class="fa fa-clock-o"></span>
|
<span class="fa fa-times"></span>
|
||||||
</a>
|
</button>
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr id="account_{{account.id}}" class="form-inline" ng-if="account.editing" ng-repeat-end>
|
<button type="button" ng-show="!rowform.$visible"
|
||||||
<td>
|
class="btn btn-xs btn-success" ng-click="rowform.$show()">
|
||||||
<input type="text" class="form-control" ng-model="account.name" />
|
<span class="fa fa-pencil-square-o"></span>
|
||||||
</td>
|
</button>
|
||||||
|
|
||||||
<td><span ng-class="valueClass(account, account.current)">{{ account.current }}</span></td>
|
<a ng-if="!isNew(account)" class="btn btn-xs btn-default" href="account/{{ account.id }}/scheduler">
|
||||||
<td><span ng-class="valueClass(account, account.pointed)">{{ account.pointed }}</span></td>
|
<span class="fa fa-clock-o"></span>
|
||||||
|
</a>
|
||||||
<td>
|
</div>
|
||||||
<input type="text" class="form-control"
|
</form>
|
||||||
ng-model="account.authorized_overdraft" />
|
</td>
|
||||||
</td>
|
</tr>
|
||||||
|
</tbody>
|
||||||
<td>
|
</table>
|
||||||
<div class="btn-group">
|
</div>
|
||||||
<button class="btn btn-xs btn-success"
|
|
||||||
ng-click="saveAccount(account)">
|
|
||||||
<span class="fa fa-floppy-o"></span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="btn btn-xs btn-default"
|
|
||||||
ng-click="cancelEditAccount(account)">
|
|
||||||
<span class="fa fa-times"></span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user