]> git.wh0rd.org - tt-rss.git/blobdiff - viewfeed.js
add quick action to edit current feed
[tt-rss.git] / viewfeed.js
index 58b7d3ecbfc6214267ff22317c67b876804c8a0b..70e8aaf0e8822aeb16399458f9b396cd794eca42 100644 (file)
@@ -1,15 +1,56 @@
 var active_post_id = false;
+var _catchup_callback_func = false;
+
+function catchup_callback() {
+       if (xmlhttp_rpc.readyState == 4) {
+               try {
+                       debug("catchup_callback");
+                       if (_catchup_callback_func) {
+                               setTimeout(_catchup_callback_func, 100);        
+                       }
+                       all_counters_callback();
+               } catch (e) {
+                       exception_error("catchup_callback", e);
+               }
+       }
+}
 
-var xmlhttp_rpc = Ajax.getTransport();
+function headlines_callback() {
+       if (xmlhttp.readyState == 4) {
+               debug("headlines_callback");
+               var f = document.getElementById("headlines-frame");
+               try {
+                       f.scrollTop = 0;
+               } catch (e) { };
+               f.innerHTML = xmlhttp.responseText;
+               update_all_counters();
+               if (typeof correctPNG != 'undefined') {
+                       correctPNG();
+               }
+               notify("");
+       }
+}
+
+function article_callback() {
+       if (xmlhttp.readyState == 4) {
+               debug("article_callback");
+               var f = document.getElementById("content-frame");
+               try {
+                       f.scrollTop = 0;
+               } catch (e) { };
+               f.innerHTML = xmlhttp.responseText;
+               if (typeof correctPNG != 'undefined') {
+                       correctPNG();
+               }
+               update_all_counters();
+       }
+}
 
 function view(id, feed_id) {
        
        try {
                debug("loading article: " + id + "/" + feed_id);
        
-               var f_document = getFeedsContext().document;
-               var m_document = parent.document;
-       
                enableHotkeys();
        
                var crow = document.getElementById("RROW-" + id);
@@ -25,16 +66,25 @@ function view(id, feed_id) {
                } 
        
                active_post_id = id; 
-               setActiveFeedId(feed_id);
-       
-               var content = m_document.getElementById("content-frame");
+               //setActiveFeedId(feed_id);
        
-               content.src = "backend.php?op=view&id=" + param_escape(id) +
-                       "&feed=" + param_escape(feed_id);
+               var content = document.getElementById("content-frame");
        
                selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
                markHeadline(active_post_id);
 
+               var query = "backend.php?op=view&id=" + param_escape(id) +
+                       "&feed=" + param_escape(feed_id);
+
+               if (xmlhttp_ready(xmlhttp)) {
+                       xmlhttp.open("GET", query, true);
+                       xmlhttp.onreadystatechange=article_callback;
+                       xmlhttp.send(null);
+               } else {
+                       debug("xmlhttp busy (@view)");
+                       printLockingError();
+               }  
+
        } catch (e) {
                exception_error("view", e);
        }
@@ -42,8 +92,6 @@ function view(id, feed_id) {
 
 function toggleMark(id) {
 
-       var f_document = parent.frames["feeds-frame"].document;
-
        if (!xmlhttp_ready(xmlhttp_rpc)) {
                printLockingError();
                return;
@@ -52,13 +100,12 @@ function toggleMark(id) {
        var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
 
        var mark_img = document.getElementById("FMARKPIC-" + id);
-       var vfeedu = f_document.getElementById("FEEDU--1");
+       var vfeedu = document.getElementById("FEEDU--1");
        var crow = document.getElementById("RROW-" + id);
 
        if (mark_img.alt != "Reset mark") {
                mark_img.src = "images/mark_set.png";
                mark_img.alt = "Reset mark";
-               mark_img.setAttribute('onclick', 'javascript:toggleMark('+id+')');
                query = query + "&mark=1";
 
                if (vfeedu && crow.className.match("Unread")) {
@@ -68,7 +115,6 @@ function toggleMark(id) {
        } else {
                mark_img.src = "images/mark_unset.png";
                mark_img.alt = "Set mark";
-               mark_img.setAttribute('onclick', 'javascript:toggleMark('+id+')');
                query = query + "&mark=0";
 
                if (vfeedu && crow.className.match("Unread")) {
@@ -77,8 +123,8 @@ function toggleMark(id) {
 
        }
 
-       var vfeedctr = f_document.getElementById("FEEDCTR--1");
-       var vfeedr = f_document.getElementById("FEEDR--1");
+       var vfeedctr = document.getElementById("FEEDCTR--1");
+       var vfeedr = document.getElementById("FEEDR--1");
 
        if (vfeedu && vfeedctr) {
                if ((+vfeedu.innerHTML) > 0) {
@@ -134,11 +180,6 @@ function moveToPost(mode) {
        } 
 }
 
-function viewfeed(id) {
-       var f = parent.frames["feeds-frame"];
-       f.viewfeed(id, 0);
-}
-
 function toggleUnread(id, cmode) {
        try {
                if (!xmlhttp_ready(xmlhttp_rpc)) {
@@ -175,7 +216,7 @@ function toggleUnread(id, cmode) {
        }
 }
 
-function selectionToggleUnread(cdm_mode) {
+function selectionToggleUnread(cdm_mode, set_state, callback_func) {
        try {
                if (!xmlhttp_ready(xmlhttp_rpc)) {
                        printLockingError();
@@ -207,11 +248,23 @@ function selectionToggleUnread(cdm_mode) {
 
                if (rows.length > 0) {
 
+                       var cmode = "";
+
+                       if (set_state == undefined) {
+                               cmode = "2";
+                       } else if (set_state == true) {
+                               cmode = "1";
+                       } else if (set_state == false) {
+                               cmode = "0";
+                       }
+
                        var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
-                               param_escape(rows.toString()) + "&cmode=2";
+                               param_escape(rows.toString()) + "&cmode=" + cmode;
+
+                       _catchup_callback_func = callback_func;
 
                        xmlhttp_rpc.open("GET", query, true);
-                       xmlhttp_rpc.onreadystatechange=all_counters_callback;
+                       xmlhttp_rpc.onreadystatechange=catchup_callback;
                        xmlhttp_rpc.send(null);
 
                }
@@ -275,7 +328,7 @@ function selectionToggleMarked(cdm_mode) {
 
 function cdmGetSelectedArticles() {
        var sel_articles = new Array();
-       var container = document.getElementById("headlinesContainer");
+       var container = document.getElementById("headlinesInnerContainer");
 
        for (i = 0; i < container.childNodes.length; i++) {
                var child = container.childNodes[i];
@@ -291,7 +344,7 @@ function cdmGetSelectedArticles() {
 
 // mode = all,none,unread
 function cdmSelectArticles(mode) {
-       var container = document.getElementById("headlinesContainer");
+       var container = document.getElementById("headlinesInnerContainer");
 
        for (i = 0; i < container.childNodes.length; i++) {
                var child = container.childNodes[i];
@@ -320,26 +373,40 @@ function cdmSelectArticles(mode) {
 }
 
 function catchupPage() {
-       selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
-       selectionToggleUnread();
-       selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
-}
 
+       if (document.getElementById("headlinesList")) {
+               selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
+               selectionToggleUnread(false, false, 'viewCurrentFeed()');
+               selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
+       } else {
+               cdmSelectArticles('all');
+               selectionToggleUnread(true, false, 'viewCurrentFeed()')
+               cdmSelectArticles('none');
+       }
+}
 
-function init() {
-       if (arguments.callee.done) return;
-       arguments.callee.done = true;           
+function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
 
-       if (parent.frames["feeds-frame"]) {
-               document.onkeydown = hotkey_handler;
+       if (!xmlhttp_ready(xmlhttp_rpc)) {
+               printLockingError();
        }
 
-       var hw = document.getElementById("headlinesList").scrollHeight;
-       var pw = parent.document.getElementById("headlines").scrollHeight;
+       var title = prompt("Please enter label title:", "");
 
-       if (hw >= pw) {
-               var bt = document.getElementById("headlineActionsBottom");
-               bt.className = "headlinesSubToolbar";
-       }
+       if (title) {
+
+               var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
+                       "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
+                       "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) + 
+                       "&title=" + param_escape(title);
+
+               debug("LFS: " + query);
        
+               xmlhttp_rpc.open("GET", query, true);
+               xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
+               xmlhttp_rpc.send(null);
+       }
+
 }
+
+