Skip to content
Browse files

Bug #3598024 Confusing "Reload Database?" message

  • Loading branch information...
1 parent 72c6130 commit b1250573f410ae8468fb8a2ed3a3b9e61f4ef234 @lem9 lem9 committed Dec 22, 2012
Showing with 15 additions and 28 deletions.
  1. +15 −28 js/db_operations.js
View
43 js/db_operations.js
@@ -40,18 +40,6 @@ AJAX.registerOnload('db_operations.js', function() {
var question = escapeHtml('CREATE DATABASE ' + $('#new_db_name').val() + ' / DROP DATABASE ' + PMA_commonParams.get('db'));
PMA_prepareForAjaxRequest($form);
- /**
- * @var button_options Object containing options for jQueryUI dialog buttons
- */
- var button_options = {};
- button_options[PMA_messages['strYes']] = function() {
- $(this).dialog("close").remove();
- PMA_commonActions.refreshMain();
- PMA_reloadNavigation();
- };
- button_options[PMA_messages['strNo']] = function() {
- $(this).dialog("close").remove();
- }
$form.PMA_confirm(question, $form.attr('action'), function(url) {
PMA_ajaxShowMessage(PMA_messages['strRenamingDatabases'], false);
@@ -60,22 +48,21 @@ AJAX.registerOnload('db_operations.js', function() {
PMA_ajaxShowMessage(data.message);
PMA_commonParams.set('db', data.newname);
- $("#page_content")
- .find('#result_query')
- .remove();
- $("#page_content")
- .prepend(data.sql_query);
-
- //Remove the empty notice div generated due to a NULL query passed to PMA_Util::getMessage()
- var $notice_class = $('#result_query').find('.notice');
- if ($notice_class.text() == '') {
- $notice_class.remove();
- }
-
- $("<span>" + PMA_messages['strReloadDatabase'] + "?</span>").dialog({
- buttons: button_options,
- modal: true
- }) //end dialog options
+ PMA_reloadNavigation();
+ // without this timeout, when looking in the navigation
+ // tree for the new db name, I only find the old name
+ setTimeout(function() {
@roccivic
roccivic added a note Dec 22, 2012

This is not going to work on remote installations, where the ajax request takes longer than 500mS :(
You may want to add a callback to PMA_reloadNavigation(), which IMO, would be the correct way to handle this issue...

@lem9
lem9 added a note Dec 22, 2012

Where should I add the callback?

@roccivic
roccivic added a note Dec 22, 2012

To the PMA_reloadNavigation() function. For what you need here, you don't even have to bother switching the context of execution. All you need is to change PMA_reloadNavigation to take an argument, then execute it after the ajax call (if it's function). Something along the lines of:

function PMA_reloadNavigation(callback) {
    // ........  SNIP ........
    $.post(url, params, function (data) {
        $throbber.css('visibility', 'hidden');
        if (data.success) {
            $('#pma_navigation_tree').html(data.message).children('div').show();
            // Fire the callback, if any
            if (typeof callback === 'function') {
                callback.call();
            }
        } else {
            PMA_ajaxShowMessage(data.error);
        }
    });
}
@roccivic
roccivic added a note Dec 22, 2012

Oh and then you'd call it as follows:

PMA_reloadNavigation(function () {
    // Do stuff...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $('#pma_navigation_tree')
+ .find("a:not('.expander')")
+ .each(function(index) {
+ var $thisAnchor = $(this);
+ if ($thisAnchor.text() == data.newname) {
+ // simulate a click on the new db name
+ // in navigation
+ $thisAnchor.trigger('click');
+ }
+ });
+ }, 500);
} else {
PMA_ajaxShowMessage(data.error, false);
}

1 comment on commit b125057

@lem9
lem9 commented on b125057 Dec 23, 2012

Thanks, I was not familiar with this technique. I committed in your name, see 5633958

Please sign in to comment.
Something went wrong with that request. Please try again.