1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview functions used on the server databases list page
4 * @name Server Databases
8 * @required js/functions.js
12 * Unbind all event handlers before tearing down a page
14 AJAX.registerTeardown('server_databases.js', function () {
15 $(document).off('submit', "#dbStatsForm");
16 $(document).off('submit', '#create_database_form.ajax');
20 * AJAX scripts for server_databases.php
22 * Actions ajaxified here:
26 AJAX.registerOnload('server_databases.js', function () {
28 * Attach Event Handler for 'Drop Databases'
30 $(document).on('submit', "#dbStatsForm", function (event) {
31 event.preventDefault();
36 * @var selected_dbs Array containing the names of the checked databases
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()) + '`;';
44 if (! selected_dbs.length) {
46 $('<div class="notice" />').text(
47 PMA_messages.strNoDatabasesSelected
54 * @var question String containing the question to be asked for confirmation
56 var question = PMA_messages.strDropDatabaseStrongWarning + ' ' +
57 PMA_sprintf(PMA_messages.strDoYouReally, selected_dbs.join('<br />'));
61 $form.prop('action') + '?' + $(this).serialize() +
62 '&drop_selected_dbs=1&is_js_confirmed=1&ajax_request=true',
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();
81 PMA_reloadNavigation();
83 $form.find('tr.removeMe').removeClass('removeMe');
84 PMA_ajaxShowMessage(data.error, false);
88 ); // end $.PMA_confirm()
89 }); //end of Drop Database action
92 * Attach Ajax event handlers for 'Create Database'.
94 $(document).on('submit', '#create_database_form.ajax', function (event) {
95 event.preventDefault();
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);
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
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();
126 PMA_ajaxShowMessage(data.error, false);
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);
136 }); // end $(document).on()