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
) {
32 debug("toggleTags: " + show_all
+ "; " + display_tags
);
34 var p
= document
.getElementById("dispSwitchPrompt");
36 if (!show_all
&& !display_tags
) {
37 displayDlg("printTagCloud");
38 } else if (show_all
) {
41 p
.innerHTML
= __("display feeds");
42 notify_progress("Loading, please wait...", true);
44 } else if (display_tags
) {
46 p
.innerHTML
= __("tag cloud");
47 notify_progress("Loading, please wait...", true);
52 exception_error("toggleTags", e
);
56 function dlg_frefresh_callback() {
57 if (xmlhttp
.readyState
== 4) {
58 // notify(xmlhttp.responseText);
60 if (getActiveFeedId() == _qfd_deleted_feed
) {
61 var h
= document
.getElementById("headlines-frame");
63 h
.innerHTML
= "<div class='whiteBox'>" + __('No feed selected.') + "</div>";
67 setTimeout('updateFeedList(false, false)', 50);
72 function refetch_callback() {
73 if (xmlhttp_ctr
.readyState
== 4) {
76 var date
= new Date();
78 last_refetch
= date
.getTime() / 1000;
80 parse_counters_reply(xmlhttp_ctr
, true);
82 debug("refetch_callback: done");
84 if (!daemon_enabled
&& !daemon_refresh_only
) {
85 notify_info("All feeds updated.");
91 exception_error("refetch_callback", e
);
97 function backend_sanity_check_callback() {
99 if (xmlhttp
.readyState
== 4) {
103 if (sanity_check_done
) {
104 fatalError(11, "Sanity check request received twice. This can indicate "+
105 "presence of Firebug or some other disrupting extension. "+
106 "Please disable it and try again.");
110 if (!xmlhttp
.responseXML
) {
111 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
115 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
118 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
122 var error_code
= reply
.getAttribute("error-code");
124 if (error_code
&& error_code
!= 0) {
125 return fatalError(error_code
, reply
.getAttribute("error-msg"));
128 debug("sanity check ok");
130 var params
= reply
.nextSibling
;
133 debug('reading init-params...');
134 var param
= params
.firstChild
;
137 var k
= param
.getAttribute("key");
138 var v
= param
.getAttribute("value");
139 debug(k
+ " => " + v
);
141 param
= param
.nextSibling
;
145 sanity_check_done
= true;
150 exception_error("backend_sanity_check_callback", e
);
155 function scheduleFeedUpdate(force
) {
157 if (!daemon_enabled
&& !daemon_refresh_only
) {
158 notify_progress("Updating feeds, please wait.", true);
159 updateTitle("Updating");
162 var query_str
= "backend.php?op=rpc&subop=";
165 query_str
= query_str
+ "forceUpdateAllFeeds";
167 query_str
= query_str
+ "updateAllFeeds";
172 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
173 firsttime_update
= false;
183 query_str
= query_str
+ "&omode=" + omode
;
184 query_str
= query_str
+ "&uctr=" + global_unread
;
186 debug("in scheduleFeedUpdate");
188 var date
= new Date();
190 var timestamp
= Math
.round(date
.getTime() / 1000);
191 query_str
= query_str
+ "&ts=" + timestamp
193 if (!xmlhttp_ready(xmlhttp_ctr
) && last_refetch
< date
.getTime() / 1000 - 60) {
194 debug("<b>xmlhttp seems to be stuck, aborting</b>");
197 xmlhttp_ctr
= Ajax
.getTransport();
201 debug("REFETCH query: " + query_str
);
203 if (xmlhttp_ready(xmlhttp_ctr
)) {
204 xmlhttp_ctr
.open("GET", query_str
, true);
205 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
206 xmlhttp_ctr
.send(null);
208 debug("xmlhttp_ctr busy");
209 //printLockingError();
213 function updateFeedList(silent
, fetch
) {
215 // if (silent != true) {
216 // notify("Loading feed list...");
219 debug("<b>updateFeedList</b>");
221 var query_str
= "backend.php?op=feeds";
224 query_str
= query_str
+ "&tags=1";
227 if (getActiveFeedId() && !activeFeedIsCat()) {
228 query_str
= query_str
+ "&actid=" + getActiveFeedId();
231 var date
= new Date();
232 var timestamp
= Math
.round(date
.getTime() / 1000);
233 query_str
= query_str
+ "&ts=" + timestamp
235 if (fetch
) query_str
= query_str
+ "&fetch=yes";
237 // var feeds_frame = document.getElementById("feeds-frame");
238 // feeds_frame.src = query_str;
240 debug("updateFeedList Q=" + query_str
);
242 if (xmlhttp_ready(xmlhttp
)) {
243 xmlhttp
.open("GET", query_str
, true);
244 xmlhttp
.onreadystatechange
=feedlist_callback
;
247 debug("xmlhttp busy");
248 //printLockingError();
253 function catchupAllFeeds() {
255 var query_str
= "backend.php?op=feeds&subop=catchupAll";
257 notify_progress("Marking all feeds as read...");
259 debug("catchupAllFeeds Q=" + query_str
);
261 if (xmlhttp_ready(xmlhttp
)) {
262 xmlhttp
.open("GET", query_str
, true);
263 xmlhttp
.onreadystatechange
=feedlist_callback
;
266 debug("xmlhttp busy");
267 //printLockingError();
275 function viewCurrentFeed(subop
) {
277 // if (getActiveFeedId()) {
278 if (getActiveFeedId() != undefined) {
279 viewfeed(getActiveFeedId(), subop
);
281 disableContainerChildren("headlinesToolbar", false, document
);
282 // viewfeed(-1, subop); // FIXME
284 return false; // block unneeded form submits
287 function viewfeed(feed
, subop
) {
288 var f
= window
.frames
["feeds-frame"];
289 f
.viewfeed(feed
, subop
);
293 scheduleFeedUpdate(false);
295 var refresh_time
= getInitParam("feeds_frame_refresh");
297 if (!refresh_time
) refresh_time
= 600;
299 setTimeout("timeout()", refresh_time
*1000);
302 function resetSearch() {
303 var searchbox
= document
.getElementById("searchbox")
305 if (searchbox
.value
!= "" && getActiveFeedId()) {
306 searchbox
.value
= "";
307 viewfeed(getActiveFeedId(), "");
311 function searchCancel() {
317 viewCurrentFeed(0, "");
320 function localPiggieFunction(enable
) {
322 var query_str
= "backend.php?op=feeds&subop=piggie";
324 if (xmlhttp_ready(xmlhttp
)) {
326 xmlhttp
.open("GET", query_str
, true);
327 xmlhttp
.onreadystatechange
=feedlist_callback
;
333 // if argument is undefined, current subtitle is not updated
334 // use blank string to clear subtitle
335 function updateTitle(s
) {
336 var tmp
= "Tiny Tiny RSS";
338 if (s
!= undefined) {
339 current_subtitle
= s
;
342 if (global_unread
> 0) {
343 tmp
= tmp
+ " (" + global_unread
+ ")";
346 if (current_subtitle
) {
347 tmp
= tmp
+ " - " + current_subtitle
;
350 if (active_title_text
.length
> 0) {
351 tmp
= tmp
+ " > " + active_title_text
;
354 document
.title
= tmp
;
357 function genericSanityCheck() {
359 if (!xmlhttp
) fatalError(1);
361 setCookie("ttrss_vf_test", "TEST");
363 if (getCookie("ttrss_vf_test") != "TEST") {
374 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
376 if (arguments
.callee
.done
) return;
377 arguments
.callee
.done
= true;
379 disableContainerChildren("headlinesToolbar", true);
381 Form
.disable("main_toolbar_form");
383 if (!genericSanityCheck())
386 if (getURLParam('debug')) {
387 document
.getElementById('debug_output').style
.display
= 'block';
388 debug('debug mode activated');
391 var params
= "&ua=" + param_escape(navigator
.userAgent
);
393 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, true);
394 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
398 exception_error("init", e
);
402 function resize_headlines() {
404 var h_frame
= document
.getElementById("headlines-frame");
405 var c_frame
= document
.getElementById("content-frame");
406 var f_frame
= document
.getElementById("footer");
408 if (!c_frame
|| !h_frame
) return;
410 debug("resize_headlines");
413 h_frame
.style
.height
= 30 + "%";
414 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
415 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
417 h_frame
.style
.height
= document
.documentElement
.clientHeight
* 0.3 + "px";
418 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
420 var c_bottom
= document
.documentElement
.clientHeight
;
423 c_bottom
= f_frame
.offsetTop
;
426 c_frame
.style
.height
= c_bottom
- (h_frame
.offsetTop
+
427 h_frame
.offsetHeight
+ 1) + "px";
428 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
433 function init_second_stage() {
437 cookie_lifetime
= getCookie("ttrss_cltime");
439 delCookie("ttrss_vf_test");
441 // document.onresize = resize_headlines;
444 var toolbar
= document
.forms
["main_toolbar_form"];
446 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
447 dropboxSelect(toolbar
.limit
, getInitParam("default_view_limit"));
449 daemon_enabled
= getInitParam("daemon_enabled") == 1;
450 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
452 setTimeout('updateFeedList(false, false)', 50);
454 debug("second stage ok");
457 exception_error("init_second_stage", e
);
461 function quickMenuChange() {
462 var chooser
= document
.getElementById("quickMenuChooser");
463 var opid
= chooser
[chooser
.selectedIndex
].value
;
465 chooser
.selectedIndex
= 0;
469 function quickMenuGo(opid
) {
472 if (opid
== "qmcPrefs") {
476 if (opid
== "qmcSearch") {
477 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
481 if (opid
== "qmcAddFeed") {
482 displayDlg("quickAddFeed");
486 if (opid
== "qmcEditFeed") {
487 editFeedDlg(getActiveFeedId());
490 if (opid
== "qmcRemoveFeed") {
491 var actid
= getActiveFeedId();
493 if (activeFeedIsCat()) {
494 alert(__("You can't unsubscribe from the category."));
499 alert(__("Please select some feed first."));
503 var fn
= getFeedName(actid
);
505 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
514 if (opid
== "qmcUpdateFeeds") {
515 scheduleFeedUpdate(true);
519 if (opid
== "qmcCatchupAll") {
524 if (opid
== "qmcShowOnlyUnread") {
529 if (opid
== "qmcAddFilter") {
530 displayDlg("quickAddFilter", getActiveFeedId());
534 exception_error("quickMenuGo", e
);
538 function qfdDelete(feed_id
) {
540 notify_progress("Removing feed...");
542 if (!xmlhttp_ready(xmlhttp
)) {
547 _qfd_deleted_feed
= feed_id
;
549 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
550 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
557 function updateFeedTitle(t
) {
558 active_title_text
= t
;
562 function toggleDispRead() {
565 if (!xmlhttp_ready(xmlhttp
)) {
570 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
572 hide_read_feeds
= !hide_read_feeds
;
574 debug("toggle_disp_read => " + hide_read_feeds
);
576 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
578 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
580 /* var query = "backend.php?op=rpc&subop=setpref" +
581 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
583 new Ajax.Request(query); */
586 exception_error("toggleDispRead", e
);
590 function parse_runtime_info(elem
) {
592 debug("parse_runtime_info: elem is null, aborting");
596 var param
= elem
.firstChild
;
598 debug("parse_runtime_info: " + param
);
601 var k
= param
.getAttribute("key");
602 var v
= param
.getAttribute("value");
604 debug("RI: " + k
+ " => " + v
);
606 if (k
== "new_version_available") {
607 var icon
= document
.getElementById("newVersionIcon");
610 icon
.style
.display
= "inline";
612 icon
.style
.display
= "none";
619 if (k
== "daemon_is_running" && v
!= 1) {
620 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
624 if (k
== "daemon_stamp_ok" && v
!= 1) {
625 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
633 /* var w = document.getElementById("noDaemonWarning");
636 if (k == "daemon_is_running" && v != 1) {
637 w.style.display = "block";
639 w.style.display = "none";
642 param
= param
.nextSibling
;
646 function catchupCurrentFeed() {
648 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
650 var str
= "Mark all articles in " + fn
+ " as read?";
652 /* if (active_feed_is_cat) {
653 str = "Mark all articles in this category as read?";
656 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
657 return viewCurrentFeed('MarkAllRead')
661 function userSwitch() {
662 var chooser
= document
.getElementById("userSwitch");
663 var user
= chooser
[chooser
.selectedIndex
].value
;
664 window
.location
= "tt-rss.php?swu=" + user
;
667 function editFeedDlg(feed
) {
672 alert(__("Please select some feed first."));
676 if (feed
<= 0 || activeFeedIsCat() || tagsAreDisplayed()) {
677 alert(__("You can't edit this kind of feed."));
681 if (xmlhttp_ready(xmlhttp
)) {
682 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
683 param_escape(feed
), true);
684 xmlhttp
.onreadystatechange
=infobox_callback
;
691 /* this functions duplicate those of prefs.js feed editor, with
692 some differences because there is no feedlist */
694 function feedEditCancel() {
699 function feedEditSave() {
703 if (!xmlhttp_ready(xmlhttp
)) {
708 // FIXME: add parameter validation
710 var query
= Form
.serialize("edit_feed_form");
712 notify_progress("Saving feed...");
714 xmlhttp
.open("POST", "backend.php", true);
715 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
716 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
724 exception_error("feedEditSave (main)", e
);