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;
12 var cookie_lifetime
= 0;
13 var active_feed_id
= 0;
14 var active_feed_is_cat
= false;
15 var number_of_feeds
= 0;
16 var sanity_check_done
= false;
18 var xmlhttp
= Ajax
.getTransport();
20 var init_params
= new Object();
22 function tagsAreDisplayed() {
26 function toggleTags(show_all
) {
30 debug("toggleTags: " + show_all
+ "; " + display_tags
);
32 var p
= document
.getElementById("dispSwitchPrompt");
34 if (!show_all
&& !display_tags
) {
35 displayDlg("printTagCloud");
36 } else if (show_all
) {
39 p
.innerHTML
= __("display feeds");
40 notify_progress("Loading, please wait...", true);
42 } else if (display_tags
) {
44 p
.innerHTML
= __("tag cloud");
45 notify_progress("Loading, please wait...", true);
50 exception_error("toggleTags", e
);
54 function dlg_frefresh_callback() {
55 if (xmlhttp
.readyState
== 4) {
56 // notify(xmlhttp.responseText);
58 if (getActiveFeedId() == _qfd_deleted_feed
) {
59 var h
= document
.getElementById("headlines-frame");
61 h
.innerHTML
= "<div class='whiteBox'>" + __('No feed selected.') + "</div>";
65 setTimeout('updateFeedList(false, false)', 50);
70 function refetch_callback2(transport
) {
73 var date
= new Date();
75 parse_counters_reply(transport
, true);
77 debug("refetch_callback2: done");
79 if (!daemon_enabled
&& !daemon_refresh_only
) {
80 notify_info("All feeds updated.");
86 exception_error("refetch_callback", e
);
91 function backend_sanity_check_callback() {
93 if (xmlhttp
.readyState
== 4) {
97 if (sanity_check_done
) {
98 fatalError(11, "Sanity check request received twice. This can indicate "+
99 "presence of Firebug or some other disrupting extension. "+
100 "Please disable it and try again.");
104 if (!xmlhttp
.responseXML
) {
105 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
109 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
112 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
116 var error_code
= reply
.getAttribute("error-code");
118 if (error_code
&& error_code
!= 0) {
119 return fatalError(error_code
, reply
.getAttribute("error-msg"));
122 debug("sanity check ok");
124 var params
= reply
.nextSibling
;
127 debug('reading init-params...');
128 var param
= params
.firstChild
;
131 var k
= param
.getAttribute("key");
132 var v
= param
.getAttribute("value");
133 debug(k
+ " => " + v
);
135 param
= param
.nextSibling
;
139 sanity_check_done
= true;
144 exception_error("backend_sanity_check_callback", e
);
149 function scheduleFeedUpdate(force
) {
151 debug("in scheduleFeedUpdate");
153 if (!daemon_enabled
&& !daemon_refresh_only
) {
154 notify_progress("Updating feeds...", true);
157 var query_str
= "backend.php?op=rpc&subop=";
160 query_str
= query_str
+ "forceUpdateAllFeeds";
162 query_str
= query_str
+ "updateAllFeeds";
167 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
168 firsttime_update
= false;
178 query_str
= query_str
+ "&omode=" + omode
;
179 query_str
= query_str
+ "&uctr=" + global_unread
;
181 var date
= new Date();
182 var timestamp
= Math
.round(date
.getTime() / 1000);
183 query_str
= query_str
+ "&ts=" + timestamp
185 debug("REFETCH query: " + query_str
);
187 new Ajax
.Request(query_str
, {
188 onComplete: function(transport
) {
189 refetch_callback2(transport
);
193 function updateFeedList(silent
, fetch
) {
195 // if (silent != true) {
196 // notify("Loading feed list...");
199 debug("<b>updateFeedList</b>");
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 var date
= new Date();
212 var timestamp
= Math
.round(date
.getTime() / 1000);
213 query_str
= query_str
+ "&ts=" + timestamp
215 if (fetch
) query_str
= query_str
+ "&fetch=yes";
217 // var feeds_frame = document.getElementById("feeds-frame");
218 // feeds_frame.src = query_str;
220 debug("updateFeedList Q=" + query_str
);
222 if (xmlhttp_ready(xmlhttp
)) {
223 xmlhttp
.open("GET", query_str
, true);
224 xmlhttp
.onreadystatechange
=feedlist_callback
;
227 debug("xmlhttp busy");
228 //printLockingError();
233 function catchupAllFeeds() {
235 var query_str
= "backend.php?op=feeds&subop=catchupAll";
237 notify_progress("Marking all feeds as read...");
239 debug("catchupAllFeeds Q=" + query_str
);
241 if (xmlhttp_ready(xmlhttp
)) {
242 xmlhttp
.open("GET", query_str
, true);
243 xmlhttp
.onreadystatechange
=feedlist_callback
;
246 debug("xmlhttp busy");
247 //printLockingError();
255 function viewCurrentFeed(subop
) {
257 // if (getActiveFeedId()) {
258 if (getActiveFeedId() != undefined) {
259 viewfeed(getActiveFeedId(), subop
);
261 disableContainerChildren("headlinesToolbar", false, document
);
262 // viewfeed(-1, subop); // FIXME
264 return false; // block unneeded form submits
267 function viewfeed(feed
, subop
) {
268 var f
= window
.frames
["feeds-frame"];
269 f
.viewfeed(feed
, subop
);
273 scheduleFeedUpdate(false);
275 var refresh_time
= getInitParam("feeds_frame_refresh");
277 if (!refresh_time
) refresh_time
= 600;
279 setTimeout("timeout()", refresh_time
*1000);
282 function resetSearch() {
283 var searchbox
= document
.getElementById("searchbox")
285 if (searchbox
.value
!= "" && getActiveFeedId()) {
286 searchbox
.value
= "";
287 viewfeed(getActiveFeedId(), "");
291 function searchCancel() {
297 viewCurrentFeed(0, "");
300 function localPiggieFunction(enable
) {
302 var query_str
= "backend.php?op=feeds&subop=piggie";
304 if (xmlhttp_ready(xmlhttp
)) {
306 xmlhttp
.open("GET", query_str
, true);
307 xmlhttp
.onreadystatechange
=feedlist_callback
;
313 // if argument is undefined, current subtitle is not updated
314 // use blank string to clear subtitle
315 function updateTitle(s
) {
316 var tmp
= "Tiny Tiny RSS";
318 if (s
!= undefined) {
319 current_subtitle
= s
;
322 if (global_unread
> 0) {
323 tmp
= tmp
+ " (" + global_unread
+ ")";
326 if (current_subtitle
) {
327 tmp
= tmp
+ " - " + current_subtitle
;
330 if (active_title_text
.length
> 0) {
331 tmp
= tmp
+ " > " + active_title_text
;
334 document
.title
= tmp
;
337 function genericSanityCheck() {
339 if (!xmlhttp
) fatalError(1);
341 setCookie("ttrss_vf_test", "TEST");
343 if (getCookie("ttrss_vf_test") != "TEST") {
354 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
356 if (arguments
.callee
.done
) return;
357 arguments
.callee
.done
= true;
359 disableContainerChildren("headlinesToolbar", true);
361 Form
.disable("main_toolbar_form");
363 if (!genericSanityCheck())
366 if (getURLParam('debug')) {
367 document
.getElementById('debug_output').style
.display
= 'block';
368 debug('debug mode activated');
371 var params
= "&ua=" + param_escape(navigator
.userAgent
);
373 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, true);
374 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
378 exception_error("init", e
);
382 function resize_headlines() {
384 var h_frame
= document
.getElementById("headlines-frame");
385 var c_frame
= document
.getElementById("content-frame");
386 var f_frame
= document
.getElementById("footer");
388 if (!c_frame
|| !h_frame
) return;
390 debug("resize_headlines");
393 h_frame
.style
.height
= 30 + "%";
394 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
395 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
397 h_frame
.style
.height
= document
.documentElement
.clientHeight
* 0.3 + "px";
398 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
400 var c_bottom
= document
.documentElement
.clientHeight
;
403 c_bottom
= f_frame
.offsetTop
;
406 c_frame
.style
.height
= c_bottom
- (h_frame
.offsetTop
+
407 h_frame
.offsetHeight
+ 1) + "px";
408 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
413 function init_second_stage() {
417 cookie_lifetime
= getCookie("ttrss_cltime");
419 delCookie("ttrss_vf_test");
421 // document.onresize = resize_headlines;
424 var toolbar
= document
.forms
["main_toolbar_form"];
426 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
427 dropboxSelect(toolbar
.limit
, getInitParam("default_view_limit"));
429 daemon_enabled
= getInitParam("daemon_enabled") == 1;
430 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
432 setTimeout('updateFeedList(false, false)', 50);
434 debug("second stage ok");
437 exception_error("init_second_stage", e
);
441 function quickMenuChange() {
442 var chooser
= document
.getElementById("quickMenuChooser");
443 var opid
= chooser
[chooser
.selectedIndex
].value
;
445 chooser
.selectedIndex
= 0;
449 function quickMenuGo(opid
) {
452 if (opid
== "qmcPrefs") {
456 if (opid
== "qmcSearch") {
457 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
461 if (opid
== "qmcAddFeed") {
462 displayDlg("quickAddFeed");
466 if (opid
== "qmcEditFeed") {
467 editFeedDlg(getActiveFeedId());
470 if (opid
== "qmcRemoveFeed") {
471 var actid
= getActiveFeedId();
473 if (activeFeedIsCat()) {
474 alert(__("You can't unsubscribe from the category."));
479 alert(__("Please select some feed first."));
483 var fn
= getFeedName(actid
);
485 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
494 if (opid
== "qmcUpdateFeeds") {
495 scheduleFeedUpdate(true);
499 if (opid
== "qmcCatchupAll") {
504 if (opid
== "qmcShowOnlyUnread") {
509 if (opid
== "qmcAddFilter") {
510 displayDlg("quickAddFilter", getActiveFeedId());
514 exception_error("quickMenuGo", e
);
518 function qfdDelete(feed_id
) {
520 notify_progress("Removing feed...");
522 if (!xmlhttp_ready(xmlhttp
)) {
527 _qfd_deleted_feed
= feed_id
;
529 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
530 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
537 function updateFeedTitle(t
) {
538 active_title_text
= t
;
542 function toggleDispRead() {
545 if (!xmlhttp_ready(xmlhttp
)) {
550 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
552 hide_read_feeds
= !hide_read_feeds
;
554 debug("toggle_disp_read => " + hide_read_feeds
);
556 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
558 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
560 /* var query = "backend.php?op=rpc&subop=setpref" +
561 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
563 new Ajax.Request(query); */
566 exception_error("toggleDispRead", e
);
570 function parse_runtime_info(elem
) {
572 debug("parse_runtime_info: elem is null, aborting");
576 var param
= elem
.firstChild
;
578 debug("parse_runtime_info: " + param
);
581 var k
= param
.getAttribute("key");
582 var v
= param
.getAttribute("value");
584 debug("RI: " + k
+ " => " + v
);
586 if (k
== "new_version_available") {
587 var icon
= document
.getElementById("newVersionIcon");
590 icon
.style
.display
= "inline";
592 icon
.style
.display
= "none";
599 if (k
== "daemon_is_running" && v
!= 1) {
600 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
604 if (k
== "daemon_stamp_ok" && v
!= 1) {
605 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
613 /* var w = document.getElementById("noDaemonWarning");
616 if (k == "daemon_is_running" && v != 1) {
617 w.style.display = "block";
619 w.style.display = "none";
622 param
= param
.nextSibling
;
626 function catchupCurrentFeed() {
628 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
630 var str
= "Mark all articles in " + fn
+ " as read?";
632 /* if (active_feed_is_cat) {
633 str = "Mark all articles in this category as read?";
636 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
637 return viewCurrentFeed('MarkAllRead')
641 function userSwitch() {
642 var chooser
= document
.getElementById("userSwitch");
643 var user
= chooser
[chooser
.selectedIndex
].value
;
644 window
.location
= "tt-rss.php?swu=" + user
;
647 function editFeedDlg(feed
) {
652 alert(__("Please select some feed first."));
656 if ((feed
<= 0 && feed
> -10) || activeFeedIsCat() || tagsAreDisplayed()) {
657 alert(__("You can't edit this kind of feed."));
661 if (xmlhttp_ready(xmlhttp
)) {
664 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
665 param_escape(feed
), true);
666 xmlhttp
.onreadystatechange
=infobox_callback
;
669 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
670 param_escape(-feed
-11), true);
671 xmlhttp
.onreadystatechange
=infobox_callback
;
679 /* this functions duplicate those of prefs.js feed editor, with
680 some differences because there is no feedlist */
682 function feedEditCancel() {
687 function feedEditSave() {
691 if (!xmlhttp_ready(xmlhttp
)) {
696 // FIXME: add parameter validation
698 var query
= Form
.serialize("edit_feed_form");
700 notify_progress("Saving feed...");
702 xmlhttp
.open("POST", "backend.php", true);
703 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
704 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
712 exception_error("feedEditSave (main)", e
);
716 function labelEditCancel() {
721 function labelEditSave() {
725 if (!xmlhttp_ready(xmlhttp
)) {
732 notify_progress("Saving label...");
734 query
= Form
.serialize("label_edit_form");
736 xmlhttp
.open("GET", "backend.php?" + query
, true);
737 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
743 exception_error("feedEditSave (main)", e
);