-/*
- 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 display_tags = false;
+var global_unread = -1;
+var active_title_text = "";
+var current_subtitle = "";
+
+var _qfd_deleted_feed = 0;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
updateFeedList();
}
-/*
-function feedlist_callback() {
- var container = document.getElementById('feeds');
+function dlg_frefresh_callback() {
if (xmlhttp.readyState == 4) {
- container.innerHTML=xmlhttp.responseText;
-
- if (first_run) {
- scheduleFeedUpdate(false);
- if (getCookie("ttrss_vf_actfeed")) {
- viewfeed(getCookie("ttrss_vf_actfeed"), 0, "");
+ notify(xmlhttp.responseText);
+ updateFeedList(false, false);
+ if (_qfd_deleted_feed) {
+ var hframe = document.getElementById("headlines-frame");
+ if (hframe) {
+ hframe.src = "backend.php?op=error&msg=No%20feed%20selected.";
}
- first_run = false;
- } else {
- notify("");
- }
+ }
+ closeDlg();
}
}
-*/
-function refetch_callback() {
+function dlg_submit_callback() {
if (xmlhttp.readyState == 4) {
+ notify(xmlhttp.responseText);
+ closeDlg();
+ }
+}
- document.title = "Tiny Tiny RSS";
- notify("All feeds updated.");
-
- if (!xmlhttp.responseXML) {
- notify("refetch_callback: backend did not return valid XML");
- return;
- }
+function dlg_display_callback() {
+ if (xmlhttp.readyState == 4) {
+ var dlg = document.getElementById("userDlg");
+ var dlg_s = document.getElementById("userDlgShadow");
- var reply = xmlhttp.responseXML.firstChild;
+ dlg.innerHTML = xmlhttp.responseText;
+ dlg_s.style.display = "block";
+ }
+}
- if (!reply) {
- notify("refetch_callback: backend did not return expected XML object");
- return;
- }
+function hide_unread_callback() {
+ if (xmlhttp.readyState == 4) {
- var f_document = window.frames["feeds-frame"].document;
+ try {
- for (var l = 0; l < reply.childNodes.length; l++) {
- var id = reply.childNodes[l].getAttribute("id");
- var ctr = reply.childNodes[l].getAttribute("counter");
+ 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 feedctr = f_document.getElementById("FEEDCTR-" + id);
- var feedu = f_document.getElementById("FEEDU-" + id);
- var feedr = f_document.getElementById("FEEDR-" + id);
+ }
+}
- if (feedctr && feedu && feedr) {
+function refetch_callback() {
+ if (xmlhttp.readyState == 4) {
+ try {
- feedu.innerHTML = ctr;
+ if (!xmlhttp.responseXML) {
+ notify("refetch_callback: backend did not return valid XML");
+ return;
+ }
+
+ var reply = xmlhttp.responseXML.firstChild;
- 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", "");
- }
+ if (!reply) {
+ notify("refetch_callback: backend did not return expected XML object");
+ return;
+ }
+
+ var error_code = reply.getAttribute("error-code");
+
+ if (error_code && error_code != 0) {
+ return fatalError(error_code);
}
- }
+
+ var f_document = window.frames["feeds-frame"].document;
+
+ parse_counters(reply, f_document, window);
+
+ updateTitle("");
+ notify("All feeds updated.");
+ } catch (e) {
+ exception_error("refetch_callback", e);
+ }
}
}
-function updateFeed(feed_id) {
+function backend_sanity_check_callback() {
- var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
+ if (xmlhttp.readyState == 4) {
- if (xmlhttp_ready(xmlhttp)) {
- xmlhttp.open("GET", query_str, true);
- xmlhttp.onreadystatechange=feed_update_callback;
- xmlhttp.send(null);
- } else {
- printLockingError();
- }
+ try {
+
+ if (!xmlhttp.responseXML) {
+ fatalError(3);
+ return;
+ }
+
+ var reply = xmlhttp.responseXML.firstChild;
+
+ if (!reply) {
+ fatalError(3);
+ return;
+ }
+
+ var error_code = reply.getAttribute("error-code");
+
+ if (error_code && error_code != 0) {
+ return fatalError(error_code);
+ }
+
+ init_second_stage();
+ } catch (e) {
+ exception_error("backend_sanity_check_callback", e);
+ }
+ }
}
function scheduleFeedUpdate(force) {
- notify("Updating feeds in background...");
+ notify("Updating feeds, please wait.");
+
+// document.title = "Tiny Tiny RSS - Updating...";
- document.title = "Tiny Tiny RSS - Updating...";
+ updateTitle("Updating");
var query_str = "backend.php?op=rpc&subop=";
query_str = query_str + "updateAllFeeds";
}
+ var omode;
+
+ if (display_tags) {
+ omode = "t";
+ } else {
+ omode = "fl";
+ }
+
+ query_str = query_str + "&omode=" + omode;
+
if (xmlhttp_ready(xmlhttp)) {
xmlhttp.open("GET", query_str, true);
xmlhttp.onreadystatechange=refetch_callback;
feeds_frame.src = query_str;
+ global_unread = 0;
+ updateTitle("");
+
}
function viewCurrentFeed(skip, subop) {
if (getActiveFeedId()) {
viewfeed(getActiveFeedId(), skip, subop);
+ } else {
+ disableContainerChildren("headlinesToolbar", false, document);
+ viewfeed(-1, skip, subop); // FIXME
}
}
function viewfeed(feed, skip, subop) {
+ var f = window.frames["feeds-frame"];
+ f.viewfeed(feed, skip, subop);
+}
-// notify("Loading headlines...");
+function timeout() {
+ scheduleFeedUpdate(false);
+ setTimeout("timeout()", 900*1000);
+}
- enableHotkeys();
+function resetSearch() {
+ var searchbox = document.getElementById("searchbox")
- var searchbox = document.getElementById("searchbox");
+ if (searchbox.value != "" && getActiveFeedId()) {
+ searchbox.value = "";
+ viewfeed(getActiveFeedId(), 0, "");
+ }
+}
- if (searchbox) {
- search_query = searchbox.value;
- } else {
- search_query = "";
- }
+function search() {
+ closeDlg();
+ viewCurrentFeed(0, "");
+}
- var viewbox = document.getElementById("viewbox");
+function localPiggieFunction(enable) {
+ if (enable) {
+ var query_str = "backend.php?op=feeds&subop=piggie";
- var view_mode;
+ if (xmlhttp_ready(xmlhttp)) {
- if (viewbox) {
- view_mode = viewbox[viewbox.selectedIndex].text;
- } else {
- view_mode = "All Posts";
+ xmlhttp.open("GET", query_str, true);
+ xmlhttp.onreadystatechange=feedlist_callback;
+ xmlhttp.send(null);
+ }
}
+}
- setCookie("ttrss_vf_vmode", view_mode);
+function localHotkeyHandler(keycode) {
- var limitbox = document.getElementById("limitbox");
+/* if (keycode == 78) {
+ return moveToPost('next');
+ }
- var limit;
+ if (keycode == 80) {
+ return moveToPost('prev');
+ } */
- if (limitbox) {
- limit = limitbox[limitbox.selectedIndex].text;
- setCookie("ttrss_vf_limit", limit);
- } else {
- limit = "All";
+ if (keycode == 82) { // r
+ return scheduleFeedUpdate(true);
}
- setActiveFeedId(feed);
-
- var f_doc = frames["feeds-frame"].document;
+ if (keycode == 85) { // u
+ if (getActiveFeedId()) {
+ return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
+ }
+ }
-// f_doc.getElementById("ACTFEEDID").innerHTML = feed;
+ if (keycode == 65) { // a
+ return toggleDispRead();
+ }
- if (subop == "MarkAllRead") {
+ var f_doc = window.frames["feeds-frame"].document;
+ var feedlist = f_doc.getElementById('feedList');
- var feedr = f_doc.getElementById("FEEDR-" + feed);
- var feedctr = f_doc.getElementById("FEEDCTR-" + feed);
-
- feedctr.className = "invisible";
+ if (keycode == 74) { // j
+ var feed = getActiveFeedId();
+ var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
+ if (new_feed) viewfeed(new_feed, 0, '');
+ }
- if (feedr.className.match("Unread")) {
- feedr.className = feedr.className.replace("Unread", "");
- }
+ if (keycode == 75) { // k
+ var feed = getActiveFeedId();
+ var new_feed = getRelativeFeedId(feedlist, feed, 'next');
+ if (new_feed) viewfeed(new_feed, 0, '');
}
- var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
- "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
- "&view=" + param_escape(view_mode) + "&limit=" + limit;
+// notify("KC: " + keycode);
- if (search_query != "") {
- query = query + "&search=" + param_escape(search_query);
+}
+
+// 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) {
+ current_subtitle = s;
}
-
- var headlines_frame = parent.frames["headlines-frame"];
- headlines_frame.location.href = query + "&addheader=true";
+ if (global_unread > 0) {
+ tmp = tmp + " (" + global_unread + ")";
+ }
- cleanSelected("feedsList");
- var feedr = document.getElementById("FEEDR-" + feed);
- if (feedr) {
- feedr.className = feedr.className + "Selected";
+ if (s) {
+ tmp = tmp + " - " + current_subtitle;
}
-
- disableContainerChildren("headlinesToolbar", false, doc);
-// notify("");
+ if (active_title_text.length > 0) {
+ tmp = tmp + " > " + active_title_text;
+ }
+ document.title = tmp;
}
+function genericSanityCheck() {
+
+ if (!xmlhttp) fatalError(1);
-function timeout() {
- scheduleFeedUpdate(true);
- setTimeout("timeout()", 1800*1000);
+ setCookie("ttrss_vf_test", "TEST");
+
+ if (getCookie("ttrss_vf_test") != "TEST") {
+ fatalError(2);
+ }
+
+ return true;
}
-function resetSearch() {
- var searchbox = document.getElementById("searchbox")
+function init() {
- if (searchbox.value != "" && getActiveFeedId()) {
- searchbox.value = "";
- viewfeed(getActiveFeedId(), 0, "");
+ try {
+
+ disableContainerChildren("headlinesToolbar", true);
+
+ if (!genericSanityCheck())
+ return;
+
+ 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 search() {
- viewCurrentFeed(0, "");
+function init_second_stage() {
+
+ try {
+
+ setCookie("ttrss_vf_actfeed", "");
+
+ 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"));
+
+ } catch (e) {
+ exception_error("init_second_stage", e);
+ }
}
-function localPiggieFunction(enable) {
- if (enable) {
- var query_str = "backend.php?op=feeds&subop=piggie";
+function quickMenuChange() {
+ var chooser = document.getElementById("quickMenuChooser");
+ var opid = chooser[chooser.selectedIndex].id;
- if (xmlhttp_ready(xmlhttp)) {
+ chooser.selectedIndex = 0;
+ quickMenuGo(opid);
+}
- xmlhttp.open("GET", query_str, true);
- xmlhttp.onreadystatechange=feedlist_callback;
- xmlhttp.send(null);
+function quickMenuGo(opid) {
+
+
+ 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.");
+ return;
+ }
+
+ if (confirm("Remove current feed?")) {
+ qfdDelete(actid);
}
+
+ return;
}
-}
-function localHotkeyHandler(keycode) {
+ if (opid == "qmcUpdateFeeds") {
+ scheduleFeedUpdate(true);
+ return;
+ }
-/* if (keycode == 78) {
- return moveToPost('next');
+ if (opid == "qmcCatchupAll") {
+ catchupAllFeeds();
+ return;
}
- if (keycode == 80) {
- return moveToPost('prev');
- } */
+ if (opid == "qmcShowOnlyUnread") {
+ toggleDispRead();
+ return;
+ }
- if (keycode == 82) {
- return scheduleFeedUpdate(true);
+ if (opid == "qmcAddFilter") {
+ displayDlg("quickAddFilter", getActiveFeedId());
}
- if (keycode == 85) {
- return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
+}
+
+function qafAdd() {
+
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
}
-// notify("KC: " + keycode);
+ var link = document.getElementById("qafInput");
+
+ if (link.value.length == 0) {
+ notify("Missing feed URL.");
+ } else {
+ notify("Adding feed...");
+
+ var cat = document.getElementById("qafCat");
+ var cat_id = "";
+
+ if (cat) {
+ cat_id = cat[cat.selectedIndex].id;
+ } else {
+ cat_id = 0;
+ }
+
+ 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 genericSanityCheck() {
+function qaddFilter() {
- 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_ready(xmlhttp)) {
+ printLockingError();
+ return
}
- setCookie("ttrss_vf_test", "TEST");
- if (getCookie("ttrss_vf_test") != "TEST") {
+ 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;
- document.getElementById("headlines").innerHTML =
- "<b>Fatal error:</b> This program requires cookies " +
- "to function properly. Your browser doesn't seem to support them.";
+ 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);
- return false;
+ regexp.value = "";
}
- return true;
}
-function init() {
- disableContainerChildren("headlinesToolbar", true);
+function displayDlg(id, param) {
- if (!genericSanityCheck())
- return;
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
+ }
- setCookie("ttrss_vf_actfeed", "");
+ notify("");
- updateFeedList(false, false);
- document.onkeydown = hotkey_handler;
+ 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();
+}
- setTimeout("timeout()", 1800*1000);
- scheduleFeedUpdate(true);
+function qfdDelete(feed_id) {
- var content = document.getElementById("content");
+ notify("Removing feed...");
- if (getCookie("ttrss_vf_vmode")) {
- var viewbox = document.getElementById("viewbox");
- viewbox.value = getCookie("ttrss_vf_vmode");
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
}
- if (getCookie("ttrss_vf_limit")) {
- var limitbox = document.getElementById("limitbox");
- limitbox.value = getCookie("ttrss_vf_limit");
+// 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);
+ xmlhttp.onreadystatechange=dlg_frefresh_callback;
+ xmlhttp.send(null);
+}
+
+
+function allFeedsMenuChange() {
+ var chooser = document.getElementById("allFeedsChooser");
+
+ var opname = chooser[chooser.selectedIndex].text;
+
+ chooser.selectedIndex = 0;
+
+ if (opname == "Update") {
+ scheduleFeedUpdate(true);
+ return;
}
-// if (getCookie("ttrss_vf_actfeed")) {
-// viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
-// }
+ if (opname == "Mark as read") {
+ catchupAllFeeds();
+ return;
+ }
+
+ if (opname == "Show only unread") {
+ toggleDispRead();
+ return;
+ }
+
+}
+function updateFeedTitle(t) {
+ active_title_text = t;
+ updateTitle();
}
+function toggleDispRead() {
+ try {
+
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
+ }
+
+ var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
+
+ hide_read_feeds = !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);
+
+ } catch (e) {
+ exception_error("toggleDispRead", e);
+ }
+}