From 5f0c8ca155e2bb50f3dfe7cf3780908ba67f61b2 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 21 Mar 2013 14:32:13 +0200 Subject: [PATCH 1/8] Added success and failure callbacks to the method that submits the index form --- js/functions.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/functions.js b/js/functions.js index 1c33569de9..bb619724f1 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2776,7 +2776,7 @@ AJAX.registerOnload('functions.js', function() { }); }); -function indexEditorDialog(url, title) +function indexEditorDialog(url, title, callback_success, callback_failure) { /*Remove the hidden dialogs if there are*/ if ($('#edit_index_dialog').length != 0) { @@ -2820,6 +2820,9 @@ function indexEditorDialog(url, title) $("#edit_index_dialog").dialog("close"); } $('div.no_indexes_defined').hide(); + if(callback_success) { + callback_success(); + } PMA_reloadNavigation(); } else { var $temp_div = $("
").append(data.error); @@ -2828,6 +2831,9 @@ function indexEditorDialog(url, title) } else { var $error = $temp_div; } + if(callback_failure) { + callback_failure(); + } PMA_ajaxShowMessage($error, false); } }); // end $.post() From 75bcf1fc623600541f244ec72032d968b2fc53fe Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 21 Mar 2013 14:35:22 +0200 Subject: [PATCH 2/8] moved the method PMA_getHtmlForDisplayIndexes to the index.lib.php file --- libraries/index.lib.php | 44 +++++++++++++++++++++++++++++++++++++ libraries/structure.lib.php | 30 ------------------------- tbl_structure.php | 1 + 3 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 libraries/index.lib.php diff --git a/libraries/index.lib.php b/libraries/index.lib.php new file mode 100644 index 0000000000..ac45bb2004 --- /dev/null +++ b/libraries/index.lib.php @@ -0,0 +1,44 @@ +' + . '
'; + $html_output .= PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']) + . sprintf( + __('Create an index on  %s columns'), + '' + ); + $html_output .= '' + . ''; + + $html_output .= '
' + . '' + . '
' + . '
'; + + return $html_output; +} + diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index 5c040fabe4..854afc578a 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -1585,36 +1585,6 @@ function PMA_getHtmlForAddColumn($columns_list) return $html_output; } -/** - * Get HTML for display indexes - * - * @return string $html_output - */ -function PMA_getHtmlForDisplayIndexes() -{ - $html_output = PMA_Util::getDivForSliderEffect( - 'indexes', __('Indexes') - ); - $html_output .= PMA_Index::getView($GLOBALS['table'], $GLOBALS['db']); - $html_output .= '
' - . '
'; - $html_output .= PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']) - . sprintf( - __('Create an index on  %s columns'), - '' - ); - $html_output .= '' - . ''; - - $html_output .= '
' - . '
' - . '' - . ''; - - return $html_output; -} - /** * Get HTML snippet for table rows in the Information ->Space usage table * diff --git a/tbl_structure.php b/tbl_structure.php index ffaa9dbe05..1d5067b0e0 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -17,6 +17,7 @@ require_once 'libraries/mysql_charsets.lib.php'; * Function implementations for this script */ require_once 'libraries/structure.lib.php'; +require_once 'libraries/index.lib.php'; $response = PMA_Response::getInstance(); $header = $response->getHeader(); From d019381903e9646ceecedefc6a6923b3f673c70d Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 21 Mar 2013 14:37:11 +0200 Subject: [PATCH 3/8] Moved the event handlers for the index form to indexes.js --- js/indexes.js | 104 +++++++++++++++++++++++++++++++++++++++++++- js/tbl_structure.js | 92 --------------------------------------- 2 files changed, 103 insertions(+), 93 deletions(-) diff --git a/js/indexes.js b/js/indexes.js index 3895bf7c85..d33046387e 100644 --- a/js/indexes.js +++ b/js/indexes.js @@ -1,7 +1,11 @@ /* vim: set expandtab sw=4 ts=4 sts=4: */ /** - * function used for index manipulation pages + * @fileoverview function used for index manipulation pages + * @name Table Structure * + * @requires jQuery + * @requires jQueryUI + * @required js/functions.js */ /** @@ -81,6 +85,9 @@ function checkIndexType() */ AJAX.registerTeardown('indexes.js', function() { $('#select_index_type').die('change'); + $('a.drop_primary_key_index_anchor.ajax').die('click'); + $("#table_index tbody tr td.edit_index.ajax, #indexes .add_index.ajax").die('click'); + $('#index_frm input[type=submit]').die('click'); }); /** @@ -89,6 +96,7 @@ AJAX.registerTeardown('indexes.js', function() { * Actions ajaxified here: * */ AJAX.registerOnload('indexes.js', function() { @@ -99,4 +107,98 @@ AJAX.registerOnload('indexes.js', function() { checkIndexType(); checkIndexName("index_frm"); }); + + /** + * Ajax Event handler for 'Drop Index' + */ + $('a.drop_primary_key_index_anchor.ajax').live('click', function(event) { + event.preventDefault(); + var $anchor = $(this); + /** + * @var $curr_row Object containing reference to the current field's row + */ + var $curr_row = $anchor.parents('tr'); + /** @var Number of columns in the key */ + var rows = $anchor.parents('td').attr('rowspan') || 1; + /** @var Rows that should be hidden */ + var $rows_to_hide = $curr_row; + for (var i = 1, $last_row = $curr_row.next(); i < rows; i++, $last_row = $last_row.next()) { + $rows_to_hide = $rows_to_hide.add($last_row); + } + + var question = escapeHtml( + $curr_row.children('td') + .children('.drop_primary_key_index_msg') + .val() + ); + + $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) { + var $msg = PMA_ajaxShowMessage(PMA_messages['strDroppingPrimaryKeyIndex'], false); + $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { + if (data.success == true) { + PMA_ajaxRemoveMessage($msg); + var $table_ref = $rows_to_hide.closest('table'); + if ($rows_to_hide.length == $table_ref.find('tbody > tr').length) { + // We are about to remove all rows from the table + $table_ref.hide('medium', function() { + $('div.no_indexes_defined').show('medium'); + $rows_to_hide.remove(); + }); + $table_ref.siblings('div.notice').hide('medium'); + } else { + // We are removing some of the rows only + toggleRowColors($rows_to_hide.last().next()); + $rows_to_hide.hide("medium", function () { + $(this).remove(); + }); + } + if ($('#result_query').length) { + $('#result_query').remove(); + } + if (data.sql_query) { + $('
') + .html(data.sql_query) + .prependTo('#page_content'); + } + PMA_reloadNavigation(); + document.location.reload(true); + } else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false); + } + }); // end $.get() + }); // end $.PMA_confirm() + }); //end Drop Primary Key/Index + + /** + *Ajax event handler for index edit + **/ + $("#table_index tbody tr td.edit_index.ajax, #indexes .add_index.ajax").live('click', function(event) { + event.preventDefault(); + if ($(this).find("a").length == 0) { + // Add index + var valid = checkFormElementInRange( + $(this).closest('form')[0], + 'added_fields', + 'Column count has to be larger than zero.' + ); + if (! valid) { + return; + } + var url = $(this).closest('form').serialize(); + var title = PMA_messages['strAddIndex']; + } else { + // Edit index + var url = $(this).find("a").attr("href"); + if (url.substring(0, 16) == "tbl_indexes.php?") { + url = url.substring(16, url.length); + } + var title = PMA_messages['strEditIndex']; + } + url += "&ajax_request=true"; + indexEditorDialog(url, title, function() { + var location = document.location.href.split("#")[0]; + // refresh the page using ajax + $('').click(AJAX.requestHandler).click(); + }); + }); }); diff --git a/js/tbl_structure.js b/js/tbl_structure.js index ebbd6291cd..0f6e5f0bf6 100644 --- a/js/tbl_structure.js +++ b/js/tbl_structure.js @@ -26,9 +26,6 @@ AJAX.registerTeardown('tbl_structure.js', function() { $("button.change_columns_anchor.ajax, input.change_columns_anchor.ajax").die('click'); $("a.drop_column_anchor.ajax").die('click'); $("a.add_primary_key_anchor.ajax").die('click'); - $('a.drop_primary_key_index_anchor.ajax').die('click'); - $("#table_index tbody tr td.edit_index.ajax, #indexes .add_index.ajax").die('click'); - $('#index_frm input[type=submit]').die('click'); $("#move_columns_anchor").die('click'); $(".append_fields_form.ajax").unbind('submit'); }); @@ -219,95 +216,6 @@ AJAX.registerOnload('tbl_structure.js', function() { }); // end $.PMA_confirm() }); //end Add Primary Key - /** - * Ajax Event handler for 'Drop Primary Key/Index' - */ - $('a.drop_primary_key_index_anchor.ajax').live('click', function(event) { - event.preventDefault(); - var $anchor = $(this); - /** - * @var $curr_row Object containing reference to the current field's row - */ - var $curr_row = $anchor.parents('tr'); - /** @var Number of columns in the key */ - var rows = $anchor.parents('td').attr('rowspan') || 1; - /** @var Rows that should be hidden */ - var $rows_to_hide = $curr_row; - for (var i = 1, $last_row = $curr_row.next(); i < rows; i++, $last_row = $last_row.next()) { - $rows_to_hide = $rows_to_hide.add($last_row); - } - - var question = escapeHtml( - $curr_row.children('td') - .children('.drop_primary_key_index_msg') - .val() - ); - - $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) { - var $msg = PMA_ajaxShowMessage(PMA_messages['strDroppingPrimaryKeyIndex'], false); - $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { - if (data.success == true) { - PMA_ajaxRemoveMessage($msg); - var $table_ref = $rows_to_hide.closest('table'); - if ($rows_to_hide.length == $table_ref.find('tbody > tr').length) { - // We are about to remove all rows from the table - $table_ref.hide('medium', function() { - $('div.no_indexes_defined').show('medium'); - $rows_to_hide.remove(); - }); - $table_ref.siblings('div.notice').hide('medium'); - } else { - // We are removing some of the rows only - toggleRowColors($rows_to_hide.last().next()); - $rows_to_hide.hide("medium", function () { - $(this).remove(); - }); - } - if ($('#result_query').length) { - $('#result_query').remove(); - } - if (data.sql_query) { - $('
') - .html(data.sql_query) - .prependTo('#page_content'); - } - PMA_reloadNavigation(); - } else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false); - } - }); // end $.get() - }); // end $.PMA_confirm() - }); //end Drop Primary Key/Index - - /** - *Ajax event handler for index edit - **/ - $("#table_index tbody tr td.edit_index.ajax, #indexes .add_index.ajax").live('click', function(event) { - event.preventDefault(); - if ($(this).find("a").length == 0) { - // Add index - var valid = checkFormElementInRange( - $(this).closest('form')[0], - 'added_fields', - 'Column count has to be larger than zero.' - ); - if (! valid) { - return; - } - var url = $(this).closest('form').serialize(); - var title = PMA_messages['strAddIndex']; - } else { - // Edit index - var url = $(this).find("a").attr("href"); - if (url.substring(0, 16) == "tbl_indexes.php?") { - url = url.substring(16, url.length); - } - var title = PMA_messages['strEditIndex']; - } - url += "&ajax_request=true"; - indexEditorDialog(url, title); - }); - /** * Inline move columns **/ From 0a00de92a0510036e617191c1f122bc8d80111f9 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 21 Mar 2013 14:38:12 +0200 Subject: [PATCH 4/8] Added the index form to the end of the page --- tbl_relation.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tbl_relation.php b/tbl_relation.php index ae6f62d5d7..5a7977999d 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -20,12 +20,14 @@ * Gets some core libraries */ require_once 'libraries/common.inc.php'; +require_once 'libraries/index.lib.php'; + $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('tbl_relation.js'); +$scripts->addFile('indexes.js'); -require_once 'libraries/tbl_common.inc.php'; $url_query .= '&goto=tbl_sql.php'; /** @@ -566,7 +568,9 @@ if (count($columns) > 0) { ); $html_output .= '' . "\n"; } else { - $html_output .= __('No index defined!'); + $html_output .= __('No index defined! Create one below'); + //$html_output .= "". + //"create index"; } // end if (a key exists) $html_output .= ''; } // end if (InnoDB) @@ -604,7 +608,7 @@ if (count($columns) > 0) { . '' . ''; } // end if (we have columns in this table) - +$html_output .= '
'. PMA_getHtmlForDisplayIndexes(); // Render HTML output PMA_Response::getInstance()->addHTML($html_output); From c2004e35e3fb568c4741bb8413ebde071bb1b9fc Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 21 Mar 2013 15:02:56 +0200 Subject: [PATCH 5/8] Page no longer reloads on drop of index --- js/indexes.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/indexes.js b/js/indexes.js index d33046387e..916e32feed 100644 --- a/js/indexes.js +++ b/js/indexes.js @@ -161,7 +161,6 @@ AJAX.registerOnload('indexes.js', function() { .prependTo('#page_content'); } PMA_reloadNavigation(); - document.location.reload(true); } else { PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false); } From 678a87954085f2cd6a0193403f4ba5d512ba7008 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 21 Mar 2013 21:15:23 +0200 Subject: [PATCH 6/8] Removed useless code --- tbl_relation.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tbl_relation.php b/tbl_relation.php index 5a7977999d..2200cd63cf 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -28,8 +28,6 @@ $scripts = $header->getScripts(); $scripts->addFile('tbl_relation.js'); $scripts->addFile('indexes.js'); -$url_query .= '&goto=tbl_sql.php'; - /** * Sets globals from $_POST */ @@ -569,8 +567,6 @@ if (count($columns) > 0) { $html_output .= '' . "\n"; } else { $html_output .= __('No index defined! Create one below'); - //$html_output .= "". - //"create index"; } // end if (a key exists) $html_output .= ''; } // end if (InnoDB) @@ -608,6 +604,7 @@ if (count($columns) > 0) { . '' . ''; } // end if (we have columns in this table) + $html_output .= '
'. PMA_getHtmlForDisplayIndexes(); // Render HTML output PMA_Response::getInstance()->addHTML($html_output); From 97deaa054c151b4f30ea7c037f19d7b621f1b8bc Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 21 Mar 2013 21:16:12 +0200 Subject: [PATCH 7/8] Fixed bug with refreshing the page in add/drop index --- js/indexes.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/indexes.js b/js/indexes.js index 916e32feed..de94076304 100644 --- a/js/indexes.js +++ b/js/indexes.js @@ -160,6 +160,9 @@ AJAX.registerOnload('indexes.js', function() { .html(data.sql_query) .prependTo('#page_content'); } + PMA_commonActions.refreshMain(false, function() { + $("a.ajax[href^=#indexes]").click(); + }); PMA_reloadNavigation(); } else { PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false); @@ -195,9 +198,10 @@ AJAX.registerOnload('indexes.js', function() { } url += "&ajax_request=true"; indexEditorDialog(url, title, function() { - var location = document.location.href.split("#")[0]; // refresh the page using ajax - $('').click(AJAX.requestHandler).click(); + PMA_commonActions.refreshMain(false, function() { + $("a.ajax[href^=#indexes]").click(); + }); }); }); }); From 963aaebdd8b068366f236eb89b9737652fa20721 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 21 Mar 2013 22:51:21 +0200 Subject: [PATCH 8/8] Fixed spacing as per guidelines --- js/functions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/functions.js b/js/functions.js index bb619724f1..b982557bcf 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2820,7 +2820,7 @@ function indexEditorDialog(url, title, callback_success, callback_failure) $("#edit_index_dialog").dialog("close"); } $('div.no_indexes_defined').hide(); - if(callback_success) { + if (callback_success) { callback_success(); } PMA_reloadNavigation(); @@ -2831,7 +2831,7 @@ function indexEditorDialog(url, title, callback_success, callback_failure) } else { var $error = $temp_div; } - if(callback_failure) { + if (callback_failure) { callback_failure(); } PMA_ajaxShowMessage($error, false);