]> git.wh0rd.org - tt-rss.git/blobdiff - tt-rss.js
schema: support for audio enclosure in ttrss_entries
[tt-rss.git] / tt-rss.js
index 0201e2a73fca62d5cb95bd2a1a76f6f098161536..5603c01cef3c6e7b7a3b6a65f699f15e6e559a06 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -1,20 +1,12 @@
-/*
-       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 = -1;
+var active_title_text = "";
+var current_subtitle = "";
 
-var global_unread = 0;
+var _qfd_deleted_feed = 0;
 
 /*@cc_on @*/
 /*@if (@_jscript_version >= 5)
@@ -51,97 +43,133 @@ function toggleTags() {
 
 function dlg_frefresh_callback() {
        if (xmlhttp.readyState == 4) {
+               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.";
+                       }
+               }
                closeDlg();
        } 
 }
 
-function dialog_refresh_callback() {
+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.style.display = "block";
+               dlg_s.style.display = "block";
        } 
 }
 
-function refetch_callback() {
+function hide_unread_callback() {
        if (xmlhttp.readyState == 4) {
 
-//             document.title = "Tiny Tiny RSS";
+               try {
 
-               if (!xmlhttp.responseXML) {
-                       notify("refetch_callback: backend did not return valid XML");
-                       return;
+                       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 reply = xmlhttp.responseXML.firstChild;
-
-               if (!reply) {
-                       notify("refetch_callback: backend did not return expected XML object");
-                       return;
-               } 
-
-               var f_document = window.frames["feeds-frame"].document;
-
-               for (var l = 0; l < reply.childNodes.length; l++) {
-                       var id = reply.childNodes[l].getAttribute("id");
-                       var ctr = reply.childNodes[l].getAttribute("counter");
-
-                       var feedctr = f_document.getElementById("FEEDCTR-" + id);
-                       var feedu = f_document.getElementById("FEEDU-" + id);
-                       var feedr = f_document.getElementById("FEEDR-" + id);
-
-/*                     TODO figure out how to update this from viewfeed.js->view()
-                       disabled for now...
-
-                       if (id == "global-unread") {
-                               global_unread = ctr;
-                       } */
+       } 
+}
 
-                       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);
                        }
-               }  
-
-               updateTitle("");
-               notify("All feeds updated.");
+       
+                       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...";
 
-       updateTitle("Updating...");
+       updateTitle("Updating");
 
        var query_str = "backend.php?op=rpc&subop=";
 
@@ -204,7 +232,7 @@ function catchupAllFeeds() {
        feeds_frame.src = query_str;
 
        global_unread = 0;
-       updateTitle();
+       updateTitle("");
 
 }
 
