]> git.wh0rd.org Git - tt-rss.git/commitdiff
unify backend sanity checking code
authorAndrew Dolgov <fox@bah.org.ru>
Mon, 13 Sep 2010 11:14:18 +0000 (15:14 +0400)
committerAndrew Dolgov <fox@bah.org.ru>
Mon, 13 Sep 2010 11:14:18 +0000 (15:14 +0400)
functions.js
prefs.js
tt-rss.js

index 59ff28efb8dd8a16aa0cb7c78e09e690e5fff481..2266bfc25e528aa774e8317f2c5b912a816403f1 100644 (file)
@@ -2,6 +2,7 @@ var hotkeys_enabled = true;
 var notify_silent = false;
 var last_progress_point = 0;
 var async_counters_work = false;
+var sanity_check_done = false;
 
 /* add method to remove element from array */
 
@@ -2200,4 +2201,76 @@ function unsubscribeFeed(feed_id, title) {
 }
 
 
+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"));
+               }
+
+               console.log("sanity check ok");
+
+               var params = reply.nextSibling;
+
+               if (params) {
+                       console.log('reading init-params...');
+                       var param = params.firstChild;
+
+                       while (param) {
+                               var k = param.getAttribute("key");
+                               var v = param.getAttribute("value");
+                               console.log(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); 
+       } 
+}
+
 
index 36e4569e4933a7c2933d08ec6dd50c2905d865c4..64fe0a3d57cc37254d3a556c705da62d22bcb142 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -4,7 +4,6 @@ var active_tab = false;
 var init_params = new Array();
 
 var caller_subop = false;
-var sanity_check_done = false;
 var hotkey_prefix = false;
 var hotkey_prefix_pressed = false;
 
@@ -12,6 +11,9 @@ var color_picker_active = false;
 var selection_disabled = false;
 var mouse_is_down = false;
 
+var db = false;
+var store = false;
+
 function feedlist_callback2(transport) {
 
        try {   
@@ -1105,62 +1107,6 @@ function selectTab(id, noupdate, subop) {
        }
 }
 
-function backend_sanity_check_callback2(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) {
-                       fatalError(3, "Sanity Check: Received reply is not XML", 
-                               transport.responseText);
-                       return;
-               }
-
-               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"));
-               }
-
-               console.log("sanity check ok");
-
-               var params = reply.nextSibling;
-
-               if (params) {
-                       console.log('reading init-params...');
-                       var param = params.firstChild;
-
-                       while (param) {
-                               var k = param.getAttribute("key");
-                               var v = param.getAttribute("value");
-                               console.log(k + " => " + v);
-                               init_params[k] = v;                                     
-                               param = param.nextSibling;
-                       }
-               }
-
-               sanity_check_done = true;
-
-               init_second_stage();
-
-       } catch (e) {
-               exception_error("backend_sanity_check_callback", e);
-       }
-}
-
 function init_second_stage() {
 
        try {
@@ -1216,7 +1162,7 @@ function init() {
                new Ajax.Request("backend.php", {
                        parameters: query,
                        onComplete: function(transport) { 
-                               backend_sanity_check_callback2(transport);
+                               backend_sanity_check_callback(transport);
                        } });
 
        } catch (e) {
index e0d822512072193bb6dbc1f92172f4e1e4eab40c..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;
@@ -98,78 +97,6 @@ function dlg_frefresh_callback(transport, deleted_feed) {
        closeInfoBox();
 }
 
-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"));
-               }
-
-               console.log("sanity check ok");
-
-               var params = reply.nextSibling;
-
-               if (params) {
-                       console.log('reading init-params...');
-                       var param = params.firstChild;
-
-                       while (param) {
-                               var k = param.getAttribute("key");
-                               var v = param.getAttribute("value");
-                               console.log(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) {
 
        console.log("in scheduleFeedUpdate");