-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
293 lines (269 loc) · 10.6 KB
/
app.ts
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
module CurrencyModule {
var Currencies = Object.freeze({
"AFN": "Afghani",
"EUR": "Euro",
"ALL": "Lek",
"DZD": "Algerian Dinar",
"USD": "US Dollar",
"AOA": "Kwanza",
"XCD": "East Caribbean Dollar",
"ARS": "Argentine Peso",
"AMD": "Armenian Dram",
"AWG": "Aruban Florin",
"AUD": "Australian Dollar",
"AZN": "Azerbaijanian Manat",
"BSD": "Bahamian Dollar",
"BHD": "Bahraini Dinar",
"BDT": "Taka",
"BBD": "Barbados Dollar",
"BYR": "Belarusian Ruble",
"BZD": "Belize Dollar",
"XOF": "CFA Franc BCEAO",
"BMD": "Bermudian Dollar",
"INR": "Indian Rupee",
"BTN": "Ngultrum",
"BOB": "Boliviano",
"BOV": "Mvdol",
"BAM": "Convertible Mark",
"BWP": "Pula",
"NOK": "Norwegian Krone",
"BRL": "Brazilian Real",
"BND": "Brunei Dollar",
"BGN": "Bulgarian Lev",
"BIF": "Burundi Franc",
"CVE": "Cabo Verde Escudo",
"KHR": "Riel",
"XAF": "CFA Franc BEAC",
"CAD": "Canadian Dollar",
"KYD": "Cayman Islands Dollar",
"CLP": "Chilean Peso",
"CLF": "Unidad de Fomento",
"CNY": "Yuan Renminbi",
"COP": "Colombian Peso",
"COU": "Unidad de Valor Real",
"KMF": "Comoro Franc",
"CDF": "Congolese Franc",
"NZD": "New Zealand Dollar",
"CRC": "Costa Rican Colon",
"HRK": "Kuna",
"CUP": "Cuban Peso",
"CUC": "Peso Convertible",
"ANG": "Netherlands Antillean Guilder",
"CZK": "Czech Koruna",
"DKK": "Danish Krone",
"DJF": "Djibouti Franc",
"DOP": "Dominican Peso",
"EGP": "Egyptian Pound",
"SVC": "El Salvador Colon",
"ERN": "Nakfa",
"ETB": "Ethiopian Birr",
"FKP": "Falkland Islands Pound",
"FJD": "Fiji Dollar",
"XPF": "CFP Franc",
"GMD": "Dalasi",
"GEL": "Lari",
"GHS": "Ghana Cedi",
"GIP": "Gibraltar Pound",
"GTQ": "Quetzal",
"GBP": "Pound Sterling",
"GNF": "Guinea Franc",
"GYD": "Guyana Dollar",
"HTG": "Gourde",
"HNL": "Lempira",
"HKD": "Hong Kong Dollar",
"HUF": "Forint",
"ISK": "Iceland Krona",
"IDR": "Rupiah",
"XDR": "SDR (Special Drawing Right)",
"IRR": "Iranian Rial",
"IQD": "Iraqi Dinar",
"ILS": "New Israeli Sheqel",
"JMD": "Jamaican Dollar",
"JPY": "Yen",
"JOD": "Jordanian Dinar",
"KZT": "Tenge",
"KES": "Kenyan Shilling",
"KPW": "North Korean Won",
"KRW": "Won",
"KWD": "Kuwaiti Dinar",
"KGS": "Som",
"LAK": "Kip",
"LBP": "Lebanese Pound",
"LSL": "Loti",
"ZAR": "Rand",
"LRD": "Liberian Dollar",
"LYD": "Libyan Dinar",
"CHF": "Swiss Franc",
"MOP": "Pataca",
"MKD": "Denar",
"MGA": "Malagasy Ariary",
"MWK": "Malawi Kwacha",
"MYR": "Malaysian Ringgit",
"MVR": "Rufiyaa",
"MRO": "Ouguiya",
"MUR": "Mauritius Rupee",
"XUA": "ADB Unit of Account",
"MXN": "Mexican Peso",
"MXV": "Mexican Unidad de Inversion (UDI)",
"MDL": "Moldovan Leu",
"MNT": "Tugrik",
"MAD": "Moroccan Dirham",
"MZN": "Mozambique Metical",
"MMK": "Kyat",
"NAD": "Namibia Dollar",
"NPR": "Nepalese Rupee",
"NIO": "Cordoba Oro",
"NGN": "Naira",
"OMR": "Rial Omani",
"PKR": "Pakistan Rupee",
"PAB": "Balboa",
"PGK": "Kina",
"PYG": "Guarani",
"PEN": "Sol",
"PHP": "Philippine Peso",
"PLN": "Zloty",
"QAR": "Qatari Rial",
"RON": "Romanian Leu",
"RUB": "Russian Ruble",
"RWF": "Rwanda Franc",
"SHP": "Saint Helena Pound",
"WST": "Tala",
"STD": "Dobra",
"SAR": "Saudi Riyal",
"RSD": "Serbian Dinar",
"SCR": "Seychelles Rupee",
"SLL": "Leone",
"SGD": "Singapore Dollar",
"XSU": "Sucre",
"SBD": "Solomon Islands Dollar",
"SOS": "Somali Shilling",
"SSP": "South Sudanese Pound",
"LKR": "Sri Lanka Rupee",
"SDG": "Sudanese Pound",
"SRD": "Surinam Dollar",
"SZL": "Lilangeni",
"SEK": "Swedish Krona",
"CHE": "WIR Euro",
"CHW": "WIR Franc",
"SYP": "Syrian Pound",
"TWD": "New Taiwan Dollar",
"TJS": "Somoni",
"TZS": "Tanzanian Shilling",
"THB": "Baht",
"TOP": "Pa’anga",
"TTD": "Trinidad and Tobago Dollar",
"TND": "Tunisian Dinar",
"TRY": "Turkish Lira",
"TMT": "Turkmenistan New Manat",
"UGX": "Uganda Shilling",
"UAH": "Hryvnia",
"AED": "UAE Dirham",
"UYU": "Peso Uruguayo",
"UYI": "Uruguay Peso en Unidades Indexadas (URUIURUI)",
"UZS": "Uzbekistan Sum",
"VUV": "Vatu",
"VEF": "Bolívar",
"VND": "Dong",
"YER": "Yemeni Rial",
"ZMW": "Zambian Kwacha",
"ZWL": "Zimbabwe Dollar"
});
interface IScopeWithCurrencySelecterController extends ng.IScope {
ctrl: CurrencySelecterController;
}
class CurrencySelecterController {
public static $inject = [];
public ngModel: ng.INgModelController;
constructor() {
}
selectCurrency = (newCurrency: string) => {
if(!newCurrency)
this.ngModel.$setViewValue(null);
else
this.ngModel.$setViewValue(newCurrency);
}
}
function CurrencySelecterDirective($compile: ng.ICompileService): ng.IDirective {
return {
restrict: 'E',
require: ['ngModel', '^^?form'],
bindToController: true,
controllerAs: 'ctrl',
controller: CurrencySelecterController,
scope: {disabled: '=ngDisabled', defaultLabel: '@'},
compile: function (element: ng.IAugmentedJQuery, attr: ng.IAttributes, transclude: ng.ITranscludeFunction) {
var preferredCurrencies: string[] = [];
var includeCurrencies: string[] = [];
var excludeCurrencies: string[] = [];
var dropdownClass = 'dropdown';
if (attr['preferredCurrencies']) {
if (typeof attr['preferredCurrencies'] === 'array')
preferredCurrencies = attr['preferredCurrencies'];
else
preferredCurrencies = attr['preferredCurrencies'].toString().split(',');
}
if (attr['includeCurrencies']) {
if (typeof attr['includeCurrencies'] === 'array')
includeCurrencies = attr['includeCurrencies'];
else
includeCurrencies = attr['includeCurrencies'].toString().split(',');
}
if (attr['excludeCurrencies']) {
if (typeof attr['excludeCurrencies'] === 'array')
excludeCurrencies = attr['excludeCurrencies'];
else
excludeCurrencies = attr['excludeCurrencies'].toString().split(',');
}
if(attr['direction']) {
if(attr['direction'].toLowerCase() === 'up')
dropdownClass = 'dropup';
}
var style = attr['style'] ? attr['style'] : '';
var options: string =
'<div class="' + dropdownClass + '" style="' + style + '"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" style="' + style + '; text-align: left; padding-left: 20px;" ng-disabled="ctrl.disabled">{{ctrl.ngModel.$viewValue ? ctrl.ngModel.$viewValue : ctrl.defaultValue}}<span class="caret" style="position: absolute; right: 10px; top: 48%;"></span></button>'
+ '<ul class="dropdown-menu currency-selecter-scrollable-menu" style="' + style + '">';
options += '<li><a href="" ng-click="ctrl.selectCurrency(\'\')" role="button">{{ctrl.defaultLabel ? ctrl.defaultLabel : ""}}</a></li>';
if (preferredCurrencies.length) {
for (var i = 0; i < preferredCurrencies.length; ++i) {
if (Currencies[preferredCurrencies[i].toUpperCase()] !== void 0) {
var ucPc = preferredCurrencies[i].toUpperCase();
options += '<li><a href="" ng-click="ctrl.selectCurrency(\'' + Currencies[ucPc] + ' (' + ucPc + ')\')" role="button">' + Currencies[ucPc] + ' (' + ucPc + ')</a></li>';
}
}
options += '<li role="separator" class="divider"></li>';
}
for (var key in Currencies) {
if ((!Currencies.hasOwnProperty(key) || preferredCurrencies.some((c, idx, arr) => c.toUpperCase() === key))
|| excludeCurrencies.some((c, idx, arr) => c.toUpperCase() === key)
|| (includeCurrencies.length !== 0 && !includeCurrencies.some((c, idx, arr) => c.toUpperCase() === key)))
continue;
options += '<li><a href="" ng-click="ctrl.selectCurrency(\'' + Currencies[key] + ' (' + key + ')\')" role="button">' + Currencies[key] + ' (' + key + ')</a></li>';
}
element.append(options);
return {
pre: (scope: IScopeWithCurrencySelecterController, element: ng.IAugmentedJQuery, attr: ng.IAttributes, ctrls) => {
$compile(element.children())(scope);
var ngModel = ctrls[0];
var formCtrl = ctrls[1];
var defaultCurrency = null;
if (attr['defaultCurrency']) {
defaultCurrency = attr['defaultCurrency'].toString();
}
ngModel.$formatters.push(m => m ? Currencies[m] + ' (' + m + ')' : null);
ngModel.$parsers.push(v => v.substr(v.lastIndexOf('(') + 1, 3));
if (!ngModel.$modelValue && defaultCurrency) {
ngModel.$setViewValue(Currencies[defaultCurrency] + ' (' + defaultCurrency + ')');
ngModel.$setPristine();
if(formCtrl)
formCtrl.$setPristine();
}
scope.ctrl.ngModel = ngModel;
}
}
}
}
}
angular.module('CurrencySelecter', []).directive('currencySelecter', ['$compile', CurrencySelecterDirective]).constant('currencyConfig', {
});
}