Quit using jQuery UI dialogs for editing privileges and adding users
This commit is contained in:
parent
b1f500c607
commit
a75d06b88b
@ -80,6 +80,72 @@ function appendNewUser(new_user_string, new_user_initial, new_user_initial_strin
|
||||
$(checkboxes_sel).trigger("change");
|
||||
}
|
||||
|
||||
function addUser($form)
|
||||
{
|
||||
if (! checkAddUser($form.get(0))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//We also need to post the value of the submit button in order to get this to work correctly
|
||||
$.post($form.attr('action'), $form.serialize() + "&adduser_submit=" + $("input[name=adduser_submit]").val(), function(data) {
|
||||
if (data.success == true) {
|
||||
// Refresh navigation, if we created a database with the name
|
||||
// that is the same as the username of the new user
|
||||
if ($('#add_user_dialog #createdb-1:checked').length) {
|
||||
PMA_reloadNavigation();
|
||||
}
|
||||
|
||||
$('#page_content').show();
|
||||
$("#add_user_dialog").remove();
|
||||
|
||||
PMA_ajaxShowMessage(data.message);
|
||||
$("#result_query").remove();
|
||||
$('#page_content').prepend(data.sql_query);
|
||||
$("#result_query").css({
|
||||
'margin-top' : '0.5em'
|
||||
});
|
||||
|
||||
//Remove the empty notice div generated due to a NULL query passed to PMA_getMessage()
|
||||
var $notice_class = $("#result_query").find('.notice');
|
||||
if ($notice_class.text() == '') {
|
||||
$notice_class.remove();
|
||||
}
|
||||
if ($('#fieldset_add_user a.ajax').attr('name') == 'db_specific') {
|
||||
|
||||
/*process the fieldset_add_user attribute and get the val of privileges*/
|
||||
var url = $('#fieldset_add_user a.ajax').attr('rel');
|
||||
|
||||
if (url.substring(url.length - 23, url.length) == "&goto=db_operations.php") {
|
||||
url = url.substring(0, url.length - 23);
|
||||
}
|
||||
url = url + "&ajax_request=true&db_specific=true";
|
||||
|
||||
/* post request for get the updated userForm table */
|
||||
$.post($form.attr('action'), url, function(priv_data) {
|
||||
|
||||
/*Remove the old userForm table*/
|
||||
if ($('#userFormDiv').length != 0) {
|
||||
$('#userFormDiv').remove();
|
||||
} else {
|
||||
$("#usersForm").remove();
|
||||
}
|
||||
if (priv_data.success == true) {
|
||||
$('<div id="userFormDiv"></div>')
|
||||
.html(priv_data.user_form)
|
||||
.insertAfter('#result_query');
|
||||
} else {
|
||||
PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + priv_data.error, false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
appendNewUser(data.new_user_string, data.new_user_initial, data.new_user_initial_string);
|
||||
}
|
||||
} else {
|
||||
PMA_ajaxShowMessage(data.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX scripts for server_privileges page.
|
||||
*
|
||||
@ -125,113 +191,30 @@ AJAX.registerOnload('server_privileges.js', function() {
|
||||
$("#fieldset_add_user a.ajax").live("click", function(event) {
|
||||
/** @lends jQuery */
|
||||
event.preventDefault();
|
||||
|
||||
var $msgbox = PMA_ajaxShowMessage();
|
||||
|
||||
/**
|
||||
* @var button_options Object containing options for jQueryUI dialog buttons
|
||||
*/
|
||||
var button_options = {};
|
||||
button_options[PMA_messages['strAddUser']] = function() {
|
||||
|
||||
/**
|
||||
* @var $form stores reference to current form
|
||||
*/
|
||||
var $form = $(this).find("form[name=usersForm]").last();
|
||||
|
||||
if (! checkAddUser($form.get(0))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//We also need to post the value of the submit button in order to get this to work correctly
|
||||
$.post($form.attr('action'), $form.serialize() + "&adduser_submit=" + $(this).find("input[name=adduser_submit]").val(), function(data) {
|
||||
if (data.success == true) {
|
||||
// Refresh navigation, if we created a database with the name
|
||||
// that is the same as the username of the new user
|
||||
if ($('#add_user_dialog #createdb_1:checked').length) {
|
||||
PMA_reloadNavigation();
|
||||
}
|
||||
|
||||
$("#add_user_dialog").dialog("close");
|
||||
PMA_ajaxShowMessage(data.message);
|
||||
$("#result_query").remove();
|
||||
$('#page_content').prepend(data.sql_query);
|
||||
|
||||
//Remove the empty notice div generated due to a NULL query passed to PMA_getMessage()
|
||||
var $notice_class = $("#result_query").find('.notice');
|
||||
if ($notice_class.text() == '') {
|
||||
$notice_class.remove();
|
||||
}
|
||||
if ($('#fieldset_add_user a.ajax').attr('name') == 'db_specific') {
|
||||
|
||||
/*process the fieldset_add_user attribute and get the val of privileges*/
|
||||
var url = $('#fieldset_add_user a.ajax').attr('rel');
|
||||
|
||||
if (url.substring(url.length - 23, url.length) == "&goto=db_operations.php") {
|
||||
url = url.substring(0, url.length - 23);
|
||||
}
|
||||
url = url + "&ajax_request=true&db_specific=true";
|
||||
|
||||
/* post request for get the updated userForm table */
|
||||
$.post($form.attr('action'), url, function(priv_data) {
|
||||
|
||||
/*Remove the old userForm table*/
|
||||
if ($('#userFormDiv').length != 0) {
|
||||
$('#userFormDiv').remove();
|
||||
} else {
|
||||
$("#usersForm").remove();
|
||||
}
|
||||
if (priv_data.success == true) {
|
||||
$('<div id="userFormDiv"></div>')
|
||||
.html(priv_data.user_form)
|
||||
.insertAfter('#result_query');
|
||||
} else {
|
||||
PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + priv_data.error, false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
appendNewUser(data.new_user_string, data.new_user_initial, data.new_user_initial_string);
|
||||
}
|
||||
} else {
|
||||
PMA_ajaxShowMessage(data.error, false);
|
||||
}
|
||||
});
|
||||
};
|
||||
button_options[PMA_messages['strCancel']] = function() { $(this).dialog("close"); };
|
||||
|
||||
$.get($(this).attr("href"), {'ajax_request':true}, function(data) {
|
||||
if (data.success == true) {
|
||||
var $div = $('<div id="add_user_dialog"></div>')
|
||||
.prepend(data.message)
|
||||
.find("#fieldset_add_user_footer").hide() //showing the "Go" and "Create User" buttons together will confuse the user
|
||||
.end()
|
||||
.find("form[name=usersForm]").append('<input type="hidden" name="ajax_request" value="true" />')
|
||||
.end()
|
||||
.dialog({
|
||||
title: PMA_messages['strAddUser'],
|
||||
width: 800,
|
||||
// height is a workaround for this Chrome problem:
|
||||
// http://bugs.jqueryui.com/ticket/4671
|
||||
// also it's interesting to be able to scroll this window
|
||||
height: 600,
|
||||
modal: true,
|
||||
buttons: button_options,
|
||||
close: function () {
|
||||
$(this).remove();
|
||||
}
|
||||
}); //dialog options end
|
||||
$('#page_content').hide();
|
||||
var $div = $('#add_user_dialog');
|
||||
if ($div.length == 0) {
|
||||
$div = $('<div id="add_user_dialog" style="margin: 0.5em;"></div>')
|
||||
.insertBefore('#page_content');
|
||||
} else {
|
||||
$div.empty();
|
||||
}
|
||||
$div.html(data.message)
|
||||
.find("form[name=usersForm]")
|
||||
.append('<input type="hidden" name="ajax_request" value="true" />')
|
||||
.end();
|
||||
displayPasswordGenerateButton();
|
||||
PMA_showHints($div);
|
||||
PMA_ajaxRemoveMessage($msgbox);
|
||||
$div.find("input[autofocus]").focus();
|
||||
$div.find("input.autofocus").focus();
|
||||
|
||||
$div.find('form[name=usersForm]').bind('submit', function (e) {
|
||||
e.preventDefault();
|
||||
$(this)
|
||||
.closest('.ui-dialog')
|
||||
.find('.ui-dialog-buttonpane .ui-button')
|
||||
.first()
|
||||
.click();
|
||||
$div.find('form[name=usersForm]').bind('submit', function (event) {
|
||||
event.preventDefault();
|
||||
addUser($(this));
|
||||
});
|
||||
} else {
|
||||
PMA_ajaxShowMessage(data.error, false);
|
||||
@ -332,12 +315,6 @@ AJAX.registerOnload('server_privileges.js', function() {
|
||||
|
||||
$(this).parents('tr').addClass('current_row');
|
||||
|
||||
/**
|
||||
* @var button_options Object containing options for jQueryUI dialog buttons
|
||||
*/
|
||||
var button_options = {};
|
||||
button_options[PMA_messages['strCancel']] = function() {$(this).dialog("close");};
|
||||
|
||||
var token = $(this).parents('form').find('input[name="token"]').val();
|
||||
$.get(
|
||||
$(this).attr('href'),
|
||||
@ -348,16 +325,15 @@ AJAX.registerOnload('server_privileges.js', function() {
|
||||
},
|
||||
function(data) {
|
||||
if (data.success == true) {
|
||||
var $div = $('<div id="edit_user_dialog"></div>')
|
||||
.append(data.message)
|
||||
.dialog({
|
||||
width: 900,
|
||||
height: 600,
|
||||
buttons: button_options,
|
||||
close: function () {
|
||||
$(this).remove();
|
||||
}
|
||||
}); //dialog options end
|
||||
$('#page_content').hide();
|
||||
var $div = $('#edit_user_dialog');
|
||||
if ($div.length == 0) {
|
||||
$div = $('<div id="edit_user_dialog" style="margin: 0.5em;"></div>')
|
||||
.insertBefore('#page_content');
|
||||
} else {
|
||||
$div.empty();
|
||||
}
|
||||
$div.html(data.message);
|
||||
displayPasswordGenerateButton();
|
||||
PMA_ajaxRemoveMessage($msgbox);
|
||||
PMA_showHints($div);
|
||||
@ -401,15 +377,17 @@ AJAX.registerOnload('server_privileges.js', function() {
|
||||
|
||||
$.post($t.attr('action'), $t.serialize() + '&' + curr_submit_name + '=' + curr_submit_value, function(data) {
|
||||
if (data.success == true) {
|
||||
$('#page_content').show();
|
||||
$("#edit_user_dialog").remove();
|
||||
|
||||
PMA_ajaxShowMessage(data.message);
|
||||
|
||||
//Close the jQueryUI dialog
|
||||
$("#edit_user_dialog").dialog("close");
|
||||
|
||||
if (data.sql_query) {
|
||||
$("#result_query").remove();
|
||||
$('#page_content').prepend(data.sql_query);
|
||||
$("#result_query").css({
|
||||
'margin-top' : '0.5em'
|
||||
});
|
||||
var $notice_class = $("#result_query").find('.notice');
|
||||
if ($notice_class.text() == '') {
|
||||
$notice_class.remove();
|
||||
|
||||
@ -364,8 +364,6 @@ function PMA_getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname)
|
||||
/**
|
||||
* Displays the privileges form table
|
||||
*
|
||||
* @param string $random_n a random number that will be appended
|
||||
* to the id of the user forms
|
||||
* @param string $db the database
|
||||
* @param string $table the table
|
||||
* @param boolean $submit wheather to display the submit button or not
|
||||
@ -375,7 +373,7 @@ function PMA_getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname)
|
||||
*
|
||||
* @return string html snippet
|
||||
*/
|
||||
function PMA_getHtmlToDisplayPrivilegesTable($random_n, $db = '*',
|
||||
function PMA_getHtmlToDisplayPrivilegesTable($db = '*',
|
||||
$table = '*', $submit = true
|
||||
) {
|
||||
$html_output = '';
|
||||
@ -468,9 +466,7 @@ function PMA_getHtmlToDisplayPrivilegesTable($random_n, $db = '*',
|
||||
);
|
||||
} else {
|
||||
// g l o b a l o r d b - s p e c i f i c
|
||||
$html_output .= PMA_getHtmlForGlobalOrDbSpecificPrivs(
|
||||
$db, $table, $row, $random_n
|
||||
);
|
||||
$html_output .= PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row);
|
||||
}
|
||||
$html_output .= '</fieldset>' . "\n";
|
||||
if ($submit) {
|
||||
@ -744,12 +740,10 @@ function PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn($row)
|
||||
* @param string $db the database
|
||||
* @param string $table the table
|
||||
* @param string $row first row from result or boolean false
|
||||
* @param string $random_n a random number that will be appended
|
||||
* to the id of the user forms
|
||||
*
|
||||
* @return string $html_output
|
||||
*/
|
||||
function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row, $random_n)
|
||||
function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row)
|
||||
{
|
||||
$privTable_names = array(0 => __('Data'),
|
||||
1 => __('Structure'),
|
||||
@ -771,27 +765,25 @@ function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row, $random_n)
|
||||
+ count($privTable[2])
|
||||
- (isset($row['Grant_priv']) ? 1 : 0)
|
||||
)
|
||||
. '" />' . "\n"
|
||||
. '<fieldset id="fieldset_user_global_rights">' . "\n"
|
||||
. '<legend>' . "\n"
|
||||
. ' '
|
||||
. ($db == '*'
|
||||
? __('Global privileges')
|
||||
: ($table == '*'
|
||||
? __('Database-specific privileges')
|
||||
: __('Table-specific privileges'))) . "\n"
|
||||
. '(<a href="#" '
|
||||
. 'onclick="setCheckboxes(\'addUsersForm_' . $random_n . '\', true); '
|
||||
. 'return false;">'
|
||||
. __('Check All') . '</a> /' . "\n"
|
||||
. '" />';
|
||||
$html_output .= '<fieldset id="fieldset_user_global_rights"><legend>';
|
||||
if ($db == '*') {
|
||||
$html_output .= __('Global privileges');
|
||||
} else if ($table == '*') {
|
||||
$html_output .= __('Database-specific privileges');
|
||||
} else {
|
||||
$html_output .= __('Table-specific privileges');
|
||||
}
|
||||
$html_output .= ' (<a href="#" '
|
||||
. 'onclick="setCheckboxes(\'fieldset_user_global_rights\', true); '
|
||||
. 'return false;">' . __('Check All') . '</a> /'
|
||||
. '<a href="#" '
|
||||
. 'onclick="setCheckboxes(\'addUsersForm_' . $random_n . '\', false); '
|
||||
. 'return false;">'
|
||||
. __('Uncheck All') . '</a>)' . "\n"
|
||||
. '</legend>' . "\n"
|
||||
. '<p><small><i>'
|
||||
. 'onclick="setCheckboxes(\'fieldset_user_global_rights\', false); '
|
||||
. 'return false;">' . __('Uncheck All') . '</a>)';
|
||||
$html_output .= '</legend>';
|
||||
$html_output .= '<p><small><i>'
|
||||
. __('Note: MySQL privilege names are expressed in English')
|
||||
. '</i></small></p>' . "\n";
|
||||
. '</i></small></p>';
|
||||
|
||||
// Output the Global privilege tables with checkboxes
|
||||
$html_output .= PMA_getHtmlForGlobalPrivTableWithCheckboxes(
|
||||
@ -803,7 +795,7 @@ function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row, $random_n)
|
||||
$html_output .= PMA_getHtmlForDisplayResourceLimits($row);
|
||||
}
|
||||
// for Safari 2.0.2
|
||||
$html_output .= '<div class="clearfloat"></div>' . "\n";
|
||||
$html_output .= '<div class="clearfloat"></div>';
|
||||
|
||||
return $html_output;
|
||||
}
|
||||
@ -1066,8 +1058,8 @@ function PMA_getHtmlForDisplayLoginInformationFields($mode = 'new')
|
||||
$html_output .= '</select>' . "\n"
|
||||
. '</span>' . "\n";
|
||||
|
||||
$html_output .= '<input type="text" name="username" maxlength="'
|
||||
. $username_length . '" title="' . __('User name') . '"'
|
||||
$html_output .= '<input type="text" name="username" class="autofocus"'
|
||||
. ' maxlength="' . $username_length . '" title="' . __('User name') . '"'
|
||||
. (empty($GLOBALS['username'])
|
||||
? ''
|
||||
: ' value="' . htmlspecialchars(
|
||||
@ -1076,8 +1068,7 @@ function PMA_getHtmlForDisplayLoginInformationFields($mode = 'new')
|
||||
: $GLOBALS['username']
|
||||
) . '"'
|
||||
)
|
||||
. ' onchange="pred_username.value = \'userdefined\';" '
|
||||
. 'autofocus="autofocus" />' . "\n"
|
||||
. ' onchange="pred_username.value = \'userdefined\';" />' . "\n"
|
||||
. '</div>' . "\n";
|
||||
|
||||
$html_output .= '<div class="item">' . "\n"
|
||||
@ -1431,20 +1422,19 @@ function PMA_getWithClauseForAddUserAndUpdatePrivs()
|
||||
/**
|
||||
* Get HTML for addUsersForm, This function call if isset($_REQUEST['adduser'])
|
||||
*
|
||||
* @param int $random_n
|
||||
* @param string $dbname
|
||||
*
|
||||
* @return string HTML for addUserForm
|
||||
*/
|
||||
function PMA_getHtmlForAddUser($random_n, $dbname)
|
||||
function PMA_getHtmlForAddUser($dbname)
|
||||
{
|
||||
$GLOBALS['url_query'] .= '&adduser=1';
|
||||
|
||||
$html_output = '<h2>' . "\n"
|
||||
. PMA_Util::getIcon('b_usradd.png') . __('Add user') . "\n"
|
||||
. '</h2>' . "\n"
|
||||
. '<form name="usersForm" id="addUsersForm_' . $random_n
|
||||
. '" action="server_privileges.php" method="post">' . "\n"
|
||||
. '<form name="usersForm" class="ajax" id="addUsersForm"'
|
||||
. ' action="server_privileges.php" method="post">' . "\n"
|
||||
. PMA_generate_common_hidden_inputs('', '')
|
||||
. PMA_getHtmlForDisplayLoginInformationFields('new');
|
||||
|
||||
@ -1477,9 +1467,7 @@ function PMA_getHtmlForAddUser($random_n, $dbname)
|
||||
}
|
||||
|
||||
$html_output .= '</fieldset>' . "\n";
|
||||
$html_output .= PMA_getHtmlToDisplayPrivilegesTable(
|
||||
$random_n, '*', '*', false
|
||||
);
|
||||
$html_output .= PMA_getHtmlToDisplayPrivilegesTable('*', '*', false);
|
||||
$html_output .= '<fieldset id="fieldset_add_user_footer" class="tblFooters">'
|
||||
. "\n"
|
||||
. '<input type="submit" name="adduser_submit" '
|
||||
@ -2998,8 +2986,6 @@ function PMA_getHtmlForDisplayUserOverviewPage($link_edit, $pmaThemeImage,
|
||||
*
|
||||
* @param boolean $dbname_is_wildcard whether database name is wildcard or not
|
||||
* @param type $url_dbname url database name that urlencode() string
|
||||
* @param integer $random_n a random number that will be appended
|
||||
* to the id of the user forms
|
||||
* @param string $username username
|
||||
* @param string $hostname host name
|
||||
* @param string $link_edit standard link to edit privileges
|
||||
@ -3010,7 +2996,7 @@ function PMA_getHtmlForDisplayUserOverviewPage($link_edit, $pmaThemeImage,
|
||||
* @return string $html_output
|
||||
*/
|
||||
function PMA_getHtmlForDisplayUserProperties($dbname_is_wildcard,$url_dbname,
|
||||
$random_n, $username, $hostname, $link_edit, $link_revoke, $dbname, $tablename
|
||||
$username, $hostname, $link_edit, $link_revoke, $dbname, $tablename
|
||||
) {
|
||||
$html_output = PMA_getHtmlHeaderForDisplayUserProperties(
|
||||
$dbname_is_wildcard, $url_dbname, $dbname, $username, $hostname, $tablename
|
||||
@ -3031,8 +3017,7 @@ function PMA_getHtmlForDisplayUserProperties($dbname_is_wildcard,$url_dbname,
|
||||
}
|
||||
|
||||
$class = ' class="ajax"';
|
||||
$html_output .= '<form' . $class . ' name="usersForm"'
|
||||
. ' id="addUsersForm_' . $random_n . '"'
|
||||
$html_output .= '<form' . $class . ' name="usersForm" id="addUsersForm"'
|
||||
. ' action="server_privileges.php" method="post">' . "\n";
|
||||
|
||||
$_params = array(
|
||||
@ -3048,7 +3033,6 @@ function PMA_getHtmlForDisplayUserProperties($dbname_is_wildcard,$url_dbname,
|
||||
$html_output .= PMA_generate_common_hidden_inputs($_params);
|
||||
|
||||
$html_output .= PMA_getHtmlToDisplayPrivilegesTable(
|
||||
$random_n,
|
||||
PMA_ifSetOr($dbname, '*', 'length'),
|
||||
PMA_ifSetOr($tablename, '*', 'length')
|
||||
);
|
||||
|
||||
@ -150,9 +150,6 @@ if (! $is_superuser) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// a random number that will be appended to the id of the user forms
|
||||
$random_n = mt_rand(0, 1000000);
|
||||
|
||||
/**
|
||||
* Changes / copies a user, part I
|
||||
*/
|
||||
@ -228,7 +225,8 @@ if (isset($_REQUEST['adduser_submit']) || isset($_REQUEST['change_copy'])) {
|
||||
$sql_query = $create_user_show . $sql_query;
|
||||
}
|
||||
list($sql_query, $message) = PMA_addUserAndCreateDatabase(
|
||||
$_error, $real_sql_query, $sql_query, $username, $hostname, $dbname
|
||||
$_error, $real_sql_query, $sql_query, $username, $hostname,
|
||||
isset($dbname) ? $dbname : null
|
||||
);
|
||||
|
||||
} else {
|
||||
@ -383,8 +381,8 @@ if ($GLOBALS['is_ajax_request']
|
||||
$link_export,
|
||||
(isset($sql_query) ? $sql_query : ''),
|
||||
$link_edit,
|
||||
(isset($hostname) ? $hostname : ''),
|
||||
(isset($username) ? $username : '')
|
||||
(isset($hostname) ? $hostname : ''),
|
||||
(isset($username) ? $username : '')
|
||||
);
|
||||
|
||||
if (! empty($message) && $message instanceof PMA_Message) {
|
||||
@ -471,8 +469,7 @@ if (empty($_REQUEST['adduser'])
|
||||
$response->addHTML(
|
||||
PMA_getHtmlForDisplayUserProperties(
|
||||
((isset ($dbname_is_wildcard)) ? $dbname_is_wildcard : ''),
|
||||
$url_dbname, $random_n,
|
||||
$username, $hostname, $link_edit, $link_revoke,
|
||||
$url_dbname, $username, $hostname, $link_edit, $link_revoke,
|
||||
(isset($dbname) ? $dbname : ''),
|
||||
(isset($tablename) ? $tablename : '')
|
||||
)
|
||||
@ -481,7 +478,7 @@ if (empty($_REQUEST['adduser'])
|
||||
} elseif (isset($_REQUEST['adduser'])) {
|
||||
// Add user
|
||||
$response->addHTML(
|
||||
PMA_getHtmlForAddUser($random_n, (isset($dbname) ? $dbname : ''))
|
||||
PMA_getHtmlForAddUser((isset($dbname) ? $dbname : ''))
|
||||
);
|
||||
} else {
|
||||
// check the privileges for a particular database.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user