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('click', "#tbl_maintenance li a.maintain_action.ajax");
9 $(document).off('click', "#drop_tbl_anchor.ajax");
10 $(document).off('click', "#drop_view_anchor.ajax");
11 $(document).off('click', "#truncate_tbl_anchor.ajax");
15 * jQuery coding for 'Table operations'. Used on tbl_operations.php
16 * Attach Ajax Event handlers for Table operations
18 AJAX.registerOnload('tbl_operations.js', function () {
20 *Ajax action for submitting the "Copy table"
22 $(document).on('submit', "#copyTable.ajax", function (event) {
23 event.preventDefault();
25 PMA_prepareForAjaxRequest($form);
26 $.post($form.attr('action'), $form.serialize() + "&submit_copy=Go", function (data) {
27 if (typeof data !== 'undefined' && data.success === true) {
28 if ($form.find("input[name='switch_to_new']").prop('checked')) {
29 PMA_commonParams.set('db', data.db);
32 $form.find("input[name='new_name']").val()
34 PMA_commonActions.refreshMain(false, function () {
35 PMA_ajaxShowMessage(data.message);
38 PMA_ajaxShowMessage(data.message);
40 // Refresh navigation when the table is copied
41 PMA_reloadNavigation();
43 PMA_ajaxShowMessage(data.error, false);
46 });//end of copyTable ajax submit
49 *Ajax action for submitting the "Move table"
51 $(document).on('submit', "#moveTableForm", function (event) {
52 event.preventDefault();
54 var db = $form.find('select[name=target_db]').val();
55 var tbl = $form.find('input[name=new_name]').val();
56 PMA_prepareForAjaxRequest($form);
57 $.post($form.attr('action'), $form.serialize() + "&submit_move=1", function (data) {
58 if (typeof data !== 'undefined' && data.success === true) {
59 PMA_commonParams.set('db', db);
60 PMA_commonParams.set('table', tbl);
61 PMA_commonActions.refreshMain(false, function () {
62 PMA_ajaxShowMessage(data.message);
64 // Refresh navigation when the table is copied
65 PMA_reloadNavigation();
67 PMA_ajaxShowMessage(data.error, false);
73 * Ajax action for submitting the "Table options"
75 $(document).on('submit', "#tableOptionsForm", function (event) {
76 event.preventDefault();
77 event.stopPropagation();
79 var $tblNameField = $form.find('input[name=new_name]');
80 if ($tblNameField.val() !== $tblNameField[0].defaultValue) {
81 // reload page and navigation if the table has been renamed
82 PMA_prepareForAjaxRequest($form);
83 var tbl = $tblNameField.val();
84 $.post($form.attr('action'), $form.serialize(), function (data) {
85 if (typeof data !== 'undefined' && data.success === true) {
86 PMA_commonParams.set('table', tbl);
87 PMA_commonActions.refreshMain(false, function () {
88 $('#page_content').html(data.message);
89 PMA_highlightSQL($('#page_content'));
92 PMA_ajaxShowMessage(data.error, false);
96 $form.removeClass('ajax').submit().addClass('ajax');
101 *Ajax events for actions in the "Table maintenance"
103 $(document).on('click', "#tbl_maintenance li a.maintain_action.ajax", function (event) {
104 event.preventDefault();
105 if ($(".sqlqueryresults").length !== 0) {
106 $(".sqlqueryresults").remove();
108 if ($(".result_query").length !== 0) {
109 $(".result_query").remove();
111 //variables which stores the common attributes
112 $.post($(this).attr('href'), { ajax_request: 1 }, function (data) {
113 function scrollToTop() {
114 $('html, body').animate({ scrollTop: 0 });
117 if (typeof data !== 'undefined' && data.success === true && data.sql_query !== undefined) {
118 PMA_ajaxShowMessage(data.message);
119 $("<div class='sqlqueryresults ajax'></div>").prependTo("#page_content");
120 $(".sqlqueryresults").html(data.sql_query);
121 PMA_highlightSQL($('#page_content'));
123 } else if (typeof data !== 'undefined' && data.success === true) {
124 var $temp_div = $("<div id='temp_div'></div>");
125 $temp_div.html(data.message);
126 var $success = $temp_div.find(".result_query .success");
127 PMA_ajaxShowMessage($success);
128 $("<div class='sqlqueryresults ajax'></div>").prependTo("#page_content");
129 $(".sqlqueryresults").html(data.message);
130 PMA_highlightSQL($('#page_content'));
132 $(".sqlqueryresults").children("fieldset,br").remove();
135 $temp_div = $("<div id='temp_div'></div>");
136 $temp_div.html(data.error);
137 var $error = $temp_div.find("code").addClass("error");
138 PMA_ajaxShowMessage($error, false);
141 });//end of table maintenance ajax click
143 $(document).on('click', "#drop_tbl_anchor.ajax", function (event) {
144 event.preventDefault();
146 * @var question String containing the question to be asked for confirmation
148 var question = PMA_messages.strDropTableStrongWarning + ' ';
149 question += PMA_sprintf(
150 PMA_messages.strDoYouReally,
151 'DROP TABLE ' + escapeHtml(PMA_commonParams.get('table'))
154 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
156 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
157 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function (data) {
158 if (typeof data !== 'undefined' && data.success === true) {
159 PMA_ajaxRemoveMessage($msgbox);
160 // Table deleted successfully, refresh both the frames
161 PMA_reloadNavigation();
162 PMA_commonParams.set('table', '');
163 PMA_commonActions.refreshMain(
164 PMA_commonParams.get('opendb_url'),
166 PMA_ajaxShowMessage(data.message);
170 PMA_ajaxShowMessage(data.error, false);
173 }); // end $.PMA_confirm()
174 }); //end of Drop Table Ajax action
176 $(document).on('click', "#drop_view_anchor.ajax", function (event) {
177 event.preventDefault();
179 * @var question String containing the question to be asked for confirmation
181 var question = PMA_messages.strDropTableStrongWarning + ' ';
182 question += PMA_sprintf(
183 PMA_messages.strDoYouReally,
184 'DROP VIEW ' + escapeHtml(PMA_commonParams.get('table'))
187 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
189 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
190 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function (data) {
191 if (typeof data !== 'undefined' && data.success === true) {
192 PMA_ajaxRemoveMessage($msgbox);
193 // Table deleted successfully, refresh both the frames
194 PMA_reloadNavigation();
195 PMA_commonParams.set('table', '');
196 PMA_commonActions.refreshMain(
197 PMA_commonParams.get('opendb_url'),
199 PMA_ajaxShowMessage(data.message);
203 PMA_ajaxShowMessage(data.error, false);
206 }); // end $.PMA_confirm()
207 }); //end of Drop View Ajax action
209 $(document).on('click', "#truncate_tbl_anchor.ajax", function (event) {
210 event.preventDefault();
212 * @var question String containing the question to be asked for confirmation
214 var question = PMA_messages.strTruncateTableStrongWarning + ' ';
215 question += PMA_sprintf(
216 PMA_messages.strDoYouReally,
217 'TRUNCATE ' + escapeHtml(PMA_commonParams.get('table'))
219 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
220 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
221 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function (data) {
222 if ($(".sqlqueryresults").length !== 0) {
223 $(".sqlqueryresults").remove();
225 if ($(".result_query").length !== 0) {
226 $(".result_query").remove();
228 if (typeof data !== 'undefined' && data.success === true) {
229 PMA_ajaxShowMessage(data.message);
230 $("<div class='sqlqueryresults ajax'></div>").prependTo("#page_content");
231 $(".sqlqueryresults").html(data.sql_query);
232 PMA_highlightSQL($('#page_content'));
234 PMA_ajaxShowMessage(data.error, false);
237 }); // end $.PMA_confirm()
238 }); //end of Truncate Table Ajax action
240 }); //end $(document).ready for 'Table operations'