2 * Unbind all event handlers before tearing down a page
4 AJAX.registerTeardown('tbl_operations.js', function () {
5 $(document).off('submit', '#copyTable.ajax');
6 $(document).off('submit', '#moveTableForm');
7 $(document).off('submit', '#tableOptionsForm');
8 $(document).off('submit', '#partitionsForm');
9 $(document).off('click', '#tbl_maintenance li a.maintain_action.ajax');
10 $(document).off('click', '#drop_tbl_anchor.ajax');
11 $(document).off('click', '#drop_view_anchor.ajax');
12 $(document).off('click', '#truncate_tbl_anchor.ajax');
16 * jQuery coding for 'Table operations'. Used on tbl_operations.php
17 * Attach Ajax Event handlers for Table operations
19 AJAX.registerOnload('tbl_operations.js', function () {
21 *Ajax action for submitting the "Copy table"
23 $(document).on('submit', '#copyTable.ajax', function (event) {
24 event.preventDefault();
26 PMA_prepareForAjaxRequest($form);
27 var argsep = PMA_commonParams.get('arg_separator');
28 $.post($form.attr('action'), $form.serialize() + argsep + 'submit_copy=Go', function (data) {
29 if (typeof data !== 'undefined' && data.success === true) {
30 if ($form.find('input[name=\'switch_to_new\']').prop('checked')) {
33 $form.find('select[name=\'target_db\']').val()
37 $form.find('input[name=\'new_name\']').val()
39 PMA_commonActions.refreshMain(false, function () {
40 PMA_ajaxShowMessage(data.message);
43 PMA_ajaxShowMessage(data.message);
45 // Refresh navigation when the table is copied
46 PMA_reloadNavigation();
48 PMA_ajaxShowMessage(data.error, false);
51 });// end of copyTable ajax submit
54 *Ajax action for submitting the "Move table"
56 $(document).on('submit', '#moveTableForm', function (event) {
57 event.preventDefault();
59 PMA_prepareForAjaxRequest($form);
60 var argsep = PMA_commonParams.get('arg_separator');
61 $.post($form.attr('action'), $form.serialize() + argsep + 'submit_move=1', function (data) {
62 if (typeof data !== 'undefined' && data.success === true) {
63 PMA_commonParams.set('db', data._params.db);
64 PMA_commonParams.set('table', data._params.table);
65 PMA_commonActions.refreshMain('tbl_sql.php', function () {
66 PMA_ajaxShowMessage(data.message);
68 // Refresh navigation when the table is copied
69 PMA_reloadNavigation();
71 PMA_ajaxShowMessage(data.error, false);
77 * Ajax action for submitting the "Table options"
79 $(document).on('submit', '#tableOptionsForm', function (event) {
80 event.preventDefault();
81 event.stopPropagation();
83 var $tblNameField = $form.find('input[name=new_name]');
84 var $tblCollationField = $form.find('select[name=tbl_collation]');
85 var collationOrigValue = $('select[name="tbl_collation"] option[selected]').val();
86 var $changeAllColumnCollationsCheckBox = $('#checkbox_change_all_collations');
87 var question = PMA_messages.strChangeAllColumnCollationsWarning;
89 if ($tblNameField.val() !== $tblNameField[0].defaultValue) {
90 // reload page and navigation if the table has been renamed
91 PMA_prepareForAjaxRequest($form);
93 if ($tblCollationField.val() !== collationOrigValue && $changeAllColumnCollationsCheckBox.is(':checked')) {
94 $form.PMA_confirm(question, $form.attr('action'), function (url) {
101 if ($tblCollationField.val() !== collationOrigValue && $changeAllColumnCollationsCheckBox.is(':checked')) {
102 $form.PMA_confirm(question, $form.attr('action'), function (url) {
103 $form.removeClass('ajax').submit().addClass('ajax');
106 $form.removeClass('ajax').submit().addClass('ajax');
110 function submitOptionsForm () {
111 $.post($form.attr('action'), $form.serialize(), function (data) {
112 if (typeof data !== 'undefined' && data.success === true) {
113 PMA_commonParams.set('table', data._params.table);
114 PMA_commonActions.refreshMain(false, function () {
115 $('#page_content').html(data.message);
116 PMA_highlightSQL($('#page_content'));
118 // Refresh navigation when the table is renamed
119 PMA_reloadNavigation();
121 PMA_ajaxShowMessage(data.error, false);
128 *Ajax events for actions in the "Table maintenance"
130 $(document).on('click', '#tbl_maintenance li a.maintain_action.ajax', function (event) {
131 event.preventDefault();
134 if ($('.sqlqueryresults').length !== 0) {
135 $('.sqlqueryresults').remove();
137 if ($('.result_query').length !== 0) {
138 $('.result_query').remove();
140 // variables which stores the common attributes
141 var params = $.param({
143 server: PMA_commonParams.get('server')
145 var postData = $link.getPostData();
147 params += PMA_commonParams.get('arg_separator') + postData;
150 $.post($link.attr('href'), params, function (data) {
151 function scrollToTop () {
152 $('html, body').animate({ scrollTop: 0 });
155 if (typeof data !== 'undefined' && data.success === true && data.sql_query !== undefined) {
156 PMA_ajaxShowMessage(data.message);
157 $('<div class=\'sqlqueryresults ajax\'></div>').prependTo('#page_content');
158 $('.sqlqueryresults').html(data.sql_query);
159 PMA_highlightSQL($('#page_content'));
161 } else if (typeof data !== 'undefined' && data.success === true) {
162 $temp_div = $('<div id=\'temp_div\'></div>');
163 $temp_div.html(data.message);
164 var $success = $temp_div.find('.result_query .success');
165 PMA_ajaxShowMessage($success);
166 $('<div class=\'sqlqueryresults ajax\'></div>').prependTo('#page_content');
167 $('.sqlqueryresults').html(data.message);
168 PMA_highlightSQL($('#page_content'));
170 $('.sqlqueryresults').children('fieldset,br').remove();
173 $temp_div = $('<div id=\'temp_div\'></div>');
174 $temp_div.html(data.error);
177 if ($temp_div.find('.error code').length !== 0) {
178 $error = $temp_div.find('.error code').addClass('error');
183 PMA_ajaxShowMessage($error, false);
186 });// end of table maintenance ajax click
189 * Ajax action for submitting the "Partition Maintenance"
190 * Also, asks for confirmation when DROP partition is submitted
192 $(document).on('submit', '#partitionsForm', function (event) {
193 event.preventDefault();
196 function submitPartitionMaintenance () {
197 var argsep = PMA_commonParams.get('arg_separator');
198 var submitData = $form.serialize() + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true';
199 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
201 $.post($form.attr('action'), submitData, AJAX.responseHandler);
204 if ($('#partition_operation_DROP').is(':checked')) {
205 var question = PMA_messages.strDropPartitionWarning;
206 $form.PMA_confirm(question, $form.attr('action'), function (url) {
207 submitPartitionMaintenance();
209 } else if ($('#partition_operation_TRUNCATE').is(':checked')) {
210 var question = PMA_messages.strTruncatePartitionWarning;
211 $form.PMA_confirm(question, $form.attr('action'), function (url) {
212 submitPartitionMaintenance();
215 submitPartitionMaintenance();
219 $(document).on('click', '#drop_tbl_anchor.ajax', function (event) {
220 event.preventDefault();
223 * @var question String containing the question to be asked for confirmation
225 var question = PMA_messages.strDropTableStrongWarning + ' ';
226 question += PMA_sprintf(
227 PMA_messages.strDoYouReally,
228 'DROP TABLE `' + escapeHtml(PMA_commonParams.get('db')) + '`.`' + escapeHtml(PMA_commonParams.get('table') + '`')
229 ) + getForeignKeyCheckboxLoader();
231 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
232 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
234 var params = getJSConfirmCommonParam(this, $link.getPostData());
236 $.post(url, params, function (data) {
237 if (typeof data !== 'undefined' && data.success === true) {
238 PMA_ajaxRemoveMessage($msgbox);
239 // Table deleted successfully, refresh both the frames
240 PMA_reloadNavigation();
241 PMA_commonParams.set('table', '');
242 PMA_commonActions.refreshMain(
243 PMA_commonParams.get('opendb_url'),
245 PMA_ajaxShowMessage(data.message);
249 PMA_ajaxShowMessage(data.error, false);
252 }, loadForeignKeyCheckbox); // end $.PMA_confirm()
253 }); // end of Drop Table Ajax action
255 $(document).on('click', '#drop_view_anchor.ajax', function (event) {
256 event.preventDefault();
259 * @var question String containing the question to be asked for confirmation
261 var question = PMA_messages.strDropTableStrongWarning + ' ';
262 question += PMA_sprintf(
263 PMA_messages.strDoYouReally,
264 'DROP VIEW `' + escapeHtml(PMA_commonParams.get('table') + '`')
267 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
268 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
269 var params = getJSConfirmCommonParam(this, $link.getPostData());
270 $.post(url, params, function (data) {
271 if (typeof data !== 'undefined' && data.success === true) {
272 PMA_ajaxRemoveMessage($msgbox);
273 // Table deleted successfully, refresh both the frames
274 PMA_reloadNavigation();
275 PMA_commonParams.set('table', '');
276 PMA_commonActions.refreshMain(
277 PMA_commonParams.get('opendb_url'),
279 PMA_ajaxShowMessage(data.message);
283 PMA_ajaxShowMessage(data.error, false);
286 }); // end $.PMA_confirm()
287 }); // end of Drop View Ajax action
289 $(document).on('click', '#truncate_tbl_anchor.ajax', function (event) {
290 event.preventDefault();
293 * @var question String containing the question to be asked for confirmation
295 var question = PMA_messages.strTruncateTableStrongWarning + ' ';
296 question += PMA_sprintf(
297 PMA_messages.strDoYouReally,
298 'TRUNCATE `' + escapeHtml(PMA_commonParams.get('db')) + '`.`' + escapeHtml(PMA_commonParams.get('table') + '`')
299 ) + getForeignKeyCheckboxLoader();
300 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
301 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
303 var params = getJSConfirmCommonParam(this, $link.getPostData());
305 $.post(url, params, function (data) {
306 if ($('.sqlqueryresults').length !== 0) {
307 $('.sqlqueryresults').remove();
309 if ($('.result_query').length !== 0) {
310 $('.result_query').remove();
312 if (typeof data !== 'undefined' && data.success === true) {
313 PMA_ajaxShowMessage(data.message);
314 $('<div class=\'sqlqueryresults ajax\'></div>').prependTo('#page_content');
315 $('.sqlqueryresults').html(data.sql_query);
316 PMA_highlightSQL($('#page_content'));
318 PMA_ajaxShowMessage(data.error, false);
321 }, loadForeignKeyCheckbox); // end $.PMA_confirm()
322 }); // end of Truncate Table Ajax action
323 }); // end $(document).ready for 'Table operations'