X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=js%2Fprefs.js;h=f7e24acdac1028b98a3677b2e4f00ef785b58823;hb=HEAD;hp=792ad6b3d4aa91b86e279c3df4aae4167398b88f;hpb=4508e3103d12f6cb9b99c3f0471b83e799d596e9;p=tt-rss.git diff --git a/js/prefs.js b/js/prefs.js old mode 100755 new mode 100644 index 792ad6b3..f7e24acd --- a/js/prefs.js +++ b/js/prefs.js @@ -1,10 +1,5 @@ /* global dijit, __ */ -let init_params = []; - -let hotkey_prefix = false; -let hotkey_prefix_pressed = false; - let seq = ""; function notify_callback2(transport, sticky) { @@ -17,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(""); }); } @@ -72,15 +54,9 @@ 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(); }); } @@ -93,7 +69,7 @@ function editUser(id) { if (dijit.byId("userEditDlg")) dijit.byId("userEditDlg").destroyRecursive(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "userEditDlg", title: __("User Editor"), style: "width: 600px", @@ -101,14 +77,9 @@ 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(); }); } }, @@ -128,7 +99,7 @@ function editFilter(id) { if (dijit.byId("filterEditDlg")) dijit.byId("filterEditDlg").destroyRecursive(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "filterEditDlg", title: __("Edit Filter"), style: "width: 600px", @@ -176,16 +147,10 @@ function editFilter(id) { notify_progress("Removing filter..."); - const id = this.attr('value').id; - - const query = "?op=pref-filters&method=remove&ids=" + - param_escape(id); + const query = { op: "pref-filters", method: "remove", ids: this.attr('value').id }; - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function (transport) { - updateFilterList(); - } + xhrPost("backend.php", query, () => { + updateFilterList(); }); } }, @@ -210,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(); }); } }, @@ -290,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.")); @@ -319,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 { @@ -348,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 { @@ -376,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()); + const query = { op: "pref-feeds", method: "remove", + ids: sel_rows.toString() }; - console.log(query); - - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function (transport) { - updateFeedList(); - } + xhrPost("backend.php", query, () => { + updateFeedList(); }); } @@ -435,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); }); } @@ -469,14 +393,12 @@ 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(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "userDetailsDlg", title: __("User details"), style: "width: 600px", @@ -517,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(); + }); } } @@ -563,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(""); - - var 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(); }); } @@ -683,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(); @@ -716,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"); @@ -795,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() { @@ -814,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", @@ -849,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); } @@ -868,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; + 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); } } - - 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); - } } 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.")); @@ -1022,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(); }); } } @@ -1044,7 +827,7 @@ function showInactiveFeeds() { if (dijit.byId("inactiveFeedsDlg")) dijit.byId("inactiveFeedsDlg").destroyRecursive(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "inactiveFeedsDlg", title: __("Feeds without recent updates"), style: "width: 600px", @@ -1054,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(); }); } @@ -1090,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) { @@ -1128,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(); }); } @@ -1158,7 +921,7 @@ function editProfiles() { const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "profileEditDlg", title: __("Settings Profiles"), style: "width: 600px", @@ -1169,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 { @@ -1195,20 +952,11 @@ 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(); }); } @@ -1220,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(); }); } @@ -1243,6 +987,7 @@ function editProfiles() { dialog.show(); } +/* function activatePrefProfile() { const sel_rows = getSelectedFeedCats(); @@ -1254,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 { @@ -1269,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; @@ -1293,11 +1027,8 @@ 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(); }); } @@ -1305,22 +1036,16 @@ function resetFilterOrder() { 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(); }); } @@ -1331,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(); }); } } @@ -1371,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) { @@ -1384,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 }); } }, @@ -1426,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(); }); }, @@ -1456,25 +1164,20 @@ 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(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "batchSubDlg", title: __("Batch subscribe"), 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(); }); } }, @@ -1488,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(); + }); } } @@ -1502,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(); + }); } }