]>
Commit | Line | Data |
---|---|---|
1 | var active_post_id = false; | |
2 | ||
3 | var article_cache = new Array(); | |
4 | ||
5 | var vgroup_last_feed = false; | |
6 | var post_under_pointer = false; | |
7 | ||
8 | var last_requested_article = false; | |
9 | ||
10 | var catchup_id_batch = []; | |
11 | var catchup_timeout_id = false; | |
12 | var feed_precache_timeout_id = false; | |
13 | var precache_idle_timeout_id = false; | |
14 | ||
15 | var cids_requested = []; | |
16 | var loaded_article_ids = []; | |
17 | ||
18 | var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null; | |
19 | ||
20 | function headlines_callback2(transport, offset, background, infscroll_req) { | |
21 | try { | |
22 | handle_rpc_json(transport); | |
23 | ||
24 | loading_set_progress(25); | |
25 | ||
26 | console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req); | |
27 | ||
28 | var is_cat = false; | |
29 | var feed_id = false; | |
30 | ||
31 | var reply = false; | |
32 | ||
33 | try { | |
34 | reply = JSON.parse(transport.responseText); | |
35 | } catch (e) { | |
36 | console.error(e); | |
37 | } | |
38 | ||
39 | if (reply) { | |
40 | ||
41 | is_cat = reply['headlines']['is_cat']; | |
42 | feed_id = reply['headlines']['id']; | |
43 | ||
44 | if (background) { | |
45 | var content = reply['headlines']['content']; | |
46 | ||
47 | if (getInitParam("cdm_auto_catchup") == 1) { | |
48 | content = content + "<div id='headlines-spacer'></div>"; | |
49 | } | |
50 | ||
51 | cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], content); | |
52 | return; | |
53 | } | |
54 | ||
55 | setActiveFeedId(feed_id, is_cat); | |
56 | ||
57 | dijit.getEnclosingWidget( | |
58 | document.forms["main_toolbar_form"].update).attr('disabled', | |
59 | is_cat || feed_id <= 0); | |
60 | ||
61 | try { | |
62 | if (offset == 0 && infscroll_req == false) { | |
63 | $("headlines-frame").scrollTop = 0; | |
64 | } | |
65 | } catch (e) { }; | |
66 | ||
67 | var headlines_count = reply['headlines-info']['count']; | |
68 | ||
69 | vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; | |
70 | ||
71 | if (parseInt(headlines_count) < getInitParam("default_article_limit")) { | |
72 | _infscroll_disable = 1; | |
73 | } else { | |
74 | _infscroll_disable = 0; | |
75 | } | |
76 | ||
77 | var counters = reply['counters']; | |
78 | var articles = reply['articles']; | |
79 | //var runtime_info = reply['runtime-info']; | |
80 | ||
81 | if (offset == 0 && infscroll_req == false) { | |
82 | loaded_article_ids = []; | |
83 | ||
84 | dijit.byId("headlines-frame").attr('content', | |
85 | reply['headlines']['content']); | |
86 | ||
87 | dijit.byId("headlines-toolbar").attr('content', | |
88 | reply['headlines']['toolbar']); | |
89 | ||
90 | $$("#headlines-frame > div[id*=RROW]").each(function(row) { | |
91 | if (loaded_article_ids.indexOf(row.id) != -1) { | |
92 | row.parentNode.removeChild(row); | |
93 | } else { | |
94 | loaded_article_ids.push(row.id); | |
95 | } | |
96 | }); | |
97 | ||
98 | if (getInitParam("cdm_auto_catchup") == 1) { | |
99 | var hsp = $("headlines-spacer"); | |
100 | if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); | |
101 | dijit.byId('headlines-frame').domNode.appendChild(hsp); | |
102 | } | |
103 | ||
104 | initHeadlinesMenu(); | |
105 | ||
106 | if (_search_query) { | |
107 | $("feed_title").innerHTML += "<span id='cancel_search'>" + | |
108 | " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" + | |
109 | "</span>"; | |
110 | } | |
111 | ||
112 | } else { | |
113 | ||
114 | if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) { | |
115 | console.log("adding some more headlines: " + headlines_count); | |
116 | ||
117 | var c = dijit.byId("headlines-frame"); | |
118 | var ids = getSelectedArticleIds2(); | |
119 | var new_elems = []; | |
120 | ||
121 | $("headlines-tmp").innerHTML = reply['headlines']['content']; | |
122 | ||
123 | var hsp = $("headlines-spacer"); | |
124 | ||
125 | if (hsp) | |
126 | c.domNode.removeChild(hsp); | |
127 | ||
128 | $$("#headlines-tmp > div").each(function(row) { | |
129 | if (row.className == 'cdmFeedTitle') { | |
130 | row.style.display = 'none'; | |
131 | c.domNode.appendChild(row); | |
132 | new_elems.push(row); | |
133 | } else if (loaded_article_ids.indexOf(row.id) == -1) { | |
134 | row.style.display = 'none'; | |
135 | c.domNode.appendChild(row); | |
136 | new_elems.push(row); | |
137 | loaded_article_ids.push(row.id); | |
138 | } else { | |
139 | row.parentNode.removeChild(row); | |
140 | } | |
141 | }); | |
142 | ||
143 | if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); | |
144 | ||
145 | fixHeadlinesOrder(getLoadedArticleIds()); | |
146 | ||
147 | if (getInitParam("cdm_auto_catchup") == 1) { | |
148 | c.domNode.appendChild(hsp); | |
149 | } | |
150 | ||
151 | console.log("added " + new_elems.size() + " headlines"); | |
152 | ||
153 | if (new_elems.size() == 0) | |
154 | _infscroll_disable = true; | |
155 | ||
156 | console.log("restore selected ids: " + ids); | |
157 | ||
158 | for (var i = 0; i < ids.length; i++) { | |
159 | markHeadline(ids[i]); | |
160 | } | |
161 | ||
162 | initHeadlinesMenu(); | |
163 | ||
164 | new_elems.each(function(child) { | |
165 | var cb = dijit.byId(child.id.replace("RROW-", "RCHK-")); | |
166 | ||
167 | if (!cb) { | |
168 | dojo.parser.parse(child); | |
169 | ||
170 | if (!Element.visible(child)) | |
171 | new Effect.Appear(child, { duration : 0.5 }); | |
172 | } else { | |
173 | c.domNode.removeChild(child); | |
174 | } | |
175 | }); | |
176 | ||
177 | } else { | |
178 | console.log("no new headlines received"); | |
179 | ||
180 | var hsp = $("headlines-spacer"); | |
181 | ||
182 | if (hsp) hsp.innerHTML = ""; | |
183 | } | |
184 | } | |
185 | ||
186 | if (headlines_count > 0) | |
187 | cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML); | |
188 | ||
189 | if (articles) { | |
190 | for (var i = 0; i < articles.length; i++) { | |
191 | var a_id = articles[i]['id']; | |
192 | cache_set("article:" + a_id, articles[i]['content']); | |
193 | } | |
194 | } else { | |
195 | console.log("no cached articles received"); | |
196 | } | |
197 | ||
198 | // do not precache stuff after fresh feed | |
199 | if (feed_id != -3) | |
200 | precache_headlines(); | |
201 | ||
202 | if (counters) | |
203 | parse_counters(counters); | |
204 | else | |
205 | request_counters(true); | |
206 | ||
207 | } else if (transport.responseText) { | |
208 | console.error("Invalid object received: " + transport.responseText); | |
209 | dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" + | |
210 | __('Could not update headlines (invalid object received - see error console for details)') + | |
211 | "</div>"); | |
212 | } else { | |
213 | //notify_error("Error communicating with server."); | |
214 | Element.show(dijit.byId("net-alert").domNode); | |
215 | } | |
216 | ||
217 | _infscroll_request_sent = 0; | |
218 | ||
219 | notify(""); | |
220 | ||
221 | } catch (e) { | |
222 | exception_error("headlines_callback2", e, transport); | |
223 | } | |
224 | } | |
225 | ||
226 | function render_article(article) { | |
227 | try { | |
228 | dijit.byId("headlines-wrap-inner").addChild( | |
229 | dijit.byId("content-insert")); | |
230 | ||
231 | var c = dijit.byId("content-insert"); | |
232 | ||
233 | try { | |
234 | c.domNode.scrollTop = 0; | |
235 | } catch (e) { }; | |
236 | ||
237 | c.attr('content', article); | |
238 | ||
239 | correctHeadlinesOffset(getActiveArticleId()); | |
240 | ||
241 | try { | |
242 | c.focus(); | |
243 | } catch (e) { }; | |
244 | ||
245 | } catch (e) { | |
246 | exception_error("render_article", e); | |
247 | } | |
248 | } | |
249 | ||
250 | function showArticleInHeadlines(id) { | |
251 | ||
252 | try { | |
253 | ||
254 | selectArticles("none"); | |
255 | ||
256 | var crow = $("RROW-" + id); | |
257 | ||
258 | if (!crow) return; | |
259 | ||
260 | var article_is_unread = crow.hasClassName("Unread"); | |
261 | ||
262 | crow.removeClassName("Unread"); | |
263 | ||
264 | selectArticles('none'); | |
265 | ||
266 | var view_mode = false; | |
267 | ||
268 | try { | |
269 | view_mode = document.forms['main_toolbar_form'].view_mode; | |
270 | view_mode = view_mode[view_mode.selectedIndex].value; | |
271 | } catch (e) { | |
272 | // | |
273 | } | |
274 | ||
275 | if (article_is_unread && view_mode == "all_articles") { | |
276 | cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML); | |
277 | } | |
278 | ||
279 | markHeadline(id); | |
280 | ||
281 | if (article_is_unread) | |
282 | _force_scheduled_update = true; | |
283 | ||
284 | } catch (e) { | |
285 | exception_error("showArticleInHeadlines", e); | |
286 | } | |
287 | } | |
288 | ||
289 | function article_callback2(transport, id) { | |
290 | try { | |
291 | console.log("article_callback2 " + id); | |
292 | ||
293 | handle_rpc_json(transport); | |
294 | ||
295 | var reply = false; | |
296 | ||
297 | try { | |
298 | reply = JSON.parse(transport.responseText); | |
299 | } catch (e) { | |
300 | console.error(e); | |
301 | } | |
302 | ||
303 | if (reply) { | |
304 | ||
305 | reply.each(function(article) { | |
306 | if (active_post_id == article['id']) { | |
307 | render_article(article['content']); | |
308 | } | |
309 | cids_requested.remove(article['id']); | |
310 | ||
311 | cache_set("article:" + article['id'], article['content']); | |
312 | }); | |
313 | ||
314 | // if (id != last_requested_article) { | |
315 | // console.log("requested article id is out of sequence, aborting"); | |
316 | // return; | |
317 | // } | |
318 | ||
319 | } else if (transport.responseText) { | |
320 | console.error("Invalid object received: " + transport.responseText); | |
321 | ||
322 | render_article("<div class='whiteBox'>" + | |
323 | __('Could not display article (invalid object received - see error console for details)') + "</div>"); | |
324 | } else { | |
325 | Element.show(dijit.byId("net-alert").domNode); | |
326 | } | |
327 | ||
328 | var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length | |
329 | request_counters(unread_in_buffer == 0); | |
330 | ||
331 | headlines_scroll_handler($("headlines-frame")); | |
332 | ||
333 | /* try { | |
334 | if (!_infscroll_disable && | |
335 | $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) { | |
336 | ||
337 | loadMoreHeadlines(); | |
338 | } | |
339 | } catch (e) { | |
340 | console.warn(e); | |
341 | } */ | |
342 | ||
343 | notify(""); | |
344 | } catch (e) { | |
345 | exception_error("article_callback2", e, transport); | |
346 | } | |
347 | } | |
348 | ||
349 | function view(id) { | |
350 | try { | |
351 | var crow = $("RROW-" + id); | |
352 | ||
353 | if (!crow) return; | |
354 | ||
355 | console.log("loading article: " + id); | |
356 | ||
357 | var cached_article = cache_get("article:" + id); | |
358 | ||
359 | console.log("cache check result: " + (cached_article != false)); | |
360 | ||
361 | hideAuxDlg(); | |
362 | ||
363 | var query = "?op=article&method=view&id=" + param_escape(id); | |
364 | ||
365 | var neighbor_ids = getRelativePostIds(id); | |
366 | ||
367 | /* only request uncached articles */ | |
368 | ||
369 | var cids_to_request = []; | |
370 | ||
371 | for (var i = 0; i < neighbor_ids.length; i++) { | |
372 | if (cids_requested.indexOf(neighbor_ids[i]) == -1) | |
373 | if (!cache_get("article:" + neighbor_ids[i])) { | |
374 | cids_to_request.push(neighbor_ids[i]); | |
375 | cids_requested.push(neighbor_ids[i]); | |
376 | } | |
377 | } | |
378 | ||
379 | console.log("additional ids: " + cids_to_request.toString()); | |
380 | ||
381 | query = query + "&cids=" + cids_to_request.toString(); | |
382 | ||
383 | var article_is_unread = crow.hasClassName("Unread"); | |
384 | ||
385 | active_post_id = id; | |
386 | showArticleInHeadlines(id); | |
387 | ||
388 | precache_headlines(); | |
389 | ||
390 | if (cached_article && article_is_unread) { | |
391 | ||
392 | query = query + "&mode=prefetch"; | |
393 | ||
394 | render_article(cached_article); | |
395 | ||
396 | } else if (cached_article) { | |
397 | ||
398 | query = query + "&mode=prefetch_old"; | |
399 | render_article(cached_article); | |
400 | ||
401 | // if we don't need to request any relative ids, we might as well skip | |
402 | // the server roundtrip altogether | |
403 | if (cids_to_request.length == 0) { | |
404 | ||
405 | /* try { | |
406 | if (!_infscroll_disable && | |
407 | $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) { | |
408 | ||
409 | loadMoreHeadlines(); | |
410 | } | |
411 | } catch (e) { | |
412 | console.warn(e); | |
413 | } */ | |
414 | ||
415 | headlines_scroll_handler($("headlines-frame")); | |
416 | ||
417 | return; | |
418 | } | |
419 | } | |
420 | ||
421 | last_requested_article = id; | |
422 | ||
423 | console.log(query); | |
424 | ||
425 | if (article_is_unread) { | |
426 | decrementFeedCounter(getActiveFeedId(), activeFeedIsCat()); | |
427 | } | |
428 | ||
429 | new Ajax.Request("backend.php", { | |
430 | parameters: query, | |
431 | onComplete: function(transport) { | |
432 | article_callback2(transport, id); | |
433 | } }); | |
434 | ||
435 | return false; | |
436 | ||
437 | } catch (e) { | |
438 | exception_error("view", e); | |
439 | } | |
440 | } | |
441 | ||
442 | function toggleMark(id, client_only) { | |
443 | try { | |
444 | var query = "?op=rpc&id=" + id + "&method=mark"; | |
445 | ||
446 | var img = $("FMPIC-" + id); | |
447 | ||
448 | if (!img) return; | |
449 | ||
450 | if (img.src.match("mark_unset")) { | |
451 | img.src = img.src.replace("mark_unset", "mark_set"); | |
452 | img.alt = __("Unstar article"); | |
453 | query = query + "&mark=1"; | |
454 | ||
455 | } else { | |
456 | img.src = img.src.replace("mark_set", "mark_unset"); | |
457 | img.alt = __("Star article"); | |
458 | query = query + "&mark=0"; | |
459 | } | |
460 | ||
461 | cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML); | |
462 | ||
463 | if (!client_only) { | |
464 | new Ajax.Request("backend.php", { | |
465 | parameters: query, | |
466 | onComplete: function(transport) { | |
467 | handle_rpc_json(transport); | |
468 | } }); | |
469 | } | |
470 | ||
471 | } catch (e) { | |
472 | exception_error("toggleMark", e); | |
473 | } | |
474 | } | |
475 | ||
476 | function togglePub(id, client_only, no_effects, note) { | |
477 | try { | |
478 | var query = "?op=rpc&id=" + id + "&method=publ"; | |
479 | ||
480 | if (note != undefined) { | |
481 | query = query + "¬e=" + param_escape(note); | |
482 | } else { | |
483 | query = query + "¬e=undefined"; | |
484 | } | |
485 | ||
486 | var img = $("FPPIC-" + id); | |
487 | ||
488 | if (!img) return; | |
489 | ||
490 | if (img.src.match("pub_unset") || note != undefined) { | |
491 | img.src = img.src.replace("pub_unset", "pub_set"); | |
492 | img.alt = __("Unpublish article"); | |
493 | query = query + "&pub=1"; | |
494 | ||
495 | } else { | |
496 | img.src = img.src.replace("pub_set", "pub_unset"); | |
497 | img.alt = __("Publish article"); | |
498 | ||
499 | query = query + "&pub=0"; | |
500 | } | |
501 | ||
502 | cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML); | |
503 | ||
504 | if (!client_only) { | |
505 | new Ajax.Request("backend.php", { | |
506 | parameters: query, | |
507 | onComplete: function(transport) { | |
508 | handle_rpc_json(transport); | |
509 | } }); | |
510 | } | |
511 | ||
512 | } catch (e) { | |
513 | exception_error("togglePub", e); | |
514 | } | |
515 | } | |
516 | ||
517 | function moveToPost(mode) { | |
518 | ||
519 | try { | |
520 | ||
521 | var rows = getVisibleArticleIds(); | |
522 | ||
523 | var prev_id = false; | |
524 | var next_id = false; | |
525 | ||
526 | if (!$('RROW-' + active_post_id)) { | |
527 | active_post_id = false; | |
528 | } | |
529 | ||
530 | if (active_post_id == false) { | |
531 | next_id = rows[0]; | |
532 | prev_id = rows[rows.length-1] | |
533 | } else { | |
534 | for (var i = 0; i < rows.length; i++) { | |
535 | if (rows[i] == active_post_id) { | |
536 | ||
537 | // Account for adjacent identical article ids. | |
538 | if (i > 0) prev_id = rows[i-1]; | |
539 | ||
540 | for (var j = i+1; j < rows.length; j++) { | |
541 | if (rows[j] != active_post_id) { | |
542 | next_id = rows[j]; | |
543 | break; | |
544 | } | |
545 | } | |
546 | break; | |
547 | } | |
548 | } | |
549 | } | |
550 | ||
551 | if (mode == "next") { | |
552 | if (next_id) { | |
553 | if (isCdmMode()) { | |
554 | ||
555 | cdmExpandArticle(next_id); | |
556 | cdmScrollToArticleId(next_id); | |
557 | ||
558 | } else { | |
559 | correctHeadlinesOffset(next_id); | |
560 | view(next_id, getActiveFeedId()); | |
561 | } | |
562 | } | |
563 | } | |
564 | ||
565 | if (mode == "prev") { | |
566 | if (prev_id) { | |
567 | if (isCdmMode()) { | |
568 | cdmExpandArticle(prev_id); | |
569 | cdmScrollToArticleId(prev_id); | |
570 | } else { | |
571 | correctHeadlinesOffset(prev_id); | |
572 | view(prev_id, getActiveFeedId()); | |
573 | } | |
574 | } | |
575 | } | |
576 | ||
577 | } catch (e) { | |
578 | exception_error("moveToPost", e); | |
579 | } | |
580 | } | |
581 | ||
582 | function toggleSelected(id, force_on) { | |
583 | try { | |
584 | ||
585 | var cb = dijit.byId("RCHK-" + id); | |
586 | var row = $("RROW-" + id); | |
587 | ||
588 | if (row) { | |
589 | if (row.hasClassName('Selected') && !force_on) { | |
590 | row.removeClassName('Selected'); | |
591 | if (cb) cb.attr("checked", false); | |
592 | } else { | |
593 | row.addClassName('Selected'); | |
594 | if (cb) cb.attr("checked", true); | |
595 | } | |
596 | } | |
597 | } catch (e) { | |
598 | exception_error("toggleSelected", e); | |
599 | } | |
600 | } | |
601 | ||
602 | function toggleUnread_afh(effect) { | |
603 | try { | |
604 | ||
605 | var elem = effect.element; | |
606 | elem.style.backgroundColor = ""; | |
607 | ||
608 | } catch (e) { | |
609 | exception_error("toggleUnread_afh", e); | |
610 | } | |
611 | } | |
612 | ||
613 | function toggleUnread(id, cmode, effect) { | |
614 | try { | |
615 | ||
616 | var row = $("RROW-" + id); | |
617 | if (row) { | |
618 | if (cmode == undefined || cmode == 2) { | |
619 | if (row.hasClassName("Unread")) { | |
620 | row.removeClassName("Unread"); | |
621 | ||
622 | if (effect) { | |
623 | new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5", | |
624 | afterFinish: toggleUnread_afh, | |
625 | queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } ); | |
626 | } | |
627 | ||
628 | } else { | |
629 | row.addClassName("Unread"); | |
630 | } | |
631 | ||
632 | } else if (cmode == 0) { | |
633 | ||
634 | row.removeClassName("Unread"); | |
635 | ||
636 | if (effect) { | |
637 | new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5", | |
638 | afterFinish: toggleUnread_afh, | |
639 | queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } ); | |
640 | } | |
641 | ||
642 | } else if (cmode == 1) { | |
643 | row.addClassName("Unread"); | |
644 | } | |
645 | ||
646 | if (cmode == undefined) cmode = 2; | |
647 | ||
648 | var query = "?op=rpc&method=catchupSelected" + | |
649 | "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id); | |
650 | ||
651 | // notify_progress("Loading, please wait..."); | |
652 | ||
653 | new Ajax.Request("backend.php", { | |
654 | parameters: query, | |
655 | onComplete: function(transport) { | |
656 | handle_rpc_json(transport); | |
657 | } }); | |
658 | ||
659 | } | |
660 | ||
661 | } catch (e) { | |
662 | exception_error("toggleUnread", e); | |
663 | } | |
664 | } | |
665 | ||
666 | function selectionRemoveLabel(id, ids) { | |
667 | try { | |
668 | ||
669 | if (!ids) ids = getSelectedArticleIds2(); | |
670 | ||
671 | if (ids.length == 0) { | |
672 | alert(__("No articles are selected.")); | |
673 | return; | |
674 | } | |
675 | ||
676 | var query = "?op=rpc&method=removeFromLabel&ids=" + | |
677 | param_escape(ids.toString()) + "&lid=" + param_escape(id); | |
678 | ||
679 | console.log(query); | |
680 | ||
681 | new Ajax.Request("backend.php", { | |
682 | parameters: query, | |
683 | onComplete: function(transport) { | |
684 | handle_rpc_json(transport); | |
685 | show_labels_in_headlines(transport); | |
686 | } }); | |
687 | ||
688 | } catch (e) { | |
689 | exception_error("selectionAssignLabel", e); | |
690 | ||
691 | } | |
692 | } | |
693 | ||
694 | function selectionAssignLabel(id, ids) { | |
695 | try { | |
696 | ||
697 | if (!ids) ids = getSelectedArticleIds2(); | |
698 | ||
699 | if (ids.length == 0) { | |
700 | alert(__("No articles are selected.")); | |
701 | return; | |
702 | } | |
703 | ||
704 | var query = "?op=rpc&method=assignToLabel&ids=" + | |
705 | param_escape(ids.toString()) + "&lid=" + param_escape(id); | |
706 | ||
707 | console.log(query); | |
708 | ||
709 | new Ajax.Request("backend.php", { | |
710 | parameters: query, | |
711 | onComplete: function(transport) { | |
712 | handle_rpc_json(transport); | |
713 | show_labels_in_headlines(transport); | |
714 | } }); | |
715 | ||
716 | } catch (e) { | |
717 | exception_error("selectionAssignLabel", e); | |
718 | ||
719 | } | |
720 | } | |
721 | ||
722 | function selectionToggleUnread(set_state, callback, no_error) { | |
723 | try { | |
724 | var rows = getSelectedArticleIds2(); | |
725 | ||
726 | if (rows.length == 0 && !no_error) { | |
727 | alert(__("No articles are selected.")); | |
728 | return; | |
729 | } | |
730 | ||
731 | for (var i = 0; i < rows.length; i++) { | |
732 | var row = $("RROW-" + rows[i]); | |
733 | if (row) { | |
734 | if (set_state == undefined) { | |
735 | if (row.hasClassName("Unread")) { | |
736 | row.removeClassName("Unread"); | |
737 | } else { | |
738 | row.addClassName("Unread"); | |
739 | } | |
740 | } | |
741 | ||
742 | if (set_state == false) { | |
743 | row.removeClassName("Unread"); | |
744 | } | |
745 | ||
746 | if (set_state == true) { | |
747 | row.addClassName("Unread"); | |
748 | } | |
749 | } | |
750 | } | |
751 | ||
752 | if (rows.length > 0) { | |
753 | ||
754 | var cmode = ""; | |
755 | ||
756 | if (set_state == undefined) { | |
757 | cmode = "2"; | |
758 | } else if (set_state == true) { | |
759 | cmode = "1"; | |
760 | } else if (set_state == false) { | |
761 | cmode = "0"; | |
762 | } | |
763 | ||
764 | var query = "?op=rpc&method=catchupSelected" + | |
765 | "&cmode=" + cmode + "&ids=" + param_escape(rows.toString()); | |
766 | ||
767 | notify_progress("Loading, please wait..."); | |
768 | ||
769 | new Ajax.Request("backend.php", { | |
770 | parameters: query, | |
771 | onComplete: function(transport) { | |
772 | handle_rpc_json(transport); | |
773 | if (callback) callback(transport); | |
774 | } }); | |
775 | ||
776 | } | |
777 | ||
778 | } catch (e) { | |
779 | exception_error("selectionToggleUnread", e); | |
780 | } | |
781 | } | |
782 | ||
783 | function selectionToggleMarked() { | |
784 | try { | |
785 | ||
786 | var rows = getSelectedArticleIds2(); | |
787 | ||
788 | if (rows.length == 0) { | |
789 | alert(__("No articles are selected.")); | |
790 | return; | |
791 | } | |
792 | ||
793 | for (var i = 0; i < rows.length; i++) { | |
794 | toggleMark(rows[i], true, true); | |
795 | } | |
796 | ||
797 | if (rows.length > 0) { | |
798 | ||
799 | var query = "?op=rpc&method=markSelected&ids=" + | |
800 | param_escape(rows.toString()) + "&cmode=2"; | |
801 | ||
802 | new Ajax.Request("backend.php", { | |
803 | parameters: query, | |
804 | onComplete: function(transport) { | |
805 | handle_rpc_json(transport); | |
806 | } }); | |
807 | ||
808 | } | |
809 | ||
810 | } catch (e) { | |
811 | exception_error("selectionToggleMarked", e); | |
812 | } | |
813 | } | |
814 | ||
815 | function selectionTogglePublished() { | |
816 | try { | |
817 | ||
818 | var rows = getSelectedArticleIds2(); | |
819 | ||
820 | if (rows.length == 0) { | |
821 | alert(__("No articles are selected.")); | |
822 | return; | |
823 | } | |
824 | ||
825 | for (var i = 0; i < rows.length; i++) { | |
826 | togglePub(rows[i], true, true); | |
827 | } | |
828 | ||
829 | if (rows.length > 0) { | |
830 | ||
831 | var query = "?op=rpc&method=publishSelected&ids=" + | |
832 | param_escape(rows.toString()) + "&cmode=2"; | |
833 | ||
834 | new Ajax.Request("backend.php", { | |
835 | parameters: query, | |
836 | onComplete: function(transport) { | |
837 | handle_rpc_json(transport); | |
838 | } }); | |
839 | ||
840 | } | |
841 | ||
842 | } catch (e) { | |
843 | exception_error("selectionToggleMarked", e); | |
844 | } | |
845 | } | |
846 | ||
847 | function getSelectedArticleIds2() { | |
848 | ||
849 | var rv = []; | |
850 | ||
851 | $$("#headlines-frame > div[id*=RROW][class*=Selected]").each( | |
852 | function(child) { | |
853 | rv.push(child.id.replace("RROW-", "")); | |
854 | }); | |
855 | ||
856 | return rv; | |
857 | } | |
858 | ||
859 | function getLoadedArticleIds() { | |
860 | var rv = []; | |
861 | ||
862 | var children = $$("#headlines-frame > div[id*=RROW-]"); | |
863 | ||
864 | children.each(function(child) { | |
865 | rv.push(child.id.replace("RROW-", "")); | |
866 | }); | |
867 | ||
868 | return rv; | |
869 | ||
870 | } | |
871 | ||
872 | // mode = all,none,unread,invert,marked,published | |
873 | function selectArticles(mode) { | |
874 | try { | |
875 | ||
876 | var children = $$("#headlines-frame > div[id*=RROW]"); | |
877 | ||
878 | children.each(function(child) { | |
879 | var id = child.id.replace("RROW-", ""); | |
880 | var cb = dijit.byId("RCHK-" + id); | |
881 | ||
882 | if (mode == "all") { | |
883 | child.addClassName("Selected"); | |
884 | if (cb) cb.attr("checked", true); | |
885 | } else if (mode == "unread") { | |
886 | if (child.hasClassName("Unread")) { | |
887 | child.addClassName("Selected"); | |
888 | if (cb) cb.attr("checked", true); | |
889 | } else { | |
890 | child.removeClassName("Selected"); | |
891 | if (cb) cb.attr("checked", false); | |
892 | } | |
893 | } else if (mode == "marked") { | |
894 | var img = $("FMPIC-" + child.id.replace("RROW-", "")); | |
895 | ||
896 | if (img && img.src.match("mark_set")) { | |
897 | child.addClassName("Selected"); | |
898 | if (cb) cb.attr("checked", true); | |
899 | } else { | |
900 | child.removeClassName("Selected"); | |
901 | if (cb) cb.attr("checked", false); | |
902 | } | |
903 | } else if (mode == "published") { | |
904 | var img = $("FPPIC-" + child.id.replace("RROW-", "")); | |
905 | ||
906 | if (img && img.src.match("pub_set")) { | |
907 | child.addClassName("Selected"); | |
908 | if (cb) cb.attr("checked", true); | |
909 | } else { | |
910 | child.removeClassName("Selected"); | |
911 | if (cb) cb.attr("checked", false); | |
912 | } | |
913 | ||
914 | } else if (mode == "invert") { | |
915 | if (child.hasClassName("Selected")) { | |
916 | child.removeClassName("Selected"); | |
917 | if (cb) cb.attr("checked", false); | |
918 | } else { | |
919 | child.addClassName("Selected"); | |
920 | if (cb) cb.attr("checked", true); | |
921 | } | |
922 | ||
923 | } else { | |
924 | child.removeClassName("Selected"); | |
925 | if (cb) cb.attr("checked", false); | |
926 | } | |
927 | }); | |
928 | ||
929 | } catch (e) { | |
930 | exception_error("selectArticles", e); | |
931 | } | |
932 | } | |
933 | ||
934 | function catchupPage() { | |
935 | ||
936 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
937 | ||
938 | var str = __("Mark all visible articles in %s as read?"); | |
939 | ||
940 | str = str.replace("%s", fn); | |
941 | ||
942 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
943 | return; | |
944 | } | |
945 | ||
946 | selectArticles('all'); | |
947 | selectionToggleUnread(false, 'viewCurrentFeed()', true); | |
948 | selectArticles('none'); | |
949 | } | |
950 | ||
951 | function deleteSelection() { | |
952 | ||
953 | try { | |
954 | ||
955 | var rows = getSelectedArticleIds2(); | |
956 | ||
957 | if (rows.length == 0) { | |
958 | alert(__("No articles are selected.")); | |
959 | return; | |
960 | } | |
961 | ||
962 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
963 | var str; | |
964 | ||
965 | if (getActiveFeedId() != 0) { | |
966 | str = __("Delete %d selected articles in %s?"); | |
967 | } else { | |
968 | str = __("Delete %d selected articles?"); | |
969 | } | |
970 | ||
971 | str = str.replace("%d", rows.length); | |
972 | str = str.replace("%s", fn); | |
973 | ||
974 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
975 | return; | |
976 | } | |
977 | ||
978 | query = "?op=rpc&method=delete&ids=" + param_escape(rows); | |
979 | ||
980 | console.log(query); | |
981 | ||
982 | new Ajax.Request("backend.php", { | |
983 | parameters: query, | |
984 | onComplete: function(transport) { | |
985 | handle_rpc_json(transport); | |
986 | viewCurrentFeed(); | |
987 | } }); | |
988 | ||
989 | } catch (e) { | |
990 | exception_error("deleteSelection", e); | |
991 | } | |
992 | } | |
993 | ||
994 | function archiveSelection() { | |
995 | ||
996 | try { | |
997 | ||
998 | var rows = getSelectedArticleIds2(); | |
999 | ||
1000 | if (rows.length == 0) { | |
1001 | alert(__("No articles are selected.")); | |
1002 | return; | |
1003 | } | |
1004 | ||
1005 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
1006 | var str; | |
1007 | var op; | |
1008 | ||
1009 | if (getActiveFeedId() != 0) { | |
1010 | str = __("Archive %d selected articles in %s?"); | |
1011 | op = "archive"; | |
1012 | } else { | |
1013 | str = __("Move %d archived articles back?"); | |
1014 | op = "unarchive"; | |
1015 | } | |
1016 | ||
1017 | str = str.replace("%d", rows.length); | |
1018 | str = str.replace("%s", fn); | |
1019 | ||
1020 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1021 | return; | |
1022 | } | |
1023 | ||
1024 | query = "?op=rpc&method="+op+"&ids=" + param_escape(rows); | |
1025 | ||
1026 | console.log(query); | |
1027 | ||
1028 | for (var i = 0; i < rows.length; i++) { | |
1029 | cache_delete("article:" + rows[i]); | |
1030 | } | |
1031 | ||
1032 | new Ajax.Request("backend.php", { | |
1033 | parameters: query, | |
1034 | onComplete: function(transport) { | |
1035 | handle_rpc_json(transport); | |
1036 | viewCurrentFeed(); | |
1037 | } }); | |
1038 | ||
1039 | } catch (e) { | |
1040 | exception_error("archiveSelection", e); | |
1041 | } | |
1042 | } | |
1043 | ||
1044 | function catchupSelection() { | |
1045 | ||
1046 | try { | |
1047 | ||
1048 | var rows = getSelectedArticleIds2(); | |
1049 | ||
1050 | if (rows.length == 0) { | |
1051 | alert(__("No articles are selected.")); | |
1052 | return; | |
1053 | } | |
1054 | ||
1055 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
1056 | ||
1057 | var str = __("Mark %d selected articles in %s as read?"); | |
1058 | ||
1059 | str = str.replace("%d", rows.length); | |
1060 | str = str.replace("%s", fn); | |
1061 | ||
1062 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1063 | return; | |
1064 | } | |
1065 | ||
1066 | selectionToggleUnread(false, 'viewCurrentFeed()', true); | |
1067 | ||
1068 | } catch (e) { | |
1069 | exception_error("catchupSelection", e); | |
1070 | } | |
1071 | } | |
1072 | ||
1073 | function editArticleTags(id) { | |
1074 | var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id); | |
1075 | ||
1076 | if (dijit.byId("editTagsDlg")) | |
1077 | dijit.byId("editTagsDlg").destroyRecursive(); | |
1078 | ||
1079 | dialog = new dijit.Dialog({ | |
1080 | id: "editTagsDlg", | |
1081 | title: __("Edit article Tags"), | |
1082 | style: "width: 600px", | |
1083 | execute: function() { | |
1084 | if (this.validate()) { | |
1085 | var query = dojo.objectToQuery(this.attr('value')); | |
1086 | ||
1087 | notify_progress("Saving article tags...", true); | |
1088 | ||
1089 | new Ajax.Request("backend.php", { | |
1090 | parameters: query, | |
1091 | onComplete: function(transport) { | |
1092 | notify(''); | |
1093 | dialog.hide(); | |
1094 | ||
1095 | var data = JSON.parse(transport.responseText); | |
1096 | ||
1097 | if (data) { | |
1098 | var tags_str = article.tags; | |
1099 | var id = tags_str.id; | |
1100 | ||
1101 | var tags = $("ATSTR-" + id); | |
1102 | var tooltip = dijit.byId("ATSTRTIP-" + id); | |
1103 | ||
1104 | if (tags) tags.innerHTML = tags_str.content; | |
1105 | if (tooltip) tooltip.attr('label', tags_str.content_full); | |
1106 | ||
1107 | cache_delete("article:" + id); | |
1108 | } | |
1109 | ||
1110 | }}); | |
1111 | } | |
1112 | }, | |
1113 | href: query, | |
1114 | }); | |
1115 | ||
1116 | var tmph = dojo.connect(dialog, 'onLoad', function() { | |
1117 | dojo.disconnect(tmph); | |
1118 | ||
1119 | new Ajax.Autocompleter('tags_str', 'tags_choices', | |
1120 | "backend.php?op=rpc&method=completeTags", | |
1121 | { tokens: ',', paramName: "search" }); | |
1122 | }); | |
1123 | ||
1124 | dialog.show(); | |
1125 | ||
1126 | } | |
1127 | ||
1128 | function cdmScrollToArticleId(id) { | |
1129 | try { | |
1130 | var ctr = $("headlines-frame"); | |
1131 | var e = $("RROW-" + id); | |
1132 | ||
1133 | if (!e || !ctr) return; | |
1134 | ||
1135 | if (e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) || | |
1136 | e.offsetTop < ctr.scrollTop) { | |
1137 | ||
1138 | ctr.scrollTop = e.offsetTop; | |
1139 | } | |
1140 | ||
1141 | } catch (e) { | |
1142 | exception_error("cdmScrollToArticleId", e); | |
1143 | } | |
1144 | } | |
1145 | ||
1146 | function getActiveArticleId() { | |
1147 | return active_post_id; | |
1148 | } | |
1149 | ||
1150 | function postMouseIn(id) { | |
1151 | post_under_pointer = id; | |
1152 | } | |
1153 | ||
1154 | function postMouseOut(id) { | |
1155 | post_under_pointer = false; | |
1156 | } | |
1157 | ||
1158 | function headlines_scroll_handler(e) { | |
1159 | try { | |
1160 | var hsp = $("headlines-spacer"); | |
1161 | ||
1162 | if (!_infscroll_disable) { | |
1163 | if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) || | |
1164 | (e.scrollHeight != 0 && | |
1165 | ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) { | |
1166 | ||
1167 | if (hsp) | |
1168 | hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " + | |
1169 | __("Loading, please wait..."); | |
1170 | ||
1171 | loadMoreHeadlines(); | |
1172 | return; | |
1173 | ||
1174 | } | |
1175 | } else { | |
1176 | if (hsp) hsp.innerHTML = ""; | |
1177 | } | |
1178 | ||
1179 | if (getInitParam("cdm_auto_catchup") == 1) { | |
1180 | ||
1181 | $$("#headlines-frame > div[id*=RROW][class*=Unread]").each( | |
1182 | function(child) { | |
1183 | if ($("headlines-frame").scrollTop > | |
1184 | (child.offsetTop + child.offsetHeight/2)) { | |
1185 | ||
1186 | var id = child.id.replace("RROW-", ""); | |
1187 | ||
1188 | if (catchup_id_batch.indexOf(id) == -1) | |
1189 | catchup_id_batch.push(id); | |
1190 | ||
1191 | //console.log("auto_catchup_batch: " + catchup_id_batch.toString()); | |
1192 | } | |
1193 | }); | |
1194 | ||
1195 | if (catchup_id_batch.length > 0) { | |
1196 | window.clearTimeout(catchup_timeout_id); | |
1197 | ||
1198 | if (!_infscroll_request_sent) { | |
1199 | catchup_timeout_id = window.setTimeout('catchupBatchedArticles()', | |
1200 | 2000); | |
1201 | } | |
1202 | } | |
1203 | } | |
1204 | ||
1205 | } catch (e) { | |
1206 | console.warn("headlines_scroll_handler: " + e); | |
1207 | } | |
1208 | } | |
1209 | ||
1210 | function catchupBatchedArticles() { | |
1211 | try { | |
1212 | if (catchup_id_batch.length > 0 && !_infscroll_request_sent) { | |
1213 | ||
1214 | // make a copy of the array | |
1215 | var batch = catchup_id_batch.slice(); | |
1216 | var query = "?op=rpc&method=catchupSelected" + | |
1217 | "&cmode=0&ids=" + param_escape(batch.toString()); | |
1218 | ||
1219 | console.log(query); | |
1220 | ||
1221 | new Ajax.Request("backend.php", { | |
1222 | parameters: query, | |
1223 | onComplete: function(transport) { | |
1224 | handle_rpc_json(transport); | |
1225 | ||
1226 | batch.each(function(id) { | |
1227 | var elem = $("RROW-" + id); | |
1228 | if (elem) elem.removeClassName("Unread"); | |
1229 | catchup_id_batch.remove(id); | |
1230 | }); | |
1231 | ||
1232 | } }); | |
1233 | } | |
1234 | ||
1235 | } catch (e) { | |
1236 | exception_error("catchupBatchedArticles", e); | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | function catchupRelativeToArticle(below, id) { | |
1241 | ||
1242 | try { | |
1243 | ||
1244 | if (!id) id = getActiveArticleId(); | |
1245 | ||
1246 | if (!id) { | |
1247 | alert(__("No article is selected.")); | |
1248 | return; | |
1249 | } | |
1250 | ||
1251 | var visible_ids = getVisibleArticleIds(); | |
1252 | ||
1253 | var ids_to_mark = new Array(); | |
1254 | ||
1255 | if (!below) { | |
1256 | for (var i = 0; i < visible_ids.length; i++) { | |
1257 | if (visible_ids[i] != id) { | |
1258 | var e = $("RROW-" + visible_ids[i]); | |
1259 | ||
1260 | if (e && e.hasClassName("Unread")) { | |
1261 | ids_to_mark.push(visible_ids[i]); | |
1262 | } | |
1263 | } else { | |
1264 | break; | |
1265 | } | |
1266 | } | |
1267 | } else { | |
1268 | for (var i = visible_ids.length-1; i >= 0; i--) { | |
1269 | if (visible_ids[i] != id) { | |
1270 | var e = $("RROW-" + visible_ids[i]); | |
1271 | ||
1272 | if (e && e.hasClassName("Unread")) { | |
1273 | ids_to_mark.push(visible_ids[i]); | |
1274 | } | |
1275 | } else { | |
1276 | break; | |
1277 | } | |
1278 | } | |
1279 | } | |
1280 | ||
1281 | if (ids_to_mark.length == 0) { | |
1282 | alert(__("No articles found to mark")); | |
1283 | } else { | |
1284 | var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length); | |
1285 | ||
1286 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { | |
1287 | ||
1288 | for (var i = 0; i < ids_to_mark.length; i++) { | |
1289 | var e = $("RROW-" + ids_to_mark[i]); | |
1290 | e.removeClassName("Unread"); | |
1291 | } | |
1292 | ||
1293 | var query = "?op=rpc&method=catchupSelected" + | |
1294 | "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString()); | |
1295 | ||
1296 | new Ajax.Request("backend.php", { | |
1297 | parameters: query, | |
1298 | onComplete: function(transport) { | |
1299 | handle_rpc_json(transport); | |
1300 | } }); | |
1301 | ||
1302 | } | |
1303 | } | |
1304 | ||
1305 | } catch (e) { | |
1306 | exception_error("catchupRelativeToArticle", e); | |
1307 | } | |
1308 | } | |
1309 | ||
1310 | function cdmExpandArticle(id) { | |
1311 | try { | |
1312 | ||
1313 | hideAuxDlg(); | |
1314 | ||
1315 | var elem = $("CICD-" + active_post_id); | |
1316 | ||
1317 | if (id == active_post_id && Element.visible(elem)) | |
1318 | return true; | |
1319 | ||
1320 | selectArticles("none"); | |
1321 | ||
1322 | var old_offset = $("RROW-" + id).offsetTop; | |
1323 | ||
1324 | if (active_post_id && elem && !getInitParam("cdm_expanded")) { | |
1325 | Element.hide(elem); | |
1326 | Element.show("CEXC-" + active_post_id); | |
1327 | } | |
1328 | ||
1329 | active_post_id = id; | |
1330 | ||
1331 | elem = $("CICD-" + id); | |
1332 | ||
1333 | if (!Element.visible(elem)) { | |
1334 | Element.show(elem); | |
1335 | Element.hide("CEXC-" + id); | |
1336 | } | |
1337 | ||
1338 | var new_offset = $("RROW-" + id).offsetTop; | |
1339 | ||
1340 | $("headlines-frame").scrollTop += (new_offset-old_offset); | |
1341 | ||
1342 | if ($("RROW-" + id).offsetTop != old_offset) | |
1343 | $("headlines-frame").scrollTop = new_offset; | |
1344 | ||
1345 | toggleUnread(id, 0, true); | |
1346 | toggleSelected(id); | |
1347 | ||
1348 | } catch (e) { | |
1349 | exception_error("cdmExpandArticle", e); | |
1350 | } | |
1351 | ||
1352 | return false; | |
1353 | } | |
1354 | ||
1355 | function fixHeadlinesOrder(ids) { | |
1356 | try { | |
1357 | for (var i = 0; i < ids.length; i++) { | |
1358 | var e = $("RROW-" + ids[i]); | |
1359 | ||
1360 | if (e) { | |
1361 | if (i % 2 == 0) { | |
1362 | e.removeClassName("even"); | |
1363 | e.addClassName("odd"); | |
1364 | } else { | |
1365 | e.removeClassName("odd"); | |
1366 | e.addClassName("even"); | |
1367 | } | |
1368 | } | |
1369 | } | |
1370 | } catch (e) { | |
1371 | exception_error("fixHeadlinesOrder", e); | |
1372 | } | |
1373 | } | |
1374 | ||
1375 | function getArticleUnderPointer() { | |
1376 | return post_under_pointer; | |
1377 | } | |
1378 | ||
1379 | function scrollArticle(offset) { | |
1380 | try { | |
1381 | if (!isCdmMode()) { | |
1382 | var ci = $("content-insert"); | |
1383 | if (ci) { | |
1384 | ci.scrollTop += offset; | |
1385 | } | |
1386 | } else { | |
1387 | var hi = $("headlines-frame"); | |
1388 | if (hi) { | |
1389 | hi.scrollTop += offset; | |
1390 | } | |
1391 | ||
1392 | } | |
1393 | } catch (e) { | |
1394 | exception_error("scrollArticle", e); | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | function show_labels_in_headlines(transport) { | |
1399 | try { | |
1400 | var data = JSON.parse(transport.responseText); | |
1401 | ||
1402 | if (data) { | |
1403 | data['info-for-headlines'].each(function(elem) { | |
1404 | var ctr = $("HLLCTR-" + elem.id); | |
1405 | ||
1406 | if (ctr) ctr.innerHTML = elem.labels; | |
1407 | }); | |
1408 | ||
1409 | cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML); | |
1410 | ||
1411 | } | |
1412 | } catch (e) { | |
1413 | exception_error("show_labels_in_headlines", e); | |
1414 | } | |
1415 | } | |
1416 | ||
1417 | function dismissArticle(id) { | |
1418 | try { | |
1419 | var elem = $("RROW-" + id); | |
1420 | ||
1421 | toggleUnread(id, 0, true); | |
1422 | ||
1423 | new Effect.Fade(elem, {duration : 0.5}); | |
1424 | ||
1425 | active_post_id = false; | |
1426 | ||
1427 | } catch (e) { | |
1428 | exception_error("dismissArticle", e); | |
1429 | } | |
1430 | } | |
1431 | ||
1432 | function dismissSelectedArticles() { | |
1433 | try { | |
1434 | ||
1435 | var ids = getVisibleArticleIds(); | |
1436 | var tmp = []; | |
1437 | var sel = []; | |
1438 | ||
1439 | for (var i = 0; i < ids.length; i++) { | |
1440 | var elem = $("RROW-" + ids[i]); | |
1441 | ||
1442 | if (elem.className && elem.hasClassName("Selected") && | |
1443 | ids[i] != active_post_id) { | |
1444 | new Effect.Fade(elem, {duration : 0.5}); | |
1445 | sel.push(ids[i]); | |
1446 | } else { | |
1447 | tmp.push(ids[i]); | |
1448 | } | |
1449 | } | |
1450 | ||
1451 | if (sel.length > 0) | |
1452 | selectionToggleUnread(false); | |
1453 | ||
1454 | fixHeadlinesOrder(tmp); | |
1455 | ||
1456 | } catch (e) { | |
1457 | exception_error("dismissSelectedArticles", e); | |
1458 | } | |
1459 | } | |
1460 | ||
1461 | function dismissReadArticles() { | |
1462 | try { | |
1463 | ||
1464 | var ids = getVisibleArticleIds(); | |
1465 | var tmp = []; | |
1466 | ||
1467 | for (var i = 0; i < ids.length; i++) { | |
1468 | var elem = $("RROW-" + ids[i]); | |
1469 | ||
1470 | if (elem.className && !elem.hasClassName("Unread") && | |
1471 | !elem.hasClassName("Selected")) { | |
1472 | ||
1473 | new Effect.Fade(elem, {duration : 0.5}); | |
1474 | } else { | |
1475 | tmp.push(ids[i]); | |
1476 | } | |
1477 | } | |
1478 | ||
1479 | fixHeadlinesOrder(tmp); | |
1480 | ||
1481 | } catch (e) { | |
1482 | exception_error("dismissSelectedArticles", e); | |
1483 | } | |
1484 | } | |
1485 | ||
1486 | function getVisibleArticleIds() { | |
1487 | var ids = []; | |
1488 | ||
1489 | try { | |
1490 | ||
1491 | getLoadedArticleIds().each(function(id) { | |
1492 | var elem = $("RROW-" + id); | |
1493 | if (elem && Element.visible(elem)) | |
1494 | ids.push(id); | |
1495 | }); | |
1496 | ||
1497 | } catch (e) { | |
1498 | exception_error("getVisibleArticleIds", e); | |
1499 | } | |
1500 | ||
1501 | return ids; | |
1502 | } | |
1503 | ||
1504 | function cdmClicked(event, id) { | |
1505 | try { | |
1506 | //var shift_key = event.shiftKey; | |
1507 | ||
1508 | hideAuxDlg(); | |
1509 | ||
1510 | if (!event.ctrlKey) { | |
1511 | ||
1512 | if (!getInitParam("cdm_expanded")) { | |
1513 | return cdmExpandArticle(id); | |
1514 | } else { | |
1515 | ||
1516 | selectArticles("none"); | |
1517 | toggleSelected(id); | |
1518 | ||
1519 | var elem = $("RROW-" + id); | |
1520 | var article_is_unread = elem.hasClassName("Unread"); | |
1521 | ||
1522 | if (elem) | |
1523 | elem.removeClassName("Unread"); | |
1524 | ||
1525 | active_post_id = id; | |
1526 | ||
1527 | if (article_is_unread) { | |
1528 | decrementFeedCounter(getActiveFeedId(), activeFeedIsCat()); | |
1529 | } | |
1530 | ||
1531 | var query = "?op=rpc&method=catchupSelected" + | |
1532 | "&cmode=0&ids=" + param_escape(id); | |
1533 | ||
1534 | new Ajax.Request("backend.php", { | |
1535 | parameters: query, | |
1536 | onComplete: function(transport) { | |
1537 | handle_rpc_json(transport); | |
1538 | } }); | |
1539 | ||
1540 | return true; | |
1541 | } | |
1542 | ||
1543 | } else { | |
1544 | toggleSelected(id, true); | |
1545 | ||
1546 | var elem = $("RROW-" + id); | |
1547 | var article_is_unread = elem.hasClassName("Unread"); | |
1548 | ||
1549 | if (article_is_unread) { | |
1550 | decrementFeedCounter(getActiveFeedId(), activeFeedIsCat()); | |
1551 | } | |
1552 | ||
1553 | toggleUnread(id, 0, false); | |
1554 | ||
1555 | openArticleInNewWindow(id); | |
1556 | } | |
1557 | ||
1558 | var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length | |
1559 | request_counters(unread_in_buffer == 0); | |
1560 | ||
1561 | } catch (e) { | |
1562 | exception_error("cdmClicked"); | |
1563 | } | |
1564 | ||
1565 | return false; | |
1566 | } | |
1567 | ||
1568 | function hlClicked(event, id) { | |
1569 | try { | |
1570 | if (event.which == 2) { | |
1571 | view(id); | |
1572 | return true; | |
1573 | } else if (event.ctrlKey) { | |
1574 | toggleSelected(id, true); | |
1575 | toggleUnread(id, 0, false); | |
1576 | openArticleInNewWindow(id); | |
1577 | return false; | |
1578 | } else { | |
1579 | view(id); | |
1580 | return false; | |
1581 | } | |
1582 | ||
1583 | } catch (e) { | |
1584 | exception_error("hlClicked"); | |
1585 | } | |
1586 | } | |
1587 | ||
1588 | function getFirstVisibleHeadlineId() { | |
1589 | var rows = getVisibleArticleIds(); | |
1590 | return rows[0]; | |
1591 | ||
1592 | } | |
1593 | ||
1594 | function getLastVisibleHeadlineId() { | |
1595 | var rows = getVisibleArticleIds(); | |
1596 | return rows[rows.length-1]; | |
1597 | } | |
1598 | ||
1599 | function openArticleInNewWindow(id) { | |
1600 | toggleUnread(id, 0, false); | |
1601 | window.open("backend.php?op=article&method=redirect&id=" + id); | |
1602 | } | |
1603 | ||
1604 | function isCdmMode() { | |
1605 | return getInitParam("combined_display_mode"); | |
1606 | } | |
1607 | ||
1608 | function markHeadline(id) { | |
1609 | var row = $("RROW-" + id); | |
1610 | if (row) { | |
1611 | var check = dijit.byId("RCHK-" + id); | |
1612 | ||
1613 | if (check) { | |
1614 | check.attr("checked", true); | |
1615 | } | |
1616 | ||
1617 | row.addClassName("Selected"); | |
1618 | } | |
1619 | } | |
1620 | ||
1621 | function getRelativePostIds(id, limit) { | |
1622 | ||
1623 | var tmp = []; | |
1624 | ||
1625 | try { | |
1626 | ||
1627 | if (!limit) limit = 6; //3 | |
1628 | ||
1629 | var ids = getVisibleArticleIds(); | |
1630 | ||
1631 | for (var i = 0; i < ids.length; i++) { | |
1632 | if (ids[i] == id) { | |
1633 | for (var k = 1; k <= limit; k++) { | |
1634 | //if (i > k-1) tmp.push(ids[i-k]); | |
1635 | if (i < ids.length-k) tmp.push(ids[i+k]); | |
1636 | } | |
1637 | break; | |
1638 | } | |
1639 | } | |
1640 | ||
1641 | } catch (e) { | |
1642 | exception_error("getRelativePostIds", e); | |
1643 | } | |
1644 | ||
1645 | return tmp; | |
1646 | } | |
1647 | ||
1648 | function correctHeadlinesOffset(id) { | |
1649 | ||
1650 | try { | |
1651 | ||
1652 | var container = $("headlines-frame"); | |
1653 | var row = $("RROW-" + id); | |
1654 | ||
1655 | if (!container || !row) return; | |
1656 | ||
1657 | var viewport = container.offsetHeight; | |
1658 | ||
1659 | var rel_offset_top = row.offsetTop - container.scrollTop; | |
1660 | var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; | |
1661 | ||
1662 | //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); | |
1663 | //console.log("Vport: " + viewport); | |
1664 | ||
1665 | if (rel_offset_top <= 0 || rel_offset_top > viewport) { | |
1666 | container.scrollTop = row.offsetTop; | |
1667 | } else if (rel_offset_bottom > viewport) { | |
1668 | ||
1669 | /* doesn't properly work with Opera in some cases because | |
1670 | Opera fucks up element scrolling */ | |
1671 | ||
1672 | container.scrollTop = row.offsetTop + row.offsetHeight - viewport; | |
1673 | } | |
1674 | ||
1675 | } catch (e) { | |
1676 | exception_error("correctHeadlinesOffset", e); | |
1677 | } | |
1678 | ||
1679 | } | |
1680 | ||
1681 | function headlineActionsChange(elem) { | |
1682 | try { | |
1683 | eval(elem.value); | |
1684 | elem.attr('value', 'false'); | |
1685 | } catch (e) { | |
1686 | exception_error("headlineActionsChange", e); | |
1687 | } | |
1688 | } | |
1689 | ||
1690 | function closeArticlePanel() { | |
1691 | ||
1692 | if (dijit.byId("content-insert")) | |
1693 | dijit.byId("headlines-wrap-inner").removeChild( | |
1694 | dijit.byId("content-insert")); | |
1695 | } | |
1696 | ||
1697 | function initHeadlinesMenu() { | |
1698 | try { | |
1699 | if (dijit.byId("headlinesMenu")) | |
1700 | dijit.byId("headlinesMenu").destroyRecursive(); | |
1701 | ||
1702 | var ids = []; | |
1703 | ||
1704 | if (!isCdmMode()) { | |
1705 | nodes = $$("#headlines-frame > div[id*=RROW]"); | |
1706 | } else { | |
1707 | nodes = $$("#headlines-frame span[id*=RTITLE]"); | |
1708 | } | |
1709 | ||
1710 | nodes.each(function(node) { | |
1711 | ids.push(node.id); | |
1712 | }); | |
1713 | ||
1714 | var menu = new dijit.Menu({ | |
1715 | id: "headlinesMenu", | |
1716 | targetNodeIds: ids, | |
1717 | }); | |
1718 | ||
1719 | var tmph = dojo.connect(menu, '_openMyself', function (event) { | |
1720 | var callerNode = event.target, match = null, tries = 0; | |
1721 | ||
1722 | while (match == null && callerNode && tries <= 3) { | |
1723 | match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$"); | |
1724 | callerNode = callerNode.parentNode; | |
1725 | ++tries; | |
1726 | } | |
1727 | ||
1728 | if (match) this.callerRowId = parseInt(match[1]); | |
1729 | ||
1730 | }); | |
1731 | ||
1732 | /* if (!isCdmMode()) | |
1733 | menu.addChild(new dijit.MenuItem({ | |
1734 | label: __("View article"), | |
1735 | onClick: function(event) { | |
1736 | view(this.getParent().callerRowId); | |
1737 | }})); */ | |
1738 | ||
1739 | menu.addChild(new dijit.MenuItem({ | |
1740 | label: __("Open original article"), | |
1741 | onClick: function(event) { | |
1742 | openArticleInNewWindow(this.getParent().callerRowId); | |
1743 | }})); | |
1744 | ||
1745 | menu.addChild(new dijit.MenuSeparator()); | |
1746 | ||
1747 | menu.addChild(new dijit.MenuItem({ | |
1748 | label: __("Mark above as read"), | |
1749 | onClick: function(event) { | |
1750 | catchupRelativeToArticle(0, this.getParent().callerRowId); | |
1751 | }})); | |
1752 | ||
1753 | menu.addChild(new dijit.MenuItem({ | |
1754 | label: __("Mark below as read"), | |
1755 | onClick: function(event) { | |
1756 | catchupRelativeToArticle(1, this.getParent().callerRowId); | |
1757 | }})); | |
1758 | ||
1759 | ||
1760 | var labels = dijit.byId("feedTree").model.getItemsInCategory(-2); | |
1761 | ||
1762 | if (labels) { | |
1763 | ||
1764 | menu.addChild(new dijit.MenuSeparator()); | |
1765 | ||
1766 | var labelAddMenu = new dijit.Menu({ownerMenu: menu}); | |
1767 | var labelDelMenu = new dijit.Menu({ownerMenu: menu}); | |
1768 | ||
1769 | labels.each(function(label) { | |
1770 | var id = label.id[0]; | |
1771 | var bare_id = id.substr(id.indexOf(":")+1); | |
1772 | var name = label.name[0]; | |
1773 | ||
1774 | bare_id = -11-bare_id; | |
1775 | ||
1776 | labelAddMenu.addChild(new dijit.MenuItem({ | |
1777 | label: name, | |
1778 | labelId: bare_id, | |
1779 | onClick: function(event) { | |
1780 | var ids = getSelectedArticleIds2(); | |
1781 | // cast to string | |
1782 | var id = this.getParent().ownerMenu.callerRowId + ""; | |
1783 | ||
1784 | ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; | |
1785 | ||
1786 | selectionAssignLabel(this.labelId, ids); | |
1787 | }})); | |
1788 | ||
1789 | labelDelMenu.addChild(new dijit.MenuItem({ | |
1790 | label: name, | |
1791 | labelId: bare_id, | |
1792 | onClick: function(event) { | |
1793 | var ids = getSelectedArticleIds2(); | |
1794 | // cast to string | |
1795 | var id = this.getParent().ownerMenu.callerRowId + ""; | |
1796 | ||
1797 | ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; | |
1798 | ||
1799 | selectionRemoveLabel(this.labelId, ids); | |
1800 | }})); | |
1801 | ||
1802 | }); | |
1803 | ||
1804 | menu.addChild(new dijit.PopupMenuItem({ | |
1805 | label: __("Assign label"), | |
1806 | popup: labelAddMenu, | |
1807 | })); | |
1808 | ||
1809 | menu.addChild(new dijit.PopupMenuItem({ | |
1810 | label: __("Remove label"), | |
1811 | popup: labelDelMenu, | |
1812 | })); | |
1813 | ||
1814 | } | |
1815 | ||
1816 | menu.startup(); | |
1817 | ||
1818 | } catch (e) { | |
1819 | exception_error("initHeadlinesMenu", e); | |
1820 | } | |
1821 | } | |
1822 | ||
1823 | ||
1824 | function player(elem) { | |
1825 | var aid = elem.getAttribute("audio-id"); | |
1826 | var status = elem.getAttribute("status"); | |
1827 | ||
1828 | var audio = $(aid); | |
1829 | ||
1830 | if (audio) { | |
1831 | if (status == 0) { | |
1832 | audio.play(); | |
1833 | status = 1; | |
1834 | elem.innerHTML = __("Playing..."); | |
1835 | elem.title = __("Click to pause"); | |
1836 | elem.addClassName("playing"); | |
1837 | } else { | |
1838 | audio.pause(); | |
1839 | status = 0; | |
1840 | elem.innerHTML = __("Play"); | |
1841 | elem.title = __("Click to play"); | |
1842 | elem.removeClassName("playing"); | |
1843 | } | |
1844 | ||
1845 | elem.setAttribute("status", status); | |
1846 | } else { | |
1847 | alert("Your browser doesn't seem to support HTML5 audio."); | |
1848 | } | |
1849 | } | |
1850 | ||
1851 | function cache_set(id, obj) { | |
1852 | //console.log("cache_set: " + id); | |
1853 | if (has_storage) | |
1854 | try { | |
1855 | sessionStorage[id] = obj; | |
1856 | } catch (e) { | |
1857 | sessionStorage.clear(); | |
1858 | } | |
1859 | } | |
1860 | ||
1861 | function cache_get(id) { | |
1862 | if (has_storage) | |
1863 | return sessionStorage[id]; | |
1864 | } | |
1865 | ||
1866 | function cache_clear() { | |
1867 | if (has_storage) | |
1868 | sessionStorage.clear(); | |
1869 | } | |
1870 | ||
1871 | function cache_delete(id) { | |
1872 | if (has_storage) | |
1873 | sessionStorage.removeItem(id); | |
1874 | } | |
1875 | ||
1876 | function cache_headlines(feed, is_cat, toolbar_obj, content_obj) { | |
1877 | if (toolbar_obj && content_obj) { | |
1878 | cache_set("feed:" + feed + ":" + is_cat, | |
1879 | JSON.stringify({toolbar: toolbar_obj, content: content_obj})); | |
1880 | } else { | |
1881 | try { | |
1882 | obj = cache_get("feed:" + feed + ":" + is_cat); | |
1883 | ||
1884 | if (obj) { | |
1885 | obj = JSON.parse(obj); | |
1886 | ||
1887 | if (toolbar_obj) obj.toolbar = toolbar_obj; | |
1888 | if (content_obj) obj.content = content_obj; | |
1889 | ||
1890 | cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj)); | |
1891 | } | |
1892 | ||
1893 | } catch (e) { | |
1894 | console.warn("cache_headlines failed: " + e); | |
1895 | } | |
1896 | } | |
1897 | } | |
1898 | ||
1899 | function render_local_headlines(feed, is_cat, obj) { | |
1900 | try { | |
1901 | ||
1902 | dijit.byId("headlines-toolbar").attr('content', | |
1903 | obj.toolbar); | |
1904 | ||
1905 | dijit.byId("headlines-frame").attr('content', | |
1906 | obj.content); | |
1907 | ||
1908 | dojo.parser.parse('headlines-toolbar'); | |
1909 | ||
1910 | $("headlines-frame").scrollTop = 0; | |
1911 | selectArticles('none'); | |
1912 | setActiveFeedId(feed, is_cat); | |
1913 | initHeadlinesMenu(); | |
1914 | ||
1915 | dijit.getEnclosingWidget( | |
1916 | document.forms["main_toolbar_form"].update).attr('disabled', | |
1917 | is_cat || feed <= 0); | |
1918 | ||
1919 | precache_headlines(); | |
1920 | ||
1921 | } catch (e) { | |
1922 | exception_error("render_local_headlines", e); | |
1923 | } | |
1924 | } | |
1925 | ||
1926 | function precache_headlines_idle() { | |
1927 | try { | |
1928 | if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) { | |
1929 | if (get_timestamp() - _viewfeed_last > 120) { | |
1930 | ||
1931 | var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds(); | |
1932 | var uncached = []; | |
1933 | ||
1934 | feeds.each(function(item) { | |
1935 | if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1])) | |
1936 | uncached.push(item); | |
1937 | }); | |
1938 | ||
1939 | if (uncached.length > 0) { | |
1940 | var rf = uncached[Math.floor(Math.random()*uncached.length)]; | |
1941 | viewfeed(rf[0], '', rf[1], 0, true); | |
1942 | } | |
1943 | } | |
1944 | } | |
1945 | precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30); | |
1946 | ||
1947 | } catch (e) { | |
1948 | exception_error("precache_headlines_idle", e); | |
1949 | } | |
1950 | } | |
1951 | ||
1952 | function precache_headlines() { | |
1953 | try { | |
1954 | if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) { | |
1955 | ||
1956 | feed_precache_timeout_id = window.setTimeout(function() { | |
1957 | var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat()); | |
1958 | var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat()); | |
1959 | ||
1960 | if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat())) | |
1961 | viewfeed(nuf, '', activeFeedIsCat(), 0, true); | |
1962 | ||
1963 | if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1])) | |
1964 | viewfeed(nf[0], '', nf[1], 0, true); | |
1965 | ||
1966 | window.setTimeout(function() { | |
1967 | feed_precache_timeout_id = false; | |
1968 | }, 3000); | |
1969 | }, 1000); | |
1970 | } | |
1971 | ||
1972 | } catch (e) { | |
1973 | exception_error("precache_headlines", e); | |
1974 | } | |
1975 | } | |
1976 | ||
1977 | function cancelSearch() { | |
1978 | try { | |
1979 | _search_query = ""; | |
1980 | viewCurrentFeed(); | |
1981 | } catch (e) { | |
1982 | exception_error("cancelSearch", e); | |
1983 | } | |
1984 | } | |
1985 | ||
1986 | function setSelectionScore() { | |
1987 | try { | |
1988 | var ids = getSelectedArticleIds2(); | |
1989 | ||
1990 | if (ids.length > 0) { | |
1991 | console.log(ids); | |
1992 | ||
1993 | var score = prompt(__("Please enter new score for selected articles:"), score); | |
1994 | ||
1995 | if (score != undefined) { | |
1996 | var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) + | |
1997 | "&score=" + param_escape(score); | |
1998 | ||
1999 | new Ajax.Request("backend.php", { | |
2000 | parameters: query, | |
2001 | onComplete: function(transport) { | |
2002 | var reply = JSON.parse(transport.responseText); | |
2003 | if (reply) { | |
2004 | console.log(ids); | |
2005 | ||
2006 | ids.each(function(id) { | |
2007 | var row = $("RROW-" + id); | |
2008 | ||
2009 | if (row) { | |
2010 | var pic = row.getElementsByClassName("hlScorePic")[0]; | |
2011 | ||
2012 | if (pic) { | |
2013 | pic.src = pic.src.replace(/score_.*?\.png/, | |
2014 | reply["score_pic"]); | |
2015 | pic.setAttribute("score", score); | |
2016 | } | |
2017 | } | |
2018 | }); | |
2019 | } | |
2020 | } }); | |
2021 | } | |
2022 | ||
2023 | } else { | |
2024 | alert(__("No articles are selected.")); | |
2025 | } | |
2026 | } catch (e) { | |
2027 | exception_error("setSelectionScore", e); | |
2028 | } | |
2029 | } | |
2030 | ||
2031 | function changeScore(id, pic) { | |
2032 | try { | |
2033 | var score = pic.getAttribute("score"); | |
2034 | ||
2035 | var new_score = prompt(__("Please enter new score for this article:"), score); | |
2036 | ||
2037 | if (new_score != undefined) { | |
2038 | ||
2039 | var query = "op=rpc&method=setScore&id=" + param_escape(id) + | |
2040 | "&score=" + param_escape(new_score); | |
2041 | ||
2042 | new Ajax.Request("backend.php", { | |
2043 | parameters: query, | |
2044 | onComplete: function(transport) { | |
2045 | var reply = JSON.parse(transport.responseText); | |
2046 | ||
2047 | if (reply) { | |
2048 | pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); | |
2049 | pic.setAttribute("score", new_score); | |
2050 | } | |
2051 | } }); | |
2052 | } | |
2053 | } catch (e) { | |
2054 | exception_error("changeScore", e); | |
2055 | } | |
2056 | } |