Translated using Weblate (Armenian)
[phpmyadmin.git] / js / tbl_operations.js
blob6300c7c390fd05ef6d3e4e9120294688dd94c8e4
1 /**
2  * Unbind all event handlers before tearing down a page
3  */
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");
13 });
15 /**
16  * jQuery coding for 'Table operations'.  Used on tbl_operations.php
17  * Attach Ajax Event handlers for Table operations
18  */
19 AJAX.registerOnload('tbl_operations.js', function () {
20     /**
21      *Ajax action for submitting the "Copy table"
22      **/
23     $(document).on('submit', "#copyTable.ajax", function (event) {
24         event.preventDefault();
25         var $form = $(this);
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);
31                     PMA_commonParams.set(
32                         'table',
33                         $form.find("input[name='new_name']").val()
34                     );
35                     PMA_commonActions.refreshMain(false, function () {
36                         PMA_ajaxShowMessage(data.message);
37                     });
38                 } else {
39                     PMA_ajaxShowMessage(data.message);
40                 }
41                 // Refresh navigation when the table is copied
42                 PMA_reloadNavigation();
43             } else {
44                 PMA_ajaxShowMessage(data.error, false);
45             }
46         }); // end $.post()
47     });//end of copyTable ajax submit
49     /**
50      *Ajax action for submitting the "Move table"
51      */
52     $(document).on('submit', "#moveTableForm", function (event) {
53         event.preventDefault();
54         var $form = $(this);
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);
64                 });
65                 // Refresh navigation when the table is copied
66                 PMA_reloadNavigation();
67             } else {
68                 PMA_ajaxShowMessage(data.error, false);
69             }
70         }); // end $.post()
71     });
73     /**
74      * Ajax action for submitting the "Table options"
75      */
76     $(document).on('submit', "#tableOptionsForm", function (event) {
77         event.preventDefault();
78         event.stopPropagation();
79         var $form = $(this);
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) {
93                     submitOptionsForm();
94                 });
95             } else {
96                 submitOptionsForm();
97             }
98         } else {
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');
103                 });
104             } else {
105                 $form.removeClass('ajax').submit().addClass('ajax');
106             }
107         }
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'));
116                     });
117                 } else {
118                     PMA_ajaxShowMessage(data.error, false);
119                 }
120             }); // end $.post()
121         }
122     });
124     /**
125      *Ajax events for actions in the "Table maintenance"
126     **/
127     $(document).on('click', "#tbl_maintenance li a.maintain_action.ajax", function (event) {
128         event.preventDefault();
129         if ($(".sqlqueryresults").length !== 0) {
130             $(".sqlqueryresults").remove();
131         }
132         if ($(".result_query").length !== 0) {
133             $(".result_query").remove();
134         }
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 });
139             }
140             var $temp_div;
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'));
146                 scrollToTop();
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'));
155                 PMA_init_slider();
156                 $(".sqlqueryresults").children("fieldset,br").remove();
157                 scrollToTop();
158             } else {
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);
163             }
164         }); // end $.post()
165     });//end of table maintenance ajax click
167     /**
168      * Ajax action for submitting the "Partition Maintenance"
169      * Also, asks for confirmation when DROP partition is submitted
170      */
171     $(document).on('submit', "#partitionsForm", function (event) {
172         event.preventDefault();
173         var $form = $(this);
175         function submitPartitionMaintenance() {
176             var submitData = $form.serialize() + '&ajax_request=true&ajax_page_request=true';
177             PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
178             AJAX.source = $form;
179             $.post($form.attr('action'), submitData, AJAX.responseHandler);
180         }
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();
186             });
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();
191             });
192         } else {
193             submitPartitionMaintenance();
194         }
195     });
197     $(document).on('click', "#drop_tbl_anchor.ajax", function (event) {
198         event.preventDefault();
199         /**
200          * @var question    String containing the question to be asked for confirmation
201          */
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'),
222                         function () {
223                             PMA_ajaxShowMessage(data.message);
224                         }
225                     );
226                 } else {
227                     PMA_ajaxShowMessage(data.error, false);
228                 }
229             }); // end $.get()
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();
235         /**
236          * @var question    String containing the question to be asked for confirmation
237          */
238         var question = PMA_messages.strDropTableStrongWarning + ' ';
239         question += PMA_sprintf(
240             PMA_messages.strDoYouReally,
241             'DROP VIEW ' + escapeHtml(PMA_commonParams.get('table'))
242         );
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'),
255                         function () {
256                             PMA_ajaxShowMessage(data.message);
257                         }
258                     );
259                 } else {
260                     PMA_ajaxShowMessage(data.error, false);
261                 }
262             }); // end $.get()
263         }); // end $.PMA_confirm()
264     }); //end of Drop View Ajax action
266     $(document).on('click', "#truncate_tbl_anchor.ajax", function (event) {
267         event.preventDefault();
268         /**
269          * @var question    String containing the question to be asked for confirmation
270          */
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();
284                 }
285                 if ($(".result_query").length !== 0) {
286                     $(".result_query").remove();
287                 }
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'));
293                 } else {
294                     PMA_ajaxShowMessage(data.error, false);
295                 }
296             }); // end $.get()
297         }, loadForeignKeyCheckbox); // end $.PMA_confirm()
298     }); //end of Truncate Table Ajax action
300 }); //end $(document).ready for 'Table operations'