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";
37 function dlg_frefresh_callback() {
38 if (xmlhttp
.readyState
== 4) {
39 // notify(xmlhttp.responseText);
41 if (getActiveFeedId() == _qfd_deleted_feed
) {
42 var h
= document
.getElementById("headlines-frame");
44 h
.innerHTML
= "<div class='whiteBox'>No feed selected.</div>";
48 setTimeout('updateFeedList(false, false)', 50);
53 function refetch_callback() {
54 if (xmlhttp_ctr
.readyState
== 4) {
57 var date
= new Date();
59 last_refetch
= date
.getTime() / 1000;
61 if (!xmlhttp_ctr
.responseXML
) {
62 notify("refetch_callback: backend did not return valid XML", true, true);
66 var reply
= xmlhttp_ctr
.responseXML
.firstChild
;
69 notify("refetch_callback: backend did not return expected XML object", true, true);
74 var error_code
= reply
.getAttribute("error-code");
76 if (error_code
&& error_code
!= 0) {
77 return fatalError(error_code
, reply
.getAttribute("error-msg"));
80 var counters
= reply
.firstChild
;
82 parse_counters(counters
, true);
84 var runtime_info
= counters
.nextSibling
;
86 parse_runtime_info(runtime_info
);
88 debug("refetch_callback: done");
90 if (!daemon_enabled
&& !daemon_refresh_only
) {
91 notify("All feeds updated.");
97 exception_error("refetch_callback", e
);
103 function backend_sanity_check_callback() {
105 if (xmlhttp
.readyState
== 4) {
109 if (!xmlhttp
.responseXML
) {
110 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
114 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
117 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
121 var error_code
= reply
.getAttribute("error-code");
123 if (error_code
&& error_code
!= 0) {
124 return fatalError(error_code
, reply
.getAttribute("error-msg"));
127 debug("sanity check ok");
129 var params
= reply
.nextSibling
;
132 debug('reading init-params...');
133 var param
= params
.firstChild
;
136 var k
= param
.getAttribute("key");
137 var v
= param
.getAttribute("value");
138 debug(k
+ " => " + v
);
140 param
= param
.nextSibling
;
147 exception_error("backend_sanity_check_callback", e
);
152 function scheduleFeedUpdate(force
) {
154 if (!daemon_enabled
&& !daemon_refresh_only
) {
155 notify("Updating feeds, please wait.", true);
156 updateTitle("Updating");
159 var query_str
= "backend.php?op=rpc&subop=";
162 query_str
= query_str
+ "forceUpdateAllFeeds";
164 query_str
= query_str
+ "updateAllFeeds";
169 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
170 firsttime_update
= false;
180 query_str
= query_str
+ "&omode=" + omode
;
181 query_str
= query_str
+ "&uctr=" + global_unread
;
183 debug("in scheduleFeedUpdate");
185 var date
= new Date();
187 if (!xmlhttp_ready(xmlhttp_ctr
) && last_refetch
< date
.getTime() / 1000 - 60) {
188 debug("<b>xmlhttp seems to be stuck, aborting</b>");
192 debug("REFETCH query: " + query_str
);
194 if (xmlhttp_ready(xmlhttp_ctr
)) {
195 xmlhttp_ctr
.open("GET", query_str
, true);
196 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
197 xmlhttp_ctr
.send(null);
199 debug("xmlhttp_ctr busy");
200 //printLockingError();
204 function updateFeedList(silent
, fetch
) {
206 // if (silent != true) {
207 // notify("Loading feed list...");
210 var query_str
= "backend.php?op=feeds";
213 query_str
= query_str
+ "&tags=1";
216 if (getActiveFeedId() && !activeFeedIsCat()) {
217 query_str
= query_str
+ "&actid=" + getActiveFeedId();
220 if (navigator
.userAgent
.match("Opera")) {
221 var date
= new Date();
222 var timestamp
= Math
.round(date
.getTime() / 1000);
223 query_str
= query_str
+ "&ts=" + timestamp
226 if (fetch
) query_str
= query_str
+ "&fetch=yes";
228 // var feeds_frame = document.getElementById("feeds-frame");
229 // feeds_frame.src = query_str;
231 debug("updateFeedList Q=" + query_str
);
233 if (xmlhttp_ready(xmlhttp
)) {
234 xmlhttp
.open("GET", query_str
, true);
235 xmlhttp
.onreadystatechange
=feedlist_callback
;
238 debug("xmlhttp busy");
239 //printLockingError();
244 function catchupAllFeeds() {
246 var query_str
= "backend.php?op=feeds&subop=catchupAll";
248 notify("Marking all feeds as read...");
250 var feeds_frame
= document
.getElementById("feeds-frame");
252 feeds_frame
.src
= query_str
;
259 function viewCurrentFeed(subop
) {
261 // if (getActiveFeedId()) {
262 if (getActiveFeedId() != undefined) {
263 viewfeed(getActiveFeedId(), subop
);
265 disableContainerChildren("headlinesToolbar", false, document
);
266 // viewfeed(-1, subop); // FIXME
268 return false; // block unneeded form submits
271 function viewfeed(feed
, subop
) {
272 var f
= window
.frames
["feeds-frame"];
273 f
.viewfeed(feed
, subop
);
277 scheduleFeedUpdate(false);
279 var refresh_time
= getInitParam("feeds_frame_refresh");
281 if (!refresh_time
) refresh_time
= 600;
283 setTimeout("timeout()", refresh_time
*1000);
286 function resetSearch() {
287 var searchbox
= document
.getElementById("searchbox")
289 if (searchbox
.value
!= "" && getActiveFeedId()) {
290 searchbox
.value
= "";
291 viewfeed(getActiveFeedId(), "");
295 function searchCancel() {
301 viewCurrentFeed(0, "");
304 function localPiggieFunction(enable
) {
306 var query_str
= "backend.php?op=feeds&subop=piggie";
308 if (xmlhttp_ready(xmlhttp
)) {
310 xmlhttp
.open("GET", query_str
, true);
311 xmlhttp
.onreadystatechange
=feedlist_callback
;
317 // if argument is undefined, current subtitle is not updated
318 // use blank string to clear subtitle
319 function updateTitle(s
) {
320 var tmp
= "Tiny Tiny RSS";
322 if (s
!= undefined) {
323 current_subtitle
= s
;
326 if (global_unread
> 0) {
327 tmp
= tmp
+ " (" + global_unread
+ ")";
330 if (current_subtitle
) {
331 tmp
= tmp
+ " - " + current_subtitle
;
334 if (active_title_text
.length
> 0) {
335 tmp
= tmp
+ " > " + active_title_text
;
338 document
.title
= tmp
;
341 function genericSanityCheck() {
343 if (!xmlhttp
) fatalError(1);
345 setCookie("ttrss_vf_test", "TEST");
347 if (getCookie("ttrss_vf_test") != "TEST") {
358 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
360 if (arguments
.callee
.done
) return;
361 arguments
.callee
.done
= true;
363 disableContainerChildren("headlinesToolbar", true);
365 Form
.disable("main_toolbar_form");
367 if (!genericSanityCheck())
370 if (getURLParam('debug')) {
371 document
.getElementById('debug_output').style
.display
= 'block';
372 debug('debug mode activated');
375 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
376 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
380 exception_error("init", e
);
384 function init_second_stage() {
388 cookie_lifetime
= getCookie("ttrss_cltime");
390 delCookie("ttrss_vf_test");
392 document
.onkeydown
= hotkey_handler
;
394 var tb
= parent
.document
.forms
["main_toolbar_form"];
396 // dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
397 // dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
399 daemon_enabled
= getInitParam("daemon_enabled") == 1;
400 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
402 setTimeout('updateFeedList(false, false)', 50);
404 debug("second stage ok");
407 exception_error("init_second_stage", e
);
411 function quickMenuChange() {
412 var chooser
= document
.getElementById("quickMenuChooser");
413 var opid
= chooser
[chooser
.selectedIndex
].value
;
415 chooser
.selectedIndex
= 0;
419 function quickMenuGo(opid
) {
422 if (opid
== "qmcPrefs") {
426 if (opid
== "qmcSearch") {
427 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
431 if (opid
== "qmcAddFeed") {
432 displayDlg("quickAddFeed");
436 if (opid
== "qmcRemoveFeed") {
437 var actid
= getActiveFeedId();
439 if (!actid
|| activeFeedIsCat()) {
440 alert("Please select some feed first.");
444 var fn
= getFeedName(actid
);
446 if (confirm("Unsubscribe from " + fn
+ "?")) {
453 if (opid
== "qmcUpdateFeeds") {
454 scheduleFeedUpdate(true);
458 if (opid
== "qmcCatchupAll") {
463 if (opid
== "qmcShowOnlyUnread") {
468 if (opid
== "qmcAddFilter") {
469 displayDlg("quickAddFilter", getActiveFeedId());
472 exception_error("quickMenuGo", e
);
476 function qfdDelete(feed_id
) {
478 notify("Removing feed...");
480 if (!xmlhttp_ready(xmlhttp
)) {
485 _qfd_deleted_feed
= feed_id
;
487 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
488 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
495 function updateFeedTitle(t
) {
496 active_title_text
= t
;
500 function toggleDispRead() {
503 if (!xmlhttp_ready(xmlhttp
)) {
508 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
510 hide_read_feeds
= !hide_read_feeds
;
512 debug("toggle_disp_read => " + hide_read_feeds
);
514 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
516 var query
= "backend.php?op=rpc&subop=setpref" +
517 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
519 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
521 new Ajax
.Request(query
);
524 exception_error("toggleDispRead", e
);
528 function parse_runtime_info(elem
) {
529 var param
= elem
.firstChild
;
531 debug("parse_runtime_info: " + param
);
534 var k
= param
.getAttribute("key");
535 var v
= param
.getAttribute("value");
537 debug("RI: " + k
+ " => " + v
);
539 var w
= document
.getElementById("noDaemonWarning");
542 if (k
== "daemon_is_running" && v
!= 1) {
543 w
.style
.display
= "block";
545 w
.style
.display
= "none";
548 param
= param
.nextSibling
;
552 function catchupCurrentFeed() {
554 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
556 var str
= "Mark all articles in " + fn
+ " as read?";
558 /* if (active_feed_is_cat) {
559 str = "Mark all articles in this category as read?";
562 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
563 return viewCurrentFeed('MarkAllRead')
567 function userSwitch() {
568 var chooser
= document
.getElementById("userSwitch");
569 var user
= chooser
[chooser
.selectedIndex
].value
;
570 window
.location
= "tt-rss.php?swu=" + user
;