From a1800171063b31a971ae312051b89d7ad21ee42e Mon Sep 17 00:00:00 2001 From: ninadsp Date: Sun, 11 Jul 2010 22:33:52 +0530 Subject: [PATCH] Moved Ajax handlers of db_structure.php to a dedicated file js/db_structure.js from js/functions.js --- db_structure.php | 1 + js/db_structure.js | 236 ++++++++++++++++++++++++++++++++++++++++++++ js/functions.js | 238 --------------------------------------------- 3 files changed, 237 insertions(+), 238 deletions(-) create mode 100644 js/db_structure.js diff --git a/db_structure.php b/db_structure.php index 73b3e7b17..747d2d8d6 100755 --- a/db_structure.php +++ b/db_structure.php @@ -13,6 +13,7 @@ require_once './libraries/common.inc.php'; require_once './libraries/Table.class.php'; $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js'; +$GLOBALS['js_include'][] = 'db_structure.js'; /** * Prepares the tables list if the user where not redirected to this script diff --git a/js/db_structure.js b/js/db_structure.js new file mode 100644 index 000000000..eac8c2c10 --- /dev/null +++ b/js/db_structure.js @@ -0,0 +1,236 @@ +/** + * jQuery code for 'Drop Database', 'Truncate Table', 'Drop Table' action on + * db_structure.php + * + */ +$(document).ready(function() { + + //Drop Database + $("#drop_db_anchor").live('click', function(event) { + event.preventDefault(); + + //context is top.frame_content, so we need to use window.parent.db to access the db var + var question = PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window.parent.db; + + $(this).PMA_confirm(question, $(this).attr('href') ,function(url) { + + PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); + $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) { + //Database deleted successfully, refresh both the frames + window.parent.refreshNavigation(); + window.parent.refreshMain(); + }) + }); + }); //end of Drop Database Ajax action + + //Truncate Table + $(".truncate_table_anchor").live('click', function(event) { + event.preventDefault(); + + //extract current table name and build the question string + var curr_table_name = $(this).parents('tr').children('th').children('a').text(); + var question = 'TRUNCATE ' + curr_table_name; + + $(this).PMA_confirm(question, $(this).attr('href'), function(url) { + + PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); + + $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) { + if(data.success == true) { + PMA_ajaxShowMessage(data.message); + //need to find a better solution here. The icon should be replaced + $(this).remove(); + } + else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); + } + }) + }) + }); //end of Truncate Table Ajax action + + //Drop Table + $(".drop_table_anchor").live('click', function(event) { + event.preventDefault(); + + //extract current table name and build the question string + var curr_row = $(this).parents('tr'); + var curr_table_name = $(curr_row).children('th').children('a').text(); + var question = 'DROP TABLE ' + curr_table_name; + + $(this).PMA_confirm(question, $(this).attr('href'), function(url) { + + PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); + + $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) { + if(data.success == true) { + PMA_ajaxShowMessage(data.message); + //need to find a better solution here. The icon should be replaced + $(curr_row).hide("medium").remove(); + } + else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); + } + }); + }); + }); //end of Drop Table Ajax action + + //Drop Column + $(".drop_column_anchor").live('click', function(event) { + event.preventDefault(); + + var curr_table_name = window.parent.table; + var curr_row = $(this).parents('tr'); + var curr_column_name = $(curr_row).children('th').children('label').text(); + var question = PMA_messages['strDoYouReally'] + ' :\n ALTER TABLE `' + curr_table_name + '` DROP `' + curr_column_name + '`'; + + $(this).PMA_confirm(question, $(this).attr('href'), function(url) { + + PMA_ajaxShowMessage(PMA_messages['strDroppingColumn']); + + $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) { + if(data.success == true) { + PMA_ajaxShowMessage(data.message); + $(curr_row).hide("medium").remove(); + } + else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); + } + }) + }); //end of Drop Column Anchor action + }) + + //Add Primary Key + $(".add_primary_key_anchor").live('click', function(event) { + event.preventDefault(); + + var curr_table_name = window.parent.table; + var curr_column_name = $(this).parents('tr').children('th').children('label').text(); + var question = PMA_messages['strDoYouReally'] + ' :\n ALTER TABLE `' + curr_table_name + '` ADD PRIMARY KEY(`' + curr_column_name + '`)'; + + $(this).PMA_confirm(question, $(this).attr('href'), function(url) { + + PMA_ajaxShowMessage(PMA_messages['strAddingPrimaryKey']); + + $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) { + if(data.success == true) { + PMA_ajaxShowMessage(data.message); + $(this).remove(); + } + else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); + } + }) + }) + })//end Add Primary Key + + //Drop Event + $('.drop_event_anchor').live('click', function(event) { + event.preventDefault(); + + var curr_event_row = $(this).parents('tr'); + var curr_event_name = $(curr_event_row).children('td:first').text(); + var question = 'DROP EVENT ' + curr_event_name; + + $(this).PMA_confirm(question, $(this).attr('href') , function(url) { + + PMA_ajaxShowMessage(PMA_messages['strDroppingEvent']); + + $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { + if(data.success == true) { + PMA_ajaxShowMessage(data.message); + $(curr_event_row).hide("medium").remove(); + } + else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); + } + }) + }) + }) + //end Drop Event + + //Drop Procedure + $('.drop_procedure_anchor').live('click', function(event) { + event.preventDefault(); + + var curr_proc_row = $(this).parents('tr'); + var question = $(curr_proc_row).children('.drop_procedure_sql').val(); + + $(this).PMA_confirm(question, $(this).attr('href'), function(url) { + + PMA_ajaxShowMessage(PMA_messages['strDroppingProcedure']); + + $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { + if(data.success == true) { + PMA_ajaxShowMessage(data.message); + $(curr_event_row).hide("medium").remove(); + } + else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); + } + }) + }) + }) + //end Drop Procedure + + //Drop Tracking + $('.drop_tracking_anchor').live('click', function(event) { + event.preventDefault(); + + var curr_tracking_row = $(this).parents('tr'); + var question = PMA_messages['strDeleteTrackingData']; + + $(this).PMA_confirm(question, $(this).attr('href'), function(url) { + + PMA_ajaxShowMessage(PMA_messages['strDeletingTrackingData']); + + $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { + if(data.success == true) { + PMA_ajaxShowMessage(data.message); + $(curr_tracking_row).hide("medium").remove(); + } + else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); + } + }) + }) + }) + //end Drop Tracking + + //Drop Primary Key/Index + $('.drop_primary_key_index_anchor').live('click', function(event) { + event.preventDefault(); + + var curr_row = $(this).parents('tr'); + var question = $(curr_row).children('.drop_primary_key_index_msg').val(); + + $(this).PMA_confirm(question, $(this).attr('href'), function(url) { + + PMA_ajaxShowMessage(PMA_messages['strDroppingPrimaryKeyIndex']); + + $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { + if(data.success == true) { + PMA_ajaxShowMessage(data.message); + $(curr_row).hide("medium").remove(); + } + else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); + } + }) + }) + }) + //end Drop Primary Key/Index + + //Calculate Real End for InnoDB + $('#real_end_input').live('click', function(event) { + event.preventDefault(); + + var question = PMA_messages['strOperationTakesLongTime']; + + $(this).PMA_confirm(question, '', function() { + return true; + }) + return false; + }) + //end Calculate Real End for InnoDB + +}, 'top.frame_content'); \ No newline at end of file diff --git a/js/functions.js b/js/functions.js index 2cd1c4758..36c9089fa 100755 --- a/js/functions.js +++ b/js/functions.js @@ -1811,244 +1811,6 @@ jQuery.fn.PMA_confirm = function(question, url, callbackFn) { .dialog({buttons: button_options}); }; -/** - * jQuery code for 'Drop Database', 'Truncate Table', 'Drop Table' action on - * db_structure.php - * - * @todo move to a different file as it is not required on every page - */ -$(document).ready(function() { - - //Drop Database - $("#drop_db_anchor").live('click', function(event) { - event.preventDefault(); - - //context is top.frame_content, so we need to use window.parent.db to access the db var - var question = PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + 'DROP DATABASE ' + window.parent.db; - - $(this).PMA_confirm(question, $(this).attr('href') ,function(url) { - - PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); - $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function(data) { - //Database deleted successfully, refresh both the frames - window.parent.refreshNavigation(); - window.parent.refreshMain(); - }) - }); - }); //end of Drop Database Ajax action - - //Truncate Table - $(".truncate_table_anchor").live('click', function(event) { - event.preventDefault(); - - //extract current table name and build the question string - var curr_table_name = $(this).parents('tr').children('th').children('a').text(); - var question = 'TRUNCATE ' + curr_table_name; - - $(this).PMA_confirm(question, $(this).attr('href'), function(url) { - - PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); - - $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) { - if(data.success == true) { - PMA_ajaxShowMessage(data.message); - //need to find a better solution here. The icon should be replaced - $(this).remove(); - } - else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); - } - }) - }) - }); //end of Truncate Table Ajax action - - //Drop Table - $(".drop_table_anchor").live('click', function(event) { - event.preventDefault(); - - //extract current table name and build the question string - var curr_row = $(this).parents('tr'); - var curr_table_name = $(curr_row).children('th').children('a').text(); - var question = 'DROP TABLE ' + curr_table_name; - - $(this).PMA_confirm(question, $(this).attr('href'), function(url) { - - PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); - - $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) { - if(data.success == true) { - PMA_ajaxShowMessage(data.message); - //need to find a better solution here. The icon should be replaced - $(curr_row).hide("medium").remove(); - } - else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); - } - }); - }); - }); //end of Drop Table Ajax action - - //Drop Column - $(".drop_column_anchor").live('click', function(event) { - event.preventDefault(); - - var curr_table_name = window.parent.table; - var curr_row = $(this).parents('tr'); - var curr_column_name = $(curr_row).children('th').children('label').text(); - var question = PMA_messages['strDoYouReally'] + ' :\n ALTER TABLE `' + curr_table_name + '` DROP `' + curr_column_name + '`'; - - $(this).PMA_confirm(question, $(this).attr('href'), function(url) { - - PMA_ajaxShowMessage(PMA_messages['strDroppingColumn']); - - $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) { - if(data.success == true) { - PMA_ajaxShowMessage(data.message); - $(curr_row).hide("medium").remove(); - } - else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); - } - }) - }); //end of Drop Column Anchor action - }) - - //Add Primary Key - $(".add_primary_key_anchor").live('click', function(event) { - event.preventDefault(); - - var curr_table_name = window.parent.table; - var curr_column_name = $(this).parents('tr').children('th').children('label').text(); - var question = PMA_messages['strDoYouReally'] + ' :\n ALTER TABLE `' + curr_table_name + '` ADD PRIMARY KEY(`' + curr_column_name + '`)'; - - $(this).PMA_confirm(question, $(this).attr('href'), function(url) { - - PMA_ajaxShowMessage(PMA_messages['strAddingPrimaryKey']); - - $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) { - if(data.success == true) { - PMA_ajaxShowMessage(data.message); - $(this).remove(); - } - else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); - } - }) - }) - })//end Add Primary Key - - //Drop Event - $('.drop_event_anchor').live('click', function(event) { - event.preventDefault(); - - var curr_event_row = $(this).parents('tr'); - var curr_event_name = $(curr_event_row).children('td:first').text(); - var question = 'DROP EVENT ' + curr_event_name; - - $(this).PMA_confirm(question, $(this).attr('href') , function(url) { - - PMA_ajaxShowMessage(PMA_messages['strDroppingEvent']); - - $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { - if(data.success == true) { - PMA_ajaxShowMessage(data.message); - $(curr_event_row).hide("medium").remove(); - } - else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); - } - }) - }) - }) - //end Drop Event - - //Drop Procedure - $('.drop_procedure_anchor').live('click', function(event) { - event.preventDefault(); - - var curr_proc_row = $(this).parents('tr'); - var question = $(curr_proc_row).children('.drop_procedure_sql').val(); - - $(this).PMA_confirm(question, $(this).attr('href'), function(url) { - - PMA_ajaxShowMessage(PMA_messages['strDroppingProcedure']); - - $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { - if(data.success == true) { - PMA_ajaxShowMessage(data.message); - $(curr_event_row).hide("medium").remove(); - } - else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); - } - }) - }) - }) - //end Drop Procedure - - //Drop Tracking - $('.drop_tracking_anchor').live('click', function(event) { - event.preventDefault(); - - var curr_tracking_row = $(this).parents('tr'); - var question = PMA_messages['strDeleteTrackingData']; - - $(this).PMA_confirm(question, $(this).attr('href'), function(url) { - - PMA_ajaxShowMessage(PMA_messages['strDeletingTrackingData']); - - $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { - if(data.success == true) { - PMA_ajaxShowMessage(data.message); - $(curr_tracking_row).hide("medium").remove(); - } - else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); - } - }) - }) - }) - //end Drop Tracking - - //Drop Primary Key/Index - $('.drop_primary_key_index_anchor').live('click', function(event) { - event.preventDefault(); - - var curr_row = $(this).parents('tr'); - var question = $(curr_row).children('.drop_primary_key_index_msg').val(); - - $(this).PMA_confirm(question, $(this).attr('href'), function(url) { - - PMA_ajaxShowMessage(PMA_messages['strDroppingPrimaryKeyIndex']); - - $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { - if(data.success == true) { - PMA_ajaxShowMessage(data.message); - $(curr_row).hide("medium").remove(); - } - else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error); - } - }) - }) - }) - //end Drop Primary Key/Index - - //Calculate Real End for InnoDB - $('#real_end_input').live('click', function(event) { - event.preventDefault(); - - var question = PMA_messages['strOperationTakesLongTime']; - - $(this).PMA_confirm(question, '', function() { - return true; - }) - return false; - }) - //end Calculate Real End for InnoDB - -}, 'top.frame_content'); //end $(document).ready() for db_structure.php - /** * jQuery coding for 'Create Table'. Used on db_operations.php, * db_structure.php and db_tracking.php (i.e., wherever