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