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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
import $ from 'jquery';
/* global Navigation */
/**
* @implements EventListener
*/
const DropDatabases = {
/**
* @param {Event} event
*/
handleEvent: function (event) {
event.preventDefault();
var $form = $(this);
/**
* @var selected_dbs Array containing the names of the checked databases
*/
var selectedDbs = [];
// 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');
selectedDbs[selectedDbs.length] = 'DROP DATABASE `' + Functions.escapeHtml($(this).val()) + '`;';
});
if (! selectedDbs.length) {
Functions.ajaxShowMessage(
$('<div class="alert alert-warning" role="alert"></div>').text(
window.Messages.strNoDatabasesSelected
),
2000
);
return;
}
/**
* @var question String containing the question to be asked for confirmation
*/
var question = window.Messages.strDropDatabaseStrongWarning + ' ' +
Functions.sprintf(window.Messages.strDoYouReally, selectedDbs.join('<br>'));
const modal = $('#dropDatabaseModal');
modal.find('.modal-body').html(question);
modal.modal('show');
const url = 'index.php?route=/server/databases/destroy&' + $(this).serialize();
$('#dropDatabaseModalDropButton').on('click', function () {
Functions.ajaxShowMessage(window.Messages.strProcessingRequest, false);
var parts = url.split('?');
var params = Functions.getJsConfirmCommonParam(this, parts[1]);
$.post(parts[0], params, function (data) {
if (typeof data !== 'undefined' && data.success === true) {
Functions.ajaxShowMessage(data.message);
var $rowsToRemove = $form.find('tr.removeMe');
var $databasesCount = $('#filter-rows-count');
var newCount = parseInt($databasesCount.text(), 10) - $rowsToRemove.length;
$databasesCount.text(newCount);
$rowsToRemove.remove();
$form.find('tbody').sortTable('.name');
if ($form.find('tbody').find('tr').length === 0) {
// user just dropped the last db on this page
window.CommonActions.refreshMain();
}
Navigation.reload();
} else {
$form.find('tr.removeMe').removeClass('removeMe');
Functions.ajaxShowMessage(data.error, false);
}
});
modal.modal('hide');
$('#dropDatabaseModalDropButton').off('click');
});
}
};
/**
* @implements EventListener
*/
const CreateDatabase = {
/**
* @param {Event} event
*/
handleEvent: 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.trigger('focus');
alert(window.Messages.strFormEmpty);
return;
}
// end remove
Functions.ajaxShowMessage(window.Messages.strProcessingRequest);
Functions.prepareForAjaxRequest($form);
$.post($form.attr('action'), $form.serialize(), function (data) {
if (typeof data !== 'undefined' && data.success === true) {
Functions.ajaxShowMessage(data.message);
var $databasesCountObject = $('#filter-rows-count');
var databasesCount = parseInt($databasesCountObject.text(), 10) + 1;
$databasesCountObject.text(databasesCount);
Navigation.reload();
// make ajax request to load db structure page - taken from ajax.js
var dbStructUrl = data.url;
dbStructUrl = dbStructUrl.replace(/amp;/ig, '');
var params = 'ajax_request=true' + window.CommonParams.get('arg_separator') + 'ajax_page_request=true';
$.get(dbStructUrl, params, window.AJAX.responseHandler);
} else {
Functions.ajaxShowMessage(data.error, false);
}
});
}
};
function checkPrivilegesForDatabase () {
var tableRows = $('.server_databases');
$.each(tableRows, function () {
$(this).on('click', function () {
window.CommonActions.setDb($(this).attr('data'));
});
});
}
window.AJAX.registerTeardown('server/databases.js', function () {
$(document).off('submit', '#dbStatsForm');
$(document).off('submit', '#create_database_form.ajax');
});
window.AJAX.registerOnload('server/databases.js', function () {
$(document).on('submit', '#dbStatsForm', DropDatabases.handleEvent);
$(document).on('submit', '#create_database_form.ajax', CreateDatabase.handleEvent);
checkPrivilegesForDatabase();
});
|