some more xhrPost refactoring (batchEditSave WIP)

master
Andrew Dolgov 6 years ago
parent fc0a3050eb
commit ef129fed2a

@ -1089,7 +1089,7 @@ class Pref_Prefs extends Handler_Protected {
print "<div class='dlgButtons'> print "<div class='dlgButtons'>
<div style='float : left'> <div style='float : left'>
<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">". <button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
__('Remove selected profiles')."</button> __('Remove selected profiles')."</button>
<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">". <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
__('Activate profile')."</button> __('Activate profile')."</button>

@ -1087,7 +1087,7 @@ function backend_sanity_check_callback(transport) {
console.log('reading init-params...'); console.log('reading init-params...');
for (const k in params) { for (const k in params) {
console.log("IP: " + k + " => " + JSON.stringify(params[k])); console.log("IP:", k, "=>", params[k]);
if (k == "label_base_index") _label_base_index = parseInt(params[k]); if (k == "label_base_index") _label_base_index = parseInt(params[k]);
} }

@ -15,44 +15,31 @@ function updateFeedList() {
let search = ""; let search = "";
if (user_search) { search = user_search.value; } if (user_search) { search = user_search.value; }
new Ajax.Request("backend.php", { xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => {
parameters: "?op=pref-feeds&search=" + param_escape(search), dijit.byId('feedConfigTab').attr('content', transport.responseText);
onComplete: function(transport) { selectTab("feedConfig", true);
dijit.byId('feedConfigTab').attr('content', transport.responseText); notify("");
selectTab("feedConfig", true); });
notify("");
} });
} }
function checkInactiveFeeds() { function checkInactiveFeeds() {
new Ajax.Request("backend.php", { xhrPost("backend.php", { op: "pref-feeds", method: "getinactivefeeds" }, (transport) => {
parameters: "?op=pref-feeds&method=getinactivefeeds", if (parseInt(transport.responseText) > 0) {
onComplete: function (transport) { Element.show(dijit.byId("pref_feeds_inactive_btn").domNode);
if (parseInt(transport.responseText) > 0) {
Element.show(dijit.byId("pref_feeds_inactive_btn").domNode);
}
} }
}); });
} }
function updateUsersList(sort_key) { function updateUsersList(sort_key) {
const user_search = $("user_search"); const user_search = $("user_search");
let search = ""; const search = user_search ? user_search.value : "";
if (user_search) {
search = user_search.value;
}
const query = "?op=pref-users&sort=" + const query = { op: "pref-users", sort: sort_key, search: search };
param_escape(sort_key) +
"&search=" + param_escape(search);
new Ajax.Request("backend.php", { xhrPost("backend.php", query, (transport) => {
parameters: query, dijit.byId('userConfigTab').attr('content', transport.responseText);
onComplete: function (transport) { selectTab("userConfig", true)
dijit.byId('userConfigTab').attr('content', transport.responseText); notify("");
selectTab("userConfig", true)
notify("");
}
}); });
} }
@ -70,16 +57,10 @@ function addUser() {
notify_progress("Adding user..."); notify_progress("Adding user...");
const query = "?op=pref-users&method=add&login=" + xhrPost("backend.php", { op: "pref-users", method: "add", login: login }, (transport) => {
param_escape(login); notify_callback2(transport);
updateUsersList();
new Ajax.Request("backend.php", { });
parameters: query,
onComplete: function (transport) {
notify_callback2(transport);
updateUsersList();
}
});
} }
@ -99,15 +80,10 @@ function editUser(id) {
if (this.validate()) { if (this.validate()) {
notify_progress("Saving data...", true); notify_progress("Saving data...", true);
const query = dojo.formToQuery("user_edit_form"); xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => {
dialog.hide();
new Ajax.Request("backend.php", { updateUsersList();
parameters: query, });
onComplete: function (transport) {
dialog.hide();
updateUsersList();
}
});
} }
}, },
href: query href: query
@ -174,16 +150,10 @@ function editFilter(id) {
notify_progress("Removing filter..."); 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", { xhrPost("backend.php", query, () => {
parameters: query, updateFilterList();
onComplete: function (transport) {
updateFilterList();
}
}); });
} }
}, },
@ -208,16 +178,9 @@ function editFilter(id) {
notify_progress("Saving data...", true); notify_progress("Saving data...", true);
const query = dojo.formToQuery("filter_edit_form"); xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => {
dialog.hide();
console.log(query); updateFilterList();
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function (transport) {
dialog.hide();
updateFilterList();
}
}); });
} }
}, },
@ -294,15 +257,12 @@ function removeSelectedLabels() {
if (ok) { if (ok) {
notify_progress("Removing selected labels..."); notify_progress("Removing selected labels...");
const query = "?op=pref-labels&method=remove&ids="+ const query = { op: "pref-labels", method: "remove",
param_escape(sel_rows.toString()); ids: sel_rows.toString() };
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
updateLabelList();
} });
xhrPost("backend.php", query, () => {
updateLabelList();
});
} }
} else { } else {
alert(__("No labels are selected.")); alert(__("No labels are selected."));
@ -322,16 +282,12 @@ function removeSelectedUsers() {
if (ok) { if (ok) {
notify_progress("Removing selected users..."); notify_progress("Removing selected users...");
const query = "?op=pref-users&method=remove&ids=" + const query = { op: "pref-users", method: "remove",
param_escape(sel_rows.toString()); ids: sel_rows.toString() };
new Ajax.Request("backend.php", { xhrPost("backend.php", query, () => {
parameters: query, updateUsersList();
onComplete: function (transport) {
updateUsersList();
}
}); });
} }
} else { } else {
@ -352,14 +308,11 @@ function removeSelectedFilters() {
if (ok) { if (ok) {
notify_progress("Removing selected filters..."); notify_progress("Removing selected filters...");
const query = "?op=pref-filters&method=remove&ids=" + const query = { op: "pref-filters", method: "remove",
param_escape(sel_rows.toString()); ids: sel_rows.toString() };
new Ajax.Request("backend.php", { xhrPost("backend.php", query, () => {
parameters: query, updateFilterList();
onComplete: function (transport) {
updateFilterList();
}
}); });
} }
} else { } else {
@ -381,16 +334,11 @@ function removeSelectedFeeds() {
notify_progress("Unsubscribing from selected feeds...", true); notify_progress("Unsubscribing from selected feeds...", true);
const query = "?op=pref-feeds&method=remove&ids=" + const query = { op: "pref-feeds", method: "remove",
param_escape(sel_rows.toString()); ids: sel_rows.toString() };
console.log(query);
new Ajax.Request("backend.php", { xhrPost("backend.php", query, () => {
parameters: query, updateFeedList();
onComplete: function (transport) {
updateFeedList();
}
}); });
} }
@ -440,14 +388,8 @@ function resetSelectedUserPass() {
const id = rows[0]; const id = rows[0];
const query = "?op=pref-users&method=resetPass&id=" + xhrPost("backend.php", { op: "pref-users", method: "resetPass", id: id }, (transport) => {
param_escape(id); notify_info(transport.responseText, true);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function (transport) {
notify_info(transport.responseText, true);
}
}); });
} }
@ -467,9 +409,7 @@ function selectedUserDetails() {
return; return;
} }
const id = rows[0]; const query = "backend.php?op=pref-users&method=userdetails&id=" + param_escape(rows[0]);
const query = "backend.php?op=pref-users&method=userdetails&id=" + id;
if (dijit.byId("userDetailsDlg")) if (dijit.byId("userDetailsDlg"))
dijit.byId("userDetailsDlg").destroyRecursive(); dijit.byId("userDetailsDlg").destroyRecursive();
@ -520,16 +460,9 @@ function joinSelectedFilters() {
if (ok) { if (ok) {
notify_progress("Joining filters..."); notify_progress("Joining filters...");
const query = "?op=pref-filters&method=join&ids="+ xhrPost("backend.php", { op: "pref-filters", method: "join", ids: rows.toString() }, () => {
param_escape(rows.toString()); updateFilterList();
});
console.log(query);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
updateFilterList();
} });
} }
} }
@ -602,19 +535,21 @@ function editSelectedFeeds() {
}, },
execute: function () { execute: function () {
if (this.validate() && confirm(__("Save changes to selected feeds?"))) { if (this.validate() && confirm(__("Save changes to selected feeds?"))) {
let query = dojo.objectToQuery(this.attr('value')); const query = this.attr('value');
//console.log(query); return;
/* Form.serialize ignores unchecked checkboxes */ /* Form.serialize ignores unchecked checkboxes */
if (!query.match("&private=") && /*if (!query.match("&private=") &&
this.getChildByName('private').attr('disabled') == false) { this.getChildByName('private').attr('disabled') == false) {
query = query + "&private=false"; query.private = "false";
} }
try { try {
if (!query.match("&cache_images=") && if (!query.match("&cache_images=") &&
this.getChildByName('cache_images').attr('disabled') == false) { this.getChildByName('cache_images').attr('disabled') == false) {
query = query + "&cache_images=false"; query.cache_images = "false";
} }
} catch (e) { } catch (e) {
} }
@ -622,36 +557,31 @@ function editSelectedFeeds() {
try { try {
if (!query.match("&hide_images=") && if (!query.match("&hide_images=") &&
this.getChildByName('hide_images').attr('disabled') == false) { this.getChildByName('hide_images').attr('disabled') == false) {
query = query + "&hide_images=false"; query.hide_images = "false";
} }
} catch (e) { } catch (e) {
} }
if (!query.match("&include_in_digest=") && if (!query.match("&include_in_digest=") &&
this.getChildByName('include_in_digest').attr('disabled') == false) { this.getChildByName('include_in_digest').attr('disabled') == false) {
query = query + "&include_in_digest=false"; query.include_in_digest = "false";
} }
if (!query.match("&always_display_enclosures=") && if (!query.match("&always_display_enclosures=") &&
this.getChildByName('always_display_enclosures').attr('disabled') == false) { this.getChildByName('always_display_enclosures').attr('disabled') == false) {
query = query + "&always_display_enclosures=false"; query.always_display_enclosures = "false";
} }
if (!query.match("&mark_unread_on_update=") && if (!query.match("&mark_unread_on_update=") &&
this.getChildByName('mark_unread_on_update').attr('disabled') == false) { this.getChildByName('mark_unread_on_update').attr('disabled') == false) {
query = query + "&mark_unread_on_update=false"; query.mark_unread_on_update = "false";
} }*/
console.log(query);
notify_progress("Saving data...", true); notify_progress("Saving data...", true);
new Ajax.Request("backend.php", { xhrPost("backend.php", query, () => {
parameters: query, dialog.hide();
onComplete: function (transport) { updateFeedList();
dialog.hide();
updateFeedList();
}
}); });
} }
}, },
@ -1172,17 +1102,13 @@ function editProfiles() {
if (ok) { if (ok) {
notify_progress("Removing selected profiles...", true); notify_progress("Removing selected profiles...", true);
const query = "?op=rpc&method=remprofiles&ids=" + const query = { op: "rpc", method: "remprofiles",
param_escape(sel_rows.toString()); ids: sel_rows.toString() };
new Ajax.Request("backend.php", { xhrPost("backend.php", query, () => {
parameters: query, notify('');
onComplete: function (transport) { editProfiles();
notify('');
editProfiles();
}
}); });
} }
} else { } else {
@ -1199,15 +1125,9 @@ function editProfiles() {
if (ok) { if (ok) {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
const query = "?op=rpc&method=setprofile&id=" + xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() }, () => {
param_escape(sel_rows.toString()); window.location.reload();
});
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function (transport) {
window.location.reload();
}
});
} }
} else { } else {
@ -1218,15 +1138,11 @@ function editProfiles() {
if (this.validate()) { if (this.validate()) {
notify_progress("Creating profile...", true); notify_progress("Creating profile...", true);
const query = "?op=rpc&method=addprofile&title=" + const query = { op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile };
param_escape(dialog.attr('value').newprofile);
new Ajax.Request("backend.php", { xhrPost("backend.php", query, () => {
parameters: query, notify('');
onComplete: function (transport) { editProfiles();
notify('');
editProfiles();
}
}); });
} }
@ -1241,6 +1157,7 @@ function editProfiles() {
dialog.show(); dialog.show();
} }
/*
function activatePrefProfile() { function activatePrefProfile() {
const sel_rows = getSelectedFeedCats(); const sel_rows = getSelectedFeedCats();
@ -1252,14 +1169,9 @@ function activatePrefProfile() {
if (ok) { if (ok) {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
const query = "?op=rpc&method=setprofile&id="+ xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() }, () => {
param_escape(sel_rows.toString()); window.location.reload();
});
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
window.location.reload();
} });
} }
} else { } else {
@ -1267,7 +1179,7 @@ function activatePrefProfile() {
} }
return false; return false;
} } */
function clearFeedAccessKeys() { function clearFeedAccessKeys() {
@ -1276,13 +1188,9 @@ function clearFeedAccessKeys() {
if (ok) { if (ok) {
notify_progress("Clearing URLs..."); notify_progress("Clearing URLs...");
const query = "?op=pref-feeds&method=clearKeys"; xhrPost("backend.php", { op: "pref-feeds", method: "clearKeys" }, () => {
notify_info("Generated URLs cleared.");
new Ajax.Request("backend.php", { });
parameters: query,
onComplete: function(transport) {
notify_info("Generated URLs cleared.");
} });
} }
return false; return false;
@ -1291,34 +1199,25 @@ function clearFeedAccessKeys() {
function resetFilterOrder() { function resetFilterOrder() {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
new Ajax.Request("backend.php", { xhrPost("backend.php", { op: "pref-filters", method: "filtersortreset" }, () => {
parameters: "?op=pref-filters&method=filtersortreset", updateFilterList();
onComplete: function (transport) { });
updateFilterList();
}
});
} }
function resetFeedOrder() { function resetFeedOrder() {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
new Ajax.Request("backend.php", { xhrPost("backend.php", { op: "pref-feeds", method: "feedsortreset" }, () => {
parameters: "?op=pref-feeds&method=feedsortreset", updateFeedList();
onComplete: function (transport) { });
updateFeedList();
}
});
} }
function resetCatOrder() { function resetCatOrder() {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
new Ajax.Request("backend.php", { xhrPost("backend.php", { op: "pref-feeds", method: "catsortreset" }, () => {
parameters: "?op=pref-feeds&method=catsortreset", updateFeedList();
onComplete: function (transport) {
updateFeedList();
}
}); });
} }
@ -1329,16 +1228,8 @@ function editCat(id, item) {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
new Ajax.Request("backend.php", { xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => {
parameters: { updateFeedList();
op: 'pref-feeds',
method: 'renamecat',
id: id,
title: new_name,
},
onComplete: function (transport) {
updateFeedList();
}
}); });
} }
} }
@ -1369,12 +1260,6 @@ function editLabel(id) {
color = bg; 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); const e = $("LICID-" + id);
if (e) { if (e) {
@ -1382,26 +1267,26 @@ function editLabel(id) {
if (bg) e.style.backgroundColor = bg; 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 () { execute: function () {
if (this.validate()) { if (this.validate()) {
const caption = this.attr('value').caption; const caption = this.attr('value').caption;
const fg_color = this.attr('value').fg_color; const fg_color = this.attr('value').fg_color;
const bg_color = this.attr('value').bg_color; const bg_color = this.attr('value').bg_color;
const query = dojo.objectToQuery(this.attr('value'));
dijit.byId('labelTree').setNameById(id, caption); dijit.byId('labelTree').setNameById(id, caption);
this.setLabelColor(id, fg_color, bg_color); this.setLabelColor(id, fg_color, bg_color);
this.hide(); this.hide();
new Ajax.Request("backend.php", { xhrPost("backend.php", this.attr('value'), () => {
parameters: query, updateFilterList(); // maybe there's labels in there
onComplete: function (transport) {
updateFilterList();
}
}); });
} }
}, },
@ -1424,12 +1309,9 @@ function customizeCSS() {
style: "width: 600px", style: "width: 600px",
execute: function () { execute: function () {
notify_progress('Saving data...', true); notify_progress('Saving data...', true);
new Ajax.Request("backend.php", {
parameters: dojo.objectToQuery(this.attr('value')), xhrPost("backend.php", this.attr('value'), () => {
onComplete: function (transport) { window.location.reload();
notify('');
window.location.reload();
}
}); });
}, },
@ -1462,17 +1344,12 @@ function batchSubscribe() {
style: "width: 600px", style: "width: 600px",
execute: function () { execute: function () {
if (this.validate()) { if (this.validate()) {
console.log(dojo.objectToQuery(this.attr('value')));
notify_progress(__("Subscribing to feeds..."), true); notify_progress(__("Subscribing to feeds..."), true);
new Ajax.Request("backend.php", { xhrPost("backend.php", this.attr('value'), () => {
parameters: dojo.objectToQuery(this.attr('value')), notify("");
onComplete: function (transport) { updateFeedList();
notify(""); dialog.hide();
updateFeedList();
dialog.hide();
}
}); });
} }
}, },
@ -1486,12 +1363,10 @@ function clearPluginData(name) {
if (confirm(__("Clear stored data for this plugin?"))) { if (confirm(__("Clear stored data for this plugin?"))) {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
new Ajax.Request("backend.php", { xhrPost("backend.php", { op: "pref-prefs", method: "clearplugindata", name: name }, () => {
parameters: "?op=pref-prefs&method=clearplugindata&name=" + param_escape(name), notify('');
onComplete: function(transport) { updatePrefsList();
notify(''); });
updatePrefsList();
} });
} }
} }
@ -1500,13 +1375,10 @@ function clearSqlLog() {
if (confirm(__("Clear all messages in the error log?"))) { if (confirm(__("Clear all messages in the error log?"))) {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
const query = "?op=pref-system&method=clearLog";
new Ajax.Request("backend.php", { xhrPost("backend.php", { op: "pref-system", method: "clearLog" }, () => {
parameters: query, updateSystemList();
onComplete: function(transport) { });
updateSystemList();
} });
} }
} }

Loading…
Cancel
Save