]> git.wh0rd.org - tt-rss.git/blobdiff - tt-rss.js
unify backend sanity checking code
[tt-rss.git] / tt-rss.js
index aeb63eb0fa63d4ca77adf54b2601ff9ac1e6bc9e..44175488dad97549fbc9fab0fd0687e423625aba 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -12,7 +12,6 @@ var firsttime_update = true;
 var _active_feed_id = 0;
 var _active_feed_is_cat = false;
 var number_of_feeds = 0;
-var sanity_check_done = false;
 var _hfd_scrolltop = 0;
 var hotkey_prefix = false;
 var hotkey_prefix_pressed = false;
@@ -28,7 +27,7 @@ function activeFeedIsCat() {
 
 function getActiveFeedId() {
        try {
-               debug("gAFID: " + _active_feed_id);
+               console.log("gAFID: " + _active_feed_id);
                return _active_feed_id;
        } catch (e) {
                exception_error("getActiveFeedId", e);
@@ -37,7 +36,7 @@ function getActiveFeedId() {
 
 function setActiveFeedId(id, is_cat) {
        try {
-               debug("sAFID(" + id + ", " + is_cat + ")");
+               console.log("sAFID(" + id + ", " + is_cat + ")");
                _active_feed_id = id;
 
                if (is_cat != undefined) {
@@ -62,7 +61,7 @@ function toggleTags(show_all) {
 
        try {
 
-       debug("toggleTags: " + show_all + "; " + display_tags);
+       console.log("toggleTags: " + show_all + "; " + display_tags);
 
        var p = $("dispSwitchPrompt");
 
@@ -98,102 +97,9 @@ function dlg_frefresh_callback(transport, deleted_feed) {
        closeInfoBox();
 }
 
-function refetch_callback2(transport) {
-       try {
-
-               var date = new Date();
-
-               parse_counters_reply(transport, true);
-
-               debug("refetch_callback2: done");
-
-/*             if (!daemon_enabled && !daemon_refresh_only) {
-                       notify_info("All feeds updated.");
-                       updateTitle("");
-               } else {
-                       //notify("");
-               } */
-       } catch (e) {
-               exception_error("refetch_callback", e);
-               updateTitle("");
-       }
-}
-
-function backend_sanity_check_callback(transport) {
-
-       try {
-
-               if (sanity_check_done) {
-                       fatalError(11, "Sanity check request received twice. This can indicate "+
-                     "presence of Firebug or some other disrupting extension. "+
-                               "Please disable it and try again.");
-                       return;
-               }
-
-               if (!transport.responseXML) {
-                       if (!store) {
-                               fatalError(3, "Sanity check: Received reply is not XML", 
-                                       transport.responseText);
-                               return;
-                       } else {
-                               init_offline();
-                               return;
-                       }
-               }
-
-               if (getURLParam("offline")) {
-                       return init_offline();
-               }
-
-               var reply = transport.responseXML.firstChild.firstChild;
-
-               if (!reply) {
-                       fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
-                       return;
-               }
-
-               var error_code = reply.getAttribute("error-code");
-       
-               if (error_code && error_code != 0) {
-                       return fatalError(error_code, reply.getAttribute("error-msg"));
-               }
-
-               debug("sanity check ok");
-
-               var params = reply.nextSibling;
-
-               if (params) {
-                       debug('reading init-params...');
-                       var param = params.firstChild;
-
-                       while (param) {
-                               var k = param.getAttribute("key");
-                               var v = param.getAttribute("value");
-                               debug(k + " => " + v);
-                               init_params[k] = v;                                     
-
-                               if (db) {
-                                       db.execute("DELETE FROM init_params WHERE key = ?", [k]);
-                                       db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
-                                               [k, v]);
-                               }
-
-                               param = param.nextSibling;
-                       }
-               }
-
-               sanity_check_done = true;
-
-               init_second_stage();
-
-       } catch (e) {
-               exception_error("backend_sanity_check_callback", e, transport); 
-       } 
-}
-
 function scheduleFeedUpdate(force) {
 
-       debug("in scheduleFeedUpdate");
+       console.log("in scheduleFeedUpdate");
 
 /*     if (!daemon_enabled && !daemon_refresh_only) {
                notify_progress("Updating feeds...", true);
@@ -223,16 +129,12 @@ function scheduleFeedUpdate(force) {
        query_str = query_str + "&omode=" + omode;
        query_str = query_str + "&uctr=" + global_unread;
 
-       var date = new Date();
-       var timestamp = Math.round(date.getTime() / 1000);
-       query_str = query_str + "&ts=" + timestamp
-
-       debug("REFETCH query: " + query_str);
+       console.log("REFETCH query: " + query_str);
 
        new Ajax.Request("backend.php", {
                parameters: query_str,
                onComplete: function(transport) { 
-                               refetch_callback2(transport); 
+                               parse_counters_reply(transport, true);
                        } });
 }
 
@@ -242,7 +144,7 @@ function updateFeedList(silent, fetch) {
 //             notify("Loading feed list...");
 //     }
 
-       debug("<b>updateFeedList</b>");
+       console.log("<b>updateFeedList</b>");
 
        if (offline_mode) return render_offline_feedlist();
 
@@ -255,17 +157,13 @@ function updateFeedList(silent, fetch) {
        if (getActiveFeedId() && !activeFeedIsCat()) {
                query_str = query_str + "&actid=" + getActiveFeedId();
        }
-
-       var date = new Date();
-       var timestamp = Math.round(date.getTime() / 1000);
-       query_str = query_str + "&ts=" + timestamp
        
        if (fetch) query_str = query_str + "&fetch=yes";
 
 //     var feeds_frame = $("feeds-frame");
 //     feeds_frame.src = query_str;
 
-       debug("updateFeedList Q=" + query_str);
+       console.log("updateFeedList Q=" + query_str);
 
        new Ajax.Request("backend.php", {
                parameters: query_str,
@@ -285,7 +183,7 @@ function catchupAllFeeds() {
 
                notify_progress("Marking all feeds as read...");
 
-               debug("catchupAllFeeds Q=" + query_str);
+               console.log("catchupAllFeeds Q=" + query_str);
 
                new Ajax.Request("backend.php", {
                        parameters: query_str,
@@ -304,7 +202,6 @@ function viewCurrentFeed(subop) {
        if (getActiveFeedId() != undefined) {
                viewfeed(getActiveFeedId(), subop, activeFeedIsCat());
        } else {
-               disableContainerChildren("headlinesToolbar", false, document);
 //             viewfeed(-1, subop); // FIXME
        }
        return false; // block unneeded form submits
@@ -336,10 +233,6 @@ function resetSearch() {
        }
 }
 
-function searchCancel() {
-       closeInfoBox(true);
-}
-
 function search() {
        closeInfoBox(); 
        viewCurrentFeed(0, "");
@@ -366,6 +259,14 @@ function updateTitle(s) {
                tmp = tmp + " > " + active_title_text;
        }
 
+       if (window.fluid) {
+               if (global_unread > 0) {
+                       window.fluid.dockBadge = global_unread;
+               } else {
+                       window.fluid.dockBadge = "";
+               }
+       }
+
        document.title = tmp;
 }
 
@@ -388,8 +289,6 @@ function init() {
 
                init_gears();
 
-               disableContainerChildren("headlinesToolbar", true);
-
                Form.disable("main_toolbar_form");
 
                if (!genericSanityCheck()) 
@@ -397,7 +296,7 @@ function init() {
 
                if (getURLParam('debug')) {
                        Element.show("debug_output");
-                       debug('debug mode activated');
+                       console.log('debug mode activated');
                }
 
                var params = "&ua=" + param_escape(navigator.userAgent);
@@ -419,7 +318,7 @@ function resize_headlines(delta_x, delta_y) {
 
        try {
 
-               debug("resize_headlines: " + delta_x + ":" + delta_y);
+               console.log("resize_headlines: " + delta_x + ":" + delta_y);
        
                var h_frame = $("headlines-frame");
                var c_frame = $("content-frame");
@@ -430,11 +329,11 @@ function resize_headlines(delta_x, delta_y) {
 
                if (!c_frame || !h_frame) return;
        
-               if (feeds_frame && getInitParam("theme") == "compat") {
+               if (feeds_frame && getInitParam("theme") == "old-skool") {
                                feeds_frame.style.bottom = f_frame.offsetHeight + "px";         
                }
        
-               if (getInitParam("theme") == "3pane") {
+               if (getInitParam("theme_options").match("horiz_resize")) {
        
                        if (delta_x != undefined) {
                                if (c_frame.offsetLeft - delta_x > feeds_frame.offsetWidth + feeds_frame.offsetLeft + 100 && c_frame.offsetWidth + delta_x > 100) {
@@ -442,7 +341,7 @@ function resize_headlines(delta_x, delta_y) {
                                }
                        }
        
-                       debug("resize_headlines: HOR-mode: " + hor_offset);
+                       console.log("resize_headlines: HOR-mode: " + hor_offset);
        
                        c_frame.style.width = (400 + hor_offset) + "px";
                        h_frame.style.right = c_frame.offsetWidth - 1 + "px";
@@ -452,7 +351,7 @@ function resize_headlines(delta_x, delta_y) {
                                4) + "px";
                        resize_grab.style.display = "block";
 
-                       resize_handle.src = "themes/3pane/images/resize_handle_vert.png";
+                       //resize_handle.src = "themes/"+getInitParam('theme')+"/images/resize_handle_vert.png";
                        resize_handle.style.paddingTop = (resize_grab.offsetHeight / 2 - 7) + "px";
        
                } else {
@@ -463,27 +362,13 @@ function resize_headlines(delta_x, delta_y) {
                                }
                        }
        
-                       debug("resize_headlines: VER-mode: " + ver_offset);
+                       console.log("resize_headlines: VER-mode: " + ver_offset);
        
                        h_frame.style.height = (300 - ver_offset) + "px";
        
                        c_frame.style.top = (h_frame.offsetTop + h_frame.offsetHeight + 0) + "px";
                        h_frame.style.height = h_frame.offsetHeight + "px";
-       
-                       var theme_c = 0;
-       
-                       if (getInitParam("theme") == "graycube") {
-                               theme_c = 1;
-                       }
 
-                       if (getInitParam("theme") == "graycube" || getInitParam("theme") == "compat") {
-                               resize_handle.src = "themes/graycube/images/resize_handle_horiz.png";
-                       }
-       
-/*                     resize_grab.style.top = (h_frame.offsetTop + h_frame.offsetHeight - 
-                               4 - theme_c) + "px";
-                       resize_grab.style.display = "block"; */
-       
                }
        
                if (getInitParam("cookie_lifetime") != 0) {
@@ -535,21 +420,21 @@ function init_second_stage() {
 
                setTimeout('updateFeedList(false, false)', 50);
 
-               debug("second stage ok");
+               console.log("second stage ok");
 
                loading_set_progress(60);
 
                ver_offset = parseInt(getCookie("ttrss_offset_ver"));
                hor_offset = parseInt(getCookie("ttrss_offset_hor"));
 
-               debug("got offsets from cookies: ver " + ver_offset + " hor " + hor_offset);
+               console.log("got offsets from cookies: ver " + ver_offset + " hor " + hor_offset);
 
                /* fuck IE */
 
                if (isNaN(hor_offset)) hor_offset = 0;
                if (isNaN(ver_offset)) ver_offset = 0;
 
-               debug("offsets from cookies [x:y]: " + hor_offset + ":" + ver_offset);
+               console.log("offsets from cookies [x:y]: " + hor_offset + ":" + ver_offset);
 
                resize_headlines();
 
@@ -576,12 +461,15 @@ function quickMenuGo(opid) {
                }
        
                if (opid == "qmcSearch") {
-                       displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
+                       displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(), 
+                               function() { 
+                                       document.forms['search_form'].query.focus();
+                               });
                        return;
                }
        
                if (opid == "qmcAddFeed") {
-                       displayDlg("quickAddFeed");
+                       quickAddFeed();
                        return;
                }
 
@@ -613,31 +501,6 @@ function quickMenuGo(opid) {
                        return;
                }
 
-               if (opid == "qmcClearFeed") {
-                       var actid = getActiveFeedId();
-
-                       if (!actid) {
-                               alert(__("Please select some feed first."));
-                               return;
-                       }
-
-                       if (activeFeedIsCat() || actid < 0) {
-                               alert(__("You can't clear this type of feed."));
-                               return;
-                       }       
-
-                       var fn = getFeedName(actid);
-
-                       var pr = __("Erase all non-starred articles in %s?").replace("%s", fn);
-
-                       if (confirm(pr)) {
-                               clearFeedArticles(actid);
-                       }
-               
-                       return;
-               }
-       
-
                if (opid == "qmcUpdateFeeds") {
                        scheduleFeedUpdate(true);
                        return;
@@ -654,7 +517,8 @@ function quickMenuGo(opid) {
                }
        
                if (opid == "qmcAddFilter") {
-                       displayDlg("quickAddFilter", getActiveFeedId());
+                       displayDlg('quickAddFilter', '',
+                          function () {document.forms['filter_add_form'].reg_exp.focus();});
                }
 
                if (opid == "qmcAddLabel") {
@@ -676,6 +540,18 @@ function quickMenuGo(opid) {
                        resize_headlines();
                }
 
+               if (opid == "qmcToggleReorder") {
+                       feedlist_sortable_enabled = !feedlist_sortable_enabled;
+
+                       if (feedlist_sortable_enabled) {
+                               notify_info("Category reordering enabled");
+                               toggle_sortable_feedlist(true);
+                       } else {
+                               notify_info("Category reordering disabled");
+                               toggle_sortable_feedlist(false);
+                       }
+               }
+
                if (opid == "qmcResetCats") {
 
                        if (confirm(__("Reset category order?"))) {
@@ -697,27 +573,6 @@ function quickMenuGo(opid) {
        }
 }
 
-function unsubscribeFeed(feed_id, title) {
-
-
-       var msg = __("Unsubscribe from %s?").replace("%s", title);
-
-       if (title == undefined || confirm(msg)) {
-               notify_progress("Removing feed...");
-
-               var query = "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id;
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                                       dlg_frefresh_callback(transport, feed_id);
-                               } });
-       }
-
-       return false;
-}
-
-
 function updateFeedTitle(t) {
        active_title_text = t;
        updateTitle();
@@ -746,19 +601,19 @@ function toggleDispRead() {
 
 function parse_runtime_info(elem) {
        if (!elem) {
-               debug("parse_runtime_info: elem is null, aborting");
+               console.log("parse_runtime_info: elem is null, aborting");
                return;
        }
 
        var param = elem.firstChild;
 
-       debug("parse_runtime_info: " + param);
+       console.log("parse_runtime_info: " + param);
 
        while (param) {
                var k = param.getAttribute("key");
                var v = param.getAttribute("value");
 
-               debug("RI: " + k + " => " + v);
+               console.log("RI: " + k + " => " + v);
 
                if (k == "num_feeds") {
                        init_params[k] = v;                                     
@@ -861,6 +716,7 @@ function editFeedDlg(feed) {
                        parameters: query,
                        onComplete: function(transport) { 
                                infobox_callback2(transport); 
+                               document.forms["edit_feed_form"].title.focus();
                        } });
 
        } catch (e) {
@@ -892,7 +748,7 @@ function feedEditSave() {
                                dlg_frefresh_callback(transport); 
                        } });
 
-
+               cache_flush();
                closeInfoBox();
 
                return false;
@@ -902,28 +758,13 @@ function feedEditSave() {
        } 
 }
 
-function clearFeedArticles(feed_id) {
-
-       notify_progress("Clearing feed...");
-
-       var query = "?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
-
-       new Ajax.Request("backend.php", {
-               parameters: query,
-               onComplete: function(transport) {
-                               dlg_frefresh_callback(transport, feed_id);
-                       } });
-
-       return false;
-}
-
 function collapse_feedlist() {
        try {
-               debug("collapse_feedlist");
+               console.log("collapse_feedlist");
                
                var theme = getInitParam("theme");
-               if (theme != "" && theme != "compact" && theme != "graycube" &&
-                               theme != "compat") return;
+               if (theme != "" && 
+                               !getInitParam("theme_options").match("collapse_feedlist")) return;
 
                var fl = $("feeds-holder");
                var fh = $("headlines-frame");
@@ -986,12 +827,12 @@ function collapse_feedlist() {
 }
 
 function viewModeChanged() {
-       cache_empty();
+       cache_flush();
        return viewCurrentFeed(0, '')
 }
 
 function viewLimitChanged() {
-       cache_empty();
+       cache_flush();
        return viewCurrentFeed(0, '')
 }
 
@@ -1078,7 +919,7 @@ function hotkey_handler(e) {
                } 
 
                if (!hotkeys_enabled) {
-                       debug("hotkeys disabled");
+                       console.log("hotkeys disabled");
                        return;
                }
 
@@ -1096,7 +937,7 @@ function hotkey_handler(e) {
                        cmdline.innerHTML = keychar;
                        Element.show(cmdline);
 
-                       debug("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
+                       console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
                        return true;
                }
 
@@ -1113,7 +954,7 @@ function hotkey_handler(e) {
                        if (keycode == 68 && shift_key) { // d
                                if (!Element.visible("debug_output")) {
                                        Element.show("debug_output");
-                                       debug('debug mode activated');
+                                       console.log('debug mode activated');
                                } else {
                                        Element.hide("debug_output");
                                }
@@ -1132,7 +973,10 @@ function hotkey_handler(e) {
                        }
 
                        if (keycode == 191 || keychar == '/') { // /
-                               displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
+                               displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(), 
+                                       function() { 
+                                               document.forms['search_form'].query.focus();
+                                       });
                                return false;
                        }
 
@@ -1318,7 +1162,7 @@ function hotkey_handler(e) {
                        }
 
                        if (keycode == 83) { // s
-                               displayDlg("quickAddFeed");
+                               quickAddFeed();
                                return false;
                        }
 
@@ -1346,6 +1190,10 @@ function hotkey_handler(e) {
                                return;
                        }
 
+                       if (keycode == 88) { // x
+                               reverseHeadlineOrder();
+                               return;
+                       }
                }
 
                /* Prefix c */
@@ -1354,7 +1202,8 @@ function hotkey_handler(e) {
                        hotkey_prefix = false;
 
                        if (keycode == 70) { // f
-                               displayDlg("quickAddFilter", getActiveFeedId());
+                               displayDlg('quickAddFilter', '',
+                                  function () {document.forms['filter_add_form'].reg_exp.focus();});
                                return false;
                        }
 
@@ -1440,9 +1289,9 @@ function hotkey_handler(e) {
                }
 
                if (hotkey_prefix) {
-                       debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
+                       console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
                } else {
-                       debug("KP: CODE=" + keycode + " CHAR=" + keychar);
+                       console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
                }
 
 
@@ -1455,72 +1304,22 @@ function feedsSortByUnread() {
        return feeds_sort_by_unread;
 }
 
-function addLabel() {
-
-       try {
-
-               var caption = prompt(__("Please enter label caption:"), "");
-
-               if (caption != undefined) {
-       
-                       if (caption == "") {
-                               alert(__("Can't create label: missing caption."));
-                               return false;
-                       }
-
-                       var query = "?op=pref-labels&subop=add&caption=" + 
-                               param_escape(caption);
-
-                       notify_progress("Loading, please wait...", true);
-
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) { 
-                                       updateFeedList();
-                       } });
-
-               }
-
-       } catch (e) {
-               exception_error("addLabel", e);
-       }
-}
-
-function visitOfficialSite() {
-       window.open("http://tt-rss.org/");
+function inPreferences() {
+       return false;
 }
 
-
-function feedBrowserSubscribe() {
+function reverseHeadlineOrder() {
        try {
 
-               var selected = getSelectedFeedsFromBrowser();
-
-               var mode = document.forms['feed_browser'].mode;
-
-               mode = mode[mode.selectedIndex].value;
-
-               if (selected.length > 0) {
-                       closeInfoBox();
-
-                       notify_progress("Loading, please wait...", true);
-
-                       var query = "?op=pref-feeds&subop=massSubscribe&ids="+
-                               param_escape(selected.toString()) + "&mode=" + param_escape(mode);
+               var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
 
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) { 
-                                       updateFeedList();
+               new Ajax.Request("backend.php", {
+                       parameters: query_str,
+                       onComplete: function(transport) { 
+                                       viewCurrentFeed();
                                } });
 
-               } else {
-                       alert(__("No feeds are selected."));
-               }
-
        } catch (e) {
-               exception_error("feedBrowserSubscribe", e);
+               exception_error("reverseHeadlineOrder", e);
        }
 }
-
-