var active_title_text = "";
var current_subtitle = "";
var daemon_enabled = false;
+var daemon_refresh_only = 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 Object();
function toggleTags() {
display_tags = !display_tags;
hframe.src = "backend.php?op=error&msg=No%20feed%20selected.";
}
}
- closeDlg();
- }
-}
-
-function dlg_submit_callback() {
- if (xmlhttp.readyState == 4) {
- notify(xmlhttp.responseText);
- closeDlg();
- }
-}
-
-function dlg_display_callback() {
- if (xmlhttp.readyState == 4) {
- var dlg = document.getElementById("userDlg");
- var dlg_s = document.getElementById("userDlgShadow");
-
- dlg.innerHTML = xmlhttp.responseText;
- dlg_s.style.display = "block";
- }
-}
-
-function hide_unread_callback() {
- if (xmlhttp.readyState == 4) {
-
- try {
-
- var reply = xmlhttp.responseXML.firstChild.firstChild;
- var value = reply.getAttribute("value");
- var hide_read_feeds = (value != "false")
- var feeds_doc = window.frames["feeds-frame"].document;
-
- hideOrShowFeeds(feeds_doc, hide_read_feeds);
-
- if (hide_read_feeds) {
- setCookie("ttrss_vf_hreadf", 1);
- } else {
- setCookie("ttrss_vf_hreadf", 0);
- }
-
- } catch (e) {
- exception_error("hide_unread_callback", e);
- }
-
+ closeInfoBox();
}
}
last_refetch = date.getTime() / 1000;
if (!xmlhttp.responseXML) {
- notify("refetch_callback: backend did not return valid XML");
+ 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");
+ 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);
+ return fatalError(error_code, reply.getAttribute("error-msg"));
}
+
+ var counters = reply.firstChild;
- var f_document = window.frames["feeds-frame"].document;
+ parse_counters(counters, true);
+
+ var runtime_info = counters.nextSibling;
- parse_counters(reply, f_document, window);
+ parse_runtime_info(runtime_info);
debug("refetch_callback: done");
- if (!daemon_enabled) {
+ if (!daemon_enabled && !daemon_refresh_only) {
notify("All feeds updated.");
updateTitle("");
} else {
try {
if (!xmlhttp.responseXML) {
- fatalError(3, "D001;" + xmlhttp.responseText);
+ fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
return;
}
- var reply = xmlhttp.responseXML.firstChild;
+ var reply = xmlhttp.responseXML.firstChild.firstChild;
if (!reply) {
- fatalError(3, "D002;" + xmlhttp.responseText);
+ 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);
+ return fatalError(error_code, reply.getAttribute("error-msg"));
}
debug("sanity check ok");
+ var params = reply.nextSibling;
+
+ if (params) {
+ debug('reading init-params...');
+ var param = params.firstChild;
+
+ while (param) {
+ var k = param.getAttribute("key");
+ var v = param.getAttribute("value");
+ debug(k + " => " + v);
+ init_params[k] = v;
+ param = param.nextSibling;
+ }
+ }
+
init_second_stage();
} catch (e) {
function scheduleFeedUpdate(force) {
- if (!daemon_enabled) {
- notify("Updating feeds, please wait.");
+ if (!daemon_enabled && !daemon_refresh_only) {
+ notify("Updating feeds, please wait.", true);
updateTitle("Updating");
}
var date = new Date();
if (!xmlhttp_ready(xmlhttp) && last_refetch < date.getTime() / 1000 - 60) {
- debug("xmlhttp seems to be stuck, aborting");
+ debug("<b>xmlhttp seems to be stuck, aborting</b>");
xmlhttp.abort();
}
disableContainerChildren("headlinesToolbar", false, document);
viewfeed(-1, skip, subop); // FIXME
}
+ return false; // block unneeded form submits
}
function viewfeed(feed, skip, subop) {
function timeout() {
scheduleFeedUpdate(false);
- var refresh_time = getCookie('ttrss_vf_refresh');
+ var refresh_time = getInitParam("feeds_frame_refresh");
- if (!refresh_time) refresh_time = 600;
+ if (!refresh_time) refresh_time = 600;
setTimeout("timeout()", refresh_time*1000);
}
}
}
+function searchCancel() {
+ closeInfoBox(true);
+}
+
function search() {
- closeDlg();
+ closeInfoBox();
viewCurrentFeed(0, "");
}
}
}
-function localHotkeyHandler(keycode) {
-
- if (keycode == 82) { // r
- return scheduleFeedUpdate(true);
- }
-
- if (keycode == 85) { // u
- if (getActiveFeedId()) {
- return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
- }
- }
-
- if (keycode == 65) { // a
- return toggleDispRead();
- }
-
- var f_doc = window.frames["feeds-frame"].document;
- var feedlist = f_doc.getElementById('feedList');
-
- if (keycode == 74) { // j
- var feed = getActiveFeedId();
- var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
- if (new_feed) viewfeed(new_feed, 0, '');
- }
-
- if (keycode == 75) { // k
- var feed = getActiveFeedId();
- var new_feed = getRelativeFeedId(feedlist, feed, 'next');
- if (new_feed) viewfeed(new_feed, 0, '');
- }
-
-// notify("KC: " + keycode);
-
-}
-
// if argument is undefined, current subtitle is not updated
// use blank string to clear subtitle
function updateTitle(s) {
disableContainerChildren("headlinesToolbar", true);
+ Form.disable("main_toolbar_form");
+
if (!genericSanityCheck())
return;
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";
+
+ var footer_height = 0;
+ var header_height = 0;
+
+ if (tf) {
+ footer_height = tf.scrollHeight;
+ }
+
+ if (th) {
+ header_height = th.scrollHeight;
+ }
+
+ f.style.height = document.body.scrollHeight - footer_height -
+ header_height - 50 + "px";
}
function init_second_stage() {
try {
- setCookie("ttrss_vf_actfeed", "");
+ cookie_lifetime = getCookie("ttrss_cltime");
+
+ delCookie("ttrss_vf_test");
updateFeedList(false, false);
document.onkeydown = hotkey_handler;
-
- var viewbox = document.getElementById("viewbox");
- var limitbox = document.getElementById("limitbox");
- dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
- dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
+ var tb = parent.document.forms["main_toolbar_form"];
+
+ dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
+ dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
- daemon_enabled = getCookie("ttrss_vf_daemon");
+ daemon_enabled = getInitParam("daemon_enabled") == 1;
+ daemon_refresh_only = getInitParam("daemon_refresh_only") == 1;
// FIXME should be callled after window resize
+ var h = document.getElementById("headlines");
+ var c = document.getElementById("content");
+
if (navigator.userAgent.match("Opera")) {
resize_feeds_frame();
-
-/* // fix headlines frame height for Opera
- var h = document.getElementById("headlines");
- var c = document.getElementById("content");
- var nh = document.body.scrollHeight * 0.25;
-
- h.style.height = nh + "px";
- c.style.height = c.scrollHeight - nh + "px"; */
-
}
debug("second stage ok");
function quickMenuChange() {
var chooser = document.getElementById("quickMenuChooser");
- var opid = chooser[chooser.selectedIndex].id;
+ var opid = chooser[chooser.selectedIndex].value;
chooser.selectedIndex = 0;
quickMenuGo(opid);
}
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) {
- notify("Please select some feed first.");
+ if (opid == "qmcPrefs") {
+ gotoPreferences();
+ }
+
+ if (opid == "qmcSearch") {
+ displayDlg("search", getActiveFeedId());
return;
}
-
- if (confirm("Remove current feed?")) {
- qfdDelete(actid);
+
+ if (opid == "qmcAddFeed") {
+ displayDlg("quickAddFeed");
+ return;
}
- return;
- }
-
- if (opid == "qmcUpdateFeeds") {
- scheduleFeedUpdate(true);
- return;
- }
-
- if (opid == "qmcCatchupAll") {
- catchupAllFeeds();
- return;
- }
-
- if (opid == "qmcShowOnlyUnread") {
- toggleDispRead();
- return;
- }
-
- if (opid == "qmcAddFilter") {
- displayDlg("quickAddFilter", getActiveFeedId());
- }
-
-}
-
-function qafAdd() {
-
- if (!xmlhttp_ready(xmlhttp)) {
- printLockingError();
- return
- }
-
- var link = document.getElementById("qafInput");
+ if (opid == "qmcRemoveFeed") {
+ var actid = getActiveFeedId();
+
+ if (!actid) {
+ alert("Please select some feed first.");
+ return;
+ }
- if (link.value.length == 0) {
- notify("Missing feed URL.");
- } else {
- notify("Adding feed...");
+ var fn = getFeedName(actid);
- var cat = document.getElementById("qafCat");
- var cat_id = "";
+ if (confirm("Unsubscribe from " + fn + "?")) {
+ qfdDelete(actid);
+ }
- if (cat) {
- cat_id = cat[cat.selectedIndex].id;
- } else {
- cat_id = 0;
+ return;
}
-
- var feeds_doc = window.frames["feeds-frame"].document;
-
- feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
-
- xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
- param_escape(link.value) + "&cid=" + param_escape(cat_id), true);
- xmlhttp.onreadystatechange=dlg_frefresh_callback;
- xmlhttp.send(null);
-
- link.value = "";
-
- }
-}
-
-function qaddFilter() {
-
- if (!xmlhttp_ready(xmlhttp)) {
- printLockingError();
- return
- }
-
- var regexp = document.getElementById("fadd_regexp");
- var match = document.getElementById("fadd_match");
- var feed = document.getElementById("fadd_feed");
- var action = document.getElementById("fadd_action");
-
- if (regexp.value.length == 0) {
- notify("Missing filter expression.");
- } else {
- notify("Adding filter...");
-
- var v_match = match[match.selectedIndex].text;
- var feed_id = feed[feed.selectedIndex].id;
- var action_id = action[action.selectedIndex].id;
-
- xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
- param_escape(regexp.value) + "&match=" + v_match +
- "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
-
- xmlhttp.onreadystatechange=dlg_submit_callback;
- xmlhttp.send(null);
-
- regexp.value = "";
- }
-
-}
-
-
-function displayDlg(id, param) {
-
- if (!xmlhttp_ready(xmlhttp)) {
- printLockingError();
- 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);
}
-
- notify("");
-
- xmlhttp.open("GET", "backend.php?op=dlg&id=" +
- param_escape(id) + "¶m=" + param_escape(param), true);
- xmlhttp.onreadystatechange=dlg_display_callback;
- xmlhttp.send(null);
-
- disableHotkeys();
-}
-
-function closeDlg() {
- var dlg = document.getElementById("userDlgShadow");
- dlg.style.display = "none";
- enableHotkeys();
}
function qfdDelete(feed_id) {
return
}
-// var feeds_doc = window.frames["feeds-frame"].document;
-// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
-
_qfd_deleted_feed = feed_id;
xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
}
-function allFeedsMenuChange() {
- var chooser = document.getElementById("allFeedsChooser");
-
- var opname = chooser[chooser.selectedIndex].text;
-
- chooser.selectedIndex = 0;
-
- if (opname == "Update") {
- scheduleFeedUpdate(true);
- return;
- }
-
- if (opname == "Mark as read") {
- catchupAllFeeds();
- return;
- }
-
- if (opname == "Show only unread") {
- toggleDispRead();
- return;
- }
-
-}
-
function updateFeedTitle(t) {
active_title_text = t;
updateTitle();
return
}
- var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
+ var hide_read_feeds = (getInitParam("hide_read_feeds") == "1");
hide_read_feeds = !hide_read_feeds;
-
+
+ debug("toggle_disp_read => " + hide_read_feeds);
+
+ hideOrShowFeeds(getFeedsContext().document, hide_read_feeds);
+
var query = "backend.php?op=rpc&subop=setpref" +
"&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
- xmlhttp.open("GET", query);
- xmlhttp.onreadystatechange=hide_unread_callback;
- xmlhttp.send(null);
+ storeInitParam("hide_read_feeds", hide_read_feeds, true);
+
+ new Ajax.Request(query);
} catch (e) {
exception_error("toggleDispRead", e);
}
}
-function debug(msg) {
- var c = document.getElementById('debug_output');
- if (c && c.style.display == "block") {
- while (c.lastChild != 'undefined' && c.childNodes.length > 20) {
- c.removeChild(c.lastChild);
+function parse_runtime_info(elem) {
+ var param = elem.firstChild;
+
+ debug("parse_runtime_info");
+
+ while (param) {
+ var k = param.getAttribute("key");
+ var v = param.getAttribute("value");
+
+ debug("RI: " + k + " => " + v);
+
+ 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;
+ }
+}
+
+function catchupCurrentFeed() {
+
+ var fn = getFeedName(getActiveFeedId());
- var d = new Date();
- var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
- ":" + leading_zero(d.getSeconds());
- c.innerHTML = "<li>[" + ts + "] " + msg + "</li>" + c.innerHTML;
+ if (confirm("Mark all articles in " + fn + " as read?")) {
+ return viewCurrentFeed(0, 'MarkAllRead')
}
}