4 var display_tags
= false;
5 var global_unread
= -1;
6 var active_title_text
= "";
7 var current_subtitle
= "";
8 var daemon_enabled
= false;
9 var daemon_refresh_only
= false;
10 var _qfd_deleted_feed
= 0;
11 var firsttime_update
= true;
13 var cookie_lifetime
= 0;
14 var active_feed_id
= 0;
15 var active_feed_is_cat
= false;
16 var number_of_feeds
= 0;
18 var xmlhttp
= Ajax
.getTransport();
19 var xmlhttp_ctr
= Ajax
.getTransport();
21 var init_params
= new Object();
23 function toggleTags() {
24 display_tags
= !display_tags
;
26 var p
= document
.getElementById("dispSwitchPrompt");
29 p
.innerHTML
= "display feeds";
31 p
.innerHTML
= "display tags";
34 notify("Loading, please wait...");
39 function dlg_frefresh_callback() {
40 if (xmlhttp
.readyState
== 4) {
41 // notify(xmlhttp.responseText);
43 if (getActiveFeedId() == _qfd_deleted_feed
) {
44 var h
= document
.getElementById("headlines-frame");
46 h
.innerHTML
= "<div class='whiteBox'>No feed selected.</div>";
50 setTimeout('updateFeedList(false, false)', 50);
55 function refetch_callback() {
56 if (xmlhttp_ctr
.readyState
== 4) {
59 var date
= new Date();
61 last_refetch
= date
.getTime() / 1000;
63 if (!xmlhttp_ctr
.responseXML
) {
64 notify("refetch_callback: backend did not return valid XML", true, true);
68 var reply
= xmlhttp_ctr
.responseXML
.firstChild
;
71 notify("refetch_callback: backend did not return expected XML object", true, true);
76 var error_code
= false;
77 var error_msg
= false;
79 if (reply
.firstChild
) {
80 error_code
= reply
.firstChild
.getAttribute("error-code");
81 error_msg
= reply
.firstChild
.getAttribute("error-msg");
85 error_code
= reply
.getAttribute("error-code");
86 error_msg
= reply
.getAttribute("error-msg");
89 if (error_code
&& error_code
!= 0) {
90 debug("refetch_callback: got error code " + error_code
);
91 return fatalError(error_code
, error_msg
);
94 var counters
= reply
.firstChild
;
96 parse_counters(counters
, true);
98 var runtime_info
= counters
.nextSibling
;
100 parse_runtime_info(runtime_info
);
102 debug("refetch_callback: done");
104 if (!daemon_enabled
&& !daemon_refresh_only
) {
105 notify("All feeds updated.");
111 exception_error("refetch_callback", e
);
117 function backend_sanity_check_callback() {
119 if (xmlhttp
.readyState
== 4) {
123 if (!xmlhttp
.responseXML
) {
124 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
128 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
131 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
135 var error_code
= reply
.getAttribute("error-code");
137 if (error_code
&& error_code
!= 0) {
138 return fatalError(error_code
, reply
.getAttribute("error-msg"));
141 debug("sanity check ok");
143 var params
= reply
.nextSibling
;
146 debug('reading init-params...');
147 var param
= params
.firstChild
;
150 var k
= param
.getAttribute("key");
151 var v
= param
.getAttribute("value");
152 debug(k
+ " => " + v
);
154 param
= param
.nextSibling
;
161 exception_error("backend_sanity_check_callback", e
);
166 function scheduleFeedUpdate(force
) {
168 if (!daemon_enabled
&& !daemon_refresh_only
) {
169 notify("Updating feeds, please wait.", true);
170 updateTitle("Updating");
173 var query_str
= "backend.php?op=rpc&subop=";
176 query_str
= query_str
+ "forceUpdateAllFeeds";
178 query_str
= query_str
+ "updateAllFeeds";
183 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
184 firsttime_update
= false;
194 query_str
= query_str
+ "&omode=" + omode
;
195 query_str
= query_str
+ "&uctr=" + global_unread
;
197 debug("in scheduleFeedUpdate");
199 var date
= new Date();
201 if (!xmlhttp_ready(xmlhttp_ctr
) && last_refetch
< date
.getTime() / 1000 - 60) {
202 debug("<b>xmlhttp seems to be stuck, aborting</b>");
206 debug("REFETCH query: " + query_str
);
208 if (xmlhttp_ready(xmlhttp_ctr
)) {
209 xmlhttp_ctr
.open("GET", query_str
, true);
210 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
211 xmlhttp_ctr
.send(null);
213 debug("xmlhttp_ctr busy");
214 //printLockingError();
218 function updateFeedList(silent
, fetch
) {
220 // if (silent != true) {
221 // notify("Loading feed list...");
224 var query_str
= "backend.php?op=feeds";
227 query_str
= query_str
+ "&tags=1";
230 if (getActiveFeedId() && !activeFeedIsCat()) {
231 query_str
= query_str
+ "&actid=" + getActiveFeedId();
234 if (navigator
.userAgent
.match("Opera")) {
235 var date
= new Date();
236 var timestamp
= Math
.round(date
.getTime() / 1000);
237 query_str
= query_str
+ "&ts=" + timestamp
240 if (fetch
) query_str
= query_str
+ "&fetch=yes";
242 // var feeds_frame = document.getElementById("feeds-frame");
243 // feeds_frame.src = query_str;
245 debug("updateFeedList Q=" + query_str
);
247 if (xmlhttp_ready(xmlhttp
)) {
248 xmlhttp
.open("GET", query_str
, true);
249 xmlhttp
.onreadystatechange
=feedlist_callback
;
252 debug("xmlhttp busy");
253 //printLockingError();
258 function catchupAllFeeds() {
260 var query_str
= "backend.php?op=feeds&subop=catchupAll";
262 notify("Marking all feeds as read...");
264 debug("catchupAllFeeds Q=" + query_str
);
266 if (xmlhttp_ready(xmlhttp
)) {
267 xmlhttp
.open("GET", query_str
, true);
268 xmlhttp
.onreadystatechange
=feedlist_callback
;
271 debug("xmlhttp busy");
272 //printLockingError();
280 function viewCurrentFeed(subop
) {
282 // if (getActiveFeedId()) {
283 if (getActiveFeedId() != undefined) {
284 viewfeed(getActiveFeedId(), subop
);
286 disableContainerChildren("headlinesToolbar", false, document
);
287 // viewfeed(-1, subop); // FIXME
289 return false; // block unneeded form submits
292 function viewfeed(feed
, subop
) {
293 var f
= window
.frames
["feeds-frame"];
294 f
.viewfeed(feed
, subop
);
298 scheduleFeedUpdate(false);
300 var refresh_time
= getInitParam("feeds_frame_refresh");
302 if (!refresh_time
) refresh_time
= 600;
304 setTimeout("timeout()", refresh_time
*1000);
307 function resetSearch() {
308 var searchbox
= document
.getElementById("searchbox")
310 if (searchbox
.value
!= "" && getActiveFeedId()) {
311 searchbox
.value
= "";
312 viewfeed(getActiveFeedId(), "");
316 function searchCancel() {
322 viewCurrentFeed(0, "");
325 function localPiggieFunction(enable
) {
327 var query_str
= "backend.php?op=feeds&subop=piggie";
329 if (xmlhttp_ready(xmlhttp
)) {
331 xmlhttp
.open("GET", query_str
, true);
332 xmlhttp
.onreadystatechange
=feedlist_callback
;
338 // if argument is undefined, current subtitle is not updated
339 // use blank string to clear subtitle
340 function updateTitle(s
) {
341 var tmp
= "Tiny Tiny RSS";
343 if (s
!= undefined) {
344 current_subtitle
= s
;
347 if (global_unread
> 0) {
348 tmp
= tmp
+ " (" + global_unread
+ ")";
351 if (current_subtitle
) {
352 tmp
= tmp
+ " - " + current_subtitle
;
355 if (active_title_text
.length
> 0) {
356 tmp
= tmp
+ " > " + active_title_text
;
359 document
.title
= tmp
;
362 function genericSanityCheck() {
364 if (!xmlhttp
) fatalError(1);
366 setCookie("ttrss_vf_test", "TEST");
368 if (getCookie("ttrss_vf_test") != "TEST") {
379 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
381 if (arguments
.callee
.done
) return;
382 arguments
.callee
.done
= true;
384 disableContainerChildren("headlinesToolbar", true);
386 Form
.disable("main_toolbar_form");
388 if (!genericSanityCheck())
391 if (getURLParam('debug')) {
392 document
.getElementById('debug_output').style
.display
= 'block';
393 debug('debug mode activated');
396 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
397 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
401 exception_error("init", e
);
405 function init_second_stage() {
409 cookie_lifetime
= getCookie("ttrss_cltime");
411 delCookie("ttrss_vf_test");
413 document
.onkeydown
= hotkey_handler
;
415 var tb
= parent
.document
.forms
["main_toolbar_form"];
417 // dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
418 // dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
420 daemon_enabled
= getInitParam("daemon_enabled") == 1;
421 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
423 setTimeout('updateFeedList(false, false)', 50);
425 debug("second stage ok");
428 exception_error("init_second_stage", e
);
432 function quickMenuChange() {
433 var chooser
= document
.getElementById("quickMenuChooser");
434 var opid
= chooser
[chooser
.selectedIndex
].value
;
436 chooser
.selectedIndex
= 0;
440 function quickMenuGo(opid
) {
443 if (opid
== "qmcPrefs") {
447 if (opid
== "qmcSearch") {
448 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
452 if (opid
== "qmcAddFeed") {
453 displayDlg("quickAddFeed");
457 if (opid
== "qmcEditFeed") {
458 editFeedDlg(getActiveFeedId());
461 if (opid
== "qmcRemoveFeed") {
462 var actid
= getActiveFeedId();
464 if (!actid
|| activeFeedIsCat()) {
465 alert("Please select some feed first.");
469 var fn
= getFeedName(actid
);
471 if (confirm("Unsubscribe from " + fn
+ "?")) {
478 if (opid
== "qmcUpdateFeeds") {
479 scheduleFeedUpdate(true);
483 if (opid
== "qmcCatchupAll") {
488 if (opid
== "qmcShowOnlyUnread") {
493 if (opid
== "qmcAddFilter") {
494 displayDlg("quickAddFilter", getActiveFeedId());
497 exception_error("quickMenuGo", e
);
501 function qfdDelete(feed_id
) {
503 notify("Removing feed...");
505 if (!xmlhttp_ready(xmlhttp
)) {
510 _qfd_deleted_feed
= feed_id
;
512 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
513 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
520 function updateFeedTitle(t
) {
521 active_title_text
= t
;
525 function toggleDispRead() {
528 if (!xmlhttp_ready(xmlhttp
)) {
533 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
535 hide_read_feeds
= !hide_read_feeds
;
537 debug("toggle_disp_read => " + hide_read_feeds
);
539 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
541 var query
= "backend.php?op=rpc&subop=setpref" +
542 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
544 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
546 new Ajax
.Request(query
);
549 exception_error("toggleDispRead", e
);
553 function parse_runtime_info(elem
) {
555 debug("parse_runtime_info: elem is null, aborting");
559 var param
= elem
.firstChild
;
561 debug("parse_runtime_info: " + param
);
564 var k
= param
.getAttribute("key");
565 var v
= param
.getAttribute("value");
567 debug("RI: " + k
+ " => " + v
);
569 var w
= document
.getElementById("noDaemonWarning");
572 if (k
== "daemon_is_running" && v
!= 1) {
573 w
.style
.display
= "block";
575 w
.style
.display
= "none";
578 param
= param
.nextSibling
;
582 function catchupCurrentFeed() {
584 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
586 var str
= "Mark all articles in " + fn
+ " as read?";
588 /* if (active_feed_is_cat) {
589 str = "Mark all articles in this category as read?";
592 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
593 return viewCurrentFeed('MarkAllRead')
597 function userSwitch() {
598 var chooser
= document
.getElementById("userSwitch");
599 var user
= chooser
[chooser
.selectedIndex
].value
;
600 window
.location
= "tt-rss.php?swu=" + user
;
603 function editFeedDlg(feed
) {
606 alert("Please select some feed first.");
610 if (xmlhttp_ready(xmlhttp
)) {
611 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
612 param_escape(feed
), true);
613 xmlhttp
.onreadystatechange
=infobox_callback
;
620 /* this functions duplicate those of prefs.js feed editor, with
621 some differences because there is no feedlist */
623 function feedEditCancel() {
628 function feedEditSave() {
632 if (!xmlhttp_ready(xmlhttp
)) {
637 // FIXME: add parameter validation
639 var query
= Form
.serialize("edit_feed_form");
641 notify("Saving feed...");
643 xmlhttp
.open("POST", "backend.php", true);
644 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
645 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
653 exception_error("feedEditSave (main)", e
);