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