devilbox/.devilbox/www/htdocs/vendor/phpmyadmin-4.9.3/setup/scripts.js

229 lines
5.9 KiB
JavaScript
Raw Normal View History

2016-10-22 14:57:10 +00:00
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functions used in Setup configuration forms
*/
// show this window in top frame
2018-04-14 09:18:00 +00:00
if (top !== self) {
2016-10-22 14:57:10 +00:00
window.top.location.href = location;
}
// ------------------------------------------------------------------
// Messages
//
$(function () {
if (window.location.protocol === 'https:') {
$('#no_https').remove();
} else {
$('#no_https a').click(function () {
var old_location = window.location;
window.location.href = 'https:' + old_location.href.substring(old_location.protocol.length);
return false;
});
2016-10-22 14:57:10 +00:00
}
var hiddenmessages = $('.hiddenmessage');
if (hiddenmessages.length > 0) {
hiddenmessages.hide();
2016-10-22 14:57:10 +00:00
var link = $('#show_hidden_messages');
link.click(function (e) {
e.preventDefault();
hiddenmessages.show();
2016-10-22 14:57:10 +00:00
$(this).remove();
});
link.html(link.html().replace('#MSG_COUNT', hiddenmessages.length));
2018-04-14 09:18:00 +00:00
link.show();
2016-10-22 14:57:10 +00:00
}
});
2018-04-14 09:18:00 +00:00
// set document width
$(document).ready(function () {
2016-10-22 14:57:10 +00:00
width = 0;
2018-04-14 09:18:00 +00:00
$('ul.tabs li').each(function () {
2016-10-22 14:57:10 +00:00
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, ...}
*/
2018-04-14 09:18:00 +00:00
function ajaxValidate (parent, id, values) {
2016-10-22 14:57:10 +00:00
parent = $(parent);
// ensure that parent is a fieldset
2018-04-14 09:18:00 +00:00
if (parent.attr('tagName') !== 'FIELDSET') {
2016-10-22 14:57:10 +00:00
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 = {};
2018-04-14 09:18:00 +00:00
if (typeof response !== 'object') {
2016-10-22 14:57:10 +00:00
error[parent.id] = [response];
2018-04-14 09:18:00 +00:00
} else if (typeof response.error !== 'undefined') {
2016-10-22 14:57:10 +00:00
error[parent.id] = [response.error];
} else {
for (var key in response) {
var value = response[key];
error[key] = jQuery.isArray(value) ? value : [value];
}
}
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, validators, {
// field validators
_field: {
/**
* hide_db field
*
* @param {boolean} isKeyUp
*/
hide_db: function (isKeyUp) {
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
*/
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
*/
Server: function (isKeyUp) {
if (!isKeyUp) {
ajaxValidate(this, 'Server', getAllValues());
}
return true;
},
/**
* Validates Server_login_options fieldset
*
* @param {boolean} isKeyUp
*/
Server_login_options: function (isKeyUp) {
return validators._fieldset.Server.apply(this, [isKeyUp]);
},
/**
* Validates Server_pmadb fieldset
*
* @param {boolean} isKeyUp
*/
Server_pmadb: function (isKeyUp) {
if (isKeyUp) {
return true;
}
var prefix = getIdPrefix($(this).find('input'));
if ($('#' + prefix + 'pmadb').val() !== '') {
ajaxValidate(this, 'Server_pmadb', getAllValues());
}
return true;
}
}
});
//
// END: Form validation and field operations
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// User preferences allow/disallow UI
//
$(function () {
$('.userprefs-allow').click(function (e) {
2018-04-14 09:18:00 +00:00
if (this !== e.target) {
2016-10-22 14:57:10 +00:00
return;
}
var el = $(this).find('input');
if (el.prop('disabled')) {
return;
}
el.prop('checked', !el.prop('checked'));
});
});
//
// END: User preferences allow/disallow UI
// ------------------------------------------------------------------
2019-12-08 07:14:01 +00:00
$(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');
});
});
});