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 />'));
59 var argsep = PMA_commonParams.get('arg_separator');
62 $form.prop('action') + '?' + $(this).serialize() +
63 argsep + 'drop_selected_dbs=1',
65 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest, false);
67 var parts = url.split('?');
68 var params = getJSConfirmCommonParam(this, parts[1]);
70 $.post(parts[0], params, function (data) {
71 if (typeof data !== 'undefined' && data.success === true) {
72 PMA_ajaxShowMessage(data.message);
74 var $rowsToRemove = $form.find('tr.removeMe');
75 var $databasesCount = $('#filter-rows-count');
76 var newCount = parseInt($databasesCount.text(), 10) - $rowsToRemove.length;
77 $databasesCount.text(newCount);
79 $rowsToRemove.remove();
80 $form.find('tbody').PMA_sort_table('.name');
81 if ($form.find('tbody').find('tr').length === 0) {
82 // user just dropped the last db on this page
83 PMA_commonActions.refreshMain();
85 PMA_reloadNavigation();
87 $form.find('tr.removeMe').removeClass('removeMe');
88 PMA_ajaxShowMessage(data.error, false);
92 ); // end $.PMA_confirm()
93 }); // end of Drop Database action
96 * Attach Ajax event handlers for 'Create Database'.
98 $(document).on('submit', '#create_database_form.ajax', function (event) {
99 event.preventDefault();
103 // TODO Remove this section when all browsers support HTML5 "required" property
104 var newDbNameInput = $form.find('input[name=new_db]');
105 if (newDbNameInput.val() === '') {
106 newDbNameInput.focus();
107 alert(PMA_messages.strFormEmpty);
112 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
113 PMA_prepareForAjaxRequest($form);
115 $.post($form.attr('action'), $form.serialize(), function (data) {
116 if (typeof data !== 'undefined' && data.success === true) {
117 PMA_ajaxShowMessage(data.message);
119 var $databases_count_object = $('#filter-rows-count');
120 var databases_count = parseInt($databases_count_object.text(), 10) + 1;
121 $databases_count_object.text(databases_count);
122 PMA_reloadNavigation();
124 // make ajax request to load db structure page - taken from ajax.js
125 var dbStruct_url = data.url_query;
126 dbStruct_url = dbStruct_url.replace(/amp;/ig, '');
127 var params = 'ajax_request=true' + PMA_commonParams.get('arg_separator') + 'ajax_page_request=true';
128 if (! (history && history.pushState)) {
129 params += PMA_MicroHistory.menus.getRequestParam();
131 $.get(dbStruct_url, params, AJAX.responseHandler);
133 PMA_ajaxShowMessage(data.error, false);
136 }); // end $(document).on()
138 /* Don't show filter if number of databases are very few */
139 var databasesCount = $('#filter-rows-count').html();
140 if (databasesCount <= 10) {
141 $('#tableFilter').hide();
144 var tableRows = $('.server_databases');
145 $.each(tableRows, function (index, item) {
146 $(this).click(function () {
147 PMA_commonActions.setDb($(this).attr('data'));