-
Notifications
You must be signed in to change notification settings - Fork 21
/
favorites-assistant.js
176 lines (133 loc) · 5.39 KB
/
favorites-assistant.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
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
function FavoritesAssistant() {
/* this is the creator function for your scene assistant object. It will be passed all the
additional parameters (after the scene name) that were passed to pushScene. The reference
to the scene controller (this.controller) has not be established yet, so any initialization
that needs the scene controller should be done in the setup function below. */
scene_helpers.addCommonSceneMethods(this);
}
FavoritesAssistant.prototype.setup = function() {
this.timelineModel = {items: []};
this.controller.setupWidget("favorites-timeline", {itemTemplate: "shared/tweet", hasNoWidgets: true, lookahead: 20, renderLimit: 20}, this.timelineModel);
this.controller.setupWidget("timeline-filter", {}, {});
this.filterState = "favorites";
this.scroller = this.controller.getSceneScroller();
this.initAppMenu({ 'items':loggedin_appmenu_items });
this.initTwit('DOM');
this.setupCommonMenus({
viewMenuItems: [
{
items:[
{label: $L("Favorites"), command:'scroll-top', 'class':"palm-header left", width:320}
]
}
],
cmdMenuItems: [
{label:$L('Compose'), icon:'compose', command:'compose', shortcut:'N'},
{
toggleCmd:'IGNORE',
items: [
{label:$L('My Timeline'), icon:'conversation', command:'my-timeline', shortcut:'T'},
{label:$L('Favorites'), iconPath:'images/theme/menu-icon-favorite.png', command:'IGNORE', shortcut:'F', 'class':"palm-header left"},
{label:$L('Search'), icon:'search', command:'search', shortcut:'S'}
]
},
{label:$L('Refresh'), icon:'sync', command:'refresh', shortcut:'R'}
]
});
/* this function is for setup tasks that have to happen when the scene is first created */
/* use Luna.View.render to render view templates and add them to the scene, if needed. */
/* setup widgets here */
/* add event handlers to listen to events from widgets */
this.setupInlineSpinner('activity-spinner-favorites');
this.refreshOnActivate = true;
};
FavoritesAssistant.prototype.activate = function(event) {
/* put in event handlers here that should only be in effect when this scene is active. For
example, key handlers that are observing the document */
// this.addPostPopup();
var thisA = this; // for closures below
var tts = sc.app.prefs.get('timeline-text-size');
this.setTimelineTextSize('#favorites-timeline', tts);
/*
Prepare for timeline entry taps
*/
this.bindTimelineEntryTaps('#favorites-timeline');
this.controller.listen("favorites-timeline", Mojo.Event.listTap, this.handleTimelineTap);
this.controller.listen("timeline-filter", Mojo.Event.filter, this.handleFilterField.bind(this));
/*
set up the public timeline
*/
this.favtl = new SpazTimeline({
'timeline_container_selector' :'#favorites-timeline',
'entry_relative_time_selector':'span.date',
'success_event':'new_favorites_timeline_data',
'failure_event':'error_favorites_timeline_data',
'event_target' :document,
'refresh_time':1000*3600,
'max_items':50,
'request_data': function() {
sc.helpers.markAllAsRead('#favorites-timeline div.timeline-entry');
thisA.showInlineSpinner('activity-spinner-favorites', 'Loading favorite tweets…');
thisA.twit.getFavorites();
},
'data_success': function(e, data) {
for (var i=0, j = data.length; i < j; i++) {
sc.app.Tweets.save(data[i]);
data[i].text = Spaz.makeItemsClickable(data[i].text);
};
thisA.filterTimeline();
sc.helpers.markAllAsRead('#favorites-timeline div.timeline-entry'); // favs are never "new"
sc.helpers.updateRelativeTimes('#favorites-timeline div.timeline-entry span.date', 'data-created_at');
thisA.hideInlineSpinner('activity-spinner-favorites');
},
'data_failure': function(e, error_obj) {
// error_obj.url
// error_obj.xhr
// error_obj.msg
var err_msg = $L("There was an error retrieving your favorites");
thisA.displayErrorInfo(err_msg, error_obj);
/*
Update relative dates
*/
sch.updateRelativeTimes('#favorites-timeline>div.timeline-entry .meta>.date', 'data-created_at');
thisA.hideInlineSpinner('activity-spinner-favorites');
},
'renderer': function() {}
});
/*
start the favs timeline
*/
if (this.refreshOnActivate) {
this.favtl.start();
this.refreshOnActivate = false;
}
};
FavoritesAssistant.prototype.deactivate = function(event) {
/*
stop listening for timeline entry taps
*/
this.unbindTimelineEntryTaps('#favorites-timeline');
this.controller.stopListening("favorites-timeline", Mojo.Event.listTap, this.handleTimelineTap);
this.controller.stopListening("timeline-filter", Mojo.Event.filter, this.handleFilterField);
/*
unbind and stop refresher for public timeline
*/
this.favtl.cleanup();
};
FavoritesAssistant.prototype.cleanup = function(event) {
/* this function should do any cleanup needed before the scene is destroyed as
a result of being popped off the scene stack */
};
FavoritesAssistant.prototype.getEntryElementByStatusId = function(id) {
var el = jQuery('#favorites-timeline div.timeline-entry[data-status-id='+id+']', this.scroller).get(0);
return el;
};
FavoritesAssistant.prototype.refresh = function(event) {
this.favtl.refresh();
};
// FavoritesAssistant.prototype.getData = function() {
// sc.helpers.markAllAsRead('#favorites-timeline>div.timeline-entry');
// this.showInlineSpinner('activity-spinner-favorites', 'Loading favorite tweets…');
//
// this.twit.getFavorites();
// };