@@ -224,8 +252,8 @@ function viewfeed(feed, skip, subop) {
 }
 
 function timeout() {
-       scheduleFeedUpdate(true);
-       setTimeout("timeout()", 1800*1000);
+       scheduleFeedUpdate(false);
+       setTimeout("timeout()", 900*1000);
 }
 
 function resetSearch() {
@@ -238,6 +266,7 @@ function resetSearch() {
 }
 
 function search() {
+       closeDlg();     
        viewCurrentFeed(0, "");
 }
 
@@ -264,48 +293,71 @@ function localHotkeyHandler(keycode) {
                return moveToPost('prev');
        } */
 
-       if (keycode == 82) {
+       if (keycode == 82) { // r
                return scheduleFeedUpdate(true);
        }
 
-       if (keycode == 85) {
-               return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
+       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) {
+               current_subtitle = s;
+       }
+
        if (global_unread > 0) {
                tmp = tmp + " (" + global_unread + ")";
        }
 
        if (s) {
-               tmp = tmp + " - " + s;
+               tmp = tmp + " - " + current_subtitle;
+       }
+
+       if (active_title_text.length > 0) {
+               tmp = tmp + " > " + active_title_text;
        }
+
        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;
@@ -313,35 +365,40 @@ function genericSanityCheck() {
 
 function init() {
 
-       disableContainerChildren("headlinesToolbar", true);
+       try {
 
-       if (!genericSanityCheck()) 
-               return;
+               disableContainerChildren("headlinesToolbar", true);
 
-       setCookie("ttrss_vf_actfeed", "");
+               if (!genericSanityCheck()) 
+                       return;
 
-       updateFeedList(false, false);
-       document.onkeydown = hotkey_handler;
+               xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
+               xmlhttp.onreadystatechange=backend_sanity_check_callback;
+               xmlhttp.send(null);
 
-       setTimeout("timeout()", 1800*1000);
-       scheduleFeedUpdate(true);
+       } catch (e) {
+               exception_error("init", e);
+       }
+}
 
-       var content = document.getElementById("content");
+function init_second_stage() {
 
-       if (getCookie("ttrss_vf_vmode")) {
-               var viewbox = document.getElementById("viewbox");
-               viewbox.value = getCookie("ttrss_vf_vmode");
-       }
+       try {
 
-       if (getCookie("ttrss_vf_limit")) {
+               setCookie("ttrss_vf_actfeed", "");
+       
+               updateFeedList(false, false);
+               document.onkeydown = hotkey_handler;
+       
+               var viewbox = document.getElementById("viewbox");                       
                var limitbox = document.getElementById("limitbox");
-               limitbox.value = getCookie("ttrss_vf_limit");
-       }
-
-//     if (getCookie("ttrss_vf_actfeed")) {
-//             viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
-//     }
 
+               dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
+               dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
+       
+       } catch (e) {
+               exception_error("init_second_stage", e);
+       }
 }
 
 function quickMenuGo() {
@@ -353,8 +410,8 @@ function quickMenuGo() {
                gotoPreferences();
        }
 
-       if (opid == "qmcAdvSearch") {
-               displayDlg("search");
+       if (opid == "qmcSearch") {
+               displayDlg("search", getActiveFeedId());
                return;
        }
 
@@ -370,8 +427,11 @@ function quickMenuGo() {
                        notify("Please select some feed first.");
                        return;
                }
+
+               if (confirm("Remove current feed?")) {
+                       qfdDelete(actid);
+               }
        
-               displayDlg("quickDelFeed", actid);
                return;
        }
 
@@ -390,6 +450,10 @@ function quickMenuGo() {
                return;
        }
 
+       if (opid == "qmcAddFilter") {
+               displayDlg("quickAddFilter", getActiveFeedId());
+       }
+
 }
 
 function qafAdd() {
@@ -405,13 +469,22 @@ function qafAdd() {
                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&subop=add&link=" +
-                       param_escape(link.value), true);
+               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);
 
@@ -420,30 +493,78 @@ function qafAdd() {
        }
 }
 
+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&regexp=" +
+                       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
+       }
+
        notify("");
 
        xmlhttp.open("GET", "backend.php?op=dlg&id=" +
                param_escape(id) + "&param=" + param_escape(param), true);
-       xmlhttp.onreadystatechange=dialog_refresh_callback;
+       xmlhttp.onreadystatechange=dlg_display_callback;
        xmlhttp.send(null);
 
+       disableHotkeys();
 }
 
 function closeDlg() {
-       var dlg = document.getElementById("userDlg");
+       var dlg = document.getElementById("userDlgShadow");
        dlg.style.display = "none";
+       enableHotkeys();
 }
 
 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
+       }
+
+//     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&subop=remove&ids=" + feed_id);
+       _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);
 }
@@ -464,26 +585,39 @@ function allFeedsMenuGo() {
                return;
        }
 
-       if (opname == "Show only read") {
+       if (opname == "Show only unread") {
                toggleDispRead();
                return;
        }
 
 }
 
+function updateFeedTitle(t) {
+       active_title_text = t;
+       updateTitle();
+}
+
 function toggleDispRead() {
-       var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
+       try {
 
-       hide_read_feeds = !hide_read_feeds;
+               if (!xmlhttp_ready(xmlhttp)) {
+                       printLockingError();
+                       return
+               }
 
-       var feeds_doc = window.frames["feeds-frame"].document;
+               var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
 
-       hideOrShowFeeds(feeds_doc, hide_read_feeds);
+               hide_read_feeds = !hide_read_feeds;
+       
+               var query = "backend.php?op=rpc&subop=setpref" +
+                       "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
 
-       if (hide_read_feeds) {
-               setCookie("ttrss_vf_hreadf", 1);
-       } else {
-               setCookie("ttrss_vf_hreadf", 0);
+               xmlhttp.open("GET", query);
+               xmlhttp.onreadystatechange=hide_unread_callback;
+               xmlhttp.send(null);
+               
+       } catch (e) {
+               exception_error("toggleDispRead", e);
        }
-
 }
+