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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
import $ from 'jquery';
/**
* Functions used in Setup configuration forms
*/
// show this window in top frame
if (top !== self) {
window.top.location.href = location;
}
// ------------------------------------------------------------------
// Messages
//
$(function () {
if (window.location.protocol === 'https:') {
$('#no_https').remove();
} else {
$('#no_https a').on('click', function () {
var oldLocation = window.location;
window.location.href = 'https:' + oldLocation.href.substring(oldLocation.protocol.length);
return false;
});
}
var hiddenMessages = $('.hiddenmessage');
if (hiddenMessages.length > 0) {
hiddenMessages.hide();
var link = $('#show_hidden_messages');
link.on('click', function (e) {
e.preventDefault();
hiddenMessages.show();
$(this).remove();
});
link.html(link.html().replace('#MSG_COUNT', hiddenMessages.length));
link.show();
}
});
// set document width
$(function () {
var width = 0;
$('ul.tabs li').each(function () {
width += $(this).width() + 10;
});
var contentWidth = width;
width += 250;
$('body').css('min-width', width);
$('.tabs_contents').css('min-width', contentWidth);
});
//
// END: Messages
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Form validation and field operations
//
/**
* Calls server-side validation procedures
*
* @param {Element} parent input field in <fieldset> or <fieldset>
* @param {String} id validator id
* @param {object} values values hash {element1_id: value, ...}
*
* @return {bool|void}
*/
function ajaxValidate (parent, id, values) {
var $parent = $(parent);
// ensure that parent is a fieldset
if ($parent.attr('tagName') !== 'FIELDSET') {
$parent = $parent.closest('fieldset');
if ($parent.length === 0) {
return false;
}
}
if ($parent.data('ajax') !== null) {
$parent.data('ajax').abort();
}
$parent.data('ajax', $.ajax({
url: 'validate.php',
cache: false,
type: 'POST',
data: {
token: $parent.closest('form').find('input[name=token]').val(),
id: id,
values: JSON.stringify(values)
},
success: function (response) {
if (response === null) {
return;
}
var error = {};
if (typeof response !== 'object') {
error[$parent.id] = [response];
} else if (typeof response.error !== 'undefined') {
error[$parent.id] = [response.error];
} else {
for (var key in response) {
var value = response[key];
error[key] = Array.isArray(value) ? value : [value];
}
}
window.Config.displayErrors(error);
},
complete: function () {
$parent.removeData('ajax');
}
}));
return true;
}
/**
* Automatic form submission on change.
*/
$(document).on('change', '.autosubmit', function (e) {
e.target.form.submit();
});
$.extend(true, window.validators, {
// field validators
field: {
/**
* hide_db field
*
* @param {boolean} isKeyUp
*
* @return {true}
*/
hide_db: function (isKeyUp) { // eslint-disable-line camelcase
if (!isKeyUp && this.value !== '') {
var data = {};
data[this.id] = this.value;
ajaxValidate(this, 'Servers/1/hide_db', data);
}
return true;
},
/**
* TrustedProxies field
*
* @param {boolean} isKeyUp
*
* @return {true}
*/
TrustedProxies: function (isKeyUp) {
if (!isKeyUp && this.value !== '') {
var data = {};
data[this.id] = this.value;
ajaxValidate(this, 'TrustedProxies', data);
}
return true;
}
},
// fieldset validators
fieldset: {
/**
* Validates Server fieldset
*
* @param {boolean} isKeyUp
*
* @return {true}
*/
Server: function (isKeyUp) {
if (!isKeyUp) {
ajaxValidate(this, 'Server', window.Config.getAllValues());
}
return true;
},
/**
* Validates Server_login_options fieldset
*
* @param {boolean} isKeyUp
*
* @return {true}
*/
Server_login_options: function (isKeyUp) { // eslint-disable-line camelcase
return window.validators.fieldset.Server.apply(this, [isKeyUp]);
},
/**
* Validates Server_pmadb fieldset
*
* @param {boolean} isKeyUp
*
* @return {true}
*/
Server_pmadb: function (isKeyUp) { // eslint-disable-line camelcase
if (isKeyUp) {
return true;
}
var prefix = window.Config.getIdPrefix($(this).find('input'));
if ($('#' + prefix + 'pmadb').val() !== '') {
ajaxValidate(this, 'Server_pmadb', window.Config.getAllValues());
}
return true;
}
}
});
//
// END: Form validation and field operations
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// User preferences allow/disallow UI
//
$(function () {
$('.userprefs-allow').on('click', function (e) {
if (this !== e.target) {
return;
}
var el = $(this).find('input');
if (el.prop('disabled')) {
return;
}
el.prop('checked', !el.prop('checked'));
});
});
//
// END: User preferences allow/disallow UI
// ------------------------------------------------------------------
$(function () {
$('.delete-server').on('click', function (e) {
e.preventDefault();
var $this = $(this);
$.post($this.attr('href'), $this.attr('data-post'), function () {
window.location.replace('index.php');
});
});
});
|