From e91e87861b7e7dff68780fcfc056ac0f0c35885d Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 3 Oct 2010 07:45:15 -0400 Subject: [PATCH] make USE work in the context of ajaxification --- js/sql.js | 35 +++++++++++++++++++++++++---------- sql.php | 5 ++++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/js/sql.js b/js/sql.js index 126784d64..285df0f0d 100644 --- a/js/sql.js +++ b/js/sql.js @@ -155,14 +155,17 @@ $(document).ready(function() { * @memberOf jQuery * @name appendToggleSpan */ - $('') - .html(PMA_messages['strToggleQueryBox']) - .appendTo("#sqlqueryform"); + // do not add this span more than once + if (! $('#sqlqueryform').find('span').is('#togglequerybox')) { + $('') + .html(PMA_messages['strToggleQueryBox']) + .appendTo("#sqlqueryform"); - // Attach the toggling of the query box visibility to a click - $("#togglequerybox").live('click', function() { - $(this).siblings().slideToggle("medium"); - }) + // Attach the toggling of the query box visibility to a click + $("#togglequerybox").bind('click', function() { + $(this).siblings().slideToggle("medium"); + }) + } /** * Ajax Event handler for 'SQL Query Submit' @@ -173,17 +176,29 @@ $(document).ready(function() { */ $("#sqlqueryform").live('submit', function(event) { event.preventDefault(); - + $form = $(this); PMA_ajaxShowMessage(); - $(this).append(''); + if (! $form.find('input:hidden').is('#ajax_request_hidden')) { + $form.append(''); + } $.post($(this).attr('action'), $(this).serialize() , function(data) { if(data.success == true) { PMA_ajaxShowMessage(data.message); + // this happens if a USE command was typed + if (typeof data.reload != 'undefined') { + $form.find('input[name=db]').val(data.db); + // need to regenerate the whole upper part + $form.find('input[name=ajax_request]').remove(); + $form.append(''); + $.post('db_sql.php', $form.serialize(), function(data) { + $('body').html(data); + }); // end inner post + } } else if (data.success == false ) { - PMA_ajaxShowMessage(data.error); + PMA_ajaxShowMessage(data.error, 50000); } else { $("#sqlqueryresults").html(data); diff --git a/sql.php b/sql.php index 698ca8a52..898c8935e 100644 --- a/sql.php +++ b/sql.php @@ -677,7 +677,10 @@ if (0 == $num_rows || $is_affected) { if(isset($GLOBALS['display_query'])) { $extra_data['sql_query'] = PMA_showMessage(NULL, $GLOBALS['display_query']); } - + if ($GLOBALS['reload'] == 1) { + $extra_data['reload'] = 1; + $extra_data['db'] = $GLOBALS['db']; + } PMA_ajaxResponse($message, $message->isSuccess(), (isset($extra_data) ? $extra_data : '')); }