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;
17 var sanity_check_done
= false;
19 var xmlhttp
= Ajax
.getTransport();
20 var xmlhttp_ctr
= Ajax
.getTransport();
22 var init_params
= new Object();
24 function tagsAreDisplayed() {
28 function toggleTags(show_all
) {
30 var p
= document
.getElementById("dispSwitchPrompt");
32 if (!show_all
&& !display_tags
) {
33 displayDlg("printTagCloud");
34 } else if (show_all
) {
37 p
.innerHTML
= __("display feeds");
38 notify_progress("Loading, please wait...", true);
40 } else if (display_tags
) {
42 p
.innerHTML
= __("tag cloud");
43 notify_progress("Loading, please wait...", true);
48 function dlg_frefresh_callback() {
49 if (xmlhttp
.readyState
== 4) {
50 // notify(xmlhttp.responseText);
52 if (getActiveFeedId() == _qfd_deleted_feed
) {
53 var h
= document
.getElementById("headlines-frame");
55 h
.innerHTML
= "<div class='whiteBox'>" + __('No feed selected.') + "</div>";
59 setTimeout('updateFeedList(false, false)', 50);
64 function refetch_callback() {
65 if (xmlhttp_ctr
.readyState
== 4) {
68 var date
= new Date();
70 last_refetch
= date
.getTime() / 1000;
72 parse_counters_reply(xmlhttp_ctr
, true);
74 debug("refetch_callback: done");
76 if (!daemon_enabled
&& !daemon_refresh_only
) {
77 notify_info("All feeds updated.");
83 exception_error("refetch_callback", e
);
89 function backend_sanity_check_callback() {
91 if (xmlhttp
.readyState
== 4) {
95 if (sanity_check_done
) {
96 fatalError(11, "Sanity check request received twice. This can indicate "+
97 "presence of Firebug or some other disrupting extension. "+
98 "Please disable it and try again.");
102 if (!xmlhttp
.responseXML
) {
103 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
107 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
110 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
114 var error_code
= reply
.getAttribute("error-code");
116 if (error_code
&& error_code
!= 0) {
117 return fatalError(error_code
, reply
.getAttribute("error-msg"));
120 debug("sanity check ok");
122 var params
= reply
.nextSibling
;
125 debug('reading init-params...');
126 var param
= params
.firstChild
;
129 var k
= param
.getAttribute("key");
130 var v
= param
.getAttribute("value");
131 debug(k
+ " => " + v
);
133 param
= param
.nextSibling
;
137 sanity_check_done
= true;
142 exception_error("backend_sanity_check_callback", e
);
147 function scheduleFeedUpdate(force
) {
149 if (!daemon_enabled
&& !daemon_refresh_only
) {
150 notify_progress("Updating feeds, please wait.", true);
151 updateTitle("Updating");
154 var query_str
= "backend.php?op=rpc&subop=";
157 query_str
= query_str
+ "forceUpdateAllFeeds";
159 query_str
= query_str
+ "updateAllFeeds";
164 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
165 firsttime_update
= false;
175 query_str
= query_str
+ "&omode=" + omode
;
176 query_str
= query_str
+ "&uctr=" + global_unread
;
178 debug("in scheduleFeedUpdate");
180 var date
= new Date();
182 var timestamp
= Math
.round(date
.getTime() / 1000);
183 query_str
= query_str
+ "&ts=" + timestamp
185 if (!xmlhttp_ready(xmlhttp_ctr
) && last_refetch
< date
.getTime() / 1000 - 60) {
186 debug("<b>xmlhttp seems to be stuck, aborting</b>");
189 xmlhttp_ctr
= Ajax
.getTransport();
193 debug("REFETCH query: " + query_str
);
195 if (xmlhttp_ready(xmlhttp_ctr
)) {
196 xmlhttp_ctr
.open("GET", query_str
, true);
197 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
198 xmlhttp_ctr
.send(null);
200 debug("xmlhttp_ctr busy");
201 //printLockingError();
205 function updateFeedList(silent
, fetch
) {
207 // if (silent != true) {
208 // notify("Loading feed list...");
211 debug("<b>updateFeedList</b>");
213 var query_str
= "backend.php?op=feeds";
216 query_str
= query_str
+ "&tags=1";
219 if (getActiveFeedId() && !activeFeedIsCat()) {
220 query_str
= query_str
+ "&actid=" + getActiveFeedId();
223 var date
= new Date();
224 var timestamp
= Math
.round(date
.getTime() / 1000);
225 query_str
= query_str
+ "&ts=" + timestamp
227 if (fetch
) query_str
= query_str
+ "&fetch=yes";
229 // var feeds_frame = document.getElementById("feeds-frame");
230 // feeds_frame.src = query_str;
232 debug("updateFeedList Q=" + query_str
);
234 if (xmlhttp_ready(xmlhttp
)) {
235 xmlhttp
.open("GET", query_str
, true);
236 xmlhttp
.onreadystatechange
=feedlist_callback
;
239 debug("xmlhttp busy");
240 //printLockingError();
245 function catchupAllFeeds() {
247 var query_str
= "backend.php?op=feeds&subop=catchupAll";
249 notify_progress("Marking all feeds as read...");
251 debug("catchupAllFeeds Q=" + query_str
);
253 if (xmlhttp_ready(xmlhttp
)) {
254 xmlhttp
.open("GET", query_str
, true);
255 xmlhttp
.onreadystatechange
=feedlist_callback
;
258 debug("xmlhttp busy");
259 //printLockingError();
267 function viewCurrentFeed(subop
) {
269 // if (getActiveFeedId()) {
270 if (getActiveFeedId() != undefined) {
271 viewfeed(getActiveFeedId(), subop
);
273 disableContainerChildren("headlinesToolbar", false, document
);
274 // viewfeed(-1, subop); // FIXME
276 return false; // block unneeded form submits
279 function viewfeed(feed
, subop
) {
280 var f
= window
.frames
["feeds-frame"];
281 f
.viewfeed(feed
, subop
);
285 scheduleFeedUpdate(false);
287 var refresh_time
= getInitParam("feeds_frame_refresh");
289 if (!refresh_time
) refresh_time
= 600;
291 setTimeout("timeout()", refresh_time
*1000);
294 function resetSearch() {
295 var searchbox
= document
.getElementById("searchbox")
297 if (searchbox
.value
!= "" && getActiveFeedId()) {
298 searchbox
.value
= "";
299 viewfeed(getActiveFeedId(), "");
303 function searchCancel() {
309 viewCurrentFeed(0, "");
312 function localPiggieFunction(enable
) {
314 var query_str
= "backend.php?op=feeds&subop=piggie";
316 if (xmlhttp_ready(xmlhttp
)) {
318 xmlhttp
.open("GET", query_str
, true);
319 xmlhttp
.onreadystatechange
=feedlist_callback
;
325 // if argument is undefined, current subtitle is not updated
326 // use blank string to clear subtitle
327 function updateTitle(s
) {
328 var tmp
= "Tiny Tiny RSS";
330 if (s
!= undefined) {
331 current_subtitle
= s
;
334 if (global_unread
> 0) {
335 tmp
= tmp
+ " (" + global_unread
+ ")";
338 if (current_subtitle
) {
339 tmp
= tmp
+ " - " + current_subtitle
;
342 if (active_title_text
.length
> 0) {
343 tmp
= tmp
+ " > " + active_title_text
;
346 document
.title
= tmp
;
349 function genericSanityCheck() {
351 if (!xmlhttp
) fatalError(1);
353 setCookie("ttrss_vf_test", "TEST");
355 if (getCookie("ttrss_vf_test") != "TEST") {
366 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
368 if (arguments
.callee
.done
) return;
369 arguments
.callee
.done
= true;
371 disableContainerChildren("headlinesToolbar", true);
373 Form
.disable("main_toolbar_form");
375 if (!genericSanityCheck())
378 if (getURLParam('debug')) {
379 document
.getElementById('debug_output').style
.display
= 'block';
380 debug('debug mode activated');
383 var params
= "&ua=" + param_escape(navigator
.userAgent
);
385 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, true);
386 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
390 exception_error("init", e
);
394 function resize_headlines() {
396 var h_frame
= document
.getElementById("headlines-frame");
397 var c_frame
= document
.getElementById("content-frame");
398 var f_frame
= document
.getElementById("footer");
400 if (!c_frame
|| !h_frame
) return;
402 debug("resize_headlines");
405 h_frame
.style
.height
= 30 + "%";
406 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
407 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
409 h_frame
.style
.height
= document
.documentElement
.clientHeight
* 0.3 + "px";
410 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
412 var c_bottom
= document
.documentElement
.clientHeight
;
415 c_bottom
= f_frame
.offsetTop
;
418 c_frame
.style
.height
= c_bottom
- (h_frame
.offsetTop
+
419 h_frame
.offsetHeight
+ 1) + "px";
420 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
425 function init_second_stage() {
429 cookie_lifetime
= getCookie("ttrss_cltime");
431 delCookie("ttrss_vf_test");
433 // document.onresize = resize_headlines;
436 var toolbar
= document
.forms
["main_toolbar_form"];
438 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
439 dropboxSelect(toolbar
.limit
, getInitParam("default_view_limit"));
441 daemon_enabled
= getInitParam("daemon_enabled") == 1;
442 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
444 setTimeout('updateFeedList(false, false)', 50);
446 debug("second stage ok");
449 exception_error("init_second_stage", e
);
453 function quickMenuChange() {
454 var chooser
= document
.getElementById("quickMenuChooser");
455 var opid
= chooser
[chooser
.selectedIndex
].value
;
457 chooser
.selectedIndex
= 0;
461 function quickMenuGo(opid
) {
464 if (opid
== "qmcPrefs") {
468 if (opid
== "qmcSearch") {
469 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
473 if (opid
== "qmcAddFeed") {
474 displayDlg("quickAddFeed");
478 if (opid
== "qmcEditFeed") {
479 editFeedDlg(getActiveFeedId());
482 if (opid
== "qmcRemoveFeed") {
483 var actid
= getActiveFeedId();
485 if (activeFeedIsCat()) {
486 alert("You can't unsubscribe from the category.");
491 alert("Please select some feed first.");
495 var fn
= getFeedName(actid
);
497 if (confirm("Unsubscribe from " + fn
+ "?")) {
504 if (opid
== "qmcUpdateFeeds") {
505 scheduleFeedUpdate(true);
509 if (opid
== "qmcCatchupAll") {
514 if (opid
== "qmcShowOnlyUnread") {
519 if (opid
== "qmcAddFilter") {
520 displayDlg("quickAddFilter", getActiveFeedId());
524 exception_error("quickMenuGo", e
);
528 function qfdDelete(feed_id
) {
530 notify_progress("Removing feed...");
532 if (!xmlhttp_ready(xmlhttp
)) {
537 _qfd_deleted_feed
= feed_id
;
539 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
540 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
547 function updateFeedTitle(t
) {
548 active_title_text
= t
;
552 function toggleDispRead() {
555 if (!xmlhttp_ready(xmlhttp
)) {
560 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
562 hide_read_feeds
= !hide_read_feeds
;
564 debug("toggle_disp_read => " + hide_read_feeds
);
566 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
568 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
570 /* var query = "backend.php?op=rpc&subop=setpref" +
571 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
573 new Ajax.Request(query); */
576 exception_error("toggleDispRead", e
);
580 function parse_runtime_info(elem
) {
582 debug("parse_runtime_info: elem is null, aborting");
586 var param
= elem
.firstChild
;
588 debug("parse_runtime_info: " + param
);
591 var k
= param
.getAttribute("key");
592 var v
= param
.getAttribute("value");
594 debug("RI: " + k
+ " => " + v
);
596 if (k
== "new_version_available") {
597 var icon
= document
.getElementById("newVersionIcon");
600 icon
.style
.display
= "inline";
602 icon
.style
.display
= "none";
609 if (k
== "daemon_is_running" && v
!= 1) {
610 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
614 if (k
== "daemon_stamp_ok" && v
!= 1) {
615 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
623 /* var w = document.getElementById("noDaemonWarning");
626 if (k == "daemon_is_running" && v != 1) {
627 w.style.display = "block";
629 w.style.display = "none";
632 param
= param
.nextSibling
;
636 function catchupCurrentFeed() {
638 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
640 var str
= "Mark all articles in " + fn
+ " as read?";
642 /* if (active_feed_is_cat) {
643 str = "Mark all articles in this category as read?";
646 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
647 return viewCurrentFeed('MarkAllRead')
651 function userSwitch() {
652 var chooser
= document
.getElementById("userSwitch");
653 var user
= chooser
[chooser
.selectedIndex
].value
;
654 window
.location
= "tt-rss.php?swu=" + user
;
657 function editFeedDlg(feed
) {
662 alert("Please select some feed first.");
666 if (feed
<= 0 || activeFeedIsCat() || tagsAreDisplayed()) {
667 alert("You can't edit this kind of feed.");
671 if (xmlhttp_ready(xmlhttp
)) {
672 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
673 param_escape(feed
), true);
674 xmlhttp
.onreadystatechange
=infobox_callback
;
681 /* this functions duplicate those of prefs.js feed editor, with
682 some differences because there is no feedlist */
684 function feedEditCancel() {
689 function feedEditSave() {
693 if (!xmlhttp_ready(xmlhttp
)) {
698 // FIXME: add parameter validation
700 var query
= Form
.serialize("edit_feed_form");
702 notify_progress("Saving feed...");
704 xmlhttp
.open("POST", "backend.php", true);
705 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
706 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
714 exception_error("feedEditSave (main)", e
);