]> git.wh0rd.org - tt-rss.git/blobdiff - js/prefs.js
feedbrowser hack
[tt-rss.git] / js / prefs.js
old mode 100755 (executable)
new mode 100644 (file)
index 1358b94..f7e24ac
@@ -55,9 +55,9 @@ function addUser() {
        notify_progress("Adding user...");
 
        xhrPost("backend.php", { op: "pref-users", method: "add", login: login }, (transport) => {
-        notify_callback2(transport);
-        updateUsersList();
-    });
+               notify_callback2(transport);
+               updateUsersList();
+       });
 
 }
 
@@ -78,9 +78,9 @@ function editUser(id) {
                                notify_progress("Saving data...", true);
 
                                xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => {
-                    dialog.hide();
-                    updateUsersList();
-                });
+                                       dialog.hide();
+                                       updateUsersList();
+                               });
                        }
                },
                href: query
@@ -248,10 +248,7 @@ 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",
@@ -274,9 +271,7 @@ 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",
@@ -299,10 +294,7 @@ 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",
@@ -324,10 +316,7 @@ 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);
 
@@ -378,9 +367,7 @@ 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];
@@ -452,9 +439,7 @@ function joinSelectedFilters() {
                return;
        }
 
-       const ok = confirm(__("Combine selected filters?"));
-
-       if (ok) {
+       if (confirm(__("Combine selected filters?"))) {
                notify_progress("Joining filters...");
 
                xhrPost("backend.php", { op: "pref-filters", method: "join", ids: rows.toString() }, () => {
@@ -567,7 +552,7 @@ function opmlImportComplete(iframe) {
                title: __("OPML Import"),
                style: "width: 600px",
                onCancel: function () {
-            window.location.reload();
+                       window.location.reload();
                },
                execute: function () {
                        window.location.reload();
@@ -601,30 +586,30 @@ function updateFilterList() {
        if (user_search) { search = user_search.value; }
 
        xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => {
-        dijit.byId('filterConfigTab').attr('content', transport.responseText);
-        notify("");
-    });
+               dijit.byId('filterConfigTab').attr('content', transport.responseText);
+               notify("");
+       });
 }
 
 function updateLabelList() {
        xhrPost("backend.php", { op: "pref-labels" }, (transport) => {
-        dijit.byId('labelConfigTab').attr('content', transport.responseText);
-        notify("");
-    });
+               dijit.byId('labelConfigTab').attr('content', transport.responseText);
+               notify("");
+       });
 }
 
 function updatePrefsList() {
-    xhrPost("backend.php", { op: "pref-prefs" }, (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() {
-    xhrPost("backend.php", { op: "pref-system" }, (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) {
@@ -633,22 +618,22 @@ function selectTab(id, noupdate) {
 
                switch (id) {
                        case "feedConfig":
-                updateFeedList();
+                               updateFeedList();
                                break;
                        case "filterConfig":
-                updateFilterList();
+                               updateFilterList();
                                break;
                        case "labelConfig":
-                updateLabelList();
+                               updateLabelList();
                                break;
                        case "genConfig":
-                updatePrefsList();
+                               updatePrefsList();
                                break;
                        case "userConfig":
-                updateUsersList();
+                               updateUsersList();
                                break;
                        case "systemConfig":
-                updateSystemList();
+                               updateSystemList();
                                break;
                        default:
                                console.warn("unknown tab", id);
@@ -699,7 +684,7 @@ function init() {
                "dijit/form/CheckBox",
                "dijit/form/DropDownButton",
                "dijit/form/FilteringSelect",
-        "dijit/form/MultiSelect",
+               "dijit/form/MultiSelect",
                "dijit/form/Form",
                "dijit/form/RadioButton",
                "dijit/form/ComboButton",
@@ -734,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);
                        }
@@ -758,79 +739,67 @@ function validatePrefsReset() {
                const query = "?op=pref-prefs&method=resetconfig";
 
                xhrPost("backend.php", { op: "pref-prefs", method: "resetconfig" }, (transport) => {
-            updatePrefsList();
-            notify_info(transport.responseText);
-        });
+                       updatePrefsList();
+                       notify_info(transport.responseText);
+               });
        }
 
        return false;
 }
 
 function pref_hotkey_handler(e) {
-    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);
-        }
+       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."));
@@ -843,18 +812,11 @@ 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();
                });
        }
 }
@@ -875,24 +837,17 @@ 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();
                                        });
                                }
 
@@ -911,21 +866,12 @@ 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);
-
+               xhrJson("backend.php", { op: "pref-feeds", method: "regenOPMLKey" }, (reply) => {
+                       if (reply) {
                                const new_link = reply.link;
-
                                const e = $('pub_opml_url');
 
                                if (new_link) {
@@ -949,17 +895,13 @@ 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();
                        });
                }
 
@@ -990,9 +932,7 @@ 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",
@@ -1012,15 +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...");
 
-                    xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() },  () => {
-                        window.location.reload();
-                    });
+                                       xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() },  () => {
+                                               window.location.reload();
+                                       });
                                }
 
                        } else {
@@ -1076,14 +1013,12 @@ function activatePrefProfile() {
 
 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...");
 
                xhrPost("backend.php", { op: "pref-feeds", method: "clearKeys" }, () => {
-            notify_info("Generated URLs cleared.");
-        });
+                       notify_info("Generated URLs cleared.");
+               });
        }
 
        return false;
@@ -1092,18 +1027,18 @@ function clearFeedAccessKeys() {
 function resetFilterOrder() {
        notify_progress("Loading, please wait...");
 
-    xhrPost("backend.php", { op: "pref-filters", method: "filtersortreset" }, () => {
-        updateFilterList();
-    });
+       xhrPost("backend.php", { op: "pref-filters", method: "filtersortreset" }, () => {
+               updateFilterList();
+       });
 }
 
 
 function resetFeedOrder() {
        notify_progress("Loading, please wait...");
 
-    xhrPost("backend.php", { op: "pref-feeds", method: "feedsortreset" }, () => {
-        updateFeedList();
-    });
+       xhrPost("backend.php", { op: "pref-feeds", method: "feedsortreset" }, () => {
+               updateFeedList();
+       });
 }
 
 function resetCatOrder() {
@@ -1160,11 +1095,11 @@ function editLabel(id) {
                                if (bg) e.style.backgroundColor = bg;
                        }
 
-            const query = { op: "pref-labels", method: "colorset", kind: kind,
-                ids: id, fg: fg, bg: bg, color: color };
+                       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
+                       xhrPost("backend.php", query, () => {
+                               updateFilterList(); // maybe there's labels in there
                        });
 
                },
@@ -1179,7 +1114,7 @@ function editLabel(id) {
                                this.hide();
 
                                xhrPost("backend.php", this.attr('value'), () => {
-                    updateFilterList(); // maybe there's labels in there
+                                       updateFilterList(); // maybe there's labels in there
                                });
                        }
                },
@@ -1229,7 +1164,7 @@ function batchSubscribe() {
 
        // overlapping widgets
        if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
-       if (dijit.byId("feedAddDlg"))    dijit.byId("feedAddDlg").destroyRecursive();
+       if (dijit.byId("feedAddDlg"))   dijit.byId("feedAddDlg").destroyRecursive();
 
        const dialog = new dijit.Dialog({
                id: "batchSubDlg",