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();
20 var init_params
= new Object();
22 function toggleTags() {
23 display_tags
= !display_tags
;
25 var p
= document
.getElementById("dispSwitchPrompt");
28 p
.innerHTML
= "display feeds";
30 p
.innerHTML
= "display tags";
36 function dlg_frefresh_callback() {
37 if (xmlhttp
.readyState
== 4) {
38 notify(xmlhttp
.responseText
);
39 setTimeout('updateFeedList(false, false)', 50);
44 function refetch_callback() {
45 if (xmlhttp
.readyState
== 4) {
48 var date
= new Date();
50 last_refetch
= date
.getTime() / 1000;
52 if (!xmlhttp
.responseXML
) {
53 notify("refetch_callback: backend did not return valid XML", true, true);
57 var reply
= xmlhttp
.responseXML
.firstChild
;
60 notify("refetch_callback: backend did not return expected XML object", true, true);
65 var error_code
= reply
.getAttribute("error-code");
67 if (error_code
&& error_code
!= 0) {
68 return fatalError(error_code
, reply
.getAttribute("error-msg"));
71 var counters
= reply
.firstChild
;
73 parse_counters(counters
, true);
75 var runtime_info
= counters
.nextSibling
;
77 parse_runtime_info(runtime_info
);
79 debug("refetch_callback: done");
81 if (!daemon_enabled
&& !daemon_refresh_only
) {
82 notify("All feeds updated.");
88 exception_error("refetch_callback", e
);
94 function backend_sanity_check_callback() {
96 if (xmlhttp
.readyState
== 4) {
100 if (!xmlhttp
.responseXML
) {
101 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
105 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
108 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
112 var error_code
= reply
.getAttribute("error-code");
114 if (error_code
&& error_code
!= 0) {
115 return fatalError(error_code
, reply
.getAttribute("error-msg"));
118 debug("sanity check ok");
120 var params
= reply
.nextSibling
;
123 debug('reading init-params...');
124 var param
= params
.firstChild
;
127 var k
= param
.getAttribute("key");
128 var v
= param
.getAttribute("value");
129 debug(k
+ " => " + v
);
131 param
= param
.nextSibling
;
138 exception_error("backend_sanity_check_callback", e
);
143 function scheduleFeedUpdate(force
) {
145 if (!daemon_enabled
&& !daemon_refresh_only
) {
146 notify("Updating feeds, please wait.", true);
147 updateTitle("Updating");
150 var query_str
= "backend.php?op=rpc&subop=";
153 query_str
= query_str
+ "forceUpdateAllFeeds";
155 query_str
= query_str
+ "updateAllFeeds";
160 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
161 firsttime_update
= false;
171 query_str
= query_str
+ "&omode=" + omode
;
172 query_str
= query_str
+ "&uctr=" + global_unread
;
174 debug("in scheduleFeedUpdate");
176 var date
= new Date();
178 if (!xmlhttp_ready(xmlhttp
) && last_refetch
< date
.getTime() / 1000 - 60) {
179 debug("<b>xmlhttp seems to be stuck, aborting</b>");
183 debug("REFETCH query: " + query_str
);
185 if (xmlhttp_ready(xmlhttp
)) {
186 xmlhttp
.open("GET", query_str
, true);
187 xmlhttp
.onreadystatechange
=refetch_callback
;
190 debug("xmlhttp busy");
191 //printLockingError();
195 function updateFeedList(silent
, fetch
) {
197 // if (silent != true) {
198 // notify("Loading feed list...");
201 var query_str
= "backend.php?op=feeds";
204 query_str
= query_str
+ "&tags=1";
207 if (getActiveFeedId() && !activeFeedIsCat()) {
208 query_str
= query_str
+ "&actid=" + getActiveFeedId();
211 if (navigator
.userAgent
.match("Opera")) {
212 var date
= new Date();
213 var timestamp
= Math
.round(date
.getTime() / 1000);
214 query_str
= query_str
+ "&ts=" + timestamp
217 if (fetch
) query_str
= query_str
+ "&fetch=yes";
219 // var feeds_frame = document.getElementById("feeds-frame");
220 // feeds_frame.src = query_str;
222 debug("updateFeedList Q=" + query_str
);
224 if (xmlhttp_ready(xmlhttp
)) {
225 xmlhttp
.open("GET", query_str
, true);
226 xmlhttp
.onreadystatechange
=feedlist_callback
;
229 debug("xmlhttp busy");
230 //printLockingError();
235 function catchupAllFeeds() {
237 var query_str
= "backend.php?op=feeds&subop=catchupAll";
239 notify("Marking all feeds as read...");
241 var feeds_frame
= document
.getElementById("feeds-frame");
243 feeds_frame
.src
= query_str
;
250 function viewCurrentFeed(subop
) {
252 // if (getActiveFeedId()) {
253 if (getActiveFeedId() != undefined) {
254 viewfeed(getActiveFeedId(), subop
);
256 disableContainerChildren("headlinesToolbar", false, document
);
257 // viewfeed(-1, subop); // FIXME
259 return false; // block unneeded form submits
262 function viewfeed(feed
, subop
) {
263 var f
= window
.frames
["feeds-frame"];
264 f
.viewfeed(feed
, subop
);
268 scheduleFeedUpdate(false);
270 var refresh_time
= getInitParam("feeds_frame_refresh");
272 if (!refresh_time
) refresh_time
= 600;
274 setTimeout("timeout()", refresh_time
*1000);
277 function resetSearch() {
278 var searchbox
= document
.getElementById("searchbox")
280 if (searchbox
.value
!= "" && getActiveFeedId()) {
281 searchbox
.value
= "";
282 viewfeed(getActiveFeedId(), "");
286 function searchCancel() {
292 viewCurrentFeed(0, "");
295 function localPiggieFunction(enable
) {
297 var query_str
= "backend.php?op=feeds&subop=piggie";
299 if (xmlhttp_ready(xmlhttp
)) {
301 xmlhttp
.open("GET", query_str
, true);
302 xmlhttp
.onreadystatechange
=feedlist_callback
;
308 // if argument is undefined, current subtitle is not updated
309 // use blank string to clear subtitle
310 function updateTitle(s
) {
311 var tmp
= "Tiny Tiny RSS";
313 if (s
!= undefined) {
314 current_subtitle
= s
;
317 if (global_unread
> 0) {
318 tmp
= tmp
+ " (" + global_unread
+ ")";
321 if (current_subtitle
) {
322 tmp
= tmp
+ " - " + current_subtitle
;
325 if (active_title_text
.length
> 0) {
326 tmp
= tmp
+ " > " + active_title_text
;
329 document
.title
= tmp
;
332 function genericSanityCheck() {
334 if (!xmlhttp
) fatalError(1);
336 setCookie("ttrss_vf_test", "TEST");
338 if (getCookie("ttrss_vf_test") != "TEST") {
349 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
351 if (arguments
.callee
.done
) return;
352 arguments
.callee
.done
= true;
354 disableContainerChildren("headlinesToolbar", true);
356 Form
.disable("main_toolbar_form");
358 if (!genericSanityCheck())
361 if (getURLParam('debug')) {
362 document
.getElementById('debug_output').style
.display
= 'block';
363 debug('debug mode activated');
366 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
367 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
371 exception_error("init", e
);
375 function init_second_stage() {
379 cookie_lifetime
= getCookie("ttrss_cltime");
381 delCookie("ttrss_vf_test");
383 document
.onkeydown
= hotkey_handler
;
385 var tb
= parent
.document
.forms
["main_toolbar_form"];
387 dropboxSelect(tb
.view_mode
, getInitParam("toolbar_view_mode"));
388 dropboxSelect(tb
.limit
, getInitParam("toolbar_limit"));
390 daemon_enabled
= getInitParam("daemon_enabled") == 1;
391 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
393 setTimeout('updateFeedList(false, false)', 50);
395 debug("second stage ok");
398 exception_error("init_second_stage", e
);
402 function quickMenuChange() {
403 var chooser
= document
.getElementById("quickMenuChooser");
404 var opid
= chooser
[chooser
.selectedIndex
].value
;
406 chooser
.selectedIndex
= 0;
410 function quickMenuGo(opid
) {
413 if (opid
== "qmcPrefs") {
417 if (opid
== "qmcSearch") {
418 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
422 if (opid
== "qmcAddFeed") {
423 displayDlg("quickAddFeed");
427 if (opid
== "qmcRemoveFeed") {
428 var actid
= getActiveFeedId();
430 if (!actid
|| activeFeedIsCat()) {
431 alert("Please select some feed first.");
435 var fn
= getFeedName(actid
);
437 if (confirm("Unsubscribe from " + fn
+ "?")) {
444 if (opid
== "qmcUpdateFeeds") {
445 scheduleFeedUpdate(true);
449 if (opid
== "qmcCatchupAll") {
454 if (opid
== "qmcShowOnlyUnread") {
459 if (opid
== "qmcAddFilter") {
460 displayDlg("quickAddFilter", getActiveFeedId());
463 exception_error("quickMenuGo", e
);
467 function qfdDelete(feed_id
) {
469 notify("Removing feed...");
471 if (!xmlhttp_ready(xmlhttp
)) {
476 _qfd_deleted_feed
= feed_id
;
478 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
479 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
484 function updateFeedTitle(t
) {
485 active_title_text
= t
;
489 function toggleDispRead() {
492 if (!xmlhttp_ready(xmlhttp
)) {
497 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
499 hide_read_feeds
= !hide_read_feeds
;
501 debug("toggle_disp_read => " + hide_read_feeds
);
503 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
505 var query
= "backend.php?op=rpc&subop=setpref" +
506 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
508 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
510 new Ajax
.Request(query
);
513 exception_error("toggleDispRead", e
);
517 function parse_runtime_info(elem
) {
518 var param
= elem
.firstChild
;
520 debug("parse_runtime_info: " + param
);
523 var k
= param
.getAttribute("key");
524 var v
= param
.getAttribute("value");
526 debug("RI: " + k
+ " => " + v
);
528 var w
= document
.getElementById("noDaemonWarning");
531 if (k
== "daemon_is_running" && v
!= 1) {
532 w
.style
.display
= "block";
534 w
.style
.display
= "none";
537 param
= param
.nextSibling
;
541 function catchupCurrentFeed() {
543 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
545 var str
= "Mark all articles in " + fn
+ " as read?";
547 /* if (active_feed_is_cat) {
548 str = "Mark all articles in this category as read?";
551 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
552 return viewCurrentFeed('MarkAllRead')