prefs: some async work (6)

This commit is contained in:
Andrew Dolgov 2009-01-24 09:16:47 +01:00
parent e9802eadd8
commit fbf7d545f7
2 changed files with 210 additions and 283 deletions

View File

@ -8,7 +8,7 @@
return;
}
$subop = $_GET["subop"];
$subop = $_REQUEST["subop"];
if ($subop == "user-details") {
@ -205,11 +205,11 @@
if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
$login = db_escape_string(trim($_GET["login"]));
$uid = db_escape_string($_GET["id"]);
$access_level = (int) $_GET["access_level"];
$email = db_escape_string(trim($_GET["email"]));
$password = db_escape_string(trim($_GET["password"]));
$login = db_escape_string(trim($_REQUEST["login"]));
$uid = db_escape_string($_REQUEST["id"]);
$access_level = (int) $_REQUEST["access_level"];
$email = db_escape_string(trim($_REQUEST["email"]));
$password = db_escape_string(trim($_REQUEST["password"]));
if ($password) {
$pwd_hash = encrypt_password($password, $login);

273
prefs.js
View File

@ -1,29 +1,12 @@
var xmlhttp = false;
var active_feed_cat = false;
var active_tab = false;
var xmlhttp = Ajax.getTransport();
var init_params = new Array();
var caller_subop = false;
var sanity_check_done = false;
var hotkey_prefix = false;
function infobox_callback() {
if (xmlhttp.readyState == 4) {
infobox_callback2(xmlhttp);
}
}
function infobox_submit_callback() {
if (xmlhttp.readyState == 4) {
infobox_submit_callback2(xmlhttp);
}
}
function replace_pubkey_callback(transport) {
try {
var link = document.getElementById("pubGenAddress");
@ -127,13 +110,17 @@ function labellist_callback2(transport) {
}
}
function userlist_callback() {
function userlist_callback2(transport) {
try {
var container = document.getElementById('prefContent');
if (xmlhttp.readyState == 4) {
container.innerHTML=xmlhttp.responseText;
if (transport.readyState == 4) {
container.innerHTML=transport.responseText;
notify("");
remove_splash();
}
} catch (e) {
exception_error("userlist_callback2", e);
}
}
function prefslist_callback2(transport) {
@ -147,12 +134,6 @@ function prefslist_callback2(transport) {
}
}
function notify_callback() {
if (xmlhttp.readyState == 4) {
notify_callback2(xmlhttp);
}
}
function notify_callback2(transport) {
notify_info(transport.responseText);
}
@ -167,23 +148,21 @@ function prefs_reset_callback2(transport) {
}
function changepass_callback() {
function changepass_callback2(transport) {
try {
if (xmlhttp.readyState == 4) {
if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
if (transport.responseText.indexOf("ERROR: ") == 0) {
notify_error(transport.responseText.replace("ERROR: ", ""));
} else {
notify_info(xmlhttp.responseText);
notify_info(transport.responseText);
var warn = document.getElementById("default_pass_warning");
if (warn) warn.style.display = "none";
}
document.forms['change_pass_form'].reset();
}
} catch (e) {
exception_error("changepass_callback", e);
exception_error("changepass_callback2", e);
}
}
@ -247,21 +226,24 @@ function updateFeedList(sort_key) {
function updateUsersList(sort_key) {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
try {
var user_search = document.getElementById("user_search");
var search = "";
if (user_search) { search = user_search.value; }
xmlhttp.open("GET", "backend.php?op=pref-users&sort="
var query = "backend.php?op=pref-users&sort="
+ param_escape(sort_key) +
"&search=" + param_escape(search), true);
xmlhttp.onreadystatechange=userlist_callback;
xmlhttp.send(null);
"&search=" + param_escape(search);
new Ajax.Request(query, {
onComplete: function(transport) {
userlist_callback2(transport);
} });
} catch (e) {
exception_error("updateUsersList", e);
}
}
function addLabel() {
@ -328,11 +310,6 @@ function addFeed() {
function addFeedCat() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
var cat = document.getElementById("fadd_cat");
if (cat.value.length == 0) {
@ -355,10 +332,7 @@ function addFeedCat() {
}
function addUser() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
try {
var sqlexp = document.getElementById("uadd_box");
@ -367,15 +341,20 @@ function addUser() {
} else {
notify_progress("Adding user...");
xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
param_escape(sqlexp.value), true);
var query = "backend.php?op=pref-users&subop=add&login=" +
param_escape(sqlexp.value);
xmlhttp.onreadystatechange=userlist_callback;
xmlhttp.send(null);
new Ajax.Request(query, {
onComplete: function(transport) {
userlist_callback2(transport);
} });
sqlexp.value = "";
}
} catch (e) {
exception_error("addUser", e);
}
}
function editUser(id) {
@ -507,10 +486,7 @@ function removeSelectedLabels() {
function removeSelectedUsers() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
try {
var sel_rows = getSelectedUsers();
@ -521,16 +497,24 @@ function removeSelectedUsers() {
if (ok) {
notify_progress("Removing selected users...");
xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
param_escape(sel_rows.toString()), true);
xmlhttp.onreadystatechange=userlist_callback;
xmlhttp.send(null);
var query = "backend.php?op=pref-users&subop=remove&ids="+
param_escape(sel_rows.toString());
new Ajax.Request(query, {
onComplete: function(transport) {
userlist_callback2(transport);
} });
}
} else {
alert(__("No users are selected."));
}
} catch (e) {
exception_error("removeSelectedUsers", e);
}
return false;
}
@ -631,11 +615,6 @@ function clearSelectedFeeds() {
function purgeSelectedFeeds() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
var sel_rows = getSelectedFeeds();
if (sel_rows.length > 0) {
@ -667,11 +646,6 @@ function purgeSelectedFeeds() {
function removeSelectedFeedCats() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
var sel_rows = getSelectedFeedCats();
if (sel_rows.length > 0) {
@ -702,11 +676,6 @@ function removeSelectedFeedCats() {
function feedEditCancel() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
try {
document.getElementById("subscribe_to_feed_btn").disabled = false;
document.getElementById("top25_feeds_btn").disabled = false;
@ -748,11 +717,6 @@ function feedEditSave() {
function userEditCancel() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
selectPrefRows('user', false); // cleanup feed selection
closeInfoBox();
@ -761,11 +725,6 @@ function userEditCancel() {
function filterEditCancel() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
try {
document.getElementById("create_filter_btn").disabled = false;
selectPrefRows('filter', false); // cleanup feed selection
@ -778,10 +737,7 @@ function filterEditCancel() {
function userEditSave() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
try {
var login = document.forms["user_edit_form"].login.value;
@ -796,11 +752,18 @@ function userEditSave() {
var query = Form.serialize("user_edit_form");
xmlhttp.open("GET", "backend.php?" + query, true);
xmlhttp.onreadystatechange=userlist_callback;
xmlhttp.send(null);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
userlist_callback2(transport);
} });
} catch (e) {
exception_error("userEditSave", e);
}
return false;
}
@ -848,6 +811,9 @@ function editSelectedUser() {
}
function resetSelectedUserPass() {
try {
var rows = getSelectedUsers();
if (rows.length == 0) {
@ -867,10 +833,18 @@ function resetSelectedUserPass() {
var id = rows[0];
xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
param_escape(id), true);
xmlhttp.onreadystatechange=userlist_callback;
xmlhttp.send(null);
var query = "backend.php?op=pref-users&subop=resetPass&id=" +
param_escape(id);
new Ajax.Request(query, {
onComplete: function(transport) {
userlist_callback2(transport);
} });
}
} catch (e) {
exception_error("resetSelectedUserPass", e);
}
}
@ -1061,11 +1035,6 @@ function selectTab(id, noupdate, subop) {
try {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
try {
var c = document.getElementById('prefContent');
c.scrollTop = 0;
@ -1128,9 +1097,7 @@ function selectTab(id, noupdate, subop) {
}
}
function backend_sanity_check_callback() {
if (xmlhttp.readyState == 4) {
function backend_sanity_check_callback2(transport) {
try {
@ -1141,16 +1108,16 @@ function backend_sanity_check_callback() {
return;
}
if (!xmlhttp.responseXML) {
if (!transport.responseXML) {
fatalError(3, "Sanity Check: Received reply is not XML",
xmlhttp.responseText);
transport.responseText);
return;
}
var reply = xmlhttp.responseXML.firstChild.firstChild;
var reply = transport.responseXML.firstChild.firstChild;
if (!reply) {
fatalError(3, "Sanity Check: Invalid RPC reply", xmlhttp.responseText);
fatalError(3, "Sanity Check: Invalid RPC reply", transport.responseText);
return;
}
@ -1185,7 +1152,6 @@ function backend_sanity_check_callback() {
exception_error("backend_sanity_check_callback", e);
}
}
}
function init_second_stage() {
@ -1234,19 +1200,14 @@ function init() {
debug('debug mode activated');
}
// IE kludge
if (!xmlhttp) {
document.getElementById("prefContent").innerHTML =
"<b>Fatal error:</b> This program needs XmlHttpRequest " +
"to function properly. Your browser doesn't seem to support it.";
return;
}
loading_set_progress(30);
xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
xmlhttp.onreadystatechange=backend_sanity_check_callback;
xmlhttp.send(null);
var query = "backend.php?op=rpc&subop=sanityCheck";
new Ajax.Request(query, {
onComplete: function(transport) {
backend_sanity_check_callback2(transport);
} });
} catch (e) {
exception_error("init", e);
@ -1631,11 +1592,6 @@ function changeUserPassword() {
try {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return false;
}
var f = document.forms["change_pass_form"];
if (f) {
@ -1670,10 +1626,12 @@ function changeUserPassword() {
notify_progress("Trying to change password...");
xmlhttp.open("POST", "backend.php", true);
xmlhttp.onreadystatechange=changepass_callback;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(query);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
changepass_callback2(transport);
} });
} catch (e) {
exception_error("changeUserPassword", e);
@ -1686,19 +1644,15 @@ function changeUserEmail() {
try {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return false;
}
var query = Form.serialize("change_email_form");
notify_progress("Trying to change e-mail...");
xmlhttp.open("POST", "backend.php", true);
xmlhttp.onreadystatechange=notify_callback;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(query);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
notify_callback2(transport);
} });
} catch (e) {
exception_error("changeUserPassword", e);
@ -1715,11 +1669,6 @@ function feedlistToggleSLAT() {
function pubRegenKey() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return false;
}
var ok = confirm(__("Replace current publishing address with a new one?"));
if (ok) {
@ -1738,25 +1687,6 @@ function pubRegenKey() {
return false;
}
function pubToClipboard() {
try {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return false;
}
var link = document.getElementById("pubGenAddress");
alert(link.href);
} catch (e) {
exception_error("pubToClipboard", e);
}
return false;
}
function validatePrefsSave() {
try {
@ -1768,10 +1698,12 @@ function validatePrefsSave() {
query = query + "&subop=save-config";
debug(query);
xmlhttp.open("POST", "backend.php", true);
xmlhttp.onreadystatechange=notify_callback;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(query);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
notify_callback2(transport);
} });
}
} catch (e) {
@ -1952,11 +1884,6 @@ function unsubscribeFeed(id, title) {
function feedsEditSave() {
try {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
var ok = confirm(__("Save changes to selected feeds?"));
if (ok) {