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 var date
= new Date();
206 var timestamp
= Math
.round(date
.getTime() / 1000);
207 query_str
= query_str
+ "&ts=" + timestamp
209 if (fetch
) query_str
= query_str
+ "&fetch=yes";
211 // var feeds_frame = document.getElementById("feeds-frame");
212 // feeds_frame.src = query_str;
214 debug("updateFeedList Q=" + query_str
);
216 if (xmlhttp_ready(xmlhttp
)) {
217 xmlhttp
.open("GET", query_str
, true);
218 xmlhttp
.onreadystatechange
=feedlist_callback
;
221 debug("xmlhttp busy");
222 //printLockingError();
227 function catchupAllFeeds() {
229 var query_str
= "backend.php?op=feeds&subop=catchupAll";
231 notify("Marking all feeds as read...");
233 debug("catchupAllFeeds Q=" + query_str
);
235 if (xmlhttp_ready(xmlhttp
)) {
236 xmlhttp
.open("GET", query_str
, true);
237 xmlhttp
.onreadystatechange
=feedlist_callback
;
240 debug("xmlhttp busy");
241 //printLockingError();
249 function viewCurrentFeed(subop
) {
251 // if (getActiveFeedId()) {
252 if (getActiveFeedId() != undefined) {
253 viewfeed(getActiveFeedId(), subop
);
255 disableContainerChildren("headlinesToolbar", false, document
);
256 // viewfeed(-1, subop); // FIXME
258 return false; // block unneeded form submits
261 function viewfeed(feed
, subop
) {
262 var f
= window
.frames
["feeds-frame"];
263 f
.viewfeed(feed
, subop
);
267 scheduleFeedUpdate(false);
269 var refresh_time
= getInitParam("feeds_frame_refresh");
271 if (!refresh_time
) refresh_time
= 600;
273 setTimeout("timeout()", refresh_time
*1000);
276 function resetSearch() {
277 var searchbox
= document
.getElementById("searchbox")
279 if (searchbox
.value
!= "" && getActiveFeedId()) {
280 searchbox
.value
= "";
281 viewfeed(getActiveFeedId(), "");
285 function searchCancel() {
291 viewCurrentFeed(0, "");
294 function localPiggieFunction(enable
) {
296 var query_str
= "backend.php?op=feeds&subop=piggie";
298 if (xmlhttp_ready(xmlhttp
)) {
300 xmlhttp
.open("GET", query_str
, true);
301 xmlhttp
.onreadystatechange
=feedlist_callback
;
307 // if argument is undefined, current subtitle is not updated
308 // use blank string to clear subtitle
309 function updateTitle(s
) {
310 var tmp
= "Tiny Tiny RSS";
312 if (s
!= undefined) {
313 current_subtitle
= s
;
316 if (global_unread
> 0) {
317 tmp
= tmp
+ " (" + global_unread
+ ")";
320 if (current_subtitle
) {
321 tmp
= tmp
+ " - " + current_subtitle
;
324 if (active_title_text
.length
> 0) {
325 tmp
= tmp
+ " > " + active_title_text
;
328 document
.title
= tmp
;
331 function genericSanityCheck() {
333 if (!xmlhttp
) fatalError(1);
335 setCookie("ttrss_vf_test", "TEST");
337 if (getCookie("ttrss_vf_test") != "TEST") {
348 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
350 if (arguments
.callee
.done
) return;
351 arguments
.callee
.done
= true;
353 disableContainerChildren("headlinesToolbar", true);
355 Form
.disable("main_toolbar_form");
357 if (!genericSanityCheck())
360 if (getURLParam('debug')) {
361 document
.getElementById('debug_output').style
.display
= 'block';
362 debug('debug mode activated');
365 var params
= "&ua=" + param_escape(navigator
.userAgent
);
367 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, 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 if (k
== "new_version_available") {
541 var icon
= document
.getElementById("newVersionIcon");
544 icon
.style
.display
= "inline";
546 icon
.style
.display
= "none";
551 if (k
== "daemon_is_running" && v
!= 1) {
552 notify("<span onclick=\"javascript:explainError(1)\">Warning: Update daemon is not runing.</span>", true, true);
555 /* var w = document.getElementById("noDaemonWarning");
558 if (k == "daemon_is_running" && v != 1) {
559 w.style.display = "block";
561 w.style.display = "none";
564 param
= param
.nextSibling
;
568 function catchupCurrentFeed() {
570 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
572 var str
= "Mark all articles in " + fn
+ " as read?";
574 /* if (active_feed_is_cat) {
575 str = "Mark all articles in this category as read?";
578 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
579 return viewCurrentFeed('MarkAllRead')
583 function userSwitch() {
584 var chooser
= document
.getElementById("userSwitch");
585 var user
= chooser
[chooser
.selectedIndex
].value
;
586 window
.location
= "tt-rss.php?swu=" + user
;
589 function editFeedDlg(feed
) {
594 alert("Please select some feed first.");
598 if (feed
<= 0 || active_feed_is_cat
|| tagsAreDisplayed()) {
599 alert("You can't edit this kind of feed.");
603 if (xmlhttp_ready(xmlhttp
)) {
604 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
605 param_escape(feed
), true);
606 xmlhttp
.onreadystatechange
=infobox_callback
;
613 /* this functions duplicate those of prefs.js feed editor, with
614 some differences because there is no feedlist */
616 function feedEditCancel() {
621 function feedEditSave() {
625 if (!xmlhttp_ready(xmlhttp
)) {
630 // FIXME: add parameter validation
632 var query
= Form
.serialize("edit_feed_form");
634 notify("Saving feed...");
636 xmlhttp
.open("POST", "backend.php", true);
637 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
638 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
646 exception_error("feedEditSave (main)", e
);
650 function localHotkeyHandler(e
) {
655 keycode
= window
.event
.keyCode
;
660 var shift_key
= false;
663 shift_key
= e
.shiftKey
;
666 if (keycode
== 66 && shift_key
) { // shift-B
668 var op
= history_pop();
671 var op_s
= op
.split(":");
674 for (i
= 0; i
< op_s
.length
; i
++) {
675 if (op_s
[i
] == 'undefined') {
679 if (op_s
[i
] == 'false') {
683 if (op_s
[i
] == 'true') {
689 debug("history split: " + op_s
);
691 if (op_s
[0] == "ARTICLE") {
692 debug("history: reverting to article " + op_s
[1] + "/" + op_s
[2]);
693 view(op_s
[1], op_s
[2], true);
696 if (op_s
[0] == "FEED") {
697 viewfeed(op_s
[1], op_s
[2], op_s
[3], op_s
[4], true);
701 notify("No operation to undo");
708 debug("LKP=" + keycode
);
711 function history_push(op
) {
712 debug("history_push: " + op
);
715 while (op_history
.length
> 30) {
720 function history_pop() {
721 var op
= op_history
.pop();
722 debug("history_pop: " + op
);
726 function history_clear() {
727 debug("history_clear");