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();
19 var xmlhttp_ctr
= Ajax
.getTransport();
21 var init_params
= new Object();
23 var op_history
= new Array();
25 function tagsAreDisplayed() {
29 function toggleTags() {
30 display_tags
= !display_tags
;
32 var p
= document
.getElementById("dispSwitchPrompt");
35 p
.innerHTML
= "display feeds";
37 p
.innerHTML
= "display tags";
40 notify("Loading, please wait...");
45 function dlg_frefresh_callback() {
46 if (xmlhttp
.readyState
== 4) {
47 // notify(xmlhttp.responseText);
49 if (getActiveFeedId() == _qfd_deleted_feed
) {
50 var h
= document
.getElementById("headlines-frame");
52 h
.innerHTML
= "<div class='whiteBox'>No feed selected.</div>";
56 setTimeout('updateFeedList(false, false)', 50);
61 function refetch_callback() {
62 if (xmlhttp_ctr
.readyState
== 4) {
65 var date
= new Date();
67 last_refetch
= date
.getTime() / 1000;
69 parse_counters_reply(xmlhttp_ctr
, true);
71 debug("refetch_callback: done");
73 if (!daemon_enabled
&& !daemon_refresh_only
) {
74 notify("All feeds updated.");
80 exception_error("refetch_callback", e
);
86 function backend_sanity_check_callback() {
88 if (xmlhttp
.readyState
== 4) {
92 if (!xmlhttp
.responseXML
) {
93 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
97 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
100 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
104 var error_code
= reply
.getAttribute("error-code");
106 if (error_code
&& error_code
!= 0) {
107 return fatalError(error_code
, reply
.getAttribute("error-msg"));
110 debug("sanity check ok");
112 var params
= reply
.nextSibling
;
115 debug('reading init-params...');
116 var param
= params
.firstChild
;
119 var k
= param
.getAttribute("key");
120 var v
= param
.getAttribute("value");
121 debug(k
+ " => " + v
);
123 param
= param
.nextSibling
;
130 exception_error("backend_sanity_check_callback", e
);
135 function scheduleFeedUpdate(force
) {
137 if (!daemon_enabled
&& !daemon_refresh_only
) {
138 notify("Updating feeds, please wait.", true);
139 updateTitle("Updating");
142 var query_str
= "backend.php?op=rpc&subop=";
145 query_str
= query_str
+ "forceUpdateAllFeeds";
147 query_str
= query_str
+ "updateAllFeeds";
152 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
153 firsttime_update
= false;
163 query_str
= query_str
+ "&omode=" + omode
;
164 query_str
= query_str
+ "&uctr=" + global_unread
;
166 debug("in scheduleFeedUpdate");
168 var date
= new Date();
170 if (!xmlhttp_ready(xmlhttp_ctr
) && last_refetch
< date
.getTime() / 1000 - 60) {
171 debug("<b>xmlhttp seems to be stuck, aborting</b>");
175 debug("REFETCH query: " + query_str
);
177 if (xmlhttp_ready(xmlhttp_ctr
)) {
178 xmlhttp_ctr
.open("GET", query_str
, true);
179 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
180 xmlhttp_ctr
.send(null);
182 debug("xmlhttp_ctr busy");
183 //printLockingError();
187 function updateFeedList(silent
, fetch
) {
189 // if (silent != true) {
190 // notify("Loading feed list...");
193 debug("<b>updateFeedList</b>");
195 var query_str
= "backend.php?op=feeds";
198 query_str
= query_str
+ "&tags=1";
201 if (getActiveFeedId() && !activeFeedIsCat()) {
202 query_str
= query_str
+ "&actid=" + getActiveFeedId();
205 if (navigator
.userAgent
.match("Opera")) {
206 var date
= new Date();
207 var timestamp
= Math
.round(date
.getTime() / 1000);
208 query_str
= query_str
+ "&ts=" + timestamp
211 if (fetch
) query_str
= query_str
+ "&fetch=yes";
213 // var feeds_frame = document.getElementById("feeds-frame");
214 // feeds_frame.src = query_str;
216 debug("updateFeedList Q=" + query_str
);
218 if (xmlhttp_ready(xmlhttp
)) {
219 xmlhttp
.open("GET", query_str
, true);
220 xmlhttp
.onreadystatechange
=feedlist_callback
;
223 debug("xmlhttp busy");
224 //printLockingError();
229 function catchupAllFeeds() {
231 var query_str
= "backend.php?op=feeds&subop=catchupAll";
233 notify("Marking all feeds as read...");
235 debug("catchupAllFeeds Q=" + query_str
);
237 if (xmlhttp_ready(xmlhttp
)) {
238 xmlhttp
.open("GET", query_str
, true);
239 xmlhttp
.onreadystatechange
=feedlist_callback
;
242 debug("xmlhttp busy");
243 //printLockingError();
251 function viewCurrentFeed(subop
) {
253 // if (getActiveFeedId()) {
254 if (getActiveFeedId() != undefined) {
255 viewfeed(getActiveFeedId(), subop
);
257 disableContainerChildren("headlinesToolbar", false, document
);
258 // viewfeed(-1, subop); // FIXME
260 return false; // block unneeded form submits
263 function viewfeed(feed
, subop
) {
264 var f
= window
.frames
["feeds-frame"];
265 f
.viewfeed(feed
, subop
);
269 scheduleFeedUpdate(false);
271 var refresh_time
= getInitParam("feeds_frame_refresh");
273 if (!refresh_time
) refresh_time
= 600;
275 setTimeout("timeout()", refresh_time
*1000);
278 function resetSearch() {
279 var searchbox
= document
.getElementById("searchbox")
281 if (searchbox
.value
!= "" && getActiveFeedId()) {
282 searchbox
.value
= "";
283 viewfeed(getActiveFeedId(), "");
287 function searchCancel() {
293 viewCurrentFeed(0, "");
296 function localPiggieFunction(enable
) {
298 var query_str
= "backend.php?op=feeds&subop=piggie";
300 if (xmlhttp_ready(xmlhttp
)) {
302 xmlhttp
.open("GET", query_str
, true);
303 xmlhttp
.onreadystatechange
=feedlist_callback
;
309 // if argument is undefined, current subtitle is not updated
310 // use blank string to clear subtitle
311 function updateTitle(s
) {
312 var tmp
= "Tiny Tiny RSS";
314 if (s
!= undefined) {
315 current_subtitle
= s
;
318 if (global_unread
> 0) {
319 tmp
= tmp
+ " (" + global_unread
+ ")";
322 if (current_subtitle
) {
323 tmp
= tmp
+ " - " + current_subtitle
;
326 if (active_title_text
.length
> 0) {
327 tmp
= tmp
+ " > " + active_title_text
;
330 document
.title
= tmp
;
333 function genericSanityCheck() {
335 if (!xmlhttp
) fatalError(1);
337 setCookie("ttrss_vf_test", "TEST");
339 if (getCookie("ttrss_vf_test") != "TEST") {
350 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
352 if (arguments
.callee
.done
) return;
353 arguments
.callee
.done
= true;
355 disableContainerChildren("headlinesToolbar", true);
357 Form
.disable("main_toolbar_form");
359 if (!genericSanityCheck())
362 if (getURLParam('debug')) {
363 document
.getElementById('debug_output').style
.display
= 'block';
364 debug('debug mode activated');
367 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
368 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
372 exception_error("init", e
);
376 function init_second_stage() {
380 cookie_lifetime
= getCookie("ttrss_cltime");
382 delCookie("ttrss_vf_test");
384 document
.onkeydown
= hotkey_handler
;
386 var tb
= parent
.document
.forms
["main_toolbar_form"];
388 // dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
389 // dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
391 daemon_enabled
= getInitParam("daemon_enabled") == 1;
392 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
394 setTimeout('updateFeedList(false, false)', 50);
396 debug("second stage ok");
399 exception_error("init_second_stage", e
);
403 function quickMenuChange() {
404 var chooser
= document
.getElementById("quickMenuChooser");
405 var opid
= chooser
[chooser
.selectedIndex
].value
;
407 chooser
.selectedIndex
= 0;
411 function quickMenuGo(opid
) {
414 if (opid
== "qmcPrefs") {
418 if (opid
== "qmcSearch") {
419 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
423 if (opid
== "qmcAddFeed") {
424 displayDlg("quickAddFeed");
428 if (opid
== "qmcEditFeed") {
429 editFeedDlg(getActiveFeedId());
432 if (opid
== "qmcRemoveFeed") {
433 var actid
= getActiveFeedId();
435 if (!actid
|| activeFeedIsCat()) {
436 alert("Please select some feed first.");
440 var fn
= getFeedName(actid
);
442 if (confirm("Unsubscribe from " + fn
+ "?")) {
449 if (opid
== "qmcUpdateFeeds") {
450 scheduleFeedUpdate(true);
454 if (opid
== "qmcCatchupAll") {
459 if (opid
== "qmcShowOnlyUnread") {
464 if (opid
== "qmcAddFilter") {
465 displayDlg("quickAddFilter", getActiveFeedId());
468 exception_error("quickMenuGo", e
);
472 function qfdDelete(feed_id
) {
474 notify("Removing feed...");
476 if (!xmlhttp_ready(xmlhttp
)) {
481 _qfd_deleted_feed
= feed_id
;
483 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
484 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
491 function updateFeedTitle(t
) {
492 active_title_text
= t
;
496 function toggleDispRead() {
499 if (!xmlhttp_ready(xmlhttp
)) {
504 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
506 hide_read_feeds
= !hide_read_feeds
;
508 debug("toggle_disp_read => " + hide_read_feeds
);
510 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
512 var query
= "backend.php?op=rpc&subop=setpref" +
513 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
515 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
517 new Ajax
.Request(query
);
520 exception_error("toggleDispRead", e
);
524 function parse_runtime_info(elem
) {
526 debug("parse_runtime_info: elem is null, aborting");
530 var param
= elem
.firstChild
;
532 debug("parse_runtime_info: " + param
);
535 var k
= param
.getAttribute("key");
536 var v
= param
.getAttribute("value");
538 debug("RI: " + k
+ " => " + v
);
540 var w
= document
.getElementById("noDaemonWarning");
543 if (k
== "daemon_is_running" && v
!= 1) {
544 w
.style
.display
= "block";
546 w
.style
.display
= "none";
549 param
= param
.nextSibling
;
553 function catchupCurrentFeed() {
555 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
557 var str
= "Mark all articles in " + fn
+ " as read?";
559 /* if (active_feed_is_cat) {
560 str = "Mark all articles in this category as read?";
563 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
564 return viewCurrentFeed('MarkAllRead')
568 function userSwitch() {
569 var chooser
= document
.getElementById("userSwitch");
570 var user
= chooser
[chooser
.selectedIndex
].value
;
571 window
.location
= "tt-rss.php?swu=" + user
;
574 function editFeedDlg(feed
) {
579 alert("Please select some feed first.");
583 if (feed
<= 0 || active_feed_is_cat
|| tagsAreDisplayed()) {
584 alert("You can't edit this kind of feed.");
588 if (xmlhttp_ready(xmlhttp
)) {
589 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
590 param_escape(feed
), true);
591 xmlhttp
.onreadystatechange
=infobox_callback
;
598 /* this functions duplicate those of prefs.js feed editor, with
599 some differences because there is no feedlist */
601 function feedEditCancel() {
606 function feedEditSave() {
610 if (!xmlhttp_ready(xmlhttp
)) {
615 // FIXME: add parameter validation
617 var query
= Form
.serialize("edit_feed_form");
619 notify("Saving feed...");
621 xmlhttp
.open("POST", "backend.php", true);
622 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
623 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
631 exception_error("feedEditSave (main)", e
);
635 function localHotkeyHandler(e
) {
640 keycode
= window
.event
.keyCode
;
645 var shift_key
= false;
648 shift_key
= e
.shiftKey
;
651 if (keycode
== 66 && shift_key
) { // shift-B
653 var op
= history_pop();
656 var op_s
= op
.split(":");
659 for (i
= 0; i
< op_s
.length
; i
++) {
660 if (op_s
[i
] == 'undefined') {
664 if (op_s
[i
] == 'false') {
668 if (op_s
[i
] == 'true') {
674 debug("history split: " + op_s
);
676 if (op_s
[0] == "ARTICLE") {
677 debug("history: reverting to article " + op_s
[1] + "/" + op_s
[2]);
678 view(op_s
[1], op_s
[2], true);
681 if (op_s
[0] == "FEED") {
682 viewfeed(op_s
[1], op_s
[2], op_s
[3], op_s
[4], true);
686 notify("No operation to undo");
693 debug("LKP=" + keycode
);
696 function history_push(op
) {
697 debug("history_push: " + op
);
700 while (op_history
.length
> 30) {
705 function history_pop() {
706 var op
= op_history
.pop();
707 debug("history_pop: " + op
);
711 function history_clear() {
712 debug("history_clear");