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 var query_str
= "backend.php?op=feeds";
196 query_str
= query_str
+ "&tags=1";
199 if (getActiveFeedId() && !activeFeedIsCat()) {
200 query_str
= query_str
+ "&actid=" + getActiveFeedId();
203 if (navigator
.userAgent
.match("Opera")) {
204 var date
= new Date();
205 var timestamp
= Math
.round(date
.getTime() / 1000);
206 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 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
366 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
370 exception_error("init", e
);
374 function init_second_stage() {
378 cookie_lifetime
= getCookie("ttrss_cltime");
380 delCookie("ttrss_vf_test");
382 document
.onkeydown
= hotkey_handler
;
384 var tb
= parent
.document
.forms
["main_toolbar_form"];
386 // dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
387 // dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
389 daemon_enabled
= getInitParam("daemon_enabled") == 1;
390 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
392 setTimeout('updateFeedList(false, false)', 50);
394 debug("second stage ok");
397 exception_error("init_second_stage", e
);
401 function quickMenuChange() {
402 var chooser
= document
.getElementById("quickMenuChooser");
403 var opid
= chooser
[chooser
.selectedIndex
].value
;
405 chooser
.selectedIndex
= 0;
409 function quickMenuGo(opid
) {
412 if (opid
== "qmcPrefs") {
416 if (opid
== "qmcSearch") {
417 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
421 if (opid
== "qmcAddFeed") {
422 displayDlg("quickAddFeed");
426 if (opid
== "qmcEditFeed") {
427 editFeedDlg(getActiveFeedId());
430 if (opid
== "qmcRemoveFeed") {
431 var actid
= getActiveFeedId();
433 if (!actid
|| activeFeedIsCat()) {
434 alert("Please select some feed first.");
438 var fn
= getFeedName(actid
);
440 if (confirm("Unsubscribe from " + fn
+ "?")) {
447 if (opid
== "qmcUpdateFeeds") {
448 scheduleFeedUpdate(true);
452 if (opid
== "qmcCatchupAll") {
457 if (opid
== "qmcShowOnlyUnread") {
462 if (opid
== "qmcAddFilter") {
463 displayDlg("quickAddFilter", getActiveFeedId());
466 exception_error("quickMenuGo", e
);
470 function qfdDelete(feed_id
) {
472 notify("Removing feed...");
474 if (!xmlhttp_ready(xmlhttp
)) {
479 _qfd_deleted_feed
= feed_id
;
481 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
482 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
489 function updateFeedTitle(t
) {
490 active_title_text
= t
;
494 function toggleDispRead() {
497 if (!xmlhttp_ready(xmlhttp
)) {
502 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
504 hide_read_feeds
= !hide_read_feeds
;
506 debug("toggle_disp_read => " + hide_read_feeds
);
508 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
510 var query
= "backend.php?op=rpc&subop=setpref" +
511 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
513 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
515 new Ajax
.Request(query
);
518 exception_error("toggleDispRead", e
);
522 function parse_runtime_info(elem
) {
524 debug("parse_runtime_info: elem is null, aborting");
528 var param
= elem
.firstChild
;
530 debug("parse_runtime_info: " + param
);
533 var k
= param
.getAttribute("key");
534 var v
= param
.getAttribute("value");
536 debug("RI: " + k
+ " => " + v
);
538 var w
= document
.getElementById("noDaemonWarning");
541 if (k
== "daemon_is_running" && v
!= 1) {
542 w
.style
.display
= "block";
544 w
.style
.display
= "none";
547 param
= param
.nextSibling
;
551 function catchupCurrentFeed() {
553 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
555 var str
= "Mark all articles in " + fn
+ " as read?";
557 /* if (active_feed_is_cat) {
558 str = "Mark all articles in this category as read?";
561 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
562 return viewCurrentFeed('MarkAllRead')
566 function userSwitch() {
567 var chooser
= document
.getElementById("userSwitch");
568 var user
= chooser
[chooser
.selectedIndex
].value
;
569 window
.location
= "tt-rss.php?swu=" + user
;
572 function editFeedDlg(feed
) {
577 alert("Please select some feed first.");
581 if (xmlhttp_ready(xmlhttp
)) {
582 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
583 param_escape(feed
), true);
584 xmlhttp
.onreadystatechange
=infobox_callback
;
591 /* this functions duplicate those of prefs.js feed editor, with
592 some differences because there is no feedlist */
594 function feedEditCancel() {
599 function feedEditSave() {
603 if (!xmlhttp_ready(xmlhttp
)) {
608 // FIXME: add parameter validation
610 var query
= Form
.serialize("edit_feed_form");
612 notify("Saving feed...");
614 xmlhttp
.open("POST", "backend.php", true);
615 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
616 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
624 exception_error("feedEditSave (main)", e
);
628 function localHotkeyHandler(e
) {
633 keycode
= window
.event
.keyCode
;
638 var shift_key
= false;
641 shift_key
= e
.shiftKey
;
644 if (keycode
== 66 && shift_key
) { // shift-B
646 var op
= history_pop();
649 var op_s
= op
.split(":");
652 for (i
= 0; i
< op_s
.length
; i
++) {
653 if (op_s
[i
] == 'undefined') {
657 if (op_s
[i
] == 'false') {
661 if (op_s
[i
] == 'true') {
667 debug("history split: " + op_s
);
669 if (op_s
[0] == "ARTICLE") {
670 debug("history: reverting to article " + op_s
[1] + "/" + op_s
[2]);
671 view(op_s
[1], op_s
[2], true);
674 if (op_s
[0] == "FEED") {
675 viewfeed(op_s
[1], op_s
[2], op_s
[3], op_s
[4], true);
679 notify("No operation to undo");
686 debug("LKP=" + keycode
);
689 function history_push(op
) {
690 debug("history_push: " + op
);
693 while (op_history
.length
> 30) {
698 function history_pop() {
699 var op
= op_history
.pop();
700 debug("history_pop: " + op
);
704 function history_clear() {
705 debug("history_clear");