-
Notifications
You must be signed in to change notification settings - Fork 98
/
bhCashboxUsers.js
37 lines (31 loc) · 951 Bytes
/
bhCashboxUsers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
angular.module('bhima.components')
.component('bhCashboxUsers', {
templateUrl : 'modules/templates/bhCashboxUsers.tmpl.html',
controller : bhCashboxUsers,
bindings : {
cashbox : '<',
},
});
bhCashboxUsers.$inject = ['CashboxService'];
// expects cashbox ID bound through 'cashbox'
function bhCashboxUsers(Cashboxes) {
const $ctrl = this;
$ctrl.$onInit = () => {
// track intiial load to allow good empty user experience
$ctrl.initialLoad = false;
};
function loadCashboxUsers(cashbox) {
Cashboxes.users.read(cashbox)
.then(users => {
$ctrl.initialLoad = true;
$ctrl.users = users;
});
}
// cashbox ID may not be available to controller on component load, allow
// this to be set any time
$ctrl.$onChanges = function onChanges(changes) {
if (changes.cashbox && changes.cashbox.currentValue) {
loadCashboxUsers(changes.cashbox.currentValue);
}
};
}