]> 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 9028482f8f166fdac2746c694a30a89cdc0b8b65..7fbb4e75d59641ab0c83df45c5f63b2617ee3a1a 100755 (executable)
@@ -1,8 +1,9 @@
-var loading_progress = 0;
-var sanity_check_done = false;
-var init_params = {};
-var _label_base_index = -1024;
-var notify_hide_timerid = false;
+/* global dijit, __ */
+
+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) {
@@ -22,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) {
@@ -44,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);
@@ -459,12 +483,7 @@ function loading_set_progress(p) {
 }
 
 function remove_splash() {
-
-       if (Element.visible("overlay")) {
-               console.log("about to remove splash, OMG!");
-               Element.hide("overlay");
-               console.log("removed splash!");
-       }
+       Element.hide("overlay");
 }
 
 function strip_tags(s) {
@@ -584,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",
@@ -850,9 +869,9 @@ function editFilterTest(query) {
                                                const result = JSON.parse(transport.responseText);
 
                                                if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
-                                                       test_dlg.results += result.size();
+                                                       test_dlg.results += result.length;
 
-                                                       console.log("got results:" + result.size());
+                                                       console.log("got results:" + result.length);
 
                                                        $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
                                                                .replace("%f", test_dlg.results)
@@ -860,7 +879,7 @@ function editFilterTest(query) {
 
                                                        console.log(offset + " " + test_dlg.max_offset);
 
-                                                       for (let i = 0; i < result.size(); i++) {
+                                                       for (let i = 0; i < result.length; i++) {
                                                                const tmp = new Element("table");
                                                                tmp.innerHTML = result[i];
                                                                dojo.parser.parse(tmp);
@@ -934,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",
@@ -1085,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) {
@@ -1123,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) {
@@ -1252,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",
@@ -1285,13 +1294,13 @@ 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",
                getSelectedFeedIds: function () {
                        const list = $$("#browseFeedList li[id*=FBROW]");
-                       const selected = new Array();
+                       const selected = [];
 
                        list.each(function (child) {
                                const id = child.id.replace("FBROW-", "");
@@ -1305,7 +1314,7 @@ function feedBrowser() {
                },
                getSelectedFeeds: function () {
                        const list = $$("#browseFeedList li.Selected");
-                       const selected = new Array();
+                       const selected = [];
 
                        list.each(function (child) {
                                const title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
@@ -1365,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");
@@ -1427,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",