-
Notifications
You must be signed in to change notification settings - Fork 0
/
address-book.dtiv.js
99 lines (79 loc) · 2.69 KB
/
address-book.dtiv.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(function() {
'use strict';
angular
.module('ctRolodex')
.directive('ctAddressBook', directive);
function directive() {
return {
templateUrl: 'address-book.tmpl.html',
scope: {
addresses: '=',
options: '=?',
onSave: '&',
onDelete: '&',
onAdd: '&',
onSelect: '&'
},
controllerAs: 'vm',
bindToController: true,
controller: function() {
var vm = this;
vm.editInProgress = false;
vm.newAddressFormVisible = !vm.addresses.length;
if (!vm.options) {
vm.options = {};
}
// Hoek.applyToDefaults() would be nice here
vm.options.enableSave = angular.isDefined(vm.options.enableSave) ? vm.options.enableSave : false;
vm.options.enableDelete = angular.isDefined(vm.options.enableDelete) ? vm.options.enableDelete : false;
vm.options.enableSelect = angular.isDefined(vm.options.enableSelect) ? vm.options.enableSelect : false;
vm.options.enableAdd = angular.isDefined(vm.options.enableAdd) ? vm.options.enableAdd : false;
vm.options.newAddressFormVisible = angular.isDefined(vm.options.newAddressFormVisible) ? vm.options.newAddressFormVisible : true;
function remove(address) {
var index = vm.addresses.indexOf(address);
vm.addresses.splice(index, 1);
}
vm.toggleNewAddressForm = function() {
vm.newAddressFormVisible = !vm.newAddressFormVisible;
vm.editInProgress = !vm.editInProgress;
};
vm.cancel = function() {
vm.newAddressFormVisible = false;
vm.editInProgress = false;
};
vm.delete = function(address) {
if (vm.options.enableDelete) {
remove(address);
vm.onDelete({
address: address
});
}
};
vm.save = function(address) {
if (vm.options.enableSave) {
vm.onSave({
address: address
});
}
};
vm.add = function(address) {
if (vm.options.enableAdd) {
vm.editInProgress = true;
vm.addresses.push(address);
vm.onAdd({
address: address
});
vm.toggleNewAddressForm();
}
};
vm.shipTo = function(address) {
if (vm.options.enableSelect) {
vm.onSelect({
address: address
});
}
};
}
};
}
})();