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_progress("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_info("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_progress("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 var timestamp
= Math
.round(date
.getTime() / 1000);
171 query_str
= query_str
+ "&ts=" + timestamp
173 if (!xmlhttp_ready(xmlhttp_ctr
) && last_refetch
< date
.getTime() / 1000 - 60) {
174 debug("<b>xmlhttp seems to be stuck, aborting</b>");
178 debug("REFETCH query: " + query_str
);
180 if (xmlhttp_ready(xmlhttp_ctr
)) {
181 xmlhttp_ctr
.open("GET", query_str
, true);
182 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
183 xmlhttp_ctr
.send(null);
185 debug("xmlhttp_ctr busy");
186 //printLockingError();
190 function updateFeedList(silent
, fetch
) {
192 // if (silent != true) {
193 // notify("Loading feed list...");
196 debug("<b>updateFeedList</b>");
198 var query_str
= "backend.php?op=feeds";
201 query_str
= query_str
+ "&tags=1";
204 if (getActiveFeedId() && !activeFeedIsCat()) {
205 query_str
= query_str
+ "&actid=" + getActiveFeedId();
208 var date
= new Date();
209 var timestamp
= Math
.round(date
.getTime() / 1000);
210 query_str
= query_str
+ "&ts=" + timestamp
212 if (fetch
) query_str
= query_str
+ "&fetch=yes";
214 // var feeds_frame = document.getElementById("feeds-frame");
215 // feeds_frame.src = query_str;
217 debug("updateFeedList Q=" + query_str
);
219 if (xmlhttp_ready(xmlhttp
)) {
220 xmlhttp
.open("GET", query_str
, true);
221 xmlhttp
.onreadystatechange
=feedlist_callback
;
224 debug("xmlhttp busy");
225 //printLockingError();
230 function catchupAllFeeds() {
232 var query_str
= "backend.php?op=feeds&subop=catchupAll";
234 notify_progress("Marking all feeds as read...");
236 debug("catchupAllFeeds Q=" + query_str
);
238 if (xmlhttp_ready(xmlhttp
)) {
239 xmlhttp
.open("GET", query_str
, true);
240 xmlhttp
.onreadystatechange
=feedlist_callback
;
243 debug("xmlhttp busy");
244 //printLockingError();
252 function viewCurrentFeed(subop
) {
254 // if (getActiveFeedId()) {
255 if (getActiveFeedId() != undefined) {
256 viewfeed(getActiveFeedId(), subop
);
258 disableContainerChildren("headlinesToolbar", false, document
);
259 // viewfeed(-1, subop); // FIXME
261 return false; // block unneeded form submits
264 function viewfeed(feed
, subop
) {
265 var f
= window
.frames
["feeds-frame"];
266 f
.viewfeed(feed
, subop
);
270 scheduleFeedUpdate(false);
272 var refresh_time
= getInitParam("feeds_frame_refresh");
274 if (!refresh_time
) refresh_time
= 600;
276 setTimeout("timeout()", refresh_time
*1000);
279 function resetSearch() {
280 var searchbox
= document
.getElementById("searchbox")
282 if (searchbox
.value
!= "" && getActiveFeedId()) {
283 searchbox
.value
= "";
284 viewfeed(getActiveFeedId(), "");
288 function searchCancel() {
294 viewCurrentFeed(0, "");
297 function localPiggieFunction(enable
) {
299 var query_str
= "backend.php?op=feeds&subop=piggie";
301 if (xmlhttp_ready(xmlhttp
)) {
303 xmlhttp
.open("GET", query_str
, true);
304 xmlhttp
.onreadystatechange
=feedlist_callback
;
310 // if argument is undefined, current subtitle is not updated
311 // use blank string to clear subtitle
312 function updateTitle(s
) {
313 var tmp
= "Tiny Tiny RSS";
315 if (s
!= undefined) {
316 current_subtitle
= s
;
319 if (global_unread
> 0) {
320 tmp
= tmp
+ " (" + global_unread
+ ")";
323 if (current_subtitle
) {
324 tmp
= tmp
+ " - " + current_subtitle
;
327 if (active_title_text
.length
> 0) {
328 tmp
= tmp
+ " > " + active_title_text
;
331 document
.title
= tmp
;
334 function genericSanityCheck() {
336 if (!xmlhttp
) fatalError(1);
338 setCookie("ttrss_vf_test", "TEST");
340 if (getCookie("ttrss_vf_test") != "TEST") {
351 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
353 if (arguments
.callee
.done
) return;
354 arguments
.callee
.done
= true;
356 disableContainerChildren("headlinesToolbar", true);
358 Form
.disable("main_toolbar_form");
360 if (!genericSanityCheck())
363 if (getURLParam('debug')) {
364 document
.getElementById('debug_output').style
.display
= 'block';
365 debug('debug mode activated');
368 var params
= "&ua=" + param_escape(navigator
.userAgent
);
370 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, true);
371 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
375 exception_error("init", e
);
379 function init_second_stage() {
383 cookie_lifetime
= getCookie("ttrss_cltime");
385 delCookie("ttrss_vf_test");
387 document
.onkeydown
= hotkey_handler
;
389 var tb
= parent
.document
.forms
["main_toolbar_form"];
391 // dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
392 // dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
394 daemon_enabled
= getInitParam("daemon_enabled") == 1;
395 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
397 setTimeout('updateFeedList(false, false)', 50);
399 debug("second stage ok");
402 exception_error("init_second_stage", e
);
406 function quickMenuChange() {
407 var chooser
= document
.getElementById("quickMenuChooser");
408 var opid
= chooser
[chooser
.selectedIndex
].value
;
410 chooser
.selectedIndex
= 0;
414 function quickMenuGo(opid
) {
417 if (opid
== "qmcPrefs") {
421 if (opid
== "qmcSearch") {
422 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
426 if (opid
== "qmcAddFeed") {
427 displayDlg("quickAddFeed");
431 if (opid
== "qmcEditFeed") {
432 editFeedDlg(getActiveFeedId());
435 if (opid
== "qmcRemoveFeed") {
436 var actid
= getActiveFeedId();
438 if (!actid
|| activeFeedIsCat()) {
439 alert("Please select some feed first.");
443 var fn
= getFeedName(actid
);
445 if (confirm("Unsubscribe from " + fn
+ "?")) {
452 if (opid
== "qmcUpdateFeeds") {
453 scheduleFeedUpdate(true);
457 if (opid
== "qmcCatchupAll") {
462 if (opid
== "qmcShowOnlyUnread") {
467 if (opid
== "qmcAddFilter") {
468 displayDlg("quickAddFilter", getActiveFeedId());
471 exception_error("quickMenuGo", e
);
475 function qfdDelete(feed_id
) {
477 notify_progress("Removing feed...");
479 if (!xmlhttp_ready(xmlhttp
)) {
484 _qfd_deleted_feed
= feed_id
;
486 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
487 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
494 function updateFeedTitle(t
) {
495 active_title_text
= t
;
499 function toggleDispRead() {
502 if (!xmlhttp_ready(xmlhttp
)) {
507 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
509 hide_read_feeds
= !hide_read_feeds
;
511 debug("toggle_disp_read => " + hide_read_feeds
);
513 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
515 var query
= "backend.php?op=rpc&subop=setpref" +
516 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
518 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
520 new Ajax
.Request(query
);
523 exception_error("toggleDispRead", e
);
527 function parse_runtime_info(elem
) {
529 debug("parse_runtime_info: elem is null, aborting");
533 var param
= elem
.firstChild
;
535 debug("parse_runtime_info: " + param
);
538 var k
= param
.getAttribute("key");
539 var v
= param
.getAttribute("value");
541 debug("RI: " + k
+ " => " + v
);
543 if (k
== "new_version_available") {
544 var icon
= document
.getElementById("newVersionIcon");
547 icon
.style
.display
= "inline";
549 icon
.style
.display
= "none";
554 if (k
== "daemon_is_running" && v
!= 1) {
555 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not runing.</span>");
558 /* var w = document.getElementById("noDaemonWarning");
561 if (k == "daemon_is_running" && v != 1) {
562 w.style.display = "block";
564 w.style.display = "none";
567 param
= param
.nextSibling
;
571 function catchupCurrentFeed() {
573 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
575 var str
= "Mark all articles in " + fn
+ " as read?";
577 /* if (active_feed_is_cat) {
578 str = "Mark all articles in this category as read?";
581 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
582 return viewCurrentFeed('MarkAllRead')
586 function userSwitch() {
587 var chooser
= document
.getElementById("userSwitch");
588 var user
= chooser
[chooser
.selectedIndex
].value
;
589 window
.location
= "tt-rss.php?swu=" + user
;
592 function editFeedDlg(feed
) {
597 alert("Please select some feed first.");
601 if (feed
<= 0 || active_feed_is_cat
|| tagsAreDisplayed()) {
602 alert("You can't edit this kind of feed.");
606 if (xmlhttp_ready(xmlhttp
)) {
607 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
608 param_escape(feed
), true);
609 xmlhttp
.onreadystatechange
=infobox_callback
;
616 /* this functions duplicate those of prefs.js feed editor, with
617 some differences because there is no feedlist */
619 function feedEditCancel() {
624 function feedEditSave() {
628 if (!xmlhttp_ready(xmlhttp
)) {
633 // FIXME: add parameter validation
635 var query
= Form
.serialize("edit_feed_form");
637 notify_progress("Saving feed...");
639 xmlhttp
.open("POST", "backend.php", true);
640 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
641 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
649 exception_error("feedEditSave (main)", e
);
653 function localHotkeyHandler(e
) {
658 keycode
= window
.event
.keyCode
;
663 var shift_key
= false;
666 shift_key
= e
.shiftKey
;
669 if (keycode
== 66 && shift_key
) { // shift-B
671 var op
= history_pop();
674 var op_s
= op
.split(":");
677 for (i
= 0; i
< op_s
.length
; i
++) {
678 if (op_s
[i
] == 'undefined') {
682 if (op_s
[i
] == 'false') {
686 if (op_s
[i
] == 'true') {
692 debug("history split: " + op_s
);
694 if (op_s
[0] == "ARTICLE") {
695 debug("history: reverting to article " + op_s
[1] + "/" + op_s
[2]);
696 view(op_s
[1], op_s
[2], true);
699 if (op_s
[0] == "FEED") {
700 viewfeed(op_s
[1], op_s
[2], op_s
[3], op_s
[4], true);
704 notify_error("No operation to undo");
711 debug("LKP=" + keycode
);
714 function history_push(op
) {
715 debug("history_push: " + op
);
718 while (op_history
.length
> 30) {
723 function history_pop() {
724 var op
= op_history
.pop();
725 debug("history_pop: " + op
);
729 function history_clear() {
730 debug("history_clear");