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 new Ajax
.Request(query_str
, {
223 onComplete: function(transport
) {
224 feedlist_callback2(transport
);
229 function catchupAllFeeds() {
231 var query_str
= "backend.php?op=feeds&subop=catchupAll";
233 notify_progress("Marking all feeds as read...");
235 debug("catchupAllFeeds Q=" + query_str
);
237 new Ajax
.Request(query_str
, {
238 onComplete: function(transport
) {
239 feedlist_callback2(transport
);
247 function viewCurrentFeed(subop
) {
249 // if (getActiveFeedId()) {
250 if (getActiveFeedId() != undefined) {
251 viewfeed(getActiveFeedId(), subop
);
253 disableContainerChildren("headlinesToolbar", false, document
);
254 // viewfeed(-1, subop); // FIXME
256 return false; // block unneeded form submits
259 function viewfeed(feed
, subop
) {
260 var f
= window
.frames
["feeds-frame"];
261 f
.viewfeed(feed
, subop
);
265 scheduleFeedUpdate(false);
267 var refresh_time
= getInitParam("feeds_frame_refresh");
269 if (!refresh_time
) refresh_time
= 600;
271 setTimeout("timeout()", refresh_time
*1000);
274 function resetSearch() {
275 var searchbox
= document
.getElementById("searchbox")
277 if (searchbox
.value
!= "" && getActiveFeedId()) {
278 searchbox
.value
= "";
279 viewfeed(getActiveFeedId(), "");
283 function searchCancel() {
289 viewCurrentFeed(0, "");
292 // if argument is undefined, current subtitle is not updated
293 // use blank string to clear subtitle
294 function updateTitle(s
) {
295 var tmp
= "Tiny Tiny RSS";
297 if (s
!= undefined) {
298 current_subtitle
= s
;
301 if (global_unread
> 0) {
302 tmp
= tmp
+ " (" + global_unread
+ ")";
305 if (current_subtitle
) {
306 tmp
= tmp
+ " - " + current_subtitle
;
309 if (active_title_text
.length
> 0) {
310 tmp
= tmp
+ " > " + active_title_text
;
313 document
.title
= tmp
;
316 function genericSanityCheck() {
318 if (!xmlhttp
) fatalError(1);
320 setCookie("ttrss_vf_test", "TEST");
322 if (getCookie("ttrss_vf_test") != "TEST") {
333 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
335 if (arguments
.callee
.done
) return;
336 arguments
.callee
.done
= true;
338 disableContainerChildren("headlinesToolbar", true);
340 Form
.disable("main_toolbar_form");
342 if (!genericSanityCheck())
345 if (getURLParam('debug')) {
346 document
.getElementById('debug_output').style
.display
= 'block';
347 debug('debug mode activated');
350 var params
= "&ua=" + param_escape(navigator
.userAgent
);
352 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, true);
353 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
357 exception_error("init", e
);
361 function resize_headlines() {
363 var h_frame
= document
.getElementById("headlines-frame");
364 var c_frame
= document
.getElementById("content-frame");
365 var f_frame
= document
.getElementById("footer");
367 if (!c_frame
|| !h_frame
) return;
369 debug("resize_headlines");
372 h_frame
.style
.height
= 30 + "%";
373 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
374 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
376 h_frame
.style
.height
= document
.documentElement
.clientHeight
* 0.3 + "px";
377 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
379 var c_bottom
= document
.documentElement
.clientHeight
;
382 c_bottom
= f_frame
.offsetTop
;
385 c_frame
.style
.height
= c_bottom
- (h_frame
.offsetTop
+
386 h_frame
.offsetHeight
+ 1) + "px";
387 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
392 function init_second_stage() {
396 cookie_lifetime
= getCookie("ttrss_cltime");
398 delCookie("ttrss_vf_test");
400 // document.onresize = resize_headlines;
403 var toolbar
= document
.forms
["main_toolbar_form"];
405 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
406 dropboxSelect(toolbar
.limit
, getInitParam("default_view_limit"));
408 daemon_enabled
= getInitParam("daemon_enabled") == 1;
409 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
411 setTimeout('updateFeedList(false, false)', 50);
413 debug("second stage ok");
416 exception_error("init_second_stage", e
);
420 function quickMenuChange() {
421 var chooser
= document
.getElementById("quickMenuChooser");
422 var opid
= chooser
[chooser
.selectedIndex
].value
;
424 chooser
.selectedIndex
= 0;
428 function quickMenuGo(opid
) {
431 if (opid
== "qmcPrefs") {
435 if (opid
== "qmcSearch") {
436 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
440 if (opid
== "qmcAddFeed") {
441 displayDlg("quickAddFeed");
445 if (opid
== "qmcEditFeed") {
446 editFeedDlg(getActiveFeedId());
449 if (opid
== "qmcRemoveFeed") {
450 var actid
= getActiveFeedId();
452 if (activeFeedIsCat()) {
453 alert(__("You can't unsubscribe from the category."));
458 alert(__("Please select some feed first."));
462 var fn
= getFeedName(actid
);
464 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
473 if (opid
== "qmcUpdateFeeds") {
474 scheduleFeedUpdate(true);
478 if (opid
== "qmcCatchupAll") {
483 if (opid
== "qmcShowOnlyUnread") {
488 if (opid
== "qmcAddFilter") {
489 displayDlg("quickAddFilter", getActiveFeedId());
493 exception_error("quickMenuGo", e
);
497 function qfdDelete(feed_id
) {
499 notify_progress("Removing feed...");
501 if (!xmlhttp_ready(xmlhttp
)) {
506 _qfd_deleted_feed
= feed_id
;
508 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
509 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
516 function updateFeedTitle(t
) {
517 active_title_text
= t
;
521 function toggleDispRead() {
524 if (!xmlhttp_ready(xmlhttp
)) {
529 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
531 hide_read_feeds
= !hide_read_feeds
;
533 debug("toggle_disp_read => " + hide_read_feeds
);
535 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
537 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
539 /* var query = "backend.php?op=rpc&subop=setpref" +
540 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
542 new Ajax.Request(query); */
545 exception_error("toggleDispRead", e
);
549 function parse_runtime_info(elem
) {
551 debug("parse_runtime_info: elem is null, aborting");
555 var param
= elem
.firstChild
;
557 debug("parse_runtime_info: " + param
);
560 var k
= param
.getAttribute("key");
561 var v
= param
.getAttribute("value");
563 debug("RI: " + k
+ " => " + v
);
565 if (k
== "new_version_available") {
566 var icon
= document
.getElementById("newVersionIcon");
569 icon
.style
.display
= "inline";
571 icon
.style
.display
= "none";
578 if (k
== "daemon_is_running" && v
!= 1) {
579 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
583 if (k
== "daemon_stamp_ok" && v
!= 1) {
584 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
592 /* var w = document.getElementById("noDaemonWarning");
595 if (k == "daemon_is_running" && v != 1) {
596 w.style.display = "block";
598 w.style.display = "none";
601 param
= param
.nextSibling
;
605 function catchupCurrentFeed() {
607 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
609 var str
= "Mark all articles in " + fn
+ " as read?";
611 /* if (active_feed_is_cat) {
612 str = "Mark all articles in this category as read?";
615 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
616 return viewCurrentFeed('MarkAllRead')
620 function editFeedDlg(feed
) {
626 alert(__("Please select some feed first."));
630 if ((feed
<= 0 && feed
> -10) || activeFeedIsCat() || tagsAreDisplayed()) {
631 alert(__("You can't edit this kind of feed."));
638 query
= "backend.php?op=pref-feeds&subop=editfeed&id=" + param_escape(feed
);
640 query
= "backend.php?op=pref-labels&subop=edit&id=" + param_escape(-feed
-11);
643 new Ajax
.Request(query
, {
644 onComplete: function(transport
) {
645 infobox_callback2(transport
);
649 exception_error("editFeedDlg", e
);
653 /* this functions duplicate those of prefs.js feed editor, with
654 some differences because there is no feedlist */
656 function feedEditCancel() {
661 function feedEditSave() {
665 if (!xmlhttp_ready(xmlhttp
)) {
670 // FIXME: add parameter validation
672 var query
= Form
.serialize("edit_feed_form");
674 notify_progress("Saving feed...");
676 xmlhttp
.open("POST", "backend.php", true);
677 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
678 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
686 exception_error("feedEditSave (main)", e
);
690 function labelEditCancel() {
695 function labelEditSave() {
699 if (!xmlhttp_ready(xmlhttp
)) {
706 notify_progress("Saving label...");
708 query
= Form
.serialize("label_edit_form");
710 xmlhttp
.open("GET", "backend.php?" + query
, true);
711 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
717 exception_error("feedEditSave (main)", e
);