Initialize account from parent.

This commit is contained in:
Alexis Lahouze 2017-07-05 21:36:23 +02:00
parent 7ace852f43
commit 2a2738ddeb

View File

@ -35,6 +35,7 @@ var balanceChartModule = angular.module('balanceChartModule', [
.component('balanceChart', { .component('balanceChart', {
template: '<div></div>', template: '<div></div>',
bindings: { bindings: {
account: '<',
onUpdate: '&' onUpdate: '&'
}, },
controller: function($routeParams, Balances, Account, $element) { controller: function($routeParams, Balances, Account, $element) {
@ -131,10 +132,6 @@ var balanceChartModule = angular.module('balanceChartModule', [
}, },
y: { y: {
show: true, show: true,
lines: [
{ value: 0, axis: 'y2' },
{ value: 0, axis: 'y', class: 'zeroline'}
]
} }
}, },
tooltip: { tooltip: {
@ -153,12 +150,34 @@ var balanceChartModule = angular.module('balanceChartModule', [
}); });
vm.loadData(); vm.loadData();
};
vm.setLines = function(account) {
if(vm.chart) {
vm.chart.ygrids([
{ value: 0, axis: 'y2' },
{ value: 0, axis: 'y', class: 'zeroline'},
]);
Account.get({id: $routeParams.accountId}, function(result) {
vm.chart.ygrids.add({ vm.chart.ygrids.add({
value: result.authorized_overdraft, class: 'overdraft' value: account.authorized_overdraft,
axis: 'y',
class: 'overdraft'
}); });
}); }
};
vm.$onChanges = function(changes) {
if('account' in changes) {
if('$promise' in vm.account && vm.account.$resolved === false) {
vm.account.$promise.then(function(account) {
vm.setLines(account);
return account;
});
} else {
vm.setLines(vm.account);
}
}
}; };
} }
}).factory('Balances', function($resource) { }).factory('Balances', function($resource) {