]> git.wh0rd.org - tt-rss.git/blobdiff - tt-rss.js
more cookie magic, basic sanity checks on init()
[tt-rss.git] / tt-rss.js
index 788750afa4bcd1bb2865691778fc9ace104ca3ad..4f532d60a194100269341bf740aa259833ad7422 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -6,6 +6,9 @@
 var xmlhttp = false;
 
 var total_unread = 0;
+var first_run = true;
+
+var search_query = "";
 
 /*@cc_on @*/
 /*@if (@_jscript_version >= 5)
@@ -26,164 +29,304 @@ if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
 }
 
+/*
 function feedlist_callback() {
        var container = document.getElementById('feeds');
        if (xmlhttp.readyState == 4) {
                container.innerHTML=xmlhttp.responseText;
 
-               var feedtu = document.getElementById("FEEDTU");
+               if (first_run) {
+                       scheduleFeedUpdate(false);
+                       if (getCookie("ttrss_vf_actfeed")) {
+                               viewfeed(getCookie("ttrss_vf_actfeed"), 0, "");
+                       }
+                       first_run = false;
+               } else {
+                       notify("");
+               } 
+       } 
+}
+*/
 
-               if (feedtu) {
-                       total_unread = feedtu.innerHTML;
-                       update_title();
-               }
+function refetch_callback() {
 
-               notify("");
-       }
+       if (xmlhttp.readyState == 4) {
+
+               document.title = "Tiny Tiny RSS";
+               notify("All feeds updated.");
+
+               updateFeedList();
+               
+       } 
 }
 
-function viewfeed_callback() {
-       var container = document.getElementById('headlines');
-       if (xmlhttp.readyState == 4) {
-               container.innerHTML = xmlhttp.responseText;
 
-               var factive = document.getElementById("FACTIVE");
-               var funread = document.getElementById("FUNREAD");
-               var ftotal = document.getElementById("FTOTAL");
+function updateFeed(feed_id) {
 
-               if (ftotal && factive && funread) {
-                       var feed_id = factive.innerHTML;
+       var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
 
-                       var feedr = document.getElementById("FEEDR-" + feed_id);
-                       var feedt = document.getElementById("FEEDT-" + feed_id);
-                       var feedu = document.getElementById("FEEDU-" + feed_id);
+       if (xmlhttp_ready(xmlhttp)) {
+               xmlhttp.open("GET", query_str, true);
+               xmlhttp.onreadystatechange=feed_update_callback;
+               xmlhttp.send(null);
+       } else {
+               printLockingError();
+       }   
 
-                       feedt.innerHTML = ftotal.innerHTML;
-                       feedu.innerHTML = funread.innerHTML;
+}
 
-                       if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
-                                       feedr.className = feedr.className + "Unread";
-                       } else if (feedu.innerHTML <= 0) {      
-                                       feedr.className = feedr.className.replace("Unread", "");
-                       }
+function scheduleFeedUpdate(force) {
 
-               }
+       notify("Updating feeds in background...");
 
-               notify("");
+       document.title = "Tiny Tiny RSS - Updating...";
 
-       }       
-}
+       var query_str = "backend.php?op=rpc&subop=";
 
-function view_callback() {
-       var container = document.getElementById('content');
-       if (xmlhttp.readyState == 4) {
-               container.innerHTML=xmlhttp.responseText;               
+       if (force) {
+               query_str = query_str + "forceUpdateAllFeeds";
+       } else {
+               query_str = query_str + "updateAllFeeds";
        }
+
+       if (xmlhttp_ready(xmlhttp)) {
+               xmlhttp.open("GET", query_str, true);
+               xmlhttp.onreadystatechange=refetch_callback;
+               xmlhttp.send(null);
+       } else {
+               printLockingError();
+       }   
 }
 
+function updateFeedList(silent, fetch) {
 
-function updateFeedList(called_from_timer, fetch) {
-
-       if (called_from_timer != true) {
-               //document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
-               notify("Updating feeds...");
-       }
+//     if (silent != true) {
+//             notify("Loading feed list...");
+//     }
 
        var query_str = "backend.php?op=feeds";
 
+       if (getActiveFeedId()) {
+               query_str = query_str + "&actid=" + getActiveFeedId();
+       }
+
        if (fetch) query_str = query_str + "&fetch=yes";
 
-       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...");
 
-       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 viewCurrentFeed(skip, subop) {
+
+       if (getActiveFeedId()) {
+               viewfeed(getActiveFeedId(), skip, subop);
+       }
+}
+
 function viewfeed(feed, skip, subop) {
 
-//     document.getElementById('headlines').innerHTML='Loading headlines, please wait...';             
-//     document.getElementById('content').innerHTML='&nbsp;';          
+//     notify("Loading headlines...");
 
-       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);
+       enableHotkeys();
 
-       notify("Loading headlines...");
+       var searchbox = document.getElementById("searchbox");
 
-}
+       if (searchbox) {
+               search_query = searchbox.value;
+       } else {
+               search_query = "";
+       } 
+
+       var viewbox = document.getElementById("viewbox");
+
+       var view_mode;
 
-function view(id,feed_id) {
+       if (viewbox) {
+               view_mode = viewbox[viewbox.selectedIndex].text;
+       } else {
+               view_mode = "All Posts";
+       }
+
+       setCookie("ttrss_vf_vmode", view_mode);
+
+       var limitbox = document.getElementById("limitbox");
+
+       var limit;
+
+       if (limitbox) {
+               limit = limitbox[limitbox.selectedIndex].text;
+               setCookie("ttrss_vf_limit", limit);
+       } else {
+               limit = "All";
+       }
 
-       var crow = document.getElementById("RROW-" + id);
+       setActiveFeedId(feed);
 
-       if (crow.className.match("Unread")) {
-               var umark = document.getElementById("FEEDU-" + feed_id);
-               umark.innerHTML = umark.innerHTML - 1;
-               crow.className = crow.className.replace("Unread", "");
+       var f_doc = frames["feeds-frame"].document;
 
-               if (umark.innerHTML == "0") {
-                       var feedr = document.getElementById("FEEDR-" + feed_id);
+//     f_doc.getElementById("ACTFEEDID").innerHTML = feed;
+
+       if (subop == "MarkAllRead") {
+
+               var feedr = f_doc.getElementById("FEEDR-" + feed);
+               var feedctr = f_doc.getElementById("FEEDCTR-" + feed);
+               
+               feedctr.className = "invisible";
+
+               if (feedr.className.match("Unread")) {
                        feedr.className = feedr.className.replace("Unread", "");
                }
-       
-               total_unread--;
+       }
 
-               update_title(); 
-       }       
+       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;
 
-       var upd_img_pic = document.getElementById("FUPDPIC-" + id);
+       if (search_query != "") {
+               query = query + "&search=" + param_escape(search_query);
+       }
+       
+       var headlines_frame = parent.frames["headlines-frame"];
 
-       if (upd_img_pic) {
-               upd_img_pic.innerHTML = "";
-       } 
+       headlines_frame.location.href = query + "&addheader=true";
 
-       document.getElementById('content').innerHTML='Loading, please wait...';         
+       cleanSelected("feedsList");
+       var feedr = document.getElementById("FEEDR-" + feed);
+       if (feedr) {
+               feedr.className = feedr.className + "Selected";
+       }
+       
+       disableContainerChildren("headlinesToolbar", false, doc);
 
-       xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
-       xmlhttp.onreadystatechange=view_callback;
-       xmlhttp.send(null);
+//     notify("");
 
 }
 
+
 function timeout() {
+       scheduleFeedUpdate(true);
+       setTimeout("timeout()", 1800*1000);
+}
 
-       updateFeedList(true);
+function resetSearch() {
+       var searchbox = document.getElementById("searchbox")
 
-       setTimeout("timeout()", 1800*1000);
+       if (searchbox.value != "" && getActiveFeedId()) {       
+               searchbox.value = "";
+               viewfeed(getActiveFeedId(), 0, "");
+       }
+}
 
+function search() {
+       checkActiveFeedId();
+       if (getActiveFeedId()) {
+               viewfeed(getActiveFeedId(), 0, "");
+       } else {
+               notify("Please select some feed first.");
+       }
 }
 
-function search(feed, sender) {
+function localPiggieFunction(enable) {
+       if (enable) {
+               var query_str = "backend.php?op=feeds&subop=piggie";
+
+               if (xmlhttp_ready(xmlhttp)) {
+
+                       xmlhttp.open("GET", query_str, true);
+                       xmlhttp.onreadystatechange=feedlist_callback;
+                       xmlhttp.send(null);
+               }
+       }
+}
 
-       notify("Search: " + feed + ", " + sender.value)
+function localHotkeyHandler(keycode) {
+
+/*     if (keycode == 78) {
+               return moveToPost('next');
+       }
+
+       if (keycode == 80) {
+               return moveToPost('prev');
+       } */
+
+       if (keycode == 82) {
+               return scheduleFeedUpdate(true);
+       }
 
-       document.getElementById('headlines').innerHTML='Loading headlines, please wait...';             
-       document.getElementById('content').innerHTML='&nbsp;';          
+       if (keycode == 85) {
+               return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
+       }
 
-       xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
-               "&search=" + param_escape(sender.value) + "&ext=SEARCH", true);
-       xmlhttp.onreadystatechange=viewfeed_callback;
-       xmlhttp.send(null);
+//     notify("KC: " + keycode);
 
 }
 
-function update_title() {
-       //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
+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;
+       }
+
+       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;
+       }
+
+       return true;
 }
 
 function init() {
+
+       disableContainerChildren("headlinesToolbar", true);
+
+       if (!genericSanityCheck()) 
+               return;
+
        updateFeedList(false, false);
+       document.onkeydown = hotkey_handler;
+
        setTimeout("timeout()", 1800*1000);
+       scheduleFeedUpdate(true);
+
+       var content = document.getElementById("content");
+
+       if (getCookie("ttrss_vf_vmode")) {
+               var viewbox = document.getElementById("viewbox");
+               viewbox.value = getCookie("ttrss_vf_vmode");
+       }
+
+       if (getCookie("ttrss_vf_limit")) {
+               var limitbox = document.getElementById("limitbox");
+               limitbox.value = getCookie("ttrss_vf_limit");
+       }
+
+//     if (getCookie("ttrss_vf_actfeed")) {
+//             viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
+//     }
+
+       setCookie("ttrss_vf_actfeed", "");
+
 }
+
+