forked from zendesk/demo_apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (39 loc) · 1.21 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
(function() {
return {
defaultState: 'loading',
events: {
// Lifecycle
'app.created': 'init',
'pane.activated': 'paneActivated',
// Requests
'getUserRelatedInfo.done': 'handleUserData',
// DOM events
'click a.app_view': 'handleIconClick'
},
requests: {
getUserRelatedInfo: function(id) {
return { url: helpers.fmt('/api/v2/users/%@/related.json', id) };
}
},
init: function() {
this.setIconState('inactive', this.assetURL('spinner.gif'));
this.ajax('getUserRelatedInfo', this.currentUser().id());
},
paneActivated: function(data) {
if (data.firstLoad) {
this.inDOM = true;
// DOM manipulation can be done from this point
}
},
handleUserData: function(data) {
this.setIconState('inactive', this.assetURL('icon_nav_bar_inactive.png'));
this.switchTo('user', {
hello: this.I18n.t('user.hello', { name: this.currentUser().name() }),
information: this.I18n.t('user.information', data.user_related)
});
},
handleIconClick: function() {
if (this.currentState === 'loading') { return false; }
}
};
}());