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 var params
= "&ua=" + param_escape(navigator
.userAgent
);
369 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, true);
370 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
374 exception_error("init", e
);
378 function init_second_stage() {
382 cookie_lifetime
= getCookie("ttrss_cltime");
384 delCookie("ttrss_vf_test");
386 document
.onkeydown
= hotkey_handler
;
388 var tb
= parent
.document
.forms
["main_toolbar_form"];
390 // dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
391 // dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
393 daemon_enabled
= getInitParam("daemon_enabled") == 1;
394 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
396 setTimeout('updateFeedList(false, false)', 50);
398 debug("second stage ok");
401 exception_error("init_second_stage", e
);
405 function quickMenuChange() {
406 var chooser
= document
.getElementById("quickMenuChooser");
407 var opid
= chooser
[chooser
.selectedIndex
].value
;
409 chooser
.selectedIndex
= 0;
413 function quickMenuGo(opid
) {
416 if (opid
== "qmcPrefs") {
420 if (opid
== "qmcSearch") {
421 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
425 if (opid
== "qmcAddFeed") {
426 displayDlg("quickAddFeed");
430 if (opid
== "qmcEditFeed") {
431 editFeedDlg(getActiveFeedId());
434 if (opid
== "qmcRemoveFeed") {
435 var actid
= getActiveFeedId();
437 if (!actid
|| activeFeedIsCat()) {
438 alert("Please select some feed first.");
442 var fn
= getFeedName(actid
);
444 if (confirm("Unsubscribe from " + fn
+ "?")) {
451 if (opid
== "qmcUpdateFeeds") {
452 scheduleFeedUpdate(true);
456 if (opid
== "qmcCatchupAll") {
461 if (opid
== "qmcShowOnlyUnread") {
466 if (opid
== "qmcAddFilter") {
467 displayDlg("quickAddFilter", getActiveFeedId());
470 exception_error("quickMenuGo", e
);
474 function qfdDelete(feed_id
) {
476 notify("Removing feed...");
478 if (!xmlhttp_ready(xmlhttp
)) {
483 _qfd_deleted_feed
= feed_id
;
485 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
486 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
493 function updateFeedTitle(t
) {
494 active_title_text
= t
;
498 function toggleDispRead() {
501 if (!xmlhttp_ready(xmlhttp
)) {
506 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
508 hide_read_feeds
= !hide_read_feeds
;
510 debug("toggle_disp_read => " + hide_read_feeds
);
512 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
514 var query
= "backend.php?op=rpc&subop=setpref" +
515 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
517 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
519 new Ajax
.Request(query
);
522 exception_error("toggleDispRead", e
);
526 function parse_runtime_info(elem
) {
528 debug("parse_runtime_info: elem is null, aborting");
532 var param
= elem
.firstChild
;
534 debug("parse_runtime_info: " + param
);
537 var k
= param
.getAttribute("key");
538 var v
= param
.getAttribute("value");
540 debug("RI: " + k
+ " => " + v
);
542 if (k
== "new_version_available") {
543 var icon
= document
.getElementById("newVersionIcon");
546 icon
.style
.display
= "inline";
548 icon
.style
.display
= "none";
553 if (k
== "daemon_is_running" && v
!= 1) {
554 notify("<span onclick=\"javascript:explainError(1)\">Warning: Update daemon is not runing.</span>", true, true);
557 /* var w = document.getElementById("noDaemonWarning");
560 if (k == "daemon_is_running" && v != 1) {
561 w.style.display = "block";
563 w.style.display = "none";
566 param
= param
.nextSibling
;
570 function catchupCurrentFeed() {
572 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
574 var str
= "Mark all articles in " + fn
+ " as read?";
576 /* if (active_feed_is_cat) {
577 str = "Mark all articles in this category as read?";
580 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
581 return viewCurrentFeed('MarkAllRead')
585 function userSwitch() {
586 var chooser
= document
.getElementById("userSwitch");
587 var user
= chooser
[chooser
.selectedIndex
].value
;
588 window
.location
= "tt-rss.php?swu=" + user
;
591 function editFeedDlg(feed
) {
596 alert("Please select some feed first.");
600 if (feed
<= 0 || active_feed_is_cat
|| tagsAreDisplayed()) {
601 alert("You can't edit this kind of feed.");
605 if (xmlhttp_ready(xmlhttp
)) {
606 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
607 param_escape(feed
), true);
608 xmlhttp
.onreadystatechange
=infobox_callback
;
615 /* this functions duplicate those of prefs.js feed editor, with
616 some differences because there is no feedlist */
618 function feedEditCancel() {
623 function feedEditSave() {
627 if (!xmlhttp_ready(xmlhttp
)) {
632 // FIXME: add parameter validation
634 var query
= Form
.serialize("edit_feed_form");
636 notify("Saving feed...");
638 xmlhttp
.open("POST", "backend.php", true);
639 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
640 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
648 exception_error("feedEditSave (main)", e
);
652 function localHotkeyHandler(e
) {
657 keycode
= window
.event
.keyCode
;
662 var shift_key
= false;
665 shift_key
= e
.shiftKey
;
668 if (keycode
== 66 && shift_key
) { // shift-B
670 var op
= history_pop();
673 var op_s
= op
.split(":");
676 for (i
= 0; i
< op_s
.length
; i
++) {
677 if (op_s
[i
] == 'undefined') {
681 if (op_s
[i
] == 'false') {
685 if (op_s
[i
] == 'true') {
691 debug("history split: " + op_s
);
693 if (op_s
[0] == "ARTICLE") {
694 debug("history: reverting to article " + op_s
[1] + "/" + op_s
[2]);
695 view(op_s
[1], op_s
[2], true);
698 if (op_s
[0] == "FEED") {
699 viewfeed(op_s
[1], op_s
[2], op_s
[3], op_s
[4], true);
703 notify("No operation to undo");
710 debug("LKP=" + keycode
);
713 function history_push(op
) {
714 debug("history_push: " + op
);
717 while (op_history
.length
> 30) {
722 function history_pop() {
723 var op
= op_history
.pop();
724 debug("history_pop: " + op
);
728 function history_clear() {
729 debug("history_clear");