X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=tt-rss.js;h=7167d058410a217c68593802bbb743466b194ccb;hb=e8614131e893af473e0a585addb19d9f4e8b8973;hp=0e71c0ecd97b5fe4fbc343402ad5680840a936fc;hpb=e2cb4c6d7a4781469798fd5cf66ddb72e5d4a57c;p=tt-rss.git diff --git a/tt-rss.js b/tt-rss.js index 0e71c0ec..7167d058 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -5,27 +5,16 @@ var display_tags = false; 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 Object(); function toggleTags() { display_tags = !display_tags; @@ -51,65 +40,27 @@ function dlg_frefresh_callback() { 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"; + closeInfoBox(); } } -function hide_unread_callback() { +function refetch_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); - } + var date = new Date(); - } -} - -function refetch_callback() { - if (xmlhttp.readyState == 4) { - try { + 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; } @@ -117,15 +68,25 @@ function refetch_callback() { 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 f_document = window.frames["feeds-frame"].document; - parse_counters(reply, f_document, window); + var counters = reply.firstChild; - updateTitle(""); - notify("All feeds updated."); + parse_counters(counters, true); + + var runtime_info = counters.nextSibling; + + parse_runtime_info(runtime_info); + + debug("refetch_callback: done"); + + if (!daemon_enabled) { + notify("All feeds updated."); + updateTitle(""); + } else { + notify(""); + } } catch (e) { exception_error("refetch_callback", e); updateTitle(""); @@ -140,23 +101,40 @@ function backend_sanity_check_callback() { try { if (!xmlhttp.responseXML) { - fatalError(3); + 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); + 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) { @@ -167,11 +145,10 @@ function backend_sanity_check_callback() { function scheduleFeedUpdate(force) { - notify("Updating feeds, please wait."); - -// 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="; @@ -183,19 +160,35 @@ function scheduleFeedUpdate(force) { 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("xmlhttp seems to be stuck, aborting"); + xmlhttp.abort(); + } if (xmlhttp_ready(xmlhttp)) { xmlhttp.open("GET", query_str, true); xmlhttp.onreadystatechange=refetch_callback; xmlhttp.send(null); } else { + debug("xmlhttp busy"); printLockingError(); } } @@ -216,6 +209,12 @@ function updateFeedList(silent, fetch) { 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"); @@ -246,6 +245,7 @@ function viewCurrentFeed(skip, subop) { disableContainerChildren("headlinesToolbar", false, document); viewfeed(-1, skip, subop); // FIXME } + return false; // block unneeded form submits } function viewfeed(feed, skip, subop) { @@ -256,9 +256,9 @@ 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); } @@ -272,8 +272,12 @@ function resetSearch() { } } +function searchCancel() { + closeInfoBox(true); +} + function search() { - closeDlg(); + closeInfoBox(); viewCurrentFeed(0, ""); } @@ -290,55 +294,12 @@ function localPiggieFunction(enable) { } } -function localHotkeyHandler(keycode) { - -/* if (keycode == 78) { - return moveToPost('next'); - } - - if (keycode == 80) { - return moveToPost('prev'); - } */ - - 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) { var tmp = "Tiny Tiny RSS"; - if (s && s.length > 0) { + if (s != undefined) { current_subtitle = s; } @@ -346,7 +307,7 @@ function updateTitle(s) { tmp = tmp + " (" + global_unread + ")"; } - if (s) { + if (current_subtitle) { tmp = tmp + " - " + current_subtitle; } @@ -374,11 +335,23 @@ function init() { try { + // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html + + if (arguments.callee.done) return; + arguments.callee.done = true; + disableContainerChildren("headlinesToolbar", true); + Form.disable("main_toolbar_form"); + if (!genericSanityCheck()) return; + if (getURLParam('debug')) { + document.getElementById('debug_output').style.display = 'block'; + debug('debug mode activated'); + } + xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true); xmlhttp.onreadystatechange=backend_sanity_check_callback; xmlhttp.send(null); @@ -388,20 +361,54 @@ function init() { } } +function resize_feeds_frame() { + var f = document.getElementById("feeds-frame"); + var tf = document.getElementById("mainFooter"); + var th = document.getElementById("mainHeader"); + + 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 = getInitParam("daemon_enabled"); + + // 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(); + } + + debug("second stage ok"); } catch (e) { exception_error("init_second_stage", e); @@ -410,157 +417,67 @@ function init_second_stage() { 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) { @@ -572,9 +489,6 @@ 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); @@ -583,30 +497,6 @@ function qfdDelete(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(); @@ -620,19 +510,46 @@ function toggleDispRead() { 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 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; + } +}