1 var active_post_id = false;
2 var _catchup_callback_func = false;
3 var last_article_view = false;
4 var active_real_feed_id = false;
6 var _tag_active_post_id = false;
7 var _tag_active_feed_id = false;
9 // FIXME: kludge, needs proper implementation
10 var _reload_feedlist_after_view = false;
12 var _cdm_wd_timeout = false;
13 var _cdm_wd_vishist = new Array();
15 function catchup_callback() {
16 if (xmlhttp_rpc.readyState == 4) {
18 debug("catchup_callback");
19 if (_catchup_callback_func) {
20 setTimeout(_catchup_callback_func, 100);
22 all_counters_callback();
24 exception_error("catchup_callback", e);
29 function headlines_callback() {
30 if (xmlhttp.readyState == 4) {
31 debug("headlines_callback");
32 var f = document.getElementById("headlines-frame");
36 f.innerHTML = xmlhttp.responseText;
37 update_all_counters();
38 if (typeof correctPNG != 'undefined') {
42 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
44 if (!document.getElementById("headlinesList")) {
45 debug("starting CDM watchdog");
46 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
47 _cdm_wd_vishist = new Array();
54 function article_callback() {
55 if (xmlhttp.readyState == 4) {
56 debug("article_callback");
57 var f = document.getElementById("content-frame");
61 f.innerHTML = xmlhttp.responseText;
63 var date = new Date();
64 last_article_view = date.getTime() / 1000;
66 if (typeof correctPNG != 'undefined') {
70 if (_reload_feedlist_after_view) {
71 setTimeout('updateFeedList(false, false)', 50);
72 _reload_feedlist_after_view = false;
74 update_all_counters();
79 function view(id, feed_id, skip_history) {
82 debug("loading article: " + id + "/" + feed_id);
84 active_real_feed_id = feed_id;
87 history_push("ARTICLE:" + id + ":" + feed_id);
93 //setActiveFeedId(feed_id);
95 var query = "backend.php?op=view&id=" + param_escape(id) +
96 "&feed=" + param_escape(feed_id);
98 var date = new Date();
100 if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
101 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
105 if (xmlhttp_ready(xmlhttp)) {
107 cleanSelected("headlinesList");
109 var crow = document.getElementById("RROW-" + active_post_id);
110 crow.className = crow.className.replace("Unread", "");
112 var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id);
115 upd_img_pic.src = "images/blank_icon.gif";
118 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
119 markHeadline(active_post_id);
121 xmlhttp.open("GET", query, true);
122 xmlhttp.onreadystatechange=article_callback;
125 debug("xmlhttp busy (@view)");
130 exception_error("view", e);
134 function toggleMark(id) {
136 if (!xmlhttp_ready(xmlhttp_rpc)) {
141 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
143 var mark_img = document.getElementById("FMARKPIC-" + id);
144 var vfeedu = document.getElementById("FEEDU--1");
145 var crow = document.getElementById("RROW-" + id);
147 if (mark_img.alt != "Reset mark") {
148 mark_img.src = "images/mark_set.png";
149 mark_img.alt = "Reset mark";
150 query = query + "&mark=1";
152 if (vfeedu && crow.className.match("Unread")) {
153 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
157 mark_img.src = "images/mark_unset.png";
158 mark_img.alt = "Set mark";
159 query = query + "&mark=0";
161 if (vfeedu && crow.className.match("Unread")) {
162 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
167 var vfeedctr = document.getElementById("FEEDCTR--1");
168 var vfeedr = document.getElementById("FEEDR--1");
170 if (vfeedu && vfeedctr) {
171 if ((+vfeedu.innerHTML) > 0) {
172 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
173 vfeedr.className = vfeedr.className + "Unread";
174 vfeedctr.className = "odd";
177 vfeedctr.className = "invisible";
178 vfeedr.className = vfeedr.className.replace("Unread", "");
182 debug("toggle starred for aid " + id);
184 new Ajax.Request(query);
188 function moveToPost(mode) {
190 // check for combined mode
191 if (!document.getElementById("headlinesList"))
194 var rows = getVisibleHeadlineIds();
199 if (!document.getElementById('RROW-' + active_post_id)) {
200 active_post_id = false;
203 if (active_post_id == false) {
204 next_id = getFirstVisibleHeadlineId();
205 prev_id = getLastVisibleHeadlineId();
207 for (var i = 0; i < rows.length; i++) {
208 if (rows[i] == active_post_id) {
215 if (mode == "next") {
216 if (next_id != undefined) {
217 view(next_id, getActiveFeedId());
221 if (mode == "prev") {
222 if ( prev_id != undefined) {
223 view(prev_id, getActiveFeedId());
228 function toggleUnread(id, cmode) {
230 if (!xmlhttp_ready(xmlhttp_rpc)) {
235 var row = document.getElementById("RROW-" + id);
237 var nc = row.className;
238 nc = nc.replace("Unread", "");
239 nc = nc.replace("Selected", "");
241 if (row.className.match("Unread")) {
244 row.className = nc + "Unread";
247 if (!cmode) cmode = 2;
249 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
250 param_escape(id) + "&cmode=" + param_escape(cmode);
252 xmlhttp_rpc.open("GET", query, true);
253 xmlhttp_rpc.onreadystatechange=all_counters_callback;
254 xmlhttp_rpc.send(null);
260 exception_error("toggleUnread", e);
264 function selectionToggleUnread(cdm_mode, set_state, callback_func) {
266 if (!xmlhttp_ready(xmlhttp_rpc)) {
274 rows = cdmGetSelectedArticles();
276 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
279 for (i = 0; i < rows.length; i++) {
280 var row = document.getElementById("RROW-" + rows[i]);
282 var nc = row.className;
283 nc = nc.replace("Unread", "");
284 nc = nc.replace("Selected", "");
286 if (row.className.match("Unread")) {
287 row.className = nc + "Selected";
289 row.className = nc + "UnreadSelected";
294 if (rows.length > 0) {
298 if (set_state == undefined) {
300 } else if (set_state == true) {
302 } else if (set_state == false) {
306 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
307 param_escape(rows.toString()) + "&cmode=" + cmode;
309 _catchup_callback_func = callback_func;
311 xmlhttp_rpc.open("GET", query, true);
312 xmlhttp_rpc.onreadystatechange=catchup_callback;
313 xmlhttp_rpc.send(null);
318 exception_error("selectionToggleUnread", e);
322 function selectionToggleMarked(cdm_mode) {
324 if (!xmlhttp_ready(xmlhttp_rpc)) {
332 rows = cdmGetSelectedArticles();
334 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
337 for (i = 0; i < rows.length; i++) {
338 var row = document.getElementById("RROW-" + rows[i]);
339 var mark_img = document.getElementById("FMARKPIC-" + rows[i]);
341 if (row && mark_img) {
343 if (mark_img.alt == "Set mark") {
344 mark_img.src = "images/mark_set.png";
345 mark_img.alt = "Reset mark";
346 mark_img.setAttribute('onclick',
347 'javascript:toggleMark('+rows[i]+', false)');
350 mark_img.src = "images/mark_unset.png";
351 mark_img.alt = "Set mark";
352 mark_img.setAttribute('onclick',
353 'javascript:toggleMark('+rows[i]+', true)');
358 if (rows.length > 0) {
360 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
361 param_escape(rows.toString()) + "&cmode=2";
363 xmlhttp_rpc.open("GET", query, true);
364 xmlhttp_rpc.onreadystatechange=all_counters_callback;
365 xmlhttp_rpc.send(null);
370 exception_error("selectionToggleMarked", e);
374 function cdmGetSelectedArticles() {
375 var sel_articles = new Array();
376 var container = document.getElementById("headlinesInnerContainer");
378 for (i = 0; i < container.childNodes.length; i++) {
379 var child = container.childNodes[i];
381 if (child.id.match("RROW-") && child.className.match("Selected")) {
382 var c_id = child.id.replace("RROW-", "");
383 sel_articles.push(c_id);
390 // mode = all,none,unread
391 function cdmSelectArticles(mode) {
392 var container = document.getElementById("headlinesInnerContainer");
394 for (i = 0; i < container.childNodes.length; i++) {
395 var child = container.childNodes[i];
397 if (child.id.match("RROW-")) {
398 var aid = child.id.replace("RROW-", "");
400 var cb = document.getElementById("RCHK-" + aid);
403 if (!child.className.match("Selected")) {
404 child.className = child.className + "Selected";
407 } else if (mode == "unread") {
408 if (child.className.match("Unread") && !child.className.match("Selected")) {
409 child.className = child.className + "Selected";
413 child.className = child.className.replace("Selected", "");
420 function catchupPage() {
422 if (document.getElementById("headlinesList")) {
423 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
424 selectionToggleUnread(false, false, 'viewCurrentFeed()');
425 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
427 cdmSelectArticles('all');
428 selectionToggleUnread(true, false, 'viewCurrentFeed()')
429 cdmSelectArticles('none');
433 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
435 if (!xmlhttp_ready(xmlhttp_rpc)) {
439 var title = prompt("Please enter label title:", "");
443 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
444 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
445 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
446 "&title=" + param_escape(title);
448 debug("LFS: " + query);
450 xmlhttp_rpc.open("GET", query, true);
451 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
452 xmlhttp_rpc.send(null);
457 function editArticleTags(id, feed_id) {
458 _tag_active_post_id = id;
459 _tag_active_feed_id = feed_id;
460 displayDlg('editArticleTags', id);
464 function tag_saved_callback() {
465 if (xmlhttp_rpc.readyState == 4) {
467 debug("in tag_saved_callback");
472 if (tagsAreDisplayed()) {
473 _reload_feedlist_after_view = true;
476 if (active_post_id == _tag_active_post_id) {
477 debug("reloading current article");
478 view(_tag_active_post_id, _tag_active_feed_id);
482 exception_error("catchup_callback", e);
487 function editTagsSave() {
489 if (!xmlhttp_ready(xmlhttp_rpc)) {
493 notify("Saving article tags...");
495 var form = document.forms["tag_edit_form"];
497 var query = Form.serialize("tag_edit_form");
499 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true);
500 xmlhttp_rpc.onreadystatechange=tag_saved_callback;
501 xmlhttp_rpc.send(null);
505 function editTagsInsert() {
508 var form = document.forms["tag_edit_form"];
510 var found_tags = form.found_tags;
511 var tags_str = form.tags_str;
513 var tag = found_tags[found_tags.selectedIndex].value;
515 if (tags_str.value.length > 0 &&
516 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
518 tags_str.value = tags_str.value + ", ";
521 tags_str.value = tags_str.value + tag + ", ";
523 found_tags.selectedIndex = 0;
526 exception_error(e, "editTagsInsert");
530 function cdmWatchdog() {
534 var ctr = document.getElementById("headlinesInnerContainer");
536 if (!ctr.hasChildNodes()) return;
538 var ids = new Array();
540 var e = ctr.firstChild;
543 if (e.className && e.className == "cdmArticleUnread" && e.id &&
544 e.id.match("RROW-")) {
546 // article fits in viewport OR article is longer than viewport and
547 // its bottom is visible
549 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
550 ctr.scrollTop + ctr.offsetHeight) {
552 // debug(e.id + " is visible " + e.offsetTop + "." +
553 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
554 // (ctr.scrollTop + ctr.offsetHeight));
556 ids.push(e.id.replace("RROW-", ""));
558 } else if (e.offsetHeight > ctr.offsetHeight &&
559 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
560 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
562 ids.push(e.id.replace("RROW-", ""));
571 debug("cdmWatchdog, ids= " + ids.toString());
573 if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) {
575 for (var i = 0; i < ids.length; i++) {
576 var e = document.getElementById("RROW-" + ids[i]);
578 e.className = e.className.replace("Unread", "");
582 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
583 param_escape(ids.toString()) + "&cmode=0";
585 /* xmlhttp_rpc.open("GET", query, true);
586 xmlhttp_rpc.onreadystatechange=all_counters_callback;
587 xmlhttp_rpc.send(null); */
591 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
594 exception_error(e, "cdmWatchdog");