forked from bdacode/zendesk-lotus-widget
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
87 lines (75 loc) · 2.81 KB
/
app.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
(function() {
return {
defaultState: 'loading',
requests: {
fetchAccountInfo: function(key) {
return {
url: 'https://webhooks.aweber.com/zendesk-widget/lotus?'+key+'&email='+this.email,
dataType: 'json'
};
}
},
events: {
'app.activated': 'requestAccountInfo',
'fetchAccountInfo.done': function(data) {
this.renderAccountInfo((data || {}));
},
'fetchAccountInfo.fail': function(data) {
this.switchTo('failed', {});
},
'ticket.requester.email.changed': 'requestAccountInfo',
'click .aweber_section': function(event) {
event.preventDefault();
var target = event.target || event.srcElement;
this.$('#aweber_submenu_'+target.id.split('_')[2]).show();
this.$('.aweber_app').hide();
},
'click .aweber_back_to_lists': function() {
this.submenus.hide();
this.$('.aweber_app').show();
},
'click .update-aweber': function(event) {
event.preventDefault();
var target = event.target || event.srcElement;
this.updateTicketInfo('customer', target.text);
}
},
renderAccountInfo: function(accountInfo) {
this.anysubs = false;
if(accountInfo.subscribed.length === 0 && accountInfo.unconfirmed.length === 0 && accountInfo.unsubscribed.length === 0) {
this.switchTo('not_found', { email: this.email });
return;
}
if(accountInfo.subscribed.length === 0 && accountInfo.unconfirmed.length === 0) {
this.anysubs = false;
} else {
this.anysubs = true;
}
this.subscribed = accountInfo.subscribed;
this.unconfirmed = accountInfo.unconfirmed;
this.unsubscribed = accountInfo.unsubscribed;
if(accountInfo.status != 'success') {
this.switchTo('failed', {});
return;
}
this.switchTo('info', {
anysubs: this.anysubs,
email: this.email,
subscribed: this.subscribed,
unconfirmed: this.unconfirmed,
unsubscribed: this.unsubscribed
});
this.submenus = this.$('.aweber_submenu');
this.submenus.hide();
},
requestAccountInfo: function() {
this.email = this.ticket().requester().email();
var key = this.settings.app_key;
if(key.length === 0) {
this.switchTo('no_key', {});
return;
}
this.ajax('fetchAccountInfo', key);
}
};
}());