user editor: use dojo stuff

This commit is contained in:
Andrew Dolgov 2013-06-11 12:04:29 +04:00
parent 10e1b51798
commit 222a61c222
2 changed files with 45 additions and 67 deletions

View File

@ -12,7 +12,7 @@ class Pref_Users extends Handler_Protected {
} }
function csrf_ignore($method) { function csrf_ignore($method) {
$csrf_ignored = array("index"); $csrf_ignored = array("index", "edit");
return array_search($method, $csrf_ignored) !== false; return array_search($method, $csrf_ignored) !== false;
} }
@ -102,11 +102,11 @@ class Pref_Users extends Handler_Protected {
global $access_level_names; global $access_level_names;
$id = $this->dbh->escape_string($_REQUEST["id"]); $id = $this->dbh->escape_string($_REQUEST["id"]);
print "<form id=\"user_edit_form\" onsubmit='return false'>"; print "<form id=\"user_edit_form\" onsubmit='return false' dojoType=\"dijit.form.Form\">";
print "<input type=\"hidden\" name=\"id\" value=\"$id\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$id\">";
print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-users\">";
print "<input type=\"hidden\" name=\"method\" value=\"editSave\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
$result = $this->dbh->query("SELECT * FROM ttrss_users WHERE id = '$id'"); $result = $this->dbh->query("SELECT * FROM ttrss_users WHERE id = '$id'");
@ -120,15 +120,13 @@ class Pref_Users extends Handler_Protected {
print "<div class=\"dlgSecCont\">"; print "<div class=\"dlgSecCont\">";
if ($sel_disabled) { if ($sel_disabled) {
print "<input type=\"hidden\" name=\"login\" value=\"$login\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"login\" value=\"$login\">";
print "<input size=\"30\" style=\"font-size : 16px\" }
onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled
value=\"$login\">";
} else {
print "<input size=\"30\" style=\"font-size : 16px\" print "<input size=\"30\" style=\"font-size : 16px\"
dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled
name=\"login\" value=\"$login\">"; name=\"login\" value=\"$login\">";
}
print "</div>"; print "</div>";
@ -139,17 +137,16 @@ class Pref_Users extends Handler_Protected {
if (!$sel_disabled) { if (!$sel_disabled) {
print_select_hash("access_level", $access_level, $access_level_names, print_select_hash("access_level", $access_level, $access_level_names,
$sel_disabled); "dojoType=\"dijit.form.Select\" $sel_disabled");
} else { } else {
print_select_hash("", $access_level, $access_level_names, print_select_hash("", $access_level, $access_level_names,
$sel_disabled); "dojoType=\"dijit.form.Select\" $sel_disabled");
print "<input type=\"hidden\" name=\"access_level\" value=\"$access_level\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"access_level\" value=\"$access_level\">";
} }
print "<br/>"; print "<hr/>";
print __('Change password to') . print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" size=\"20\" onkeypress=\"return filterCR(event, userEditSave)\" placeholder=\"Change password to\"
" <input type=\"password\" size=\"20\" onkeypress=\"return filterCR(event, userEditSave)\"
name=\"password\">"; name=\"password\">";
print "</div>"; print "</div>";
@ -157,8 +154,7 @@ class Pref_Users extends Handler_Protected {
print "<div class=\"dlgSec\">".__("Options")."</div>"; print "<div class=\"dlgSec\">".__("Options")."</div>";
print "<div class=\"dlgSecCont\">"; print "<div class=\"dlgSecCont\">";
print __('E-mail: '). print "<input dojoType=\"dijit.form.TextBox\" size=\"30\" name=\"email\" onkeypress=\"return filterCR(event, userEditSave)\" placeholder=\"Email\"
" <input size=\"30\" name=\"email\" onkeypress=\"return filterCR(event, userEditSave)\"
value=\"$email\">"; value=\"$email\">";
print "</div>"; print "</div>";
@ -168,9 +164,9 @@ class Pref_Users extends Handler_Protected {
print "</form>"; print "</form>";
print "<div class=\"dlgButtons\"> print "<div class=\"dlgButtons\">
<button onclick=\"return userEditSave()\">". <button dojoType=\"dijit.form.Button\" type=\"submit\">".
__('Save')."</button> __('Save')."</button>
<button onclick=\"return userEditCancel()\">". <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('userEditDlg').hide()\">".
__('Cancel')."</button></div>"; __('Cancel')."</button></div>";
return; return;

View File

@ -85,15 +85,34 @@ function editUser(id, event) {
try { try {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
var query = "?op=pref-users&method=edit&id=" + var query = "backend.php?op=pref-users&method=edit&id=" +
param_escape(id); param_escape(id);
if (dijit.byId("userEditDlg"))
dijit.byId("userEditDlg").destroyRecursive();
dialog = new dijit.Dialog({
id: "userEditDlg",
title: __("User Editor"),
style: "width: 600px",
execute: function() {
if (this.validate()) {
notify_progress("Saving data...", true);
var query = dojo.formToQuery("user_edit_form");
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
infobox_callback2(transport, __("User Editor")); dialog.hide();
document.forms['user_edit_form'].login.focus(); updateUsersList();
} }); }});
}
},
href: query});
dialog.show();
} catch (e) { } catch (e) {
exception_error("editUser", e); exception_error("editUser", e);
@ -463,43 +482,6 @@ function purgeSelectedFeeds() {
return false; return false;
} }
function userEditCancel() {
closeInfoBox();
return false;
}
function userEditSave() {
try {
var login = document.forms["user_edit_form"].login.value;
if (login.length == 0) {
alert(__("Login field cannot be blank."));
return;
}
notify_progress("Saving user...");
closeInfoBox();
var query = Form.serialize("user_edit_form");
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
updateUsersList();
} });
} catch (e) {
exception_error("userEditSave", e);
}
return false;
}
function editSelectedUser() { function editSelectedUser() {
var rows = getSelectedUsers(); var rows = getSelectedUsers();