]> git.wh0rd.org - tt-rss.git/blobdiff - js/prefs.js
remove ok = confirm() thing
[tt-rss.git] / js / prefs.js
index a1f5423e7286231ac02bb8f7b3d6d39d833f5761..965e12fa6ee42fb35a5b2be79e2f0793bba7a823 100755 (executable)
@@ -1,8 +1,5 @@
 /* global dijit, __ */
 
-let hotkey_prefix = false;
-let hotkey_prefix_pressed = false;
-
 let seq = "";
 
 function notify_callback2(transport, sticky) {
@@ -15,44 +12,31 @@ function updateFeedList() {
        let search = "";
        if (user_search) { search = user_search.value; }
 
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-feeds&search=" + param_escape(search),
-               onComplete: function(transport) {
-                       dijit.byId('feedConfigTab').attr('content', transport.responseText);
-                       selectTab("feedConfig", true);
-                       notify("");
-               } });
+       xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => {
+               dijit.byId('feedConfigTab').attr('content', transport.responseText);
+               selectTab("feedConfig", true);
+               notify("");
+       });
 }
 
 function checkInactiveFeeds() {
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-feeds&method=getinactivefeeds",
-               onComplete: function (transport) {
-                       if (parseInt(transport.responseText) > 0) {
-                               Element.show(dijit.byId("pref_feeds_inactive_btn").domNode);
-                       }
+       xhrPost("backend.php", { op: "pref-feeds", method: "getinactivefeeds" }, (transport) => {
+               if (parseInt(transport.responseText) > 0) {
+                       Element.show(dijit.byId("pref_feeds_inactive_btn").domNode);
                }
        });
 }
 
 function updateUsersList(sort_key) {
        const user_search = $("user_search");
-       let search = "";
-       if (user_search) {
-               search = user_search.value;
-       }
+       const search = user_search ? user_search.value : "";
 
-       const query = "?op=pref-users&sort=" +
-               param_escape(sort_key) +
-               "&search=" + param_escape(search);
+       const query = { op: "pref-users", sort:  sort_key, search: search };
 
-       new Ajax.Request("backend.php", {
-               parameters: query,
-               onComplete: function (transport) {
-                       dijit.byId('userConfigTab').attr('content', transport.responseText);
-                       selectTab("userConfig", true)
-                       notify("");
-               }
+       xhrPost("backend.php", query, (transport) => {
+               dijit.byId('userConfigTab').attr('content', transport.responseText);
+               selectTab("userConfig", true)
+               notify("");
        });
 }
 
@@ -70,16 +54,10 @@ function addUser() {
 
        notify_progress("Adding user...");
 
-       const query = "?op=pref-users&method=add&login=" +
-               param_escape(login);
-
-       new Ajax.Request("backend.php", {
-               parameters: query,
-               onComplete: function (transport) {
-                       notify_callback2(transport);
-                       updateUsersList();
-               }
-       });
+       xhrPost("backend.php", { op: "pref-users", method: "add", login: login }, (transport) => {
+        notify_callback2(transport);
+        updateUsersList();
+    });
 
 }
 
@@ -99,15 +77,10 @@ function editUser(id) {
                        if (this.validate()) {
                                notify_progress("Saving data...", true);
 
-                               const query = dojo.formToQuery("user_edit_form");
-
-                               new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function (transport) {
-                                               dialog.hide();
-                                               updateUsersList();
-                                       }
-                               });
+                               xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => {
+                    dialog.hide();
+                    updateUsersList();
+                });
                        }
                },
                href: query
@@ -174,16 +147,10 @@ function editFilter(id) {
 
                                notify_progress("Removing filter...");
 
-                               const id = this.attr('value').id;
+                               const query = { op: "pref-filters", method: "remove", ids: this.attr('value').id };
 
-                               const query = "?op=pref-filters&method=remove&ids=" +
-                                       param_escape(id);
-
-                               new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function (transport) {
-                                               updateFilterList();
-                                       }
+                               xhrPost("backend.php", query, () => {
+                                       updateFilterList();
                                });
                        }
                },
@@ -208,16 +175,9 @@ function editFilter(id) {
 
                                notify_progress("Saving data...", true);
 
-                               const query = dojo.formToQuery("filter_edit_form");
-
-                               console.log(query);
-
-                               new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function (transport) {
-                                               dialog.hide();
-                                               updateFilterList();
-                                       }
+                               xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => {
+                                       dialog.hide();
+                                       updateFilterList();
                                });
                        }
                },
@@ -288,21 +248,15 @@ function removeSelectedLabels() {
        const sel_rows = getSelectedLabels();
 
        if (sel_rows.length > 0) {
-
-               const ok = confirm(__("Remove selected labels?"));
-
-               if (ok) {
+               if (confirm(__("Remove selected labels?"))) {
                        notify_progress("Removing selected labels...");
 
-                       const query = "?op=pref-labels&method=remove&ids="+
-                               param_escape(sel_rows.toString());
-
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) {
-                                               updateLabelList();
-                                       } });
+                       const query = { op: "pref-labels", method: "remove",
+                               ids: sel_rows.toString() };
 
+                       xhrPost("backend.php",  query, () => {
+                               updateLabelList();
+                       });
                }
        } else {
                alert(__("No labels are selected."));
@@ -317,21 +271,15 @@ function removeSelectedUsers() {
 
        if (sel_rows.length > 0) {
 
-               const ok = confirm(__("Remove selected users? Neither default admin nor your account will be removed."));
-
-               if (ok) {
+               if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) {
                        notify_progress("Removing selected users...");
 
-                       const query = "?op=pref-users&method=remove&ids=" +
-                               param_escape(sel_rows.toString());
+                       const query = { op: "pref-users", method: "remove",
+                               ids: sel_rows.toString() };
 
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function (transport) {
-                                       updateUsersList();
-                               }
+                       xhrPost("backend.php", query, () => {
+                               updateUsersList();
                        });
-
                }
 
        } else {
@@ -346,20 +294,14 @@ function removeSelectedFilters() {
        const sel_rows = getSelectedFilters();
 
        if (sel_rows.length > 0) {
-
-               const ok = confirm(__("Remove selected filters?"));
-
-               if (ok) {
+               if (confirm(__("Remove selected filters?"))) {
                        notify_progress("Removing selected filters...");
 
-                       const query = "?op=pref-filters&method=remove&ids=" +
-                               param_escape(sel_rows.toString());
+                       const query = { op: "pref-filters", method: "remove",
+                               ids:  sel_rows.toString() };
 
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function (transport) {
-                                       updateFilterList();
-                               }
+                       xhrPost("backend.php", query, () => {
+                               updateFilterList();
                        });
                }
        } else {
@@ -374,23 +316,15 @@ function removeSelectedFeeds() {
        const sel_rows = getSelectedFeeds();
 
        if (sel_rows.length > 0) {
-
-               const ok = confirm(__("Unsubscribe from selected feeds?"));
-
-               if (ok) {
+               if (confirm(__("Unsubscribe from selected feeds?"))) {
 
                        notify_progress("Unsubscribing from selected feeds...", true);
 
-                       const query = "?op=pref-feeds&method=remove&ids=" +
-                               param_escape(sel_rows.toString());
-
-                       console.log(query);
+                       const query = { op: "pref-feeds", method: "remove",
+                               ids: sel_rows.toString() };
 
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function (transport) {
-                                       updateFeedList();
-                               }
+                       xhrPost("backend.php", query, () => {
+                               updateFeedList();
                        });
                }
 
@@ -433,21 +367,13 @@ function resetSelectedUserPass() {
                return;
        }
 
-       const ok = confirm(__("Reset password of selected user?"));
-
-       if (ok) {
+       if (confirm(__("Reset password of selected user?"))) {
                notify_progress("Resetting password for selected user...");
 
                const id = rows[0];
 
-               const query = "?op=pref-users&method=resetPass&id=" +
-                       param_escape(id);
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function (transport) {
-                               notify_info(transport.responseText, true);
-                       }
+               xhrPost("backend.php", { op: "pref-users", method: "resetPass", id: id }, (transport) => {
+                       notify_info(transport.responseText, true);
                });
 
        }
@@ -467,9 +393,7 @@ function selectedUserDetails() {
                return;
        }
 
-       const id = rows[0];
-
-       const query = "backend.php?op=pref-users&method=userdetails&id=" + id;
+       const query = "backend.php?op=pref-users&method=userdetails&id=" + param_escape(rows[0]);
 
        if (dijit.byId("userDetailsDlg"))
                dijit.byId("userDetailsDlg").destroyRecursive();
@@ -515,21 +439,12 @@ function joinSelectedFilters() {
                return;
        }
 
-       const ok = confirm(__("Combine selected filters?"));
-
-       if (ok) {
+       if (confirm(__("Combine selected filters?"))) {
                notify_progress("Joining filters...");
 
-               const query = "?op=pref-filters&method=join&ids="+
-                       param_escape(rows.toString());
-
-               console.log(query);
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                                       updateFilterList();
-                       } });
+               xhrPost("backend.php", { op: "pref-filters", method: "join", ids: rows.toString() }, () => {
+                       updateFilterList();
+               });
        }
 }
 
@@ -561,106 +476,62 @@ function editSelectedFeeds() {
 
        notify_progress("Loading, please wait...");
 
-       const query = "backend.php?op=pref-feeds&method=editfeeds&ids=" +
-               param_escape(rows.toString());
-
-       console.log(query);
-
        if (dijit.byId("feedEditDlg"))
                dijit.byId("feedEditDlg").destroyRecursive();
 
-       new Ajax.Request("backend.php", {
-               parameters: query,
-               onComplete: function (transport) {
-
-                       notify("");
-
-                       const dialog = new dijit.Dialog({
-                               id: "feedEditDlg",
-                               title: __("Edit Multiple Feeds"),
-                               style: "width: 600px",
-                               getChildByName: function (name) {
-                                       let rv = null;
-                                       this.getChildren().each(
-                                               function (child) {
-                                                       if (child.name == name) {
-                                                               rv = child;
-                                                               return;
-                                                       }
-                                               });
-                                       return rv;
-                               },
-                               toggleField: function (checkbox, elem, label) {
-                                       this.getChildByName(elem).attr('disabled', !checkbox.checked);
-
-                                       if ($(label))
-                                               if (checkbox.checked)
-                                                       $(label).removeClassName('insensitive');
-                                               else
-                                                       $(label).addClassName('insensitive');
-
-                               },
-                               execute: function () {
-                                       if (this.validate() && confirm(__("Save changes to selected feeds?"))) {
-                                               let query = dojo.objectToQuery(this.attr('value'));
-
-                                               /* Form.serialize ignores unchecked checkboxes */
-
-                                               if (!query.match("&private=") &&
-                                                       this.getChildByName('private').attr('disabled') == false) {
-                                                       query = query + "&private=false";
-                                               }
-
-                                               try {
-                                                       if (!query.match("&cache_images=") &&
-                                                               this.getChildByName('cache_images').attr('disabled') == false) {
-                                                               query = query + "&cache_images=false";
-                                                       }
-                                               } catch (e) {
-                                               }
-
-                                               try {
-                                                       if (!query.match("&hide_images=") &&
-                                                               this.getChildByName('hide_images').attr('disabled') == false) {
-                                                               query = query + "&hide_images=false";
-                                                       }
-                                               } catch (e) {
+       xhrPost("backend.php", { op: "pref-feeds", method: "editfeeds", ids: rows.toString() }, (transport) => {
+               notify("");
+
+               const dialog = new dijit.Dialog({
+                       id: "feedEditDlg",
+                       title: __("Edit Multiple Feeds"),
+                       style: "width: 600px",
+                       getChildByName: function (name) {
+                               let rv = null;
+                               this.getChildren().each(
+                                       function (child) {
+                                               if (child.name == name) {
+                                                       rv = child;
+                                                       return;
                                                }
+                                       });
+                               return rv;
+                       },
+                       toggleField: function (checkbox, elem, label) {
+                               this.getChildByName(elem).attr('disabled', !checkbox.checked);
 
-                                               if (!query.match("&include_in_digest=") &&
-                                                       this.getChildByName('include_in_digest').attr('disabled') == false) {
-                                                       query = query + "&include_in_digest=false";
-                                               }
+                               if ($(label))
+                                       if (checkbox.checked)
+                                               $(label).removeClassName('insensitive');
+                                       else
+                                               $(label).addClassName('insensitive');
 
-                                               if (!query.match("&always_display_enclosures=") &&
-                                                       this.getChildByName('always_display_enclosures').attr('disabled') == false) {
-                                                       query = query + "&always_display_enclosures=false";
-                                               }
+                       },
+                       execute: function () {
+                               if (this.validate() && confirm(__("Save changes to selected feeds?"))) {
+                                       const query = this.attr('value');
 
-                                               if (!query.match("&mark_unread_on_update=") &&
-                                                       this.getChildByName('mark_unread_on_update').attr('disabled') == false) {
-                                                       query = query + "&mark_unread_on_update=false";
-                                               }
+                                       /* normalize unchecked checkboxes because [] is not serialized */
 
-                                               console.log(query);
+                                       Object.keys(query).each((key) => {
+                                               let val = query[key];
 
-                                               notify_progress("Saving data...", true);
+                                               if (typeof val == "object" && val.length == 0)
+                                                       query[key] = ["off"];
+                                       });
 
-                                               new Ajax.Request("backend.php", {
-                                                       parameters: query,
-                                                       onComplete: function (transport) {
-                                                               dialog.hide();
-                                                               updateFeedList();
-                                                       }
-                                               });
-                                       }
-                               },
-                               content: transport.responseText
-                       });
+                                       notify_progress("Saving data...", true);
 
-                       dialog.show();
+                                       xhrPost("backend.php", query, () => {
+                                               dialog.hide();
+                                               updateFeedList();
+                                       });
+                               }
+                       },
+                       content: transport.responseText
+               });
 
-               }
+               dialog.show();
        });
 }
 
@@ -714,57 +585,58 @@ function updateFilterList() {
        let search = "";
        if (user_search) { search = user_search.value; }
 
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-filters&search=" + param_escape(search),
-               onComplete: function(transport) {
-                       dijit.byId('filterConfigTab').attr('content', transport.responseText);
-                       notify("");
-               } });
+       xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => {
+        dijit.byId('filterConfigTab').attr('content', transport.responseText);
+        notify("");
+    });
 }
 
 function updateLabelList() {
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-labels",
-               onComplete: function(transport) {
-                       dijit.byId('labelConfigTab').attr('content', transport.responseText);
-                       notify("");
-               } });
+       xhrPost("backend.php", { op: "pref-labels" }, (transport) => {
+        dijit.byId('labelConfigTab').attr('content', transport.responseText);
+        notify("");
+    });
 }
 
 function updatePrefsList() {
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-prefs",
-               onComplete: function(transport) {
-                       dijit.byId('genConfigTab').attr('content', transport.responseText);
-                       notify("");
-               } });
+    xhrPost("backend.php", { op: "pref-prefs" }, (transport) => {
+        dijit.byId('genConfigTab').attr('content', transport.responseText);
+        notify("");
+    });
 }
 
 function updateSystemList() {
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-system",
-               onComplete: function(transport) {
-                       dijit.byId('systemConfigTab').attr('content', transport.responseText);
-                       notify("");
-               } });
+    xhrPost("backend.php", { op: "pref-system" }, (transport) => {
+        dijit.byId('systemConfigTab').attr('content', transport.responseText);
+        notify("");
+    });
 }
 
 function selectTab(id, noupdate) {
        if (!noupdate) {
                notify_progress("Loading, please wait...");
 
-               if (id == "feedConfig") {
-                       updateFeedList();
-               } else if (id == "filterConfig") {
-                       updateFilterList();
-               } else if (id == "labelConfig") {
-                       updateLabelList();
-               } else if (id == "genConfig") {
-                       updatePrefsList();
-               } else if (id == "userConfig") {
-                       updateUsersList();
-               } else if (id == "systemConfig") {
-                       updateSystemList();
+               switch (id) {
+                       case "feedConfig":
+                updateFeedList();
+                               break;
+                       case "filterConfig":
+                updateFilterList();
+                               break;
+                       case "labelConfig":
+                updateLabelList();
+                               break;
+                       case "genConfig":
+                updatePrefsList();
+                               break;
+                       case "userConfig":
+                updateUsersList();
+                               break;
+                       case "systemConfig":
+                updateSystemList();
+                               break;
+                       default:
+                               console.warn("unknown tab", id);
                }
 
                const tab = dijit.byId(id + "Tab");
@@ -793,7 +665,7 @@ function init_second_stage() {
                window.setTimeout(function() { editFeed(param) }, 100);
        }
 
-       setTimeout(hotkey_prefix_timeout, 5*1000);
+       setInterval(hotkey_prefix_timeout, 5*1000);
 }
 
 function init() {
@@ -847,16 +719,12 @@ function init() {
                                loading_set_progress(50);
 
                                const clientTzOffset = new Date().getTimezoneOffset() * 60;
+                               const params = { op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset };
 
-                               new Ajax.Request("backend.php", {
-                                       parameters: {
-                                               op: "rpc", method: "sanityCheck",
-                                               clientTzOffset: clientTzOffset
-                                       },
-                                       onComplete: function (transport) {
-                                               backend_sanity_check_callback(transport);
-                                       }
+                               xhrPost("backend.php", params, (transport) => {
+                                       backend_sanity_check_callback(transport);
                                });
+
                        } catch (e) {
                                exception_error(e);
                        }
@@ -866,148 +734,72 @@ function init() {
 
 
 function validatePrefsReset() {
-       const ok = confirm(__("Reset to defaults?"));
-
-       if (ok) {
+       if (confirm(__("Reset to defaults?"))) {
 
                const query = "?op=pref-prefs&method=resetconfig";
-               console.log(query);
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               updatePrefsList();
-                               notify_info(transport.responseText);
-                       } });
 
+               xhrPost("backend.php", { op: "pref-prefs", method: "resetconfig" }, (transport) => {
+            updatePrefsList();
+            notify_info(transport.responseText);
+        });
        }
 
        return false;
-
 }
 
 function pref_hotkey_handler(e) {
-
-       if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
-
-       let keycode = false;
-       let shift_key = false;
-
-       const cmdline = $('cmdline');
-
-       try {
-               shift_key = e.shiftKey;
-       } catch (e) {
-
-       }
-
-       if (window.event) {
-               keycode = window.event.keyCode;
-       } else if (e) {
-               keycode = e.which;
-       }
-
-       let keychar = String.fromCharCode(keycode);
-
-       if (keycode == 27) { // escape
-               hotkey_prefix = false;
-       }
-
-       if (keycode == 16) return; // ignore lone shift
-       if (keycode == 17) return; // ignore lone ctrl
-
-       if (!shift_key) keychar = keychar.toLowerCase();
-
-       var hotkeys = getInitParam("hotkeys");
-
-       if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) {
-
-               const date = new Date();
-               const ts = Math.round(date.getTime() / 1000);
-
-               hotkey_prefix = keychar;
-               hotkey_prefix_pressed = ts;
-
-               cmdline.innerHTML = keychar;
-               Element.show(cmdline);
-
-               return true;
-       }
-
-       Element.hide(cmdline);
-
-       let hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
-       hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
-       hotkey_prefix = false;
-
-       let hotkey_action = false;
-       var hotkeys = getInitParam("hotkeys");
-
-       for (const sequence in hotkeys[1]) {
-               if (sequence == hotkey) {
-                       hotkey_action = hotkeys[1][sequence];
-                       break;
-               }
-       }
-
-       switch (hotkey_action) {
-               case "feed_subscribe":
-                       quickAddFeed();
-                       return false;
-               case "create_label":
-                       addLabel();
-                       return false;
-               case "create_filter":
-                       quickAddFilter();
-                       return false;
-               case "help_dialog":
-                       //helpDialog("prefs");
-                       return false;
-               default:
-                       console.log("unhandled action: " + hotkey_action + "; hotkey: " + hotkey);
+    if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
+
+    const action_name = keyevent_to_action(e);
+
+    if (action_name) {
+        switch (action_name) {
+            case "feed_subscribe":
+                quickAddFeed();
+                return false;
+            case "create_label":
+                addLabel();
+                return false;
+            case "create_filter":
+                quickAddFilter();
+                return false;
+            case "help_dialog":
+                helpDialog("main");
+                return false;
+            default:
+                console.log("unhandled action: " + action_name + "; keycode: " + e.which);
+        }
        }
 }
 
 function removeCategory(id, item) {
 
-       const ok = confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name));
-
-       if (ok) {
-               const query = "?op=pref-feeds&method=removeCat&ids=" +
-                       param_escape(id);
-
+       if (confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name))) {
                notify_progress("Removing category...");
 
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function (transport) {
-                               notify('');
-                               updateFeedList();
-                       }
-               });
+        const query = { op: "pref-feeds", method: "removeCat",
+            ids: id };
+
+               xhrPost("backend.php", query, () => {
+            notify('');
+            updateFeedList();
+        });
        }
 }
 
 function removeSelectedCategories() {
-
        const sel_rows = getSelectedCategories();
 
        if (sel_rows.length > 0) {
-
-               const ok = confirm(__("Remove selected categories?"));
-
-               if (ok) {
+               if (confirm(__("Remove selected categories?"))) {
                        notify_progress("Removing selected categories...");
 
-                       const query = "?op=pref-feeds&method=removeCat&ids="+
-                               param_escape(sel_rows.toString());
-
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) {
-                                               updateFeedList();
-                                       } });
+                       const query = { op: "pref-feeds", method: "removeCat",
+                               ids: sel_rows.toString() };
 
+                       xhrPost("backend.php", query, () => {
+                updateFeedList();
+            });
                }
        } else {
                alert(__("No categories are selected."));
@@ -1020,19 +812,12 @@ function createCategory() {
        const title = prompt(__("Category title:"));
 
        if (title) {
-
                notify_progress("Creating category...");
 
-               const query = "?op=pref-feeds&method=addCat&cat=" +
-                       param_escape(title);
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function (transport) {
-                               notify('');
-                               updateFeedList();
-                       }
-               });
+               xhrPost("backend.php", { op: "pref-feeds", method: "addCat", cat: title }, () => {
+            notify('');
+            updateFeedList();
+        });
        }
 }
 
@@ -1052,25 +837,18 @@ function showInactiveFeeds() {
                removeSelected: function () {
                        const sel_rows = this.getSelectedFeeds();
 
-                       console.log(sel_rows);
-
                        if (sel_rows.length > 0) {
-                               const ok = confirm(__("Remove selected feeds?"));
-
-                               if (ok) {
+                               if (confirm(__("Remove selected feeds?"))) {
                                        notify_progress("Removing selected feeds...", true);
 
-                                       const query = "?op=pref-feeds&method=remove&ids=" +
-                                               param_escape(sel_rows.toString());
+                                       const query = { op: "pref-feeds", method: "remove",
+                                               ids: sel_rows.toString() };
 
-                                       new Ajax.Request("backend.php", {
-                                               parameters: query,
-                                               onComplete: function (transport) {
-                                                       notify('');
-                                                       dialog.hide();
-                                                       updateFeedList();
-                                               }
-                                       });
+                                       xhrPost("backend.php", query, () => {
+                        notify('');
+                        dialog.hide();
+                        updateFeedList();
+                    });
                                }
 
                        } else {
@@ -1088,36 +866,27 @@ function showInactiveFeeds() {
 }
 
 function opmlRegenKey() {
-       const ok = confirm(__("Replace current OPML publishing address with a new one?"));
-
-       if (ok) {
-
+       if (confirm(__("Replace current OPML publishing address with a new one?"))) {
                notify_progress("Trying to change address...", true);
 
-               const query = "?op=pref-feeds&method=regenOPMLKey";
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function (transport) {
-                               const reply = JSON.parse(transport.responseText);
-
-                               const new_link = reply.link;
+               xhrJson("backend.php", { op: "pref-feeds", method: "regenOPMLKey" }, (reply) => {
+            if (reply) {
+                const new_link = reply.link;
+                const e = $('pub_opml_url');
 
-                               const e = $('pub_opml_url');
+                if (new_link) {
+                    e.href = new_link;
+                    e.innerHTML = new_link;
 
-                               if (new_link) {
-                                       e.href = new_link;
-                                       e.innerHTML = new_link;
+                    new Effect.Highlight(e);
 
-                                       new Effect.Highlight(e);
+                    notify('');
 
-                                       notify('');
-
-                               } else {
-                                       notify_error("Could not change feed URL.");
-                               }
-                       }
-               });
+                } else {
+                    notify_error("Could not change feed URL.");
+                }
+            }
+        });
        }
        return false;
 }
@@ -1126,18 +895,14 @@ function labelColorReset() {
        const labels = getSelectedLabels();
 
        if (labels.length > 0) {
-               const ok = confirm(__("Reset selected labels to default colors?"));
+               if (confirm(__("Reset selected labels to default colors?"))) {
 
-               if (ok) {
-                       const query = "?op=pref-labels&method=colorreset&ids=" +
-                               param_escape(labels.toString());
+                       const query = { op: "pref-labels", method: "colorreset",
+                               ids: labels.toString() };
 
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function (transport) {
-                                       updateLabelList();
-                               }
-                       });
+                       xhrPost("backend.php", query, () => {
+                updateLabelList();
+            });
                }
 
        } else {
@@ -1167,22 +932,16 @@ function editProfiles() {
                        const sel_rows = this.getSelectedProfiles();
 
                        if (sel_rows.length > 0) {
-                               const ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed."));
-
-                               if (ok) {
+                               if (confirm(__("Remove selected profiles? Active and default profiles will not be removed."))) {
                                        notify_progress("Removing selected profiles...", true);
 
-                                       const query = "?op=rpc&method=remprofiles&ids=" +
-                                               param_escape(sel_rows.toString());
+                                       const query = { op: "rpc", method: "remprofiles",
+                                               ids: sel_rows.toString() };
 
-                                       new Ajax.Request("backend.php", {
-                                               parameters: query,
-                                               onComplete: function (transport) {
-                                                       notify('');
-                                                       editProfiles();
-                                               }
+                                       xhrPost("backend.php", query, () => {
+                                               notify('');
+                                               editProfiles();
                                        });
-
                                }
 
                        } else {
@@ -1193,21 +952,12 @@ function editProfiles() {
                        const sel_rows = this.getSelectedProfiles();
 
                        if (sel_rows.length == 1) {
-
-                               const ok = confirm(__("Activate selected profile?"));
-
-                               if (ok) {
+                               if (confirm(__("Activate selected profile?"))) {
                                        notify_progress("Loading, please wait...");
 
-                                       const query = "?op=rpc&method=setprofile&id=" +
-                                               param_escape(sel_rows.toString());
-
-                                       new Ajax.Request("backend.php", {
-                                               parameters: query,
-                                               onComplete: function (transport) {
-                                                       window.location.reload();
-                                               }
-                                       });
+                    xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() },  () => {
+                        window.location.reload();
+                    });
                                }
 
                        } else {
@@ -1218,15 +968,11 @@ function editProfiles() {
                        if (this.validate()) {
                                notify_progress("Creating profile...", true);
 
-                               const query = "?op=rpc&method=addprofile&title=" +
-                                       param_escape(dialog.attr('value').newprofile);
+                               const query = { op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile };
 
-                               new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function (transport) {
-                                               notify('');
-                                               editProfiles();
-                                       }
+                               xhrPost("backend.php", query, () => {
+                                       notify('');
+                                       editProfiles();
                                });
 
                        }
@@ -1241,6 +987,7 @@ function editProfiles() {
        dialog.show();
 }
 
+/*
 function activatePrefProfile() {
 
        const sel_rows = getSelectedFeedCats();
@@ -1252,14 +999,9 @@ function activatePrefProfile() {
                if (ok) {
                        notify_progress("Loading, please wait...");
 
-                       const query = "?op=rpc&method=setprofile&id="+
-                               param_escape(sel_rows.toString());
-
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) {
-                                       window.location.reload();
-                               } });
+                       xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() },  () => {
+                               window.location.reload();
+                       });
                }
 
        } else {
@@ -1267,22 +1009,16 @@ function activatePrefProfile() {
        }
 
        return false;
-}
+} */
 
 function clearFeedAccessKeys() {
 
-       const ok = confirm(__("This will invalidate all previously generated feed URLs. Continue?"));
-
-       if (ok) {
+       if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) {
                notify_progress("Clearing URLs...");
 
-               const query = "?op=pref-feeds&method=clearKeys";
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               notify_info("Generated URLs cleared.");
-                       } });
+               xhrPost("backend.php", { op: "pref-feeds", method: "clearKeys" }, () => {
+            notify_info("Generated URLs cleared.");
+        });
        }
 
        return false;
@@ -1291,34 +1027,25 @@ function clearFeedAccessKeys() {
 function resetFilterOrder() {
        notify_progress("Loading, please wait...");
 
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-filters&method=filtersortreset",
-               onComplete: function (transport) {
-                       updateFilterList();
-               }
-       });
+    xhrPost("backend.php", { op: "pref-filters", method: "filtersortreset" }, () => {
+        updateFilterList();
+    });
 }
 
 
 function resetFeedOrder() {
        notify_progress("Loading, please wait...");
 
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-feeds&method=feedsortreset",
-               onComplete: function (transport) {
-                       updateFeedList();
-               }
-       });
+    xhrPost("backend.php", { op: "pref-feeds", method: "feedsortreset" }, () => {
+        updateFeedList();
+    });
 }
 
 function resetCatOrder() {
        notify_progress("Loading, please wait...");
 
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-feeds&method=catsortreset",
-               onComplete: function (transport) {
-                       updateFeedList();
-               }
+       xhrPost("backend.php", { op: "pref-feeds", method: "catsortreset" }, () => {
+               updateFeedList();
        });
 }
 
@@ -1329,16 +1056,8 @@ function editCat(id, item) {
 
                notify_progress("Loading, please wait...");
 
-               new Ajax.Request("backend.php", {
-                       parameters: {
-                               op: 'pref-feeds',
-                               method: 'renamecat',
-                               id: id,
-                               title: new_name,
-                       },
-                       onComplete: function (transport) {
-                               updateFeedList();
-                       }
+               xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => {
+                       updateFeedList();
                });
        }
 }
@@ -1369,12 +1088,6 @@ function editLabel(id) {
                                color = bg;
                        }
 
-                       const query = "?op=pref-labels&method=colorset&kind=" + kind +
-                               "&ids=" + param_escape(id) + "&fg=" + param_escape(fg) +
-                               "&bg=" + param_escape(bg) + "&color=" + param_escape(color);
-
-                       //              console.log(query);
-
                        const e = $("LICID-" + id);
 
                        if (e) {
@@ -1382,26 +1095,26 @@ function editLabel(id) {
                                if (bg) e.style.backgroundColor = bg;
                        }
 
-                       new Ajax.Request("backend.php", {parameters: query});
+            const query = { op: "pref-labels", method: "colorset", kind: kind,
+                ids: id, fg: fg, bg: bg, color: color };
+
+            xhrPost("backend.php", query, () => {
+                updateFilterList(); // maybe there's labels in there
+                       });
 
-                       updateFilterList();
                },
                execute: function () {
                        if (this.validate()) {
                                const caption = this.attr('value').caption;
                                const fg_color = this.attr('value').fg_color;
                                const bg_color = this.attr('value').bg_color;
-                               const query = dojo.objectToQuery(this.attr('value'));
 
                                dijit.byId('labelTree').setNameById(id, caption);
                                this.setLabelColor(id, fg_color, bg_color);
                                this.hide();
 
-                               new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function (transport) {
-                                               updateFilterList();
-                                       }
+                               xhrPost("backend.php", this.attr('value'), () => {
+                    updateFilterList(); // maybe there's labels in there
                                });
                        }
                },
@@ -1424,12 +1137,9 @@ function customizeCSS() {
                style: "width: 600px",
                execute: function () {
                        notify_progress('Saving data...', true);
-                       new Ajax.Request("backend.php", {
-                               parameters: dojo.objectToQuery(this.attr('value')),
-                               onComplete: function (transport) {
-                                       notify('');
-                                       window.location.reload();
-                               }
+
+                       xhrPost("backend.php", this.attr('value'), () => {
+                               window.location.reload();
                        });
 
                },
@@ -1462,17 +1172,12 @@ function batchSubscribe() {
                style: "width: 600px",
                execute: function () {
                        if (this.validate()) {
-                               console.log(dojo.objectToQuery(this.attr('value')));
-
                                notify_progress(__("Subscribing to feeds..."), true);
 
-                               new Ajax.Request("backend.php", {
-                                       parameters: dojo.objectToQuery(this.attr('value')),
-                                       onComplete: function (transport) {
-                                               notify("");
-                                               updateFeedList();
-                                               dialog.hide();
-                                       }
+                               xhrPost("backend.php", this.attr('value'), () => {
+                                       notify("");
+                                       updateFeedList();
+                                       dialog.hide();
                                });
                        }
                },
@@ -1486,12 +1191,10 @@ function clearPluginData(name) {
        if (confirm(__("Clear stored data for this plugin?"))) {
                notify_progress("Loading, please wait...");
 
-               new Ajax.Request("backend.php", {
-                       parameters: "?op=pref-prefs&method=clearplugindata&name=" + param_escape(name),
-                       onComplete: function(transport) {
-                               notify('');
-                               updatePrefsList();
-                       } });
+               xhrPost("backend.php", { op: "pref-prefs", method: "clearplugindata", name: name }, () => {
+                       notify('');
+                       updatePrefsList();
+               });
        }
 }
 
@@ -1500,13 +1203,10 @@ function clearSqlLog() {
        if (confirm(__("Clear all messages in the error log?"))) {
 
                notify_progress("Loading, please wait...");
-               const query = "?op=pref-system&method=clearLog";
 
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               updateSystemList();
-                       } });
+               xhrPost("backend.php",  { op: "pref-system", method: "clearLog" }, () => {
+                       updateSystemList();
+               });
 
        }
 }