Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-07-01 22:23:22 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-07-01 22:23:22 +0300
commita55b8e88f9a9a66bf3d33b154a41e5fc0d59db2c (patch)
tree1981965cbebf8795da9b218c9fcec99a38a31709
parent85032cc159b0d0ad027a09e1fcba8c64315a4bc9 (diff)
Assign config.js globals to the window object
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r--js/src/config.js301
-rw-r--r--js/src/functions.js11
-rw-r--r--js/src/navigation.js18
-rw-r--r--js/src/server/status/monitor.js11
-rw-r--r--js/src/setup/scripts.js14
-rw-r--r--js/src/sql.js17
-rw-r--r--libraries/classes/Config/FormDisplayTemplate.php3
-rw-r--r--libraries/config.values.php2
-rw-r--r--templates/config/form_display/display.twig14
-rw-r--r--templates/config/form_display/input.twig2
-rw-r--r--test/classes/Config/FormDisplayTemplateTest.php4
-rw-r--r--test/classes/Config/PageSettingsTest.php6
12 files changed, 196 insertions, 207 deletions
diff --git a/js/src/config.js b/js/src/config.js
index 756e859a81..c1d343d4f2 100644
--- a/js/src/config.js
+++ b/js/src/config.js
@@ -1,9 +1,10 @@
/**
* Functions used in configuration forms and on user preferences pages
*/
+window.Config = {};
-var configInlineParams;
-var configScriptLoaded;
+window.configInlineParams;
+window.configScriptLoaded;
/**
* checks whether browser supports web storage
@@ -13,7 +14,7 @@ var configScriptLoaded;
*
* @return {boolean}
*/
-function isStorageSupported (type, warn = false) {
+window.Config.isStorageSupported = (type, warn = false) => {
try {
window[type].setItem('PMATest', 'test');
// Check whether key-value pair was set successfully
@@ -29,10 +30,10 @@ function isStorageSupported (type, warn = false) {
}
}
return false;
-}
+};
// default values for fields
-var defaultValues = {};
+window.defaultValues = {};
/**
* Returns field type
@@ -81,7 +82,7 @@ function markField (field) {
// checkboxes uses parent <span> for marking
var $fieldMarker = (type === 'checkbox') ? $field.parent() : $field;
- setRestoreDefaultBtn($field, !isDefault);
+ setRestoreDefaultBtn($field, ! isDefault);
$fieldMarker[isDefault ? 'removeClass' : 'addClass']('custom');
}
@@ -161,8 +162,7 @@ function getFieldValue (field, fieldType) {
*
* @return {object}
*/
-// eslint-disable-next-line no-unused-vars
-function getAllValues () {
+window.Config.getAllValues = () => {
var $elements = $('fieldset input, fieldset select, fieldset textarea');
var values = {};
var type;
@@ -179,7 +179,7 @@ function getAllValues () {
}
}
return values;
-}
+};
/**
* Checks whether field has its default value
@@ -192,20 +192,20 @@ function getAllValues () {
function checkFieldDefault (field, type) {
var $field = $(field);
var fieldId = $field.attr('id');
- if (typeof defaultValues[fieldId] === 'undefined') {
+ if (typeof window.defaultValues[fieldId] === 'undefined') {
return true;
}
var isDefault = true;
var currentValue = getFieldValue($field, type);
if (type !== 'select') {
- isDefault = currentValue === defaultValues[fieldId];
+ isDefault = currentValue === window.defaultValues[fieldId];
} else {
// compare arrays, will work for our representation of select values
- if (currentValue.length !== defaultValues[fieldId].length) {
+ if (currentValue.length !== window.defaultValues[fieldId].length) {
isDefault = false;
} else {
for (var i = 0; i < currentValue.length; i++) {
- if (currentValue[i] !== defaultValues[fieldId][i]) {
+ if (currentValue[i] !== window.defaultValues[fieldId][i]) {
isDefault = false;
break;
}
@@ -221,20 +221,19 @@ function checkFieldDefault (field, type) {
*
* @return {string}
*/
-// eslint-disable-next-line no-unused-vars
-function getIdPrefix (element) {
+window.Config.getIdPrefix = function (element) {
return $(element).attr('id').replace(/[^-]+$/, '');
-}
+};
// ------------------------------------------------------------------
// Form validation and field operations
//
// form validator assignments
-var validate = {};
+let validate = {};
// form validator list
-var validators = {
+window.validators = {
// regexp: numeric value
regExpNumeric: /^[0-9]+$/,
// regexp: extract parts from PCRE expression
@@ -250,7 +249,7 @@ var validators = {
if (isKeyUp && this.value === '') {
return true;
}
- var result = this.value !== '0' && validators.regExpNumeric.test(this.value);
+ var result = this.value !== '0' && window.validators.regExpNumeric.test(this.value);
return result ? true : Messages.error_nan_p;
},
/**
@@ -264,7 +263,7 @@ var validators = {
if (isKeyUp && this.value === '') {
return true;
}
- var result = validators.regExpNumeric.test(this.value);
+ var result = window.validators.regExpNumeric.test(this.value);
return result ? true : Messages.error_nan_nneg;
},
/**
@@ -276,7 +275,7 @@ var validators = {
if (this.value === '') {
return true;
}
- var result = validators.regExpNumeric.test(this.value) && this.value !== '0';
+ var result = window.validators.regExpNumeric.test(this.value) && this.value !== '0';
return result && this.value <= 65535 ? true : Messages.error_incorrect_port;
},
/**
@@ -292,7 +291,7 @@ var validators = {
return true;
}
// convert PCRE regexp
- var parts = regexp.match(validators.regExpPcreExtract);
+ var parts = regexp.match(window.validators.regExpPcreExtract);
var valid = this.value.match(new RegExp(parts[2], parts[3])) !== null;
return valid ? true : Messages.error_invalid_value;
},
@@ -312,11 +311,9 @@ var validators = {
return val <= maxValue ? true : Functions.sprintf(Messages.error_value_lte, maxValue);
},
// field validators
- field: {
- },
+ field: {},
// fieldset validators
- fieldset: {
- }
+ fieldset: {}
};
/**
@@ -327,9 +324,8 @@ var validators = {
* @param {boolean} onKeyUp whether fire on key up
* @param {Array} params validation function parameters
*/
-// eslint-disable-next-line no-unused-vars
-function registerFieldValidator (id, type, onKeyUp, params) {
- if (typeof validators[type] === 'undefined') {
+window.Config.registerFieldValidator = (id, type, onKeyUp, params) => {
+ if (typeof window.validators[type] === 'undefined') {
return;
}
if (typeof validate[id] === 'undefined') {
@@ -338,7 +334,7 @@ function registerFieldValidator (id, type, onKeyUp, params) {
if (validate[id].length === 0) {
validate[id].push([type, params, onKeyUp]);
}
-}
+};
/**
* Returns validation functions associated with form field
@@ -351,8 +347,8 @@ function registerFieldValidator (id, type, onKeyUp, params) {
function getFieldValidators (fieldId, onKeyUpOnly) {
// look for field bound validator
var name = fieldId && fieldId.match(/[^-]+$/)[0];
- if (typeof validators.field[name] !== 'undefined') {
- return [[validators.field[name], null]];
+ if (typeof window.validators.field[name] !== 'undefined') {
+ return [[window.validators.field[name], null]];
}
// look for registered validators
@@ -360,10 +356,10 @@ function getFieldValidators (fieldId, onKeyUpOnly) {
if (typeof validate[fieldId] !== 'undefined') {
// validate[field_id]: array of [type, params, onKeyUp]
for (var i = 0, imax = validate[fieldId].length; i < imax; i++) {
- if (onKeyUpOnly && !validate[fieldId][i][2]) {
+ if (onKeyUpOnly && ! validate[fieldId][i][2]) {
continue;
}
- functions.push([validators[validate[fieldId][i][0]], validate[fieldId][i][1]]);
+ functions.push([window.validators[validate[fieldId][i][0]], validate[fieldId][i][1]]);
}
}
@@ -378,7 +374,7 @@ function getFieldValidators (fieldId, onKeyUpOnly) {
*
* @param {object} errorList list of errors in the form {field id: error array}
*/
-function displayErrors (errorList) {
+window.Config.displayErrors = function (errorList) {
var tempIsEmpty = function (item) {
return item !== '';
};
@@ -398,7 +394,7 @@ function displayErrors (errorList) {
errors = $.grep(errors, tempIsEmpty);
// CSS error class
- if (!isFieldset) {
+ if (! isFieldset) {
// checkboxes uses parent <span> for marking
var $fieldMarker = ($field.attr('type') === 'checkbox') ? $field.parent() : $field;
$fieldMarker[errors.length ? 'addClass' : 'removeClass']('field-error');
@@ -426,7 +422,7 @@ function displayErrors (errorList) {
$errorCnt.remove();
}
}
-}
+};
/**
* Validates fields and fieldsets and call displayError function as required
@@ -442,7 +438,7 @@ function setDisplayError () {
$('fieldset.optbox').each(function () {
validateFieldset(this, false, errors);
});
- displayErrors(errors);
+ window.Config.displayErrors(errors);
}
/**
@@ -454,8 +450,8 @@ function setDisplayError () {
*/
function validateFieldset (fieldset, isKeyUp, errors) {
var $fieldset = $(fieldset);
- if ($fieldset.length && typeof validators.fieldset[$fieldset.attr('id')] !== 'undefined') {
- var fieldsetErrors = validators.fieldset[$fieldset.attr('id')].apply($fieldset[0], [isKeyUp]);
+ if ($fieldset.length && typeof window.validators.fieldset[$fieldset.attr('id')] !== 'undefined') {
+ var fieldsetErrors = window.validators.fieldset[$fieldset.attr('id')].apply($fieldset[0], [isKeyUp]);
for (var fieldId in fieldsetErrors) {
if (typeof errors[fieldId] === 'undefined') {
errors[fieldId] = [];
@@ -510,25 +506,25 @@ function validateFieldAndFieldset (field, isKeyUp) {
var errors = {};
validateField($field, isKeyUp, errors);
validateFieldset($field.closest('fieldset.optbox'), isKeyUp, errors);
- displayErrors(errors);
+ window.Config.displayErrors(errors);
}
-function loadInlineConfig () {
- if (!Array.isArray(configInlineParams)) {
+window.Config.loadInlineConfig = () => {
+ if (! Array.isArray(window.configInlineParams)) {
return;
}
- for (var i = 0; i < configInlineParams.length; ++i) {
- if (typeof configInlineParams[i] === 'function') {
- configInlineParams[i]();
+ for (var i = 0; i < window.configInlineParams.length; ++i) {
+ if (typeof window.configInlineParams[i] === 'function') {
+ window.configInlineParams[i]();
}
}
-}
+};
-function setupValidation () {
+window.Config.setupValidation = function () {
validate = {};
- configScriptLoaded = true;
- if (configScriptLoaded && typeof configInlineParams !== 'undefined') {
- loadInlineConfig();
+ window.configScriptLoaded = true;
+ if (window.configScriptLoaded && typeof window.configInlineParams !== 'undefined') {
+ window.Config.loadInlineConfig();
}
// register validators and mark custom values
var $elements = $('.optbox input[id], .optbox select[id], .optbox textarea[id]');
@@ -567,11 +563,11 @@ function setupValidation () {
validateFieldset(this, false, errors);
});
- displayErrors(errors);
+ window.Config.displayErrors(errors);
} else if ($checkPageRefresh) {
$checkPageRefresh.val('1');
}
-}
+};
//
// END: Form validation and field operations
@@ -600,13 +596,13 @@ function adjustPrefsNotification () {
*/
function restoreField (fieldId) {
var $field = $('#' + fieldId);
- if ($field.length === 0 || defaultValues[fieldId] === undefined) {
+ if ($field.length === 0 || window.defaultValues[fieldId] === undefined) {
return;
}
- setFieldValue($field, getFieldType($field), defaultValues[fieldId]);
+ setFieldValue($field, getFieldType($field), window.defaultValues[fieldId]);
}
-function setupRestoreField () {
+window.Config.setupRestoreField = function () {
$('div.tab-content')
.on('mouseenter', '.restore-default, .set-value', function () {
$(this).css('opacity', 1);
@@ -631,7 +627,7 @@ function setupRestoreField () {
.find('.restore-default, .set-value')
// inline-block for IE so opacity inheritance works
.css({ display: 'inline-block', opacity: 0.25 });
-}
+};
//
// END: "Restore default" and "set value" buttons
@@ -693,9 +689,9 @@ function updatePrefsDate () {
* Prepares message which informs that localStorage preferences are available and can be imported or deleted
*/
function offerPrefsAutoimport () {
- var hasConfig = (isStorageSupported('localStorage')) && (window.localStorage.config || false);
+ var hasConfig = (window.Config.isStorageSupported('localStorage')) && (window.localStorage.config || false);
var $cnt = $('#prefs_autoload');
- if (!$cnt.length || !hasConfig) {
+ if (! $cnt.length || ! hasConfig) {
return;
}
$cnt.find('a').on('click', function (e) {
@@ -723,104 +719,103 @@ function offerPrefsAutoimport () {
$cnt.show();
}
-window.Config = {
- /**
- * @return {function}
- */
- off: function () {
- return function () {
- $('.optbox input[id], .optbox select[id], .optbox textarea[id]').off('change').off('keyup');
- $('.optbox input[type=button][name=submit_reset]').off('click');
- $('div.tab-content').off();
- $('#import_local_storage, #export_local_storage').off('click');
- $('form.prefs-form').off('change').off('submit');
- $(document).off('click', 'div.click-hide-message');
- $('#prefs_autoload').find('a').off('click');
- };
- },
- /**
- * @return {function}
- */
- on: function () {
- return function () {
- var $topmenuUpt = $('#user_prefs_tabs');
- $topmenuUpt.find('a.active').attr('rel', 'samepage');
- $topmenuUpt.find('a:not(.active)').attr('rel', 'newpage');
-
- setupValidation();
- adjustPrefsNotification();
-
- $('.optbox input[type=button][name=submit_reset]').on('click', function () {
- var fields = $(this).closest('fieldset').find('input, select, textarea');
- for (var i = 0, imax = fields.length; i < imax; i++) {
- setFieldValue(fields[i], getFieldType(fields[i]), defaultValues[fields[i].id]);
- }
- setDisplayError();
- });
-
- setupRestoreField();
+/**
+ * @return {function}
+ */
+window.Config.off = function () {
+ return function () {
+ $('.optbox input[id], .optbox select[id], .optbox textarea[id]').off('change').off('keyup');
+ $('.optbox input[type=button][name=submit_reset]').off('click');
+ $('div.tab-content').off();
+ $('#import_local_storage, #export_local_storage').off('click');
+ $('form.prefs-form').off('change').off('submit');
+ $(document).off('click', 'div.click-hide-message');
+ $('#prefs_autoload').find('a').off('click');
+ };
+};
- offerPrefsAutoimport();
- var $radios = $('#import_local_storage, #export_local_storage');
- if (!$radios.length) {
- return;
+/**
+ * @return {function}
+ */
+window.Config.on = function () {
+ return function () {
+ var $topmenuUpt = $('#user_prefs_tabs');
+ $topmenuUpt.find('a.active').attr('rel', 'samepage');
+ $topmenuUpt.find('a:not(.active)').attr('rel', 'newpage');
+
+ window.Config.setupValidation();
+ adjustPrefsNotification();
+
+ $('.optbox input[type=button][name=submit_reset]').on('click', function () {
+ var fields = $(this).closest('fieldset').find('input, select, textarea');
+ for (var i = 0, imax = fields.length; i < imax; i++) {
+ setFieldValue(fields[i], getFieldType(fields[i]), window.defaultValues[fields[i].id]);
}
+ setDisplayError();
+ });
- // enable JavaScript dependent fields
- $radios
- .prop('disabled', false)
- .add('#export_text_file, #import_text_file')
- .on('click', function () {
- var enableId = $(this).attr('id');
- var disableId;
- if (enableId.match(/local_storage$/)) {
- disableId = enableId.replace(/local_storage$/, 'text_file');
- } else {
- disableId = enableId.replace(/text_file$/, 'local_storage');
- }
- $('#opts_' + disableId).addClass('disabled').find('input').prop('disabled', true);
- $('#opts_' + enableId).removeClass('disabled').find('input').prop('disabled', false);
- });
-
- // detect localStorage state
- var lsSupported = isStorageSupported('localStorage', true);
- var lsExists = lsSupported ? (window.localStorage.config || false) : false;
- $('div.localStorage-' + (lsSupported ? 'un' : '') + 'supported').hide();
- $('div.localStorage-' + (lsExists ? 'empty' : 'exists')).hide();
- if (lsExists) {
- updatePrefsDate();
- }
- $('form.prefs-form').on('change', function () {
- var $form = $(this);
- var disabled = false;
- if (!lsSupported) {
- disabled = $form.find('input[type=radio][value$=local_storage]').prop('checked');
- } else if (!lsExists && $form.attr('name') === 'prefs_import' &&
- $('#import_local_storage')[0].checked
- ) {
- disabled = true;
- }
- $form.find('input[type=submit]').prop('disabled', disabled);
- }).on('submit', function (e) {
- var $form = $(this);
- if ($form.attr('name') === 'prefs_export' && $('#export_local_storage')[0].checked) {
- e.preventDefault();
- // use AJAX to read JSON settings and save them
- savePrefsToLocalStorage($form);
- } else if ($form.attr('name') === 'prefs_import' && $('#import_local_storage')[0].checked) {
- // set 'json' input and submit form
- $form.find('input[name=json]').val(window.localStorage.config);
+ window.Config.setupRestoreField();
+
+ offerPrefsAutoimport();
+ var $radios = $('#import_local_storage, #export_local_storage');
+ if (! $radios.length) {
+ return;
+ }
+
+ // enable JavaScript dependent fields
+ $radios
+ .prop('disabled', false)
+ .add('#export_text_file, #import_text_file')
+ .on('click', function () {
+ var enableId = $(this).attr('id');
+ var disableId;
+ if (enableId.match(/local_storage$/)) {
+ disableId = enableId.replace(/local_storage$/, 'text_file');
+ } else {
+ disableId = enableId.replace(/text_file$/, 'local_storage');
}
+ $('#opts_' + disableId).addClass('disabled').find('input').prop('disabled', true);
+ $('#opts_' + enableId).removeClass('disabled').find('input').prop('disabled', false);
});
- $(document).on('click', 'div.click-hide-message', function () {
- $(this)
- .hide()
- .parent('.card-body')
- .css('height', '')
- .next('form')
- .show();
- });
- };
- }
+ // detect localStorage state
+ var lsSupported = window.Config.isStorageSupported('localStorage', true);
+ var lsExists = lsSupported ? (window.localStorage.config || false) : false;
+ $('div.localStorage-' + (lsSupported ? 'un' : '') + 'supported').hide();
+ $('div.localStorage-' + (lsExists ? 'empty' : 'exists')).hide();
+ if (lsExists) {
+ updatePrefsDate();
+ }
+ $('form.prefs-form').on('change', function () {
+ var $form = $(this);
+ var disabled = false;
+ if (! lsSupported) {
+ disabled = $form.find('input[type=radio][value$=local_storage]').prop('checked');
+ } else if (! lsExists && $form.attr('name') === 'prefs_import' &&
+ $('#import_local_storage')[0].checked
+ ) {
+ disabled = true;
+ }
+ $form.find('input[type=submit]').prop('disabled', disabled);
+ }).on('submit', function (e) {
+ var $form = $(this);
+ if ($form.attr('name') === 'prefs_export' && $('#export_local_storage')[0].checked) {
+ e.preventDefault();
+ // use AJAX to read JSON settings and save them
+ savePrefsToLocalStorage($form);
+ } else if ($form.attr('name') === 'prefs_import' && $('#import_local_storage')[0].checked) {
+ // set 'json' input and submit form
+ $form.find('input[name=json]').val(window.localStorage.config);
+ }
+ });
+
+ $(document).on('click', 'div.click-hide-message', function () {
+ $(this)
+ .hide()
+ .parent('.card-body')
+ .css('height', '')
+ .next('form')
+ .show();
+ });
+ };
};
diff --git a/js/src/functions.js b/js/src/functions.js
index ea219b7f1c..cc515049d7 100644
--- a/js/src/functions.js
+++ b/js/src/functions.js
@@ -1,5 +1,4 @@
/* global Navigation */
-/* global isStorageSupported */ // js/config.js
/* global ChartType, ColumnType, DataTable, JQPlotChartFactory */ // js/chart.js
/* global DatabaseStructure */ // js/database/structure.js
/* global mysqlDocBuiltin, mysqlDocKeyword */ // js/doclinks.js
@@ -939,7 +938,7 @@ Functions.onloadIdleEvent = function () {
function UpdateIdleTime () {
var href = 'index.php?route=/';
var guid = 'default';
- if (isStorageSupported('sessionStorage')) {
+ if (window.Config.isStorageSupported('sessionStorage')) {
guid = window.sessionStorage.guid;
}
var params = {
@@ -974,7 +973,7 @@ Functions.onloadIdleEvent = function () {
updateTimeout = window.setTimeout(UpdateIdleTime, interval);
} else { // timeout occurred
clearInterval(incInterval);
- if (isStorageSupported('sessionStorage')) {
+ if (window.Config.isStorageSupported('sessionStorage')) {
window.sessionStorage.clear();
}
// append the login form on the page, disable all the forms which were not disabled already, close all the open jqueryui modal boxes
@@ -1002,7 +1001,7 @@ Functions.onloadIdleEvent = function () {
window.CommonParams.get('LoginCookieValidity'),
window.CommonParams.get('session_gc_maxlifetime')
);
- if (isStorageSupported('sessionStorage')) {
+ if (window.Config.isStorageSupported('sessionStorage')) {
window.sessionStorage.setItem('guid', guid());
}
var interval = (sessionTimeout - 5) * 1000;
@@ -3515,7 +3514,7 @@ Functions.onloadRecentFavoriteTables = () => {
cache: false,
type: 'POST',
data: {
- 'favoriteTables': (isStorageSupported('localStorage') && typeof window.localStorage.favoriteTables !== 'undefined')
+ 'favoriteTables': (window.Config.isStorageSupported('localStorage') && typeof window.localStorage.favoriteTables !== 'undefined')
? window.localStorage.favoriteTables
: '',
'server': window.CommonParams.get('server'),
@@ -3523,7 +3522,7 @@ Functions.onloadRecentFavoriteTables = () => {
},
success: function (data) {
// Update localStorage.
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.favoriteTables = data.favoriteTables;
}
$('#pma_favorite_list').html(data.list);
diff --git a/js/src/navigation.js b/js/src/navigation.js
index 2586f9f130..d37a34fa5e 100644
--- a/js/src/navigation.js
+++ b/js/src/navigation.js
@@ -4,8 +4,6 @@
* @package phpMyAdmin-Navigation
*/
-/* global isStorageSupported, setupRestoreField, setupValidation */ // js/config.js
-
var Navigation = {};
/**
@@ -15,7 +13,7 @@ var Navigation = {};
*/
Navigation.treeStateUpdate = function () {
// update if session storage is supported
- if (isStorageSupported('sessionStorage')) {
+ if (window.Config.isStorageSupported('sessionStorage')) {
var storage = window.sessionStorage;
// try catch necessary here to detect whether
// content to be stored exceeds storage capacity
@@ -42,7 +40,7 @@ Navigation.treeStateUpdate = function () {
* @return {void}
*/
Navigation.filterStateUpdate = function (filterName, filterValue) {
- if (isStorageSupported('sessionStorage')) {
+ if (window.Config.isStorageSupported('sessionStorage')) {
var storage = window.sessionStorage;
try {
var currentFilter = $.extend({}, JSON.parse(storage.getItem('navTreeSearchFilters')));
@@ -62,7 +60,7 @@ Navigation.filterStateUpdate = function (filterName, filterValue) {
* @return {void}
*/
Navigation.filterStateRestore = function () {
- if (isStorageSupported('sessionStorage')
+ if (window.Config.isStorageSupported('sessionStorage')
&& typeof window.sessionStorage.navTreeSearchFilters !== 'undefined'
) {
var searchClauses = JSON.parse(window.sessionStorage.navTreeSearchFilters);
@@ -530,7 +528,7 @@ Navigation.onload = () => function () {
}
}
- var hasLocalStorage = isStorageSupported('localStorage') &&
+ var hasLocalStorage = window.Config.isStorageSupported('localStorage') &&
typeof window.localStorage.favoriteTables !== 'undefined';
$.ajax({
url: $self.attr('href'),
@@ -550,7 +548,7 @@ Navigation.onload = () => function () {
$('#' + anchorId).attr('title')
);
// Update localStorage.
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.favoriteTables = data.favoriteTables;
}
} else {
@@ -560,7 +558,7 @@ Navigation.onload = () => function () {
});
});
// Check if session storage is supported
- if (isStorageSupported('sessionStorage')) {
+ if (window.Config.isStorageSupported('sessionStorage')) {
var storage = window.sessionStorage;
// remove tree from storage if Navi_panel config form is submitted
$(document).on('submit', 'form.config-form', function () {
@@ -902,8 +900,8 @@ Navigation.ensureSettings = function (selflink) {
$.post('index.php?route=/navigation&ajax_request=1', params, function (data) {
if (typeof data !== 'undefined' && data.success) {
$('#pma_navi_settings_container').html(data.message);
- setupRestoreField();
- setupValidation();
+ window.Config.setupRestoreField();
+ window.Config.setupValidation();
$('#pma_navigation_settings').find('form').attr('action', selflink);
} else {
Functions.ajaxShowMessage(data.error);
diff --git a/js/src/server/status/monitor.js b/js/src/server/status/monitor.js
index d7b12b9a1c..936017b288 100644
--- a/js/src/server/status/monitor.js
+++ b/js/src/server/status/monitor.js
@@ -7,7 +7,6 @@
* @requires js/functions.js
*/
-/* global isStorageSupported */ // js/config.js
/* global firstDayOfCalendar, themeImagePath */ // templates/javascript/variables.twig
/* global variableNames */ // templates/server/status/monitor/index.twig
@@ -669,7 +668,7 @@ window.AJAX.registerOnload('server/status/monitor.js', function () {
// If json ok, try applying config
try {
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.monitorCharts = JSON.stringify(json.monitorCharts);
window.localStorage.monitorSettings = JSON.stringify(json.monitorSettings);
}
@@ -677,7 +676,7 @@ window.AJAX.registerOnload('server/status/monitor.js', function () {
} catch (err) {
alert(Messages.strFailedBuildingGrid);
// If an exception is thrown, load default again
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.removeItem('monitorCharts');
window.localStorage.removeItem('monitorSettings');
}
@@ -702,7 +701,7 @@ window.AJAX.registerOnload('server/status/monitor.js', function () {
$('a[href="#clearMonitorConfig"]').on('click', function (event) {
event.preventDefault();
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.removeItem('monitorCharts');
window.localStorage.removeItem('monitorSettings');
window.localStorage.removeItem('monitorVersion');
@@ -989,7 +988,7 @@ window.AJAX.registerOnload('server/status/monitor.js', function () {
var i;
/* Apply default values & config */
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
if (typeof window.localStorage.monitorCharts !== 'undefined') {
runtime.charts = JSON.parse(window.localStorage.monitorCharts);
}
@@ -2198,7 +2197,7 @@ window.AJAX.registerOnload('server/status/monitor.js', function () {
gridCopy[key].maxYLabel = elem.maxYLabel;
});
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.monitorCharts = JSON.stringify(gridCopy);
window.localStorage.monitorSettings = JSON.stringify(monitorSettings);
window.localStorage.monitorVersion = monitorProtocolVersion;
diff --git a/js/src/setup/scripts.js b/js/src/setup/scripts.js
index c7671c1fa9..83de7b6a0d 100644
--- a/js/src/setup/scripts.js
+++ b/js/src/setup/scripts.js
@@ -2,8 +2,6 @@
* Functions used in Setup configuration forms
*/
-/* global displayErrors, getAllValues, getIdPrefix, validators */ // js/config.js
-
// show this window in top frame
if (top !== self) {
window.top.location.href = location;
@@ -107,7 +105,7 @@ function ajaxValidate (parent, id, values) {
error[key] = Array.isArray(value) ? value : [value];
}
}
- displayErrors(error);
+ window.Config.displayErrors(error);
},
complete: function () {
$parent.removeData('ajax');
@@ -124,7 +122,7 @@ $(document).on('change', '.autosubmit', function (e) {
e.target.form.submit();
});
-$.extend(true, validators, {
+$.extend(true, window.validators, {
// field validators
field: {
/**
@@ -169,7 +167,7 @@ $.extend(true, validators, {
*/
Server: function (isKeyUp) {
if (!isKeyUp) {
- ajaxValidate(this, 'Server', getAllValues());
+ ajaxValidate(this, 'Server', window.Config.getAllValues());
}
return true;
},
@@ -181,7 +179,7 @@ $.extend(true, validators, {
* @return {true}
*/
Server_login_options: function (isKeyUp) { // eslint-disable-line camelcase
- return validators.fieldset.Server.apply(this, [isKeyUp]);
+ return window.validators.fieldset.Server.apply(this, [isKeyUp]);
},
/**
* Validates Server_pmadb fieldset
@@ -195,9 +193,9 @@ $.extend(true, validators, {
return true;
}
- var prefix = getIdPrefix($(this).find('input'));
+ var prefix = window.Config.getIdPrefix($(this).find('input'));
if ($('#' + prefix + 'pmadb').val() !== '') {
- ajaxValidate(this, 'Server_pmadb', getAllValues());
+ ajaxValidate(this, 'Server_pmadb', window.Config.getAllValues());
}
return true;
diff --git a/js/src/sql.js b/js/src/sql.js
index 661ba78cc3..c8543575f8 100644
--- a/js/src/sql.js
+++ b/js/src/sql.js
@@ -8,7 +8,6 @@
*/
/* global Navigation */
-/* global isStorageSupported */ // js/config.js
/* global makeGrid */ // js/makegrid.js
/* global themeImagePath */ // templates/javascript/variables.twig
@@ -47,7 +46,7 @@ Sql.urlEncode = function (str) {
Sql.autoSave = function (query) {
if (query) {
var key = Sql.getAutoSavedKey();
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.setItem(key, query);
} else {
window.Cookies.set(key, query, { path: window.CommonParams.get('rootPath') });
@@ -69,7 +68,7 @@ Sql.showThisQuery = function (db, table, query) {
'table': table,
'query': query
};
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.showThisQuery = 1;
window.localStorage.showThisQueryObject = JSON.stringify(showThisQueryObject);
} else {
@@ -85,7 +84,7 @@ Sql.showThisQuery = function (db, table, query) {
Sql.setShowThisQuery = function () {
var db = $('input[name="db"]').val();
var table = $('input[name="table"]').val();
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
if (window.localStorage.showThisQueryObject !== undefined) {
var storedDb = JSON.parse(window.localStorage.showThisQueryObject).db;
var storedTable = JSON.parse(window.localStorage.showThisQueryObject).table;
@@ -115,7 +114,7 @@ Sql.setShowThisQuery = function () {
*/
Sql.autoSaveWithSort = function (query) {
if (query) {
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.setItem('autoSavedSqlSort', query);
} else {
window.Cookies.set('autoSavedSqlSort', query, { path: window.CommonParams.get('rootPath') });
@@ -129,7 +128,7 @@ Sql.autoSaveWithSort = function (query) {
* @return {void}
*/
Sql.clearAutoSavedSort = function () {
- if (isStorageSupported('localStorage')) {
+ if (window.Config.isStorageSupported('localStorage')) {
window.localStorage.removeItem('autoSavedSqlSort');
} else {
window.Cookies.set('autoSavedSqlSort', '', { path: window.CommonParams.get('rootPath') });
@@ -302,7 +301,7 @@ const insertQuery = function (queryType) {
key += '.' + table;
}
key = 'autoSavedSql_' + key;
- if (isStorageSupported('localStorage') &&
+ if (window.Config.isStorageSupported('localStorage') &&
typeof window.localStorage.getItem(key) === 'string') {
setQuery(window.localStorage.getItem(key));
} else if (window.Cookies.get(key, { path: window.CommonParams.get('rootPath') })) {
@@ -464,7 +463,7 @@ window.AJAX.registerOnload('sql.js', function () {
$('#sqlquery').on('input propertychange', function () {
Sql.autoSave($('#sqlquery').val());
});
- var useLocalStorageValue = isStorageSupported('localStorage') && typeof window.localStorage.autoSavedSqlSort !== 'undefined';
+ var useLocalStorageValue = window.Config.isStorageSupported('localStorage') && typeof window.localStorage.autoSavedSqlSort !== 'undefined';
// Save sql query with sort
if ($('#RememberSorting') !== undefined && $('#RememberSorting').is(':checked')) {
$('select[name="sql_query"]').on('change', function () {
@@ -1204,7 +1203,7 @@ Sql.getAutoSavedKey = function () {
Sql.checkSavedQuery = function () {
var key = Sql.getAutoSavedKey();
- if (isStorageSupported('localStorage') &&
+ if (window.Config.isStorageSupported('localStorage') &&
typeof window.localStorage.getItem(key) === 'string') {
Functions.ajaxShowMessage(Messages.strPreviousSaveQuery);
} else if (window.Cookies.get(key, { path: window.CommonParams.get('rootPath') })) {
diff --git a/libraries/classes/Config/FormDisplayTemplate.php b/libraries/classes/Config/FormDisplayTemplate.php
index a7ae0bbbcd..946a3a6634 100644
--- a/libraries/classes/Config/FormDisplayTemplate.php
+++ b/libraries/classes/Config/FormDisplayTemplate.php
@@ -150,7 +150,8 @@ class FormDisplayTemplate
}
$vArgs = $vArgs ? ", ['" . implode("', '", $vArgs) . "']" : '';
- $jsArray[] = "registerFieldValidator('" . $fieldId . "', '" . $vName . "', true" . $vArgs . ')';
+ $jsArray[] = "window.Config.registerFieldValidator('"
+ . $fieldId . "', '" . $vName . "', true" . $vArgs . ')';
}
}
diff --git a/libraries/config.values.php b/libraries/config.values.php
index e16a9279db..eb7c7f047d 100644
--- a/libraries/config.values.php
+++ b/libraries/config.values.php
@@ -376,7 +376,7 @@ return [
/**
* Basic validator assignments (functions from libraries/config/Validator.php
- * and 'validators' object in js/config.js)
+ * and 'window.validators' object in js/config.js)
* Use only full paths and form ids
*/
'_validators' => [
diff --git a/templates/config/form_display/display.twig b/templates/config/form_display/display.twig
index d68259584d..9d427e7d1b 100644
--- a/templates/config/form_display/display.twig
+++ b/templates/config/form_display/display.twig
@@ -26,7 +26,7 @@
<fieldset class="optbox">
<legend>{{ form.descriptions.name }}</legend>
- {# This must match with displayErrors() in scripts.js #}
+ {# This must match with window.Config.displayErrors() in scripts.js #}
{% if form.errors is iterable and form.errors|length > 0 %}
<dl class="errors">
{% for error in form.errors %}
@@ -54,10 +54,10 @@
</form>
<script type="text/javascript">
- if (typeof configInlineParams === 'undefined' || !Array.isArray(configInlineParams)) {
- configInlineParams = [];
+ if (typeof window.configInlineParams === 'undefined' || !Array.isArray(window.configInlineParams)) {
+ window.configInlineParams = [];
}
- configInlineParams.push(function () {
+ window.configInlineParams.push(function () {
{{ js_array|join(';\n')|raw }};
$.extend(Messages, {
@@ -68,11 +68,11 @@
'error_value_lte': '{{ 'Value must be less than or equal to %s!'|trans|e('js') }}',
});
- $.extend(defaultValues, {
+ $.extend(window.defaultValues, {
{{ js_default|join(",\n ")|raw }}
});
});
- if (typeof configScriptLoaded !== 'undefined' && configInlineParams) {
- loadInlineConfig();
+ if (typeof window.configScriptLoaded !== 'undefined' && window.configInlineParams) {
+ window.Config.loadInlineConfig();
}
</script>
diff --git a/templates/config/form_display/input.twig b/templates/config/form_display/input.twig
index 09b42c03b7..95fd2f777a 100644
--- a/templates/config/form_display/input.twig
+++ b/templates/config/form_display/input.twig
@@ -65,7 +65,7 @@
</a>
{% endif %}
- {# This must match with displayErrors() in scripts/config.js. #}
+ {# This must match with window.Config.displayErrors() in scripts/config.js. #}
{% if has_errors %}
<dl class="inline_errors">
{% for error in errors %}
diff --git a/test/classes/Config/FormDisplayTemplateTest.php b/test/classes/Config/FormDisplayTemplateTest.php
index 542d309759..f80a6e998c 100644
--- a/test/classes/Config/FormDisplayTemplateTest.php
+++ b/test/classes/Config/FormDisplayTemplateTest.php
@@ -266,10 +266,10 @@ class FormDisplayTemplateTest extends AbstractTestCase
$this->assertEquals(
[
- 'registerFieldValidator(\'testID\', \'\\\';\', true, '
+ 'window.Config.registerFieldValidator(\'testID\', \'\\\';\', true, '
. '[\'\\\\r\\\\n\\\\\\\''
. '<scrIpt></\\\' + \\\'script>\'])',
- 'registerFieldValidator(\'testID\', \'\', true)',
+ 'window.Config.registerFieldValidator(\'testID\', \'\', true)',
],
$js
);
diff --git a/test/classes/Config/PageSettingsTest.php b/test/classes/Config/PageSettingsTest.php
index 57adc4db68..97eef18ab2 100644
--- a/test/classes/Config/PageSettingsTest.php
+++ b/test/classes/Config/PageSettingsTest.php
@@ -61,9 +61,9 @@ class PageSettingsTest extends AbstractTestCase
$this->assertStringContainsString('<input type="hidden" name="submit_save" value="Browse">', $html);
$this->assertStringContainsString(
- "registerFieldValidator('MaxRows', 'validatePositiveNumber', true);\n"
- . "registerFieldValidator('RepeatCells', 'validateNonNegativeNumber', true);\n"
- . "registerFieldValidator('LimitChars', 'validatePositiveNumber', true);\n",
+ "window.Config.registerFieldValidator('MaxRows', 'validatePositiveNumber', true);\n"
+ . "window.Config.registerFieldValidator('RepeatCells', 'validateNonNegativeNumber', true);\n"
+ . "window.Config.registerFieldValidator('LimitChars', 'validatePositiveNumber', true);\n",
$html
);
}