]> 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 1776c1c3314fd67e845ce48e2136191969f297c6..5603c01cef3c6e7b7a3b6a65f699f15e6e559a06 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -1,13 +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 xmlhttp_rpc = false;
-
 var total_unread = 0;
 var first_run = true;
+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)
@@ -18,105 +17,159 @@ try {
 } catch (e) {
        try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
-               xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
                xmlhttp = false;
-               xmlhttp_rpc = false;
        }
 }
 @end @*/
 
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
-       xmlhttp_rpc = new XMLHttpRequest();
-
 }
 
-function notify_callback() {
-       var container = document.getElementById('notify');
-       if (xmlhttp.readyState == 4) {
-               container.innerHTML=xmlhttp.responseText;
+function toggleTags() {
+       display_tags = !display_tags;
+
+       var p = document.getElementById("dispSwitchPrompt");
+
+       if (display_tags) {
+               p.innerHTML = "display feeds";
+       } else {
+               p.innerHTML = "display tags";
        }
+       
+       updateFeedList();
 }
 
-function feedlist_callback() {
-       var container = document.getElementById('feeds');
+function dlg_frefresh_callback() {
        if (xmlhttp.readyState == 4) {
-               container.innerHTML=xmlhttp.responseText;
-
-//             var feedtu = document.getElementById("FEEDTU");
-//             if (feedtu) {
-//                     total_unread = feedtu.innerHTML;
-//                     update_title();
-//             }
-
-               if (first_run) {
-                       scheduleFeedUpdate(false);
-                       first_run = false;
-               } else {
-                       notify("");
+               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 viewfeed_callback() {
-       var container = document.getElementById('headlines');
+function dlg_submit_callback() {
        if (xmlhttp.readyState == 4) {
-               container.innerHTML = xmlhttp.responseText;
-
-               var factive = document.getElementById("FACTIVE");
-               var funread = document.getElementById("FUNREAD");
-               var ftotal = document.getElementById("FTOTAL");
+               notify(xmlhttp.responseText);
+               closeDlg();
+       } 
+}
 
-               if (ftotal && factive && funread) {
-                       var feed_id = factive.innerHTML;
+function dlg_display_callback() {
+       if (xmlhttp.readyState == 4) {
+               var dlg = document.getElementById("userDlg");
+               var dlg_s = document.getElementById("userDlgShadow");
 
-                       var feedr = document.getElementById("FEEDR-" + feed_id);
-                       var feedt = document.getElementById("FEEDT-" + feed_id);
-                       var feedu = document.getElementById("FEEDU-" + feed_id);
+               dlg.innerHTML = xmlhttp.responseText;
+               dlg_s.style.display = "block";
+       } 
+}
 
-                       feedt.innerHTML = ftotal.innerHTML;
-                       feedu.innerHTML = funread.innerHTML;
+function hide_unread_callback() {
+       if (xmlhttp.readyState == 4) {
 
-                       if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
-                                       feedr.className = feedr.className + "Unread";
-                       } else if (feedu.innerHTML <= 0) {      
-                                       feedr.className = feedr.className.replace("Unread", "");
-                       }
+               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);
                }
 
-               notify("");
-
-       }       
+       } 
 }
 
-function view_callback() {
-       var container = document.getElementById('content');
+function refetch_callback() {
        if (xmlhttp.readyState == 4) {
-               container.innerHTML=xmlhttp.responseText;               
+               try {
+
+                       if (!xmlhttp.responseXML) {
+                               notify("refetch_callback: backend did not return valid XML");
+                               return;
+                       }
+               
+                       var reply = xmlhttp.responseXML.firstChild;
+       
+                       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 refetch_callback() {
-       if (xmlhttp_rpc.readyState == 4) {
-               notify("All feeds updated");
-               
-               var container = document.getElementById('feeds');
+function backend_sanity_check_callback() {
 
-               container.innerHTML = xmlhttp_rpc.responseText;
+       if (xmlhttp.readyState == 4) {
 
-               document.title = "Tiny Tiny RSS";
+               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();
 
-               //updateFeedList(true, false);
-       }
+               } 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=";
 
@@ -126,188 +179,445 @@ function scheduleFeedUpdate(force) {
                query_str = query_str + "updateAllFeeds";
        }
 
-       if (xmlhttp_rpc.readyState == 4 || xmlhttp_rpc.readyState == 0) {
-               xmlhttp_rpc.open("GET", query_str, true);
-               xmlhttp_rpc.onreadystatechange=refetch_callback;
-               xmlhttp_rpc.send(null);
+       var omode;
+
+       if (display_tags) {
+               omode = "t";
        } else {
-               printLockingError();
+               omode = "fl";
        }
+
+       query_str = query_str + "&omode=" + omode;
+
+       if (xmlhttp_ready(xmlhttp)) {
+               xmlhttp.open("GET", query_str, true);
+               xmlhttp.onreadystatechange=refetch_callback;
+               xmlhttp.send(null);
+       } else {
+               printLockingError();
+       }   
 }
 
 function updateFeedList(silent, fetch) {
-       
-       if (silent != true) {
-               notify("Loading feed list...");
-       }
+
+//     if (silent != true) {
+//             notify("Loading feed list...");
+//     }
 
        var query_str = "backend.php?op=feeds";
 
+       if (display_tags) {
+               query_str = query_str + "&tags=1";
+       }
+
+       if (getActiveFeedId()) {
+               query_str = query_str + "&actid=" + getActiveFeedId();
+       }
+
        if (fetch) query_str = query_str + "&fetch=yes";
 
-       if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
-               xmlhttp.open("GET", query_str, true);
-               xmlhttp.onreadystatechange=feedlist_callback;
-               xmlhttp.send(null);
+       var feeds_frame = document.getElementById("feeds-frame");
+
+       feeds_frame.src = query_str;
+}
+
+function catchupAllFeeds() {
+
+       var query_str = "backend.php?op=feeds&subop=catchupAll";
+
+       notify("Marking all feeds as read...");
+
+       var feeds_frame = document.getElementById("feeds-frame");
+
+       feeds_frame.src = query_str;
+
+       global_unread = 0;
+       updateTitle("");
+
+}
+
+function viewCurrentFeed(skip, subop) {
+
+       if (getActiveFeedId()) {
+               viewfeed(getActiveFeedId(), skip, subop);
        } else {
-               printLockingError();
+               disableContainerChildren("headlinesToolbar", false, document);
+               viewfeed(-1, skip, subop); // FIXME
        }
 }
 
-function catchupPage(feed) {
+function viewfeed(feed, skip, subop) {
+       var f = window.frames["feeds-frame"];
+       f.viewfeed(feed, skip, subop);
+}
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
-               printLockingError();
-               return
+function timeout() {
+       scheduleFeedUpdate(false);
+       setTimeout("timeout()", 900*1000);
+}
+
+function resetSearch() {
+       var searchbox = document.getElementById("searchbox")
+
+       if (searchbox.value != "" && getActiveFeedId()) {       
+               searchbox.value = "";
+               viewfeed(getActiveFeedId(), 0, "");
        }
+}
 
-       var content = document.getElementById("headlinesList");
+function search() {
+       closeDlg();     
+       viewCurrentFeed(0, "");
+}
 
-       var rows = new Array();
+function localPiggieFunction(enable) {
+       if (enable) {
+               var query_str = "backend.php?op=feeds&subop=piggie";
 
-       for (i = 0; i < content.rows.length; i++) {
-               var row_id = content.rows[i].id.replace("RROW-", "");
-               if (row_id.length > 0) {
-                       if (content.rows[i].className.match("Unread")) {
-                               rows.push(row_id);      
-                               content.rows[i].className = content.rows[i].className.replace("Unread", "");
-                       }
+               if (xmlhttp_ready(xmlhttp)) {
+
+                       xmlhttp.open("GET", query_str, true);
+                       xmlhttp.onreadystatechange=feedlist_callback;
+                       xmlhttp.send(null);
+               }
+       }
+}
+
+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 (rows.length > 0) {
+       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 + " - " + current_subtitle;
+       }
+
+       if (active_title_text.length > 0) {
+               tmp = tmp + " > " + active_title_text;
+       }
+
+       document.title = tmp;
+}
 
-               var feedr = document.getElementById("FEEDR-" + feed);
-               var feedu = document.getElementById("FEEDU-" + feed);
+function genericSanityCheck() {
+
+       if (!xmlhttp) fatalError(1);
+
+       setCookie("ttrss_vf_test", "TEST");
        
-               feedu.innerHTML = feedu.innerHTML - rows.length;
+       if (getCookie("ttrss_vf_test") != "TEST") {
+               fatalError(2);
+       }
+
+       return true;
+}
+
+function init() {
+
+       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 init_second_stage() {
+
+       try {
+
+               setCookie("ttrss_vf_actfeed", "");
        
-               if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
-                               feedr.className = feedr.className + "Unread";
-               } else if (feedu.innerHTML <= 0) {      
-                               feedr.className = feedr.className.replace("Unread", "");
-               } 
-
-               var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" + 
-                       param_escape(rows.toString());
+               updateFeedList(false, false);
+               document.onkeydown = hotkey_handler;
        
-               notify("Marking this page as read...");
+               var viewbox = document.getElementById("viewbox");                       
+               var limitbox = document.getElementById("limitbox");
+
+               dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
+               dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
        
-               xmlhttp.open("GET", query_str, true);
-               xmlhttp.onreadystatechange=notify_callback;
-               xmlhttp.send(null);
+       } catch (e) {
+               exception_error("init_second_stage", e);
+       }
+}
 
-       } else {
-               notify("No unread items on this page.");
+function quickMenuGo() {
 
+       var chooser = document.getElementById("quickMenuChooser");
+       var opid = chooser[chooser.selectedIndex].id;
+
+       if (opid == "qmcPrefs") {
+               gotoPreferences();
        }
-}
 
-function catchupAllFeeds() {
+       if (opid == "qmcSearch") {
+               displayDlg("search", getActiveFeedId());
+               return;
+       }
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
-               printLockingError();
-               return
+       if (opid == "qmcAddFeed") {
+               displayDlg("quickAddFeed");
+               return;
        }
-       var query_str = "backend.php?op=feeds&subop=catchupAll";
 
-       notify("Marking all feeds as read...");
+       if (opid == "qmcRemoveFeed") {
+               var actid = getActiveFeedId();
 
-       xmlhttp.open("GET", query_str, true);
-       xmlhttp.onreadystatechange=feedlist_callback;
-       xmlhttp.send(null);
+               if (!actid) {
+                       notify("Please select some feed first.");
+                       return;
+               }
 
-}
+               if (confirm("Remove current feed?")) {
+                       qfdDelete(actid);
+               }
+       
+               return;
+       }
 
-function viewfeed(feed, skip, subop) {
+       if (opid == "qmcUpdateFeeds") {
+               scheduleFeedUpdate(true);
+               return;
+       }
 
-//     document.getElementById('headlines').innerHTML='Loading headlines, please wait...';             
-//     document.getElementById('content').innerHTML='&nbsp;';          
+       if (opid == "qmcCatchupAll") {
+               catchupAllFeeds();
+               return;
+       }
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
+       if (opid == "qmcShowOnlyUnread") {
+               toggleDispRead();
+               return;
+       }
+
+       if (opid == "qmcAddFilter") {
+               displayDlg("quickAddFilter", getActiveFeedId());
+       }
+
+}
+
+function qafAdd() {
+
+       if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
                return
        }
 
-       xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
-               "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
-       xmlhttp.onreadystatechange=viewfeed_callback;
-       xmlhttp.send(null);
+       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;
 
-       notify("Loading headlines...");
+               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 view(id,feed_id) {
+function qaddFilter() {
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
+       if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
                return
        }
 
-       var crow = document.getElementById("RROW-" + id);
+       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 (crow.className.match("Unread")) {
-               var umark = document.getElementById("FEEDU-" + feed_id);
-               umark.innerHTML = umark.innerHTML - 1;
-               crow.className = crow.className.replace("Unread", "");
+       if (regexp.value.length == 0) {
+               notify("Missing filter expression.");
+       } else {
+               notify("Adding filter...");
 
-               if (umark.innerHTML == "0") {
-                       var feedr = document.getElementById("FEEDR-" + feed_id);
-                       feedr.className = feedr.className.replace("Unread", "");
-               }
-       
-               total_unread--;
+               var v_match = match[match.selectedIndex].text;
+               var feed_id = feed[feed.selectedIndex].id;
+               var action_id = action[action.selectedIndex].id;
 
-               update_title(); 
-       }       
+               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);
 
-       var upd_img_pic = document.getElementById("FUPDPIC-" + id);
+               regexp.value = "";
+       }
 
-       if (upd_img_pic) {
-               upd_img_pic.innerHTML = "";
-       } 
+}
 
-       document.getElementById('content').innerHTML='Loading, please wait...';         
 
-       xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
-       xmlhttp.onreadystatechange=view_callback;
-       xmlhttp.send(null);
+function displayDlg(id, param) {
 
-}
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
 
-function timeout() {
+       notify("");
 
-       scheduleFeedUpdate(true);
+       xmlhttp.open("GET", "backend.php?op=dlg&id=" +
+               param_escape(id) + "&param=" + param_escape(param), true);
+       xmlhttp.onreadystatechange=dlg_display_callback;
+       xmlhttp.send(null);
 
-       setTimeout("timeout()", 1800*1000);
+       disableHotkeys();
+}
 
+function closeDlg() {
+       var dlg = document.getElementById("userDlgShadow");
+       dlg.style.display = "none";
+       enableHotkeys();
 }
 
-function search(feed, sender) {
+function qfdDelete(feed_id) {
+
+       notify("Removing feed...");
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
+       if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
                return
        }
 
-       notify("Search: " + feed + ", " + sender.value)
+//     var feeds_doc = window.frames["feeds-frame"].document;
+//     feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
 
-       document.getElementById('headlines').innerHTML='Loading headlines, please wait...';             
-       document.getElementById('content').innerHTML='&nbsp;';          
+       _qfd_deleted_feed = feed_id;
 
-       xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
-               "&search=" + param_escape(sender.value) + "&subop=search", true);
-       xmlhttp.onreadystatechange=viewfeed_callback;
+       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");
+
+       var opname = chooser[chooser.selectedIndex].text;
+
+       if (opname == "Update") {
+               scheduleFeedUpdate(true);
+               return;
+       }
+
+       if (opname == "Mark as read") {
+               catchupAllFeeds();
+               return;
+       }
+
+       if (opname == "Show only unread") {
+               toggleDispRead();
+               return;
+       }
 
 }
 
-function update_title() {
-       //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
+function updateFeedTitle(t) {
+       active_title_text = t;
+       updateTitle();
 }
 
-function init() {
-       updateFeedList(false, false);
-       setTimeout("timeout()", 1800*1000);
+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);
+       }
 }
+