-/*
- This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
- Licensed under GPL v.2 or (at your preference) any later version.
-*/
-
var xmlhttp = false;
-
var total_unread = 0;
var first_run = true;
-
-var search_query = "";
-var search_mode = "";
-
var display_tags = false;
-//var display_read_feeds = true;
-
-var global_unread = 0;
+var global_unread = -1;
+var active_title_text = "";
+var current_subtitle = "";
+var daemon_enabled = false;
+var _qfd_deleted_feed = 0;
+var firsttime_update = true;
+var last_refetch = 0;
+var cookie_lifetime = 0;
+var active_feed_id = 0;
-/*@cc_on @*/
-/*@if (@_jscript_version >= 5)
-// JScript gives us Conditional compilation, we can cope with old IE versions.
-// and security blocked creation of the objects.
-try {
- xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
-} catch (e) {
- try {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (E) {
- xmlhttp = false;
- }
-}
-@end @*/
+var xmlhttp = Ajax.getTransport();
-if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
- xmlhttp = new XMLHttpRequest();
-}
+var init_params = new Array();
function toggleTags() {
display_tags = !display_tags;
function dlg_frefresh_callback() {
if (xmlhttp.readyState == 4) {
+ notify(xmlhttp.responseText);
updateFeedList(false, false);
- closeDlg();
- }
-}
-
-function dialog_refresh_callback() {
- if (xmlhttp.readyState == 4) {
- var dlg = document.getElementById("userDlg");
-
- dlg.innerHTML = xmlhttp.responseText;
- dlg.style.display = "block";
+ if (_qfd_deleted_feed) {
+ var hframe = document.getElementById("headlines-frame");
+ if (hframe) {
+ hframe.src = "backend.php?op=error&msg=No%20feed%20selected.";
+ }
+ }
+ closeInfoBox();
}
}
function refetch_callback() {
if (xmlhttp.readyState == 4) {
+ try {
-// document.title = "Tiny Tiny RSS";
+ var date = new Date();
- if (!xmlhttp.responseXML) {
- notify("refetch_callback: backend did not return valid XML");
- return;
- }
+ last_refetch = date.getTime() / 1000;
- var reply = xmlhttp.responseXML.firstChild;
+ if (!xmlhttp.responseXML) {
+ notify("refetch_callback: backend did not return valid XML", true, true);
+ return;
+ }
+
+ var reply = xmlhttp.responseXML.firstChild;
+
+ if (!reply) {
+ notify("refetch_callback: backend did not return expected XML object", true, true);
+ updateTitle("");
+ return;
+ }
+
+ var error_code = reply.getAttribute("error-code");
+
+ if (error_code && error_code != 0) {
+ return fatalError(error_code, reply.getAttribute("error-msg"));
+ }
- if (!reply) {
- notify("refetch_callback: backend did not return expected XML object");
- return;
- }
+ var counters = reply.firstChild;
+
+ parse_counters(counters, true);
- var f_document = window.frames["feeds-frame"].document;
+ var runtime_info = counters.nextSibling;
- for (var l = 0; l < reply.childNodes.length; l++) {
- var id = reply.childNodes[l].getAttribute("id");
- var ctr = reply.childNodes[l].getAttribute("counter");
+ parse_runtime_info(runtime_info);
- var feedctr = f_document.getElementById("FEEDCTR-" + id);
- var feedu = f_document.getElementById("FEEDU-" + id);
- var feedr = f_document.getElementById("FEEDR-" + id);
+ debug("refetch_callback: done");
-/* TODO figure out how to update this from viewfeed.js->view()
- disabled for now...
+ if (!daemon_enabled) {
+ notify("All feeds updated.");
+ updateTitle("");
+ } else {
+ notify("");
+ }
+ } catch (e) {
+ exception_error("refetch_callback", e);
+ updateTitle("");
+ }
+ }
+}
- if (id == "global-unread") {
- global_unread = ctr;
- } */
+function backend_sanity_check_callback() {
- if (feedctr && feedu && feedr) {
+ if (xmlhttp.readyState == 4) {
- feedu.innerHTML = ctr;
+ try {
+
+ if (!xmlhttp.responseXML) {
+ fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
+ return;
+ }
- if (ctr > 0) {
- feedctr.className = "odd";
- if (!feedr.className.match("Unread")) {
- feedr.className = feedr.className + "Unread";
- }
- } else {
- feedctr.className = "invisible";
- feedr.className = feedr.className.replace("Unread", "");
- }
+ var reply = xmlhttp.responseXML.firstChild.firstChild;
+
+ if (!reply) {
+ fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
+ return;
}
- }
+
+ var error_code = reply.getAttribute("error-code");
+
+ if (error_code && error_code != 0) {
+ return fatalError(error_code, reply.getAttribute("error-msg"));
+ }
+
+ debug("sanity check ok");
- updateTitle("");
- notify("All feeds updated.");
+ var params = reply.nextSibling;
- }
-}
+ if (params) {
+ debug('reading init-params...');
+ var param = params.firstChild;
-function updateFeed(feed_id) {
+ while (param) {
+ var k = param.getAttribute("key");
+ var v = param.getAttribute("value");
+ debug(k + " => " + v);
+ init_params[k] = v;
+ param = param.nextSibling;
+ }
+ }
- var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
-
- if (xmlhttp_ready(xmlhttp)) {
- xmlhttp.open("GET", query_str, true);
- xmlhttp.onreadystatechange=feed_update_callback;
- xmlhttp.send(null);
- } else {
- printLockingError();
- }
+ init_second_stage();
+ } catch (e) {
+ exception_error("backend_sanity_check_callback", e);
+ }
+ }
}
function scheduleFeedUpdate(force) {
- notify("Updating feeds in background...");
-
-// document.title = "Tiny Tiny RSS - Updating...";
-
- updateTitle("Updating...");
+ if (!daemon_enabled) {
+ notify("Updating feeds, please wait.", true);
+ updateTitle("Updating");
+ }
var query_str = "backend.php?op=rpc&subop=";
var omode;
- if (display_tags) {
- omode = "t";
+ if (firsttime_update && !navigator.userAgent.match("Opera")) {
+ firsttime_update = false;
+ omode = "T";
} else {
- omode = "fl";
+ if (display_tags) {
+ omode = "t";
+ } else {
+ omode = "flc";
+ }
}
-
+
query_str = query_str + "&omode=" + omode;
+ query_str = query_str + "&uctr=" + global_unread;
+
+ debug("in scheduleFeedUpdate");
+
+ var date = new Date();
+
+ if (!xmlhttp_ready(xmlhttp) && last_refetch < date.getTime() / 1000 - 60) {
+ debug("<b>xmlhttp seems to be stuck, aborting</b>");
+ xmlhttp.abort();
+ }
if (xmlhttp_ready(xmlhttp)) {
xmlhttp.open("GET", query_str, true);
xmlhttp.onreadystatechange=refetch_callback;
xmlhttp.send(null);
} else {
+ debug("xmlhttp busy");
printLockingError();
}
}
query_str = query_str + "&actid=" + getActiveFeedId();
}
+ if (navigator.userAgent.match("Opera")) {
+ var date = new Date();
+ var timestamp = Math.round(date.getTime() / 1000);
+ query_str = query_str + "&ts=" + timestamp
+ }
+
if (fetch) query_str = query_str + "&fetch=yes";
var feeds_frame = document.getElementById("feeds-frame");
feeds_frame.src = query_str;
global_unread = 0;
- updateTitle();
+ updateTitle("");
}
disableContainerChildren("headlinesToolbar", false, document);
viewfeed(-1, skip, subop); // FIXME
}
+ return false; // block unneeded form submits
}
function viewfeed(feed, skip, subop) {
}
function timeout() {
- scheduleFeedUpdate(true);
- setTimeout("timeout()", 1800*1000);
+ scheduleFeedUpdate(false);
+
+ var refresh_time = getInitParam("feeds_frame_refresh");
+
+ if (!refresh_time) refresh_time = 600;
+
+ setTimeout("timeout()", refresh_time*1000);
}
function resetSearch() {
}
}
+function searchCancel() {
+ closeInfoBox(true);
+}
+
function search() {
+ closeInfoBox();
viewCurrentFeed(0, "");
}
}
}
-function localHotkeyHandler(keycode) {
+// if argument is undefined, current subtitle is not updated
+// use blank string to clear subtitle
+function updateTitle(s) {
+ var tmp = "Tiny Tiny RSS";
-/* if (keycode == 78) {
- return moveToPost('next');
+ if (s != undefined) {
+ current_subtitle = s;
}
- if (keycode == 80) {
- return moveToPost('prev');
- } */
-
- if (keycode == 82) {
- return scheduleFeedUpdate(true);
+ if (global_unread > 0) {
+ tmp = tmp + " (" + global_unread + ")";
}
- if (keycode == 85) {
- return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
+ if (current_subtitle) {
+ tmp = tmp + " - " + current_subtitle;
}
-// notify("KC: " + keycode);
-
-}
-
-function updateTitle(s) {
- var tmp = "Tiny Tiny RSS";
-
- if (global_unread > 0) {
- tmp = tmp + " (" + global_unread + ")";
+ if (active_title_text.length > 0) {
+ tmp = tmp + " > " + active_title_text;
}
- if (s) {
- tmp = tmp + " - " + s;
- }
document.title = tmp;
}
function genericSanityCheck() {
- if (!xmlhttp) {
- document.getElementById("headlines").innerHTML =
- "<b>Fatal error:</b> This program requires XmlHttpRequest " +
- "to function properly. Your browser doesn't seem to support it.";
- return false;
- }
+ if (!xmlhttp) fatalError(1);
setCookie("ttrss_vf_test", "TEST");
+
if (getCookie("ttrss_vf_test") != "TEST") {
-
- document.getElementById("headlines").innerHTML =
- "<b>Fatal error:</b> This program requires cookies " +
- "to function properly. Your browser doesn't seem to support them.";
-
- return false;
+ fatalError(2);
}
return true;
function init() {
- disableContainerChildren("headlinesToolbar", true);
-
- if (!genericSanityCheck())
- return;
+ try {
- setCookie("ttrss_vf_actfeed", "");
+ // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
- updateFeedList(false, false);
- document.onkeydown = hotkey_handler;
+ if (arguments.callee.done) return;
+ arguments.callee.done = true;
- setTimeout("timeout()", 1800*1000);
- scheduleFeedUpdate(true);
+ disableContainerChildren("headlinesToolbar", true);
- var content = document.getElementById("content");
+ Form.disable("main_toolbar_form");
- if (getCookie("ttrss_vf_vmode")) {
- var viewbox = document.getElementById("viewbox");
- viewbox.value = getCookie("ttrss_vf_vmode");
- }
+ if (!genericSanityCheck())
+ return;
- if (getCookie("ttrss_vf_limit")) {
- var limitbox = document.getElementById("limitbox");
- limitbox.value = getCookie("ttrss_vf_limit");
- }
+ if (getURLParam('debug')) {
+ document.getElementById('debug_output').style.display = 'block';
+ debug('debug mode activated');
+ }
-// if (getCookie("ttrss_vf_actfeed")) {
-// viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
-// }
+ xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
+ xmlhttp.onreadystatechange=backend_sanity_check_callback;
+ xmlhttp.send(null);
+ } catch (e) {
+ exception_error("init", e);
+ }
}
-function quickMenuGo() {
-
- var chooser = document.getElementById("quickMenuChooser");
- var opid = chooser[chooser.selectedIndex].id;
-
- if (opid == "qmcPrefs") {
- gotoPreferences();
- }
+function resize_feeds_frame() {
+ var f = document.getElementById("feeds-frame");
+ var tf = document.getElementById("mainFooter");
+ var th = document.getElementById("mainHeader");
+
+ f.style.height = document.body.scrollHeight - tf.scrollHeight -
+ th.scrollHeight - 50 + "px";
+}
- if (opid == "qmcAdvSearch") {
- displayDlg("search");
- return;
- }
+function init_second_stage() {
- if (opid == "qmcAddFeed") {
- displayDlg("quickAddFeed");
- return;
- }
+ try {
- if (opid == "qmcRemoveFeed") {
- var actid = getActiveFeedId();
+ cookie_lifetime = getCookie("ttrss_cltime");
- if (!actid) {
- notify("Please select some feed first.");
- return;
- }
+ delCookie("ttrss_vf_test");
- displayDlg("quickDelFeed", actid);
- return;
- }
-
- if (opid == "qmcUpdateFeeds") {
- scheduleFeedUpdate(true);
- return;
- }
-
- if (opid == "qmcCatchupAll") {
- catchupAllFeeds();
- return;
- }
-
- if (opid == "qmcShowOnlyUnread") {
- toggleDispRead();
- return;
- }
-
-}
-
-function qafAdd() {
+ updateFeedList(false, false);
+ document.onkeydown = hotkey_handler;
- if (!xmlhttp_ready(xmlhttp)) {
- printLockingError();
- return
- }
+ var tb = parent.document.forms["main_toolbar_form"];
- var link = document.getElementById("qafInput");
+ dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
+ dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
- if (link.value.length == 0) {
- notify("Missing feed URL.");
- } else {
- notify("Adding feed...");
-
- var feeds_doc = window.frames["feeds-frame"].document;
+ daemon_enabled = getInitParam("daemon_enabled");
- feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
+ // FIXME should be callled after window resize
- xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
- param_escape(link.value), true);
- xmlhttp.onreadystatechange=dlg_frefresh_callback;
- xmlhttp.send(null);
+ var h = document.getElementById("headlines");
+ var c = document.getElementById("content");
- link.value = "";
+ if (navigator.userAgent.match("Opera")) {
+ resize_feeds_frame();
+ }
+ debug("second stage ok");
+
+ } catch (e) {
+ exception_error("init_second_stage", e);
}
}
-function displayDlg(id, param) {
+function quickMenuChange() {
+ var chooser = document.getElementById("quickMenuChooser");
+ var opid = chooser[chooser.selectedIndex].value;
- notify("");
+ chooser.selectedIndex = 0;
+ quickMenuGo(opid);
+}
- xmlhttp.open("GET", "backend.php?op=dlg&id=" +
- param_escape(id) + "¶m=" + param_escape(param), true);
- xmlhttp.onreadystatechange=dialog_refresh_callback;
- xmlhttp.send(null);
+function quickMenuGo(opid) {
+ try {
-}
+ if (opid == "qmcPrefs") {
+ gotoPreferences();
+ }
+
+ if (opid == "qmcSearch") {
+ displayDlg("search", getActiveFeedId());
+ return;
+ }
+
+ if (opid == "qmcAddFeed") {
+ displayDlg("quickAddFeed");
+ return;
+ }
+
+ if (opid == "qmcRemoveFeed") {
+ var actid = getActiveFeedId();
+
+ if (!actid) {
+ alert("Please select some feed first.");
+ return;
+ }
-function closeDlg() {
- var dlg = document.getElementById("userDlg");
- dlg.style.display = "none";
+ var fn = getFeedName(actid);
+
+ if (confirm("Unsubscribe from " + fn + "?")) {
+ qfdDelete(actid);
+ }
+
+ return;
+ }
+
+ if (opid == "qmcUpdateFeeds") {
+ scheduleFeedUpdate(true);
+ return;
+ }
+
+ if (opid == "qmcCatchupAll") {
+ catchupAllFeeds();
+ return;
+ }
+
+ if (opid == "qmcShowOnlyUnread") {
+ toggleDispRead();
+ return;
+ }
+
+ if (opid == "qmcAddFilter") {
+ displayDlg("quickAddFilter", getActiveFeedId());
+ }
+ } catch (e) {
+ exception_error("quickMenuGo", e);
+ }
}
function qfdDelete(feed_id) {
notify("Removing feed...");
- var feeds_doc = window.frames["feeds-frame"].document;
- feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
+ }
+
+ _qfd_deleted_feed = feed_id;
- xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
+ xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
xmlhttp.onreadystatechange=dlg_frefresh_callback;
xmlhttp.send(null);
}
-function allFeedsMenuGo() {
- var chooser = document.getElementById("allFeedsChooser");
+function updateFeedTitle(t) {
+ active_title_text = t;
+ updateTitle();
+}
- var opname = chooser[chooser.selectedIndex].text;
+function toggleDispRead() {
+ try {
- if (opname == "Update") {
- scheduleFeedUpdate(true);
- return;
- }
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
+ }
- if (opname == "Mark as read") {
- catchupAllFeeds();
- return;
- }
+ var hide_read_feeds = (getInitParam("hide_read_feeds") == "1");
- if (opname == "Show only read") {
- toggleDispRead();
- return;
- }
+ hide_read_feeds = !hide_read_feeds;
-}
+ debug("toggle_disp_read => " + hide_read_feeds);
-function toggleDispRead() {
- var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
-
- hide_read_feeds = !hide_read_feeds;
+ hideOrShowFeeds(getFeedsContext().document, hide_read_feeds);
- var feeds_doc = window.frames["feeds-frame"].document;
+ var query = "backend.php?op=rpc&subop=setpref" +
+ "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
- hideOrShowFeeds(feeds_doc, hide_read_feeds);
+ storeInitParam("hide_read_feeds", hide_read_feeds, true);
- if (hide_read_feeds) {
- setCookie("ttrss_vf_hreadf", 1);
- } else {
- setCookie("ttrss_vf_hreadf", 0);
+ new Ajax.Request(query);
+
+ } catch (e) {
+ exception_error("toggleDispRead", e);
}
+}
+
+function parse_runtime_info(elem) {
+ var param = elem.firstChild;
+ while (param) {
+ var k = param.getAttribute("key");
+ var v = param.getAttribute("value");
+
+ var w = document.getElementById("noDaemonWarning");
+
+ if (w) {
+ if (k == "daemon_is_running" && v != 1) {
+ w.style.display = "block";
+ } else {
+ w.style.display = "none";
+ }
+ }
+ param = param.nextSibling;
+ }
}