/* global dijit, __ */
-let hotkey_prefix = false;
-let hotkey_prefix_pressed = false;
-
let seq = "";
function notify_callback2(transport, sticky) {
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",
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",
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",
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);
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];
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() }, () => {
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?"))) {
- const query = this.attr('value');
-
- /* normalize unchecked checkboxes because [] is not serialized */
-
- Object.keys(query).each((key) => {
- let val = query[key];
-
- if (typeof val == "object" && val.length == 0)
- query[key] = ["off"];
- });
-
- notify_progress("Saving data...", true);
-
- xhrPost("backend.php", query, () => {
- dialog.hide();
- updateFeedList();
- });
- }
- },
- content: transport.responseText
- });
+ 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);
- dialog.show();
+ if ($(label))
+ if (checkbox.checked)
+ $(label).removeClassName('insensitive');
+ else
+ $(label).addClassName('insensitive');
- }
+ },
+ execute: function () {
+ if (this.validate() && confirm(__("Save changes to selected feeds?"))) {
+ const query = this.attr('value');
+
+ /* normalize unchecked checkboxes because [] is not serialized */
+
+ Object.keys(query).each((key) => {
+ let val = query[key];
+
+ if (typeof val == "object" && val.length == 0)
+ query[key] = ["off"];
+ });
+
+ notify_progress("Saving data...", true);
+
+ xhrPost("backend.php", query, () => {
+ dialog.hide();
+ updateFeedList();
+ });
+ }
+ },
+ content: transport.responseText
+ });
+
+ dialog.show();
});
}
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");
window.setTimeout(function() { editFeed(param) }, 100);
}
- setTimeout(hotkey_prefix_timeout, 5*1000);
+ setInterval(hotkey_prefix_timeout, 5*1000);
}
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);
}
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."));
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();
+ });
}
}
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 {
}
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');
- const new_link = reply.link;
+ if (new_link) {
+ e.href = new_link;
+ e.innerHTML = new_link;
- const e = $('pub_opml_url');
+ new Effect.Highlight(e);
- if (new_link) {
- e.href = new_link;
- e.innerHTML = new_link;
+ notify('');
- new Effect.Highlight(e);
-
- notify('');
-
- } else {
- notify_error("Could not change feed URL.");
- }
- }
- });
+ } else {
+ notify_error("Could not change feed URL.");
+ }
+ }
+ });
}
return false;
}
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 {
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",
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() }, () => {
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" }, () => {