Ajaxified Change Password action on main page

This commit is contained in:
ninadsp
2010-08-03 19:10:37 +05:30
parent 94b7567ec8
commit c897adc3a4
5 changed files with 68 additions and 4 deletions

View File

@@ -2072,4 +2072,51 @@ $(document).ready(function() {
} }
}) })
}) })
})
/**
* jQuery coding for 'Change Password' on main.php
*/
$(document).ready(function() {
$('#change_password_anchor').live('click', function(event) {
event.preventDefault();
var button_options = {};
button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
$.get($(this).attr('href'), {'ajax_request': true}, function(data) {
$('<div id="change_password_dialog></div>')
.dialog({
title: top.frame_content.PMA_messages['strChangePassword'],
width: 600,
buttons : button_options
})
.append(data);
})
})
$("#change_password_form").find('input[name=change_pw]').live('click', function(event) {
event.preventDefault();
var the_form = $("#change_password_form");
PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
$(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
$.post($(the_form).attr('action'), $(the_form).serialize(), function(data) {
if(data.success == true) {
PMA_ajaxShowMessage(data.message);
$("#topmenucontainer").after(data.sql_query);
$("#change_password_dialog").hide().remove();
}
else {
PMA_ajaxShowMessage(data.error);
}
})
})
}) })

View File

@@ -103,6 +103,7 @@ $js_messages['strChangeDisplay'] = __('Choose column to display');
/* password generation */ /* password generation */
$js_messages['strGeneratePassword'] = __('Generate password'); $js_messages['strGeneratePassword'] = __('Generate password');
$js_messages['strGenerate'] = __('Generate'); $js_messages['strGenerate'] = __('Generate');
$js_messages['strChangePassword'] = __('Change Password');
echo "var PMA_messages = new Array();\n"; echo "var PMA_messages = new Array();\n";
foreach ($js_messages as $name => $js_message) { foreach ($js_messages as $name => $js_message) {

View File

@@ -19,7 +19,7 @@ $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
// Displays the form // Displays the form
?> ?>
<form method="post" action="<?php echo $GLOBALS['PMA_PHP_SELF']; ?>" name="chgPassword" onsubmit="return checkPassword(this)"> <form method="post" id="change_password_form" action="<?php echo $GLOBALS['PMA_PHP_SELF']; ?>" name="chgPassword" onsubmit="return checkPassword(this)">
<?php echo PMA_generate_common_hidden_inputs(); <?php echo PMA_generate_common_hidden_inputs();
if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) { if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) {
echo '<input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n" echo '<input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"

View File

@@ -13,6 +13,7 @@ require_once './libraries/common.inc.php';
$GLOBALS['js_include'][] = 'colorpicker/js/colorpicker.js'; $GLOBALS['js_include'][] = 'colorpicker/js/colorpicker.js';
$GLOBALS['js_include'][] = 'main_custom_color.js'; $GLOBALS['js_include'][] = 'main_custom_color.js';
$GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
// Handles some variables that may have been sent by the calling script // Handles some variables that may have been sent by the calling script
$GLOBALS['db'] = ''; $GLOBALS['db'] = '';
@@ -88,7 +89,7 @@ if ($server > 0
if ($cfg['Server']['auth_type'] != 'config') { if ($cfg['Server']['auth_type'] != 'config') {
if ($cfg['ShowChgPassword']) { if ($cfg['ShowChgPassword']) {
PMA_printListItem(__('Change password'), 'li_change_password', PMA_printListItem(__('Change password'), 'li_change_password',
'./user_password.php?' . $common_url_query); './user_password.php?' . $common_url_query, null, null, 'change_password_anchor');
} }
$http_logout = ($cfg['Server']['auth_type'] == 'http') $http_logout = ($cfg['Server']['auth_type'] == 'http')
@@ -364,8 +365,9 @@ if ($cfg['SuhosinDisableWarning'] == false && @ini_get('suhosin.request.max_valu
* @param string $url make item as link with $url as target * @param string $url make item as link with $url as target
* @param string $mysql_help_page display a link to MySQL's manual * @param string $mysql_help_page display a link to MySQL's manual
* @param string $target special target for $url * @param string $target special target for $url
* @param string $a_id id for the anchor, used for jQuery to hook in functions
*/ */
function PMA_printListItem($name, $id = null, $url = null, $mysql_help_page = null, $target = null) function PMA_printListItem($name, $id = null, $url = null, $mysql_help_page = null, $target = null, $a_id = null)
{ {
echo '<li id="' . $id . '">'; echo '<li id="' . $id . '">';
if (null !== $url) { if (null !== $url) {
@@ -373,6 +375,9 @@ function PMA_printListItem($name, $id = null, $url = null, $mysql_help_page = nu
if (null !== $target) { if (null !== $target) {
echo ' target="' . $target . '"'; echo ' target="' . $target . '"';
} }
if (null != $a_id) {
echo ' id="' . $a_id .'"';
}
echo '>'; echo '>';
} }

View File

@@ -71,6 +71,10 @@ if (isset($_REQUEST['nopass'])) {
$password = $_REQUEST['pma_pw']; $password = $_REQUEST['pma_pw'];
} }
if($GLOBALS['is_ajax_request'] == true && $_error == true) {
PMA_ajaxResponse($message, false);
}
if (! $_error) { if (! $_error) {
// Defines the url to return to in case of error in the sql statement // Defines the url to return to in case of error in the sql statement
@@ -101,10 +105,17 @@ if (isset($_REQUEST['nopass'])) {
$_url_params['old_usr'] = 'relog'; $_url_params['old_usr'] = 'relog';
} }
$message = PMA_Message::success(__('The profile has been updated.'));
if($GLOBALS['is_ajax_request'] == true) {
$extra_data['sql_query'] = PMA_showMessage(NULL, $sql_query, 'success');
PMA_ajaxResponse($message, true, $extra_data);
}
// Displays the page // Displays the page
require_once './libraries/header.inc.php'; require_once './libraries/header.inc.php';
echo '<h1>' . __('Change password') . '</h1>' . "\n\n"; echo '<h1>' . __('Change password') . '</h1>' . "\n\n";
PMA_showMessage(__('The profile has been updated.'), $sql_query, 'success'); PMA_showMessage($message, $sql_query, 'success');
?> ?>
<a href="index.php<?php echo PMA_generate_common_url($_url_params); ?>" target="_parent"> <a href="index.php<?php echo PMA_generate_common_url($_url_params); ?>" target="_parent">
<strong><?php echo __('Back'); ?></strong></a> <strong><?php echo __('Back'); ?></strong></a>