From 3cf937022ee6d0a164f39780acf69b4602642d95 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Sat, 2 Jun 2012 15:34:32 +0100 Subject: [PATCH] Integrated ajax responses from user_password.php with PMA_Response class --- js/functions.js | 2 +- libraries/Response.class.php | 46 +++++++++++++++++++++++++++++------- user_password.php | 13 +++++++--- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/js/functions.js b/js/functions.js index 1cf4adc9f3..5dd7c8d65b 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2631,7 +2631,7 @@ $(function() { $.post($the_form.attr('action'), $the_form.serialize() + '&change_pw='+ this_value, function(data) { if (data.success == true) { - $("#floating_menubar").after(data.sql_query); + $("#floating_menubar").after(data.message); $("#change_password_dialog").hide().remove(); $("#edit_user_dialog").dialog("close").remove(); $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax'); diff --git a/libraries/Response.class.php b/libraries/Response.class.php index 79bda66f21..10bed3d265 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -66,6 +66,14 @@ class PMA_Response * @var bool */ private $_isAjax; + /** + * Whether there were any errors druing the processing of the request + * Only used for ajax responses + * + * @access private + * @var bool + */ + private $_isSuccess; /** * Cretes a new class instance @@ -81,6 +89,7 @@ class PMA_Response $this->_JSON = array(); $this->_footer = new PMA_Footer(); + $this->_isSuccess = true; $this->_isAjax = false; if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $this->_isAjax = true; @@ -102,6 +111,20 @@ class PMA_Response return self::$_instance; } + /** + * FIXME + * + * @return void + */ + public function isSuccess($state) + { + if ($state) { + $this->_isSuccess = true; + } else { + $this->_isSuccess = false; + } + } + /** * Disables the rendering of the header * and the footer in responses @@ -144,8 +167,10 @@ class PMA_Response */ public function addHTML($content) { - if (is_string($content)) { - $this->_HTML .= $content; + if ($value instanceof PMA_Message) { + $this->_HTML = $value->getDisplay(); + } else { + $this->_HTML = $value; } } @@ -166,7 +191,11 @@ class PMA_Response $this->addJSON($key, $value); } } else { - $this->_JSON[$json] .= $value; + if ($value instanceof PMA_Message) { + $this->_JSON[$json] = $value->getDisplay(); + } else { + $this->_JSON[$json] = $value; + } } } @@ -209,13 +238,12 @@ class PMA_Response // header('Content-Type: text/html; charset=utf-8'); echo $this->_getDisplay(); } else { - if (isset($this->_JSON['message'])) { - $message = $this->_JSON['message']; - unset($this->_JSON['message']); - } else { - $message = $this->_getDisplay(); + if (! isset($this->_JSON['message'])) { + $this->_JSON['message'] = $this->_getDisplay(); } - PMA_ajaxResponse($message, true, $this->_JSON); + $message = $this->_JSON['message']; + unset($this->_JSON['message']); + PMA_ajaxResponse($message, $this->_isSuccess, $this->_JSON); } } diff --git a/user_password.php b/user_password.php index d43959dc4b..a462ba2951 100644 --- a/user_password.php +++ b/user_password.php @@ -77,12 +77,19 @@ function PMA_getChangePassMessage($change_password_message, $sql_query = '') /** * If in an Ajax request, we don't need to show the rest of the page */ + $response = PMA_Response::getInstance(); if ($change_password_message['error']) { - PMA_ajaxResponse($change_password_message['msg'], false); + $response->addJSON('message', $change_password_message['msg']); + $response->isSuccess(false); } else { - $extra_data['sql_query'] = PMA_getMessage($change_password_message['msg'], $sql_query, 'success'); - PMA_ajaxResponse($change_password_message['msg'], true, $extra_data); + $sql_query = PMA_getMessage( + $change_password_message['msg'], + $sql_query, + 'success' + ); + $response->addJSON('message', $sql_query); } + exit; } }