]>
Commit | Line | Data |
---|---|---|
1 | var _infscroll_disable = 0; | |
2 | var _infscroll_request_sent = 0; | |
3 | var _search_query = false; | |
4 | var _viewfeed_last = 0; | |
5 | ||
6 | var counters_last_request = 0; | |
7 | ||
8 | function viewCategory(cat) { | |
9 | viewfeed(cat, '', true); | |
10 | return false; | |
11 | } | |
12 | ||
13 | function loadMoreHeadlines() { | |
14 | try { | |
15 | console.log("loadMoreHeadlines"); | |
16 | ||
17 | var offset = 0; | |
18 | ||
19 | var view_mode = document.forms["main_toolbar_form"].view_mode.value; | |
20 | var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; | |
21 | var num_all = $$("#headlines-frame > div[id*=RROW]").length; | |
22 | var num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat()); | |
23 | ||
24 | // TODO implement marked & published | |
25 | ||
26 | if (view_mode == "marked") { | |
27 | console.warn("loadMoreHeadlines: marked is not implemented, falling back."); | |
28 | offset = num_all; | |
29 | } else if (view_mode == "published") { | |
30 | console.warn("loadMoreHeadlines: published is not implemented, falling back."); | |
31 | offset = num_all; | |
32 | } else if (view_mode == "unread") { | |
33 | offset = unread_in_buffer; | |
34 | } else if (_search_query) { | |
35 | offset = num_all; | |
36 | } else if (view_mode == "adaptive") { | |
37 | if (num_unread > 0) | |
38 | offset = unread_in_buffer; | |
39 | else | |
40 | offset = num_all; | |
41 | } else { | |
42 | offset = num_all; | |
43 | } | |
44 | ||
45 | console.log("offset: " + offset); | |
46 | ||
47 | viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset, false, true); | |
48 | ||
49 | } catch (e) { | |
50 | exception_error("viewNextFeedPage", e); | |
51 | } | |
52 | } | |
53 | ||
54 | ||
55 | function viewfeed(feed, method, is_cat, offset, background, infscroll_req) { | |
56 | try { | |
57 | if (is_cat == undefined) | |
58 | is_cat = false; | |
59 | else | |
60 | is_cat = !!is_cat; | |
61 | ||
62 | if (method == undefined) method = ''; | |
63 | if (offset == undefined) offset = 0; | |
64 | if (background == undefined) background = false; | |
65 | if (infscroll_req == undefined) infscroll_req = false; | |
66 | ||
67 | last_requested_article = 0; | |
68 | ||
69 | if (feed != getActiveFeedId() || activeFeedIsCat() != is_cat) { | |
70 | if (!background && _search_query) _search_query = false; | |
71 | } | |
72 | ||
73 | if (!background) { | |
74 | _viewfeed_last = get_timestamp(); | |
75 | ||
76 | if (getActiveFeedId() != feed || offset == 0) { | |
77 | setActiveArticleId(0); | |
78 | _infscroll_disable = 0; | |
79 | } | |
80 | ||
81 | if (offset != 0 && !method) { | |
82 | var timestamp = get_timestamp(); | |
83 | ||
84 | if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) { | |
85 | //console.log("infscroll request in progress, aborting"); | |
86 | return; | |
87 | } | |
88 | ||
89 | _infscroll_request_sent = timestamp; | |
90 | } | |
91 | } | |
92 | ||
93 | Form.enable("main_toolbar_form"); | |
94 | ||
95 | var toolbar_query = Form.serialize("main_toolbar_form"); | |
96 | ||
97 | var query = "?op=feeds&method=view&feed=" + feed + "&" + | |
98 | toolbar_query; | |
99 | ||
100 | if (method) { | |
101 | query = query + "&m=" + param_escape(method); | |
102 | } | |
103 | ||
104 | if (!background) { | |
105 | if (_search_query) { | |
106 | force_nocache = true; | |
107 | query = query + "&" + _search_query; | |
108 | //_search_query = false; | |
109 | } | |
110 | ||
111 | if (offset != 0) { | |
112 | query = query + "&skip=" + offset; | |
113 | ||
114 | // to prevent duplicate feed titles when showing grouped vfeeds | |
115 | if (vgroup_last_feed) { | |
116 | query = query + "&vgrlf=" + param_escape(vgroup_last_feed); | |
117 | } | |
118 | } else { | |
119 | if (!method && !is_cat && feed == getActiveFeedId()) { | |
120 | query = query + "&m=ForceUpdate"; | |
121 | } | |
122 | } | |
123 | ||
124 | Form.enable("main_toolbar_form"); | |
125 | ||
126 | if (!setFeedExpandoIcon(feed, is_cat, | |
127 | (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) | |
128 | notify_progress("Loading, please wait...", true); | |
129 | } | |
130 | ||
131 | query += "&cat=" + is_cat; | |
132 | ||
133 | console.log(query); | |
134 | ||
135 | new Ajax.Request("backend.php", { | |
136 | parameters: query, | |
137 | onComplete: function(transport) { | |
138 | setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); | |
139 | headlines_callback2(transport, offset, background, infscroll_req); | |
140 | } }); | |
141 | ||
142 | } catch (e) { | |
143 | exception_error("viewfeed", e); | |
144 | } | |
145 | } | |
146 | ||
147 | function feedlist_init() { | |
148 | try { | |
149 | console.log("in feedlist init"); | |
150 | ||
151 | document.onkeydown = hotkey_handler; | |
152 | setTimeout("hotkey_prefix_timeout()", 5*1000); | |
153 | ||
154 | if (!getActiveFeedId()) { | |
155 | viewfeed(-3); | |
156 | } else { | |
157 | viewfeed(getActiveFeedId(), '', activeFeedIsCat()); | |
158 | } | |
159 | ||
160 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
161 | ||
162 | request_counters(true); | |
163 | timeout(); | |
164 | ||
165 | } catch (e) { | |
166 | exception_error("feedlist/init", e); | |
167 | } | |
168 | } | |
169 | ||
170 | ||
171 | function request_counters(force) { | |
172 | try { | |
173 | var date = new Date(); | |
174 | var timestamp = Math.round(date.getTime() / 1000); | |
175 | ||
176 | if (force || timestamp - counters_last_request > 5) { | |
177 | console.log("scheduling request of counters..."); | |
178 | ||
179 | counters_last_request = timestamp; | |
180 | ||
181 | var query = "?op=rpc&method=getAllCounters&seq=" + next_seq(); | |
182 | ||
183 | if (!force) | |
184 | query = query + "&last_article_id=" + getInitParam("last_article_id"); | |
185 | ||
186 | console.log(query); | |
187 | ||
188 | new Ajax.Request("backend.php", { | |
189 | parameters: query, | |
190 | onComplete: function(transport) { | |
191 | try { | |
192 | handle_rpc_json(transport); | |
193 | } catch (e) { | |
194 | exception_error("request_counters", e); | |
195 | } | |
196 | } }); | |
197 | ||
198 | } else { | |
199 | console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request)); | |
200 | } | |
201 | ||
202 | } catch (e) { | |
203 | exception_error("request_counters", e); | |
204 | } | |
205 | } | |
206 | ||
207 | function parse_counters(elems, scheduled_call) { | |
208 | try { | |
209 | for (var l = 0; l < elems.length; l++) { | |
210 | ||
211 | var id = elems[l].id; | |
212 | var kind = elems[l].kind; | |
213 | var ctr = parseInt(elems[l].counter); | |
214 | var error = elems[l].error; | |
215 | var has_img = elems[l].has_img; | |
216 | var updated = elems[l].updated; | |
217 | ||
218 | if (id == "global-unread") { | |
219 | global_unread = ctr; | |
220 | updateTitle(); | |
221 | continue; | |
222 | } | |
223 | ||
224 | if (id == "subscribed-feeds") { | |
225 | feeds_found = ctr; | |
226 | continue; | |
227 | } | |
228 | ||
229 | if (getFeedUnread(id, (kind == "cat")) != ctr || | |
230 | (kind == "cat")) { | |
231 | } | |
232 | ||
233 | setFeedUnread(id, (kind == "cat"), ctr); | |
234 | ||
235 | if (kind != "cat") { | |
236 | setFeedValue(id, false, 'error', error); | |
237 | setFeedValue(id, false, 'updated', updated); | |
238 | ||
239 | if (id > 0) { | |
240 | if (has_img) { | |
241 | setFeedIcon(id, false, | |
242 | getInitParam("icons_url") + "/" + id + ".ico"); | |
243 | } else { | |
244 | setFeedIcon(id, false, 'images/blank_icon.gif'); | |
245 | } | |
246 | } | |
247 | } | |
248 | } | |
249 | ||
250 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
251 | ||
252 | } catch (e) { | |
253 | exception_error("parse_counters", e); | |
254 | } | |
255 | } | |
256 | ||
257 | function getFeedUnread(feed, is_cat) { | |
258 | try { | |
259 | var tree = dijit.byId("feedTree"); | |
260 | ||
261 | if (tree && tree.model) | |
262 | return tree.model.getFeedUnread(feed, is_cat); | |
263 | ||
264 | } catch (e) { | |
265 | // | |
266 | } | |
267 | ||
268 | return -1; | |
269 | } | |
270 | ||
271 | function getFeedCategory(feed) { | |
272 | try { | |
273 | var tree = dijit.byId("feedTree"); | |
274 | ||
275 | if (tree && tree.model) | |
276 | return tree.getFeedCategory(feed); | |
277 | ||
278 | } catch (e) { | |
279 | // | |
280 | } | |
281 | ||
282 | return false; | |
283 | } | |
284 | ||
285 | function hideOrShowFeeds(hide) { | |
286 | var tree = dijit.byId("feedTree"); | |
287 | ||
288 | if (tree) | |
289 | return tree.hideRead(hide, getInitParam("hide_read_shows_special")); | |
290 | } | |
291 | ||
292 | function getFeedName(feed, is_cat) { | |
293 | var tree = dijit.byId("feedTree"); | |
294 | ||
295 | if (tree && tree.model) | |
296 | return tree.model.getFeedValue(feed, is_cat, 'name'); | |
297 | } | |
298 | ||
299 | function getFeedValue(feed, is_cat, key) { | |
300 | try { | |
301 | var tree = dijit.byId("feedTree"); | |
302 | ||
303 | if (tree && tree.model) | |
304 | return tree.model.getFeedValue(feed, is_cat, key); | |
305 | ||
306 | } catch (e) { | |
307 | // | |
308 | } | |
309 | return ''; | |
310 | } | |
311 | ||
312 | function setFeedUnread(feed, is_cat, unread) { | |
313 | try { | |
314 | var tree = dijit.byId("feedTree"); | |
315 | ||
316 | if (tree && tree.model) | |
317 | return tree.model.setFeedUnread(feed, is_cat, unread); | |
318 | ||
319 | } catch (e) { | |
320 | exception_error("setFeedUnread", e); | |
321 | } | |
322 | } | |
323 | ||
324 | function setFeedValue(feed, is_cat, key, value) { | |
325 | try { | |
326 | var tree = dijit.byId("feedTree"); | |
327 | ||
328 | if (tree && tree.model) | |
329 | return tree.model.setFeedValue(feed, is_cat, key, value); | |
330 | ||
331 | } catch (e) { | |
332 | // | |
333 | } | |
334 | } | |
335 | ||
336 | function selectFeed(feed, is_cat) { | |
337 | try { | |
338 | var tree = dijit.byId("feedTree"); | |
339 | ||
340 | if (tree) return tree.selectFeed(feed, is_cat); | |
341 | ||
342 | } catch (e) { | |
343 | exception_error("selectFeed", e); | |
344 | } | |
345 | } | |
346 | ||
347 | function setFeedIcon(feed, is_cat, src) { | |
348 | try { | |
349 | var tree = dijit.byId("feedTree"); | |
350 | ||
351 | if (tree) return tree.setFeedIcon(feed, is_cat, src); | |
352 | ||
353 | } catch (e) { | |
354 | exception_error("setFeedIcon", e); | |
355 | } | |
356 | } | |
357 | ||
358 | function setFeedExpandoIcon(feed, is_cat, src) { | |
359 | try { | |
360 | var tree = dijit.byId("feedTree"); | |
361 | ||
362 | if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); | |
363 | ||
364 | } catch (e) { | |
365 | exception_error("setFeedIcon", e); | |
366 | } | |
367 | return false; | |
368 | } | |
369 | ||
370 | function getNextUnreadFeed(feed, is_cat) { | |
371 | try { | |
372 | var tree = dijit.byId("feedTree"); | |
373 | var nuf = tree.model.getNextUnreadFeed(feed, is_cat); | |
374 | ||
375 | if (nuf) | |
376 | return tree.model.store.getValue(nuf, 'bare_id'); | |
377 | ||
378 | } catch (e) { | |
379 | exception_error("getNextUnreadFeed", e); | |
380 | } | |
381 | } | |
382 | ||
383 | function catchupCurrentFeed(elem) { | |
384 | ||
385 | if (elem) { | |
386 | var toolbar = document.forms["main_toolbar_form"]; | |
387 | var catchup_feed = dijit.getEnclosingWidget(toolbar.catchup_feed); | |
388 | var mode = catchup_feed.attr('value'); | |
389 | ||
390 | if (mode != 'default') { | |
391 | catchupFeed(getActiveFeedId(), activeFeedIsCat(), mode); | |
392 | catchup_feed.attr('value', 'default'); | |
393 | } | |
394 | } else { | |
395 | catchupFeed(getActiveFeedId(), activeFeedIsCat()); | |
396 | } | |
397 | } | |
398 | ||
399 | function catchupFeedInGroup(id) { | |
400 | try { | |
401 | ||
402 | var title = getFeedName(id); | |
403 | ||
404 | var str = __("Mark all articles in %s as read?").replace("%s", title); | |
405 | ||
406 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { | |
407 | return viewCurrentFeed('MarkAllReadGR:' + id); | |
408 | } | |
409 | ||
410 | } catch (e) { | |
411 | exception_error("catchupFeedInGroup", e); | |
412 | } | |
413 | } | |
414 | ||
415 | function catchupFeed(feed, is_cat, mode) { | |
416 | try { | |
417 | if (is_cat == undefined) is_cat = false; | |
418 | ||
419 | var str = false; | |
420 | ||
421 | switch (mode) { | |
422 | case "1day": | |
423 | str = __("Mark all articles in %s older than 1 day as read?"); | |
424 | break; | |
425 | case "1week": | |
426 | str = __("Mark all articles in %s older than 1 week as read?"); | |
427 | break; | |
428 | case "2weeks": | |
429 | str = __("Mark all articles in %s older than 2 weeks as read?"); | |
430 | break; | |
431 | default: | |
432 | str = __("Mark all articles in %s as read?"); | |
433 | } | |
434 | ||
435 | var fn = getFeedName(feed, is_cat); | |
436 | ||
437 | str = str.replace("%s", fn); | |
438 | ||
439 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
440 | return; | |
441 | } | |
442 | ||
443 | var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" + | |
444 | feed + "&is_cat=" + is_cat + "&mode=" + mode; | |
445 | ||
446 | console.log(catchup_query); | |
447 | ||
448 | notify_progress("Loading, please wait...", true); | |
449 | ||
450 | new Ajax.Request("backend.php", { | |
451 | parameters: catchup_query, | |
452 | onComplete: function(transport) { | |
453 | handle_rpc_json(transport); | |
454 | ||
455 | var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; | |
456 | ||
457 | if (show_next_feed) { | |
458 | var nuf = getNextUnreadFeed(feed, is_cat); | |
459 | ||
460 | if (nuf) { | |
461 | viewfeed(nuf, '', is_cat); | |
462 | } | |
463 | } else { | |
464 | if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) { | |
465 | viewCurrentFeed(); | |
466 | } | |
467 | } | |
468 | ||
469 | notify(""); | |
470 | } }); | |
471 | ||
472 | } catch (e) { | |
473 | exception_error("catchupFeed", e); | |
474 | } | |
475 | } | |
476 | ||
477 | function decrementFeedCounter(feed, is_cat) { | |
478 | try { | |
479 | var ctr = getFeedUnread(feed, is_cat); | |
480 | ||
481 | if (ctr > 0) { | |
482 | setFeedUnread(feed, is_cat, ctr - 1); | |
483 | global_unread = global_unread - 1; | |
484 | updateTitle(); | |
485 | ||
486 | if (!is_cat) { | |
487 | var cat = parseInt(getFeedCategory(feed)); | |
488 | ||
489 | if (!isNaN(cat)) { | |
490 | ctr = getFeedUnread(cat, true); | |
491 | ||
492 | if (ctr > 0) { | |
493 | setFeedUnread(cat, true, ctr - 1); | |
494 | } | |
495 | } | |
496 | } | |
497 | } | |
498 | ||
499 | } catch (e) { | |
500 | exception_error("decrement_feed_counter", e); | |
501 | } | |
502 | } | |
503 | ||
504 |