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 $.post($form.attr('action'), $form.serialize() + "&submit_copy=Go", function (data) {
28 if (typeof data !== 'undefined' && data.success === true) {
29 if ($form.find("input[name='switch_to_new']").prop('checked')) {
30 PMA_commonParams.set('db', data.db);
33 $form.find("input[name='new_name']").val()
35 PMA_commonActions.refreshMain(false, function () {
36 PMA_ajaxShowMessage(data.message);
39 PMA_ajaxShowMessage(data.message);
41 // Refresh navigation when the table is copied
42 PMA_reloadNavigation();
44 PMA_ajaxShowMessage(data.error, false);
47 });//end of copyTable ajax submit
50 *Ajax action for submitting the "Move table"
52 $(document).on('submit', "#moveTableForm", function (event) {
53 event.preventDefault();
55 var db = $form.find('select[name=target_db]').val();
56 var tbl = $form.find('input[name=new_name]').val();
57 PMA_prepareForAjaxRequest($form);
58 $.post($form.attr('action'), $form.serialize() + "&submit_move=1", function (data) {
59 if (typeof data !== 'undefined' && data.success === true) {
60 PMA_commonParams.set('db', db);
61 PMA_commonParams.set('table', tbl);
62 PMA_commonActions.refreshMain(false, function () {
63 PMA_ajaxShowMessage(data.message);
65 // Refresh navigation when the table is copied
66 PMA_reloadNavigation();
68 PMA_ajaxShowMessage(data.error, false);
74 * Ajax action for submitting the "Table options"
76 $(document).on('submit', "#tableOptionsForm", function (event) {
77 event.preventDefault();
78 event.stopPropagation();
80 var $tblNameField = $form.find('input[name=new_name]');
81 var $tblCollationField = $form.find('select[name=tbl_collation]');
82 var collationOrigValue = $('select[name="tbl_collation"] option[selected]').val();
83 var $changeAllColumnCollationsCheckBox = $('#checkbox_change_all_collations');
84 var question = PMA_messages.strChangeAllColumnCollationsWarning;
86 if ($tblNameField.val() !== $tblNameField[0].defaultValue) {
87 // reload page and navigation if the table has been renamed
88 PMA_prepareForAjaxRequest($form);
89 var tbl = $tblNameField.val();
91 if ($tblCollationField.val() !== collationOrigValue && $changeAllColumnCollationsCheckBox.is(':checked')) {
92 $form.PMA_confirm(question, $form.attr('action'), function (url) {
100 if ($tblCollationField.val() !== collationOrigValue && $changeAllColumnCollationsCheckBox.is(':checked')) {
101 $form.PMA_confirm(question, $form.attr('action'), function (url) {
102 $form.removeClass('ajax').submit().addClass('ajax');
105 $form.removeClass('ajax').submit().addClass('ajax');
109 function submitOptionsForm() {
110 $.post($form.attr('action'), $form.serialize(), function (data) {
111 if (typeof data !== 'undefined' && data.success === true) {
112 PMA_commonParams.set('table', tbl);
113 PMA_commonActions.refreshMain(false, function () {
114 $('#page_content').html(data.message);
115 PMA_highlightSQL($('#page_content'));
118 PMA_ajaxShowMessage(data.error, false);
125 *Ajax events for actions in the "Table maintenance"
127 $(document).on('click', "#tbl_maintenance li a.maintain_action.ajax", function (event) {
128 event.preventDefault();
129 if ($(".sqlqueryresults").length !== 0) {
130 $(".sqlqueryresults").remove();
132 if ($(".result_query").length !== 0) {
133 $(".result_query").remove();
135 //variables which stores the common attributes
136 $.post($(this).attr('href'), { ajax_request: 1 }, function (data) {
137 function scrollToTop() {
138 $('html, body').animate({ scrollTop: 0 });
141 if (typeof data !== 'undefined' && data.success === true && data.sql_query !== undefined) {
142 PMA_ajaxShowMessage(data.message);
143 $("<div class='sqlqueryresults ajax'></div>").prependTo("#page_content");
144 $(".sqlqueryresults").html(data.sql_query);
145 PMA_highlightSQL($('#page_content'));
147 } else if (typeof data !== 'undefined' && data.success === true) {
148 var $temp_div = $("<div id='temp_div'></div>");
149 $temp_div.html(data.message);
150 var $success = $temp_div.find(".result_query .success");
151 PMA_ajaxShowMessage($success);
152 $("<div class='sqlqueryresults ajax'></div>").prependTo("#page_content");
153 $(".sqlqueryresults").html(data.message);
154 PMA_highlightSQL($('#page_content'));
156 $(".sqlqueryresults").children("fieldset,br").remove();
159 $temp_div = $("<div id='temp_div'></div>");
160 $temp_div.html(data.error);
161 var $error = $temp_div.find("code").addClass("error");
162 PMA_ajaxShowMessage($error, false);
165 });//end of table maintenance ajax click
168 * Ajax action for submitting the "Partition Maintenance"
169 * Also, asks for confirmation when DROP partition is submitted
171 $(document).on('submit', "#partitionsForm", function (event) {
172 event.preventDefault();
175 function submitPartitionMaintenance() {
176 var submitData = $form.serialize() + '&ajax_request=true&ajax_page_request=true';
177 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
179 $.post($form.attr('action'), submitData, AJAX.responseHandler);
182 if ($('#partition_operation_DROP').is(':checked')) {
183 var question = PMA_messages.strDropPartitionWarning;
184 $form.PMA_confirm(question, $form.attr('action'), function (url) {
185 submitPartitionMaintenance();
187 } else if ($('#partition_operation_TRUNCATE').is(':checked')) {
188 var question = PMA_messages.strTruncatePartitionWarning;
189 $form.PMA_confirm(question, $form.attr('action'), function (url) {
190 submitPartitionMaintenance();
193 submitPartitionMaintenance();
197 $(document).on('click', "#drop_tbl_anchor.ajax", function (event) {
198 event.preventDefault();
200 * @var question String containing the question to be asked for confirmation
202 var question = PMA_messages.strDropTableStrongWarning + ' ';
203 question += PMA_sprintf(
204 PMA_messages.strDoYouReally,
205 'DROP TABLE ' + escapeHtml(PMA_commonParams.get('table'))
206 ) + getForeignKeyCheckboxLoader();
208 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
210 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
212 var params = getJSConfirmCommonParam(this);
214 $.get(url, params, function (data) {
215 if (typeof data !== 'undefined' && data.success === true) {
216 PMA_ajaxRemoveMessage($msgbox);
217 // Table deleted successfully, refresh both the frames
218 PMA_reloadNavigation();
219 PMA_commonParams.set('table', '');
220 PMA_commonActions.refreshMain(
221 PMA_commonParams.get('opendb_url'),
223 PMA_ajaxShowMessage(data.message);
227 PMA_ajaxShowMessage(data.error, false);
230 }, loadForeignKeyCheckbox); // end $.PMA_confirm()
231 }); //end of Drop Table Ajax action
233 $(document).on('click', "#drop_view_anchor.ajax", function (event) {
234 event.preventDefault();
236 * @var question String containing the question to be asked for confirmation
238 var question = PMA_messages.strDropTableStrongWarning + ' ';
239 question += PMA_sprintf(
240 PMA_messages.strDoYouReally,
241 'DROP VIEW ' + escapeHtml(PMA_commonParams.get('table'))
244 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
246 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
247 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function (data) {
248 if (typeof data !== 'undefined' && data.success === true) {
249 PMA_ajaxRemoveMessage($msgbox);
250 // Table deleted successfully, refresh both the frames
251 PMA_reloadNavigation();
252 PMA_commonParams.set('table', '');
253 PMA_commonActions.refreshMain(
254 PMA_commonParams.get('opendb_url'),
256 PMA_ajaxShowMessage(data.message);
260 PMA_ajaxShowMessage(data.error, false);
263 }); // end $.PMA_confirm()
264 }); //end of Drop View Ajax action
266 $(document).on('click', "#truncate_tbl_anchor.ajax", function (event) {
267 event.preventDefault();
269 * @var question String containing the question to be asked for confirmation
271 var question = PMA_messages.strTruncateTableStrongWarning + ' ';
272 question += PMA_sprintf(
273 PMA_messages.strDoYouReally,
274 'TRUNCATE ' + escapeHtml(PMA_commonParams.get('table'))
275 ) + getForeignKeyCheckboxLoader();
276 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
277 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
279 var params = getJSConfirmCommonParam(this);
281 $.get(url, params, function (data) {
282 if ($(".sqlqueryresults").length !== 0) {
283 $(".sqlqueryresults").remove();
285 if ($(".result_query").length !== 0) {
286 $(".result_query").remove();
288 if (typeof data !== 'undefined' && data.success === true) {
289 PMA_ajaxShowMessage(data.message);
290 $("<div class='sqlqueryresults ajax'></div>").prependTo("#page_content");
291 $(".sqlqueryresults").html(data.sql_query);
292 PMA_highlightSQL($('#page_content'));
294 PMA_ajaxShowMessage(data.error, false);
297 }, loadForeignKeyCheckbox); // end $.PMA_confirm()
298 }); //end of Truncate Table Ajax action
300 }); //end $(document).ready for 'Table operations'