-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathelt.js
66 lines (58 loc) · 1.6 KB
/
elt.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
const currencyOptions = {
formatWithSymbol: true,
precision: 2,
separator: ',',
};
const baseURL = "https://www.extra-life.org/api/";
function createApiActionFor(fuseaction){
return function(data, callback) {
let timestamp = {
timestamp: new Date().getTime()
};
$.ajax({
type: 'GET',
url: baseURL + fuseaction.replace("{}", data),
timestamp,
success: callback,
error: function() {
callback({});
}
});
};
}
function createDateApiActionFor(fuseaction){
return function(data, callDate, callback) {
let timestamp = {
timestamp: new Date().getTime()
};
let callURL = baseURL + fuseaction.replace("{}", data);
callURL = callURL.replace("[]", callDate.toISOString());
$.ajax({
type: 'GET',
url: callURL,
timestamp,
success: callback,
error: function() {
callback({});
}
});
};
}
window.ELT = {
isEmpty: function(value) {
return (value == null || value === "");
},
toCurrency: function( value ) {
return currency(value, currencyOptions).format();
},
api: {
participant: createApiActionFor('participants/{}'),
participantDonations: createApiActionFor('participants/{}/donations'),
participantDonationsAfterDate: createDateApiActionFor('participants/{}/donations?where=createdDateUTC>[]'),
participantIncentives: createApiActionFor('1.3/participants/{}/incentives'),
team: createApiActionFor('teams/{}'),
teamParticipants: createApiActionFor('teams/{}/participants'),
teamDonations: createDateApiActionFor('teams/{}/donations'),
teamDonationsAfterDate: createDateApiActionFor('teams/{}/donations?where=createdDateUTC>[]'),
},
};