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 function catchup_callback() {
13 if (xmlhttp_rpc
.readyState
== 4) {
15 debug("catchup_callback");
16 if (_catchup_callback_func
) {
17 setTimeout(_catchup_callback_func
, 100);
19 all_counters_callback();
21 exception_error("catchup_callback", e
);
26 function headlines_callback() {
27 if (xmlhttp
.readyState
== 4) {
28 debug("headlines_callback");
29 var f
= document
.getElementById("headlines-frame");
33 f
.innerHTML
= xmlhttp
.responseText
;
34 update_all_counters();
35 if (typeof correctPNG
!= 'undefined') {
42 function article_callback() {
43 if (xmlhttp
.readyState
== 4) {
44 debug("article_callback");
45 var f
= document
.getElementById("content-frame");
49 f
.innerHTML
= xmlhttp
.responseText
;
51 var date
= new Date();
52 last_article_view
= date
.getTime() / 1000;
54 if (typeof correctPNG
!= 'undefined') {
58 if (_reload_feedlist_after_view
) {
59 setTimeout('updateFeedList(false, false)', 50);
60 _reload_feedlist_after_view
= false;
62 update_all_counters();
67 function view(id
, feed_id
, skip_history
) {
70 debug("loading article: " + id
+ "/" + feed_id
);
72 active_real_feed_id
= feed_id
;
75 history_push("ARTICLE:" + id
+ ":" + feed_id
);
81 //setActiveFeedId(feed_id);
83 var query
= "backend.php?op=view&id=" + param_escape(id
) +
84 "&feed=" + param_escape(feed_id
);
86 var date
= new Date();
88 if (!xmlhttp_ready(xmlhttp
) && last_article_view
< date
.getTime() / 1000 - 15) {
89 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
93 if (xmlhttp_ready(xmlhttp
)) {
95 cleanSelected("headlinesList");
97 var crow
= document
.getElementById("RROW-" + active_post_id
);
98 crow
.className
= crow
.className
.replace("Unread", "");
100 var upd_img_pic
= document
.getElementById("FUPDPIC-" + active_post_id
);
103 upd_img_pic
.src
= "images/blank_icon.gif";
106 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
107 markHeadline(active_post_id
);
109 xmlhttp
.open("GET", query
, true);
110 xmlhttp
.onreadystatechange
=article_callback
;
113 debug("xmlhttp busy (@view)");
118 exception_error("view", e
);
122 function toggleMark(id
) {
124 if (!xmlhttp_ready(xmlhttp_rpc
)) {
129 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
131 var mark_img
= document
.getElementById("FMARKPIC-" + id
);
132 var vfeedu
= document
.getElementById("FEEDU--1");
133 var crow
= document
.getElementById("RROW-" + id
);
135 if (mark_img
.alt
!= "Reset mark") {
136 mark_img
.src
= "images/mark_set.png";
137 mark_img
.alt
= "Reset mark";
138 query
= query
+ "&mark=1";
140 if (vfeedu
&& crow
.className
.match("Unread")) {
141 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) + 1;
145 mark_img
.src
= "images/mark_unset.png";
146 mark_img
.alt
= "Set mark";
147 query
= query
+ "&mark=0";
149 if (vfeedu
&& crow
.className
.match("Unread")) {
150 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) - 1;
155 var vfeedctr
= document
.getElementById("FEEDCTR--1");
156 var vfeedr
= document
.getElementById("FEEDR--1");
158 if (vfeedu
&& vfeedctr
) {
159 if ((+vfeedu
.innerHTML
) > 0) {
160 if (crow
.className
.match("Unread") && !vfeedr
.className
.match("Unread")) {
161 vfeedr
.className
= vfeedr
.className
+ "Unread";
162 vfeedctr
.className
= "odd";
165 vfeedctr
.className
= "invisible";
166 vfeedr
.className
= vfeedr
.className
.replace("Unread", "");
170 debug("toggle starred for aid " + id
);
172 new Ajax
.Request(query
);
176 function moveToPost(mode
) {
178 // check for combined mode
179 if (!document
.getElementById("headlinesList"))
182 var rows
= getVisibleHeadlineIds();
187 if (!document
.getElementById('RROW-' + active_post_id
)) {
188 active_post_id
= false;
191 if (active_post_id
== false) {
192 next_id
= getFirstVisibleHeadlineId();
193 prev_id
= getLastVisibleHeadlineId();
195 for (var i
= 0; i
< rows
.length
; i
++) {
196 if (rows
[i
] == active_post_id
) {
203 if (mode
== "next") {
204 if (next_id
!= undefined) {
205 view(next_id
, getActiveFeedId());
209 if (mode
== "prev") {
210 if ( prev_id
!= undefined) {
211 view(prev_id
, getActiveFeedId());
216 function toggleUnread(id
, cmode
) {
218 if (!xmlhttp_ready(xmlhttp_rpc
)) {
223 var row
= document
.getElementById("RROW-" + id
);
225 var nc
= row
.className
;
226 nc
= nc
.replace("Unread", "");
227 nc
= nc
.replace("Selected", "");
229 if (row
.className
.match("Unread")) {
232 row
.className
= nc
+ "Unread";
235 if (!cmode
) cmode
= 2;
237 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
238 param_escape(id
) + "&cmode=" + param_escape(cmode
);
240 xmlhttp_rpc
.open("GET", query
, true);
241 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
242 xmlhttp_rpc
.send(null);
248 exception_error("toggleUnread", e
);
252 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
) {
254 if (!xmlhttp_ready(xmlhttp_rpc
)) {
262 rows
= cdmGetSelectedArticles();
264 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
267 for (i
= 0; i
< rows
.length
; i
++) {
268 var row
= document
.getElementById("RROW-" + rows
[i
]);
270 var nc
= row
.className
;
271 nc
= nc
.replace("Unread", "");
272 nc
= nc
.replace("Selected", "");
274 if (row
.className
.match("Unread")) {
275 row
.className
= nc
+ "Selected";
277 row
.className
= nc
+ "UnreadSelected";
282 if (rows
.length
> 0) {
286 if (set_state
== undefined) {
288 } else if (set_state
== true) {
290 } else if (set_state
== false) {
294 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
295 param_escape(rows
.toString()) + "&cmode=" + cmode
;
297 _catchup_callback_func
= callback_func
;
299 xmlhttp_rpc
.open("GET", query
, true);
300 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
301 xmlhttp_rpc
.send(null);
306 exception_error("selectionToggleUnread", e
);
310 function selectionToggleMarked(cdm_mode
) {
312 if (!xmlhttp_ready(xmlhttp_rpc
)) {
320 rows
= cdmGetSelectedArticles();
322 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
325 for (i
= 0; i
< rows
.length
; i
++) {
326 var row
= document
.getElementById("RROW-" + rows
[i
]);
327 var mark_img
= document
.getElementById("FMARKPIC-" + rows
[i
]);
329 if (row
&& mark_img
) {
331 if (mark_img
.alt
== "Set mark") {
332 mark_img
.src
= "images/mark_set.png";
333 mark_img
.alt
= "Reset mark";
334 mark_img
.setAttribute('onclick',
335 'javascript:toggleMark('+rows
[i
]+', false)');
338 mark_img
.src
= "images/mark_unset.png";
339 mark_img
.alt
= "Set mark";
340 mark_img
.setAttribute('onclick',
341 'javascript:toggleMark('+rows
[i
]+', true)');
346 if (rows
.length
> 0) {
348 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
349 param_escape(rows
.toString()) + "&cmode=2";
351 xmlhttp_rpc
.open("GET", query
, true);
352 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
353 xmlhttp_rpc
.send(null);
358 exception_error("selectionToggleMarked", e
);
362 function cdmGetSelectedArticles() {
363 var sel_articles
= new Array();
364 var container
= document
.getElementById("headlinesInnerContainer");
366 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
367 var child
= container
.childNodes
[i
];
369 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
370 var c_id
= child
.id
.replace("RROW-", "");
371 sel_articles
.push(c_id
);
378 // mode = all,none,unread
379 function cdmSelectArticles(mode
) {
380 var container
= document
.getElementById("headlinesInnerContainer");
382 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
383 var child
= container
.childNodes
[i
];
385 if (child
.id
.match("RROW-")) {
386 var aid
= child
.id
.replace("RROW-", "");
388 var cb
= document
.getElementById("RCHK-" + aid
);
391 if (!child
.className
.match("Selected")) {
392 child
.className
= child
.className
+ "Selected";
395 } else if (mode
== "unread") {
396 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
397 child
.className
= child
.className
+ "Selected";
401 child
.className
= child
.className
.replace("Selected", "");
408 function catchupPage() {
410 if (document
.getElementById("headlinesList")) {
411 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
412 selectionToggleUnread(false, false, 'viewCurrentFeed()');
413 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
415 cdmSelectArticles('all');
416 selectionToggleUnread(true, false, 'viewCurrentFeed()')
417 cdmSelectArticles('none');
421 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
423 if (!xmlhttp_ready(xmlhttp_rpc
)) {
427 var title
= prompt("Please enter label title:", "");
431 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
432 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
433 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
434 "&title=" + param_escape(title
);
436 debug("LFS: " + query
);
438 xmlhttp_rpc
.open("GET", query
, true);
439 xmlhttp_rpc
.onreadystatechange
=dlg_frefresh_callback
;
440 xmlhttp_rpc
.send(null);
445 function editArticleTags(id
, feed_id
) {
446 _tag_active_post_id
= id
;
447 _tag_active_feed_id
= feed_id
;
448 displayDlg('editArticleTags', id
);
452 function tag_saved_callback() {
453 if (xmlhttp_rpc
.readyState
== 4) {
455 debug("in tag_saved_callback");
460 if (tagsAreDisplayed()) {
461 _reload_feedlist_after_view
= true;
464 if (active_post_id
== _tag_active_post_id
) {
465 debug("reloading current article");
466 view(_tag_active_post_id
, _tag_active_feed_id
);
470 exception_error("catchup_callback", e
);
475 function editTagsSave() {
477 if (!xmlhttp_ready(xmlhttp_rpc
)) {
481 notify("Saving article tags...");
483 var form
= document
.forms
["tag_edit_form"];
485 var query
= Form
.serialize("tag_edit_form");
487 xmlhttp_rpc
.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query
, true);
488 xmlhttp_rpc
.onreadystatechange
=tag_saved_callback
;
489 xmlhttp_rpc
.send(null);
493 function editTagsInsert() {
496 var form
= document
.forms
["tag_edit_form"];
498 var found_tags
= form
.found_tags
;
499 var tags_str
= form
.tags_str
;
501 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
503 if (tags_str
.value
.length
> 0 &&
504 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
506 tags_str
.value
= tags_str
.value
+ ", ";
509 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
511 found_tags
.selectedIndex
= 0;
514 exception_error(e
, "editTagsInsert");