Translated using Weblate (Armenian)
[phpmyadmin.git] / js / server_databases.js
blobb92d48140c6116827994cc35175966fd200f0b94
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * @fileoverview    functions used on the server databases list page
4  * @name            Server Databases
5  *
6  * @requires    jQuery
7  * @requires    jQueryUI
8  * @required    js/functions.js
9  */
11 /**
12  * Unbind all event handlers before tearing down a page
13  */
14 AJAX.registerTeardown('server_databases.js', function () {
15     $(document).off('submit', "#dbStatsForm");
16     $(document).off('submit', '#create_database_form.ajax');
17 });
19 /**
20  * AJAX scripts for server_databases.php
21  *
22  * Actions ajaxified here:
23  * Drop Databases
24  *
25  */
26 AJAX.registerOnload('server_databases.js', function () {
27     /**
28      * Attach Event Handler for 'Drop Databases'
29      */
30     $(document).on('submit', "#dbStatsForm", function (event) {
31         event.preventDefault();
33         var $form = $(this);
35         /**
36          * @var selected_dbs Array containing the names of the checked databases
37          */
38         var selected_dbs = [];
39         // loop over all checked checkboxes, except the .checkall_box checkbox
40         $form.find('input:checkbox:checked:not(.checkall_box)').each(function () {
41             $(this).closest('tr').addClass('removeMe');
42             selected_dbs[selected_dbs.length] = 'DROP DATABASE `' + escapeHtml($(this).val()) + '`;';
43         });
44         if (! selected_dbs.length) {
45             PMA_ajaxShowMessage(
46                 $('<div class="notice" />').text(
47                     PMA_messages.strNoDatabasesSelected
48                 ),
49                 2000
50             );
51             return;
52         }
53         /**
54          * @var question    String containing the question to be asked for confirmation
55          */
56         var question = PMA_messages.strDropDatabaseStrongWarning + ' ' +
57             PMA_sprintf(PMA_messages.strDoYouReally, selected_dbs.join('<br />'));
59         $(this).PMA_confirm(
60             question,
61             $form.prop('action') + '?' + $(this).serialize() +
62                 '&drop_selected_dbs=1&is_js_confirmed=1&ajax_request=true',
63             function (url) {
64                 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest, false);
66                 $.post(url, function (data) {
67                     if (typeof data !== 'undefined' && data.success === true) {
68                         PMA_ajaxShowMessage(data.message);
70                         var $rowsToRemove = $form.find('tr.removeMe');
71                         var $databasesCount = $('#databases_count');
72                         var newCount = parseInt($databasesCount.text(), 10) - $rowsToRemove.length;
73                         $databasesCount.text(newCount);
75                         $rowsToRemove.remove();
76                         $form.find('tbody').PMA_sort_table('.name');
77                         if ($form.find('tbody').find('tr').length === 0) {
78                             // user just dropped the last db on this page
79                             PMA_commonActions.refreshMain();
80                         }
81                         PMA_reloadNavigation();
82                     } else {
83                         $form.find('tr.removeMe').removeClass('removeMe');
84                         PMA_ajaxShowMessage(data.error, false);
85                     }
86                 }); // end $.post()
87             }
88         ); // end $.PMA_confirm()
89     }); //end of Drop Database action
91     /**
92      * Attach Ajax event handlers for 'Create Database'.
93      */
94     $(document).on('submit', '#create_database_form.ajax', function (event) {
95         event.preventDefault();
97         var $form = $(this);
99         // TODO Remove this section when all browsers support HTML5 "required" property
100         var newDbNameInput = $form.find('input[name=new_db]');
101         if (newDbNameInput.val() === '') {
102             newDbNameInput.focus();
103             alert(PMA_messages.strFormEmpty);
104             return;
105         }
106         // end remove
108         PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
109         PMA_prepareForAjaxRequest($form);
111         $.post($form.attr('action'), $form.serialize(), function (data) {
112             if (typeof data !== 'undefined' && data.success === true) {
113                 PMA_ajaxShowMessage(data.message);
115                 //Append database's row to table
116                 $("#tabledatabases")
117                 .find('tbody')
118                 .append(data.new_db_string)
119                 .PMA_sort_table('.name');
121                 var $databases_count_object = $('#databases_count');
122                 var databases_count = parseInt($databases_count_object.text(), 10) + 1;
123                 $databases_count_object.text(databases_count);
124                 PMA_reloadNavigation();
125             } else {
126                 PMA_ajaxShowMessage(data.error, false);
127             }
129             // make ajax request to load db structure page - taken from ajax.js
130             var dbStruct_url = data.url_query;
131             dbStruct_url = dbStruct_url.replace(/amp;/ig, '');
132             var params = 'ajax_request=true&ajax_page_request=true';
133             params += AJAX.cache.menus.getRequestParam();
134             $.get(dbStruct_url, params, AJAX.responseHandler);
135         }); // end $.post()
136     }); // end $(document).on()
137 }); // end $()