From 1ed073f178f65e13635db7bf92ebc5c9e61e7fc0 Mon Sep 17 00:00:00 2001 From: Ashutosh Dhundhara Date: Wed, 13 Aug 2014 15:21:01 +0530 Subject: [PATCH] Drop foreign key anchor in Relation view. Signed-off-by: Ashutosh Dhundhara --- js/messages.php | 1 + js/tbl_relation.js | 32 ++++++++++++++++++++++++++++++++ libraries/tbl_relation.lib.php | 32 +++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/js/messages.php b/js/messages.php index 3f4d5933ad..9b676280c8 100644 --- a/js/messages.php +++ b/js/messages.php @@ -40,6 +40,7 @@ $js_messages['strTruncateTableStrongWarning'] = __('You are about to TRUNCATE a $js_messages['strDeleteTrackingData'] = __('Delete tracking data for this table'); $js_messages['strDeletingTrackingData'] = __('Deleting tracking data'); $js_messages['strDroppingPrimaryKeyIndex'] = __('Dropping Primary Key/Index'); +$js_messages['strDroppingForeignKey'] = __('Dropping Foreign key.'); $js_messages['strOperationTakesLongTime'] = __('This operation could take a long time. Proceed anyway?'); $js_messages['strDropUserGroupWarning'] = __('Do you really want to delete user group "%s"?'); $js_messages['strConfirmDeleteQBESearch'] = __('Do you really want to delete the search "%s"?'); diff --git a/js/tbl_relation.js b/js/tbl_relation.js index 67522ed6d0..2da5b20359 100644 --- a/js/tbl_relation.js +++ b/js/tbl_relation.js @@ -115,6 +115,7 @@ AJAX.registerTeardown('tbl_relation.js', function () { ); $('body').off('click', 'a.add_foreign_key_field'); $('body').off('click', 'a.add_foreign_key'); + $('a.drop_foreign_key_anchor.ajax').off('click'); }); AJAX.registerOnload('tbl_relation.js', function () { @@ -190,4 +191,35 @@ AJAX.registerOnload('tbl_relation.js', function () { // Finally add the row. $new_row.insertAfter($prev_row); }); + + /** + * Ajax Event handler for 'Drop Foreign key' + */ + $('a.drop_foreign_key_anchor.ajax').on('click', function (event) { + event.preventDefault(); + var $anchor = $(this); + + // Object containing reference to the current field's row + var $curr_row = $anchor.parents('tr'); + + var question = escapeHtml( + $curr_row.children('td') + .children('.drop_foreign_key_msg') + .val() + ); + + $anchor.PMA_confirm(question, $anchor.attr('href'), function (url) { + var $msg = PMA_ajaxShowMessage(PMA_messages.strDroppingForeignKey, false); + $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function (data) { + if (data.success === true) { + PMA_ajaxRemoveMessage($msg); + PMA_commonActions.refreshMain(false, function () { + // Do nothing + }); + } else { + PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest + " : " + data.error, false); + } + }); // end $.get() + }); // end $.PMA_confirm() + }); //end Drop Foreign key }); diff --git a/libraries/tbl_relation.lib.php b/libraries/tbl_relation.lib.php index 6802f30f58..b0a583108d 100644 --- a/libraries/tbl_relation.lib.php +++ b/libraries/tbl_relation.lib.php @@ -371,7 +371,8 @@ function PMA_getHtmlForForeignKeyForm($columns, $existrel_foreign, $db, . '' . __('Foreign key constraints') . '' . ''; - $html_output .= '' + $html_output .= ''; + $html_output .= '' . ''; + // Drop key anchor. + $html_output .= ''; $html_output .= '
' . __('Constraint properties') . '
' . __('Actions') . '' . __('Constraint properties') . '' . __('Column') . PMA_Util::showHint( @@ -428,6 +429,35 @@ function PMA_getHtmlForForeignKeyRow($one_key, $odd_row, $columns, $i, $options_array, $tbl_storage_engine, $db ) { $html_output = '
'; + if (isset($one_key['constraint'])) { + $drop_fk_query = 'ALTER TABLE ' . PMA_Util::backquote($GLOBALS['table']) + . ' DROP FOREIGN KEY ' + . PMA_Util::backquote($one_key['constraint']) . ';'; + $this_params = $GLOBALS['url_params']; + $this_params['goto'] = 'tbl_relation.php'; + $this_params['back'] = 'tbl_relation.php'; + $this_params['sql_query'] = $drop_fk_query; + $this_params['message_to_show'] = sprintf( + __('Foreign key constraint %s has been dropped'), + $one_key['constraint'] + ); + $js_msg = PMA_jsFormat( + 'ALTER TABLE ' . $GLOBALS['table'] + . ' DROP FOREIGN KEY ' + . $one_key['constraint'] . ';' + ); + + $html_output .= ''; + $html_output .= ' ' + . PMA_Util::getIcon('b_drop.png', __('Drop')) . ''; + } + $html_output .= ''; $html_output .= ''; $constraint_name = isset($one_key['constraint'])