]> git.wh0rd.org - tt-rss.git/blobdiff - js/functions.js
use xhrPost in more places; various minor cleanup
[tt-rss.git] / js / functions.js
index d46d22c0b810fb890eb1bb462f2aa2d84e9ceff6..7fbb4e75d59641ab0c83df45c5f63b2617ee3a1a 100755 (executable)
@@ -1,10 +1,9 @@
 /* global dijit, __ */
 
-var loading_progress = 0;
-var sanity_check_done = false;
-var init_params = {};
-var _label_base_index = -1024;
-var notify_hide_timerid = false;
+let init_params = {};
+let _label_base_index = -1024;
+let loading_progress = 0;
+let notify_hide_timerid = false;
 
 Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
        function (callOriginal, options) {
@@ -24,6 +23,29 @@ Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
        }
 );
 
+/* xhr shorthand helpers */
+
+function xhrPost(url, params, complete) {
+       console.log("xhrPost:", params);
+    new Ajax.Request(url, {
+        parameters: params,
+        onComplete: complete
+    });
+}
+
+function xhrJson(url, params, complete) {
+    xhrPost(url, params, (reply) => {
+        try {
+            const obj = JSON.parse(reply.responseText);
+            complete(obj);
+        } catch (e) {
+            console.error("xhrJson", e, reply);
+            complete(null);
+        }
+
+    })
+}
+
 /* add method to remove element from array */
 
 Array.prototype.remove = function(s) {
@@ -46,14 +68,14 @@ function exception_error(e, e_compat, filename, lineno, colno) {
                const msg = e.toString();
 
                try {
-                       new Ajax.Request("backend.php", {
-                               parameters: {op: "rpc", method: "log",
+                       xhrPost("backend.php",
+                               {op: "rpc", method: "log",
                                        file: e.fileName ? e.fileName : filename,
                                        line: e.lineNumber ? e.lineNumber : lineno,
                                        msg: msg, context: e.stack},
-                               onComplete: function (transport) {
+                               (transport) => {
                                        console.warn(transport.responseText);
-                               } });
+                               });
 
                } catch (e) {
                        console.error("Exception while trying to log the error.", e);
@@ -581,7 +603,7 @@ function quickAddFeed() {
        if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
        if (dijit.byId("feedAddDlg"))   dijit.byId("feedAddDlg").destroyRecursive();
 
-       var dialog = new dijit.Dialog({
+       const dialog = new dijit.Dialog({
                id: "feedAddDlg",
                title: __("Subscribe to Feed"),
                style: "width: 600px",
@@ -931,7 +953,7 @@ function quickAddFilter() {
        if (dijit.byId("filterEditDlg"))
                dijit.byId("filterEditDlg").destroyRecursive();
 
-       var dialog = new dijit.Dialog({
+       const dialog = new dijit.Dialog({
                id: "filterEditDlg",
                title: __("Create Filter"),
                style: "width: 600px",
@@ -1082,13 +1104,6 @@ function unsubscribeFeed(feed_id, title) {
 
 function backend_sanity_check_callback(transport) {
 
-       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;
-       }
-
        const reply = JSON.parse(transport.responseText);
 
        if (!reply) {
@@ -1120,10 +1135,7 @@ function backend_sanity_check_callback(transport) {
                window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params);
        }
 
-       sanity_check_done = true;
-
        init_second_stage();
-
 }
 
 function genUrlChangeKey(feed, is_cat) {
@@ -1249,7 +1261,7 @@ function editFeed(feed) {
        if (dijit.byId("feedEditDlg"))
                dijit.byId("feedEditDlg").destroyRecursive();
 
-       var dialog = new dijit.Dialog({
+       const dialog = new dijit.Dialog({
                id: "feedEditDlg",
                title: __("Edit Feed"),
                style: "width: 600px",
@@ -1282,7 +1294,7 @@ function feedBrowser() {
        if (dijit.byId("feedBrowserDlg"))
                dijit.byId("feedBrowserDlg").destroyRecursive();
 
-       var dialog = new dijit.Dialog({
+       const dialog = new dijit.Dialog({
                id: "feedBrowserDlg",
                title: __("More Feeds"),
                style: "width: 600px",
@@ -1362,15 +1374,11 @@ function feedBrowser() {
 
                                        Element.hide('feed_browser_spinner');
 
-                                       const c = $("browseFeedList");
-
                                        const reply = JSON.parse(transport.responseText);
-
-                                       const r = reply['content'];
                                        const mode = reply['mode'];
 
-                                       if (c && r) {
-                                               c.innerHTML = r;
+                                       if ($("browseFeedList") && reply['content']) {
+                        $("browseFeedList").innerHTML = reply['content'];
                                        }
 
                                        dojo.parser.parse("browseFeedList");
@@ -1424,7 +1432,7 @@ function showFeedsWithErrors() {
        if (dijit.byId("errorFeedsDlg"))
                dijit.byId("errorFeedsDlg").destroyRecursive();
 
-       var dialog = new dijit.Dialog({
+       const dialog = new dijit.Dialog({
                id: "errorFeedsDlg",
                title: __("Feeds with update errors"),
                style: "width: 600px",