Merged branch official/master. Resolved merge conflicts introduced due to merging of Piotr and Martynas's branches
This commit is contained in:
748
js/config.js
Normal file
748
js/config.js
Normal file
@@ -0,0 +1,748 @@
|
||||
/**
|
||||
* Functions used in configuration forms and on user preferences pages
|
||||
*/
|
||||
|
||||
// default values for fields
|
||||
var defaultValues = {};
|
||||
|
||||
// language strings
|
||||
var PMA_messages = {};
|
||||
|
||||
/**
|
||||
* Returns field type
|
||||
*
|
||||
* @param {Element} field
|
||||
*/
|
||||
function getFieldType(field) {
|
||||
field = $(field);
|
||||
var tagName = field.attr('tagName');
|
||||
if (tagName == 'INPUT') {
|
||||
return field.attr('type');
|
||||
} else if (tagName == 'SELECT') {
|
||||
return 'select';
|
||||
} else if (tagName == 'TEXTAREA') {
|
||||
return 'text';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets field value
|
||||
*
|
||||
* value must be of type:
|
||||
* o undefined (omitted) - restore default value (form default, not PMA default)
|
||||
* o String - if field_type is 'text'
|
||||
* o boolean - if field_type is 'checkbox'
|
||||
* o Array of values - if field_type is 'select'
|
||||
*
|
||||
* @param {Element} field
|
||||
* @param {String} field_type see {@link #getFieldType}
|
||||
* @param {String|Boolean} [value]
|
||||
*/
|
||||
function setFieldValue(field, field_type, value) {
|
||||
field = $(field);
|
||||
switch (field_type) {
|
||||
case 'text':
|
||||
field.attr('value', (value != undefined ? value : field.attr('defaultValue')));
|
||||
break;
|
||||
case 'checkbox':
|
||||
field.attr('checked', (value != undefined ? value : field.attr('defaultChecked')));
|
||||
break;
|
||||
case 'select':
|
||||
var options = field.attr('options');
|
||||
var i, imax = options.length;
|
||||
if (value == undefined) {
|
||||
for (i = 0; i < imax; i++) {
|
||||
options[i].selected = options[i].defaultSelected;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < imax; i++) {
|
||||
options[i].selected = (value.indexOf(options[i].value) != -1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
markField(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets field value
|
||||
*
|
||||
* Will return one of:
|
||||
* o String - if type is 'text'
|
||||
* o boolean - if type is 'checkbox'
|
||||
* o Array of values - if type is 'select'
|
||||
*
|
||||
* @param {Element} field
|
||||
* @param {String} field_type returned by {@link #getFieldType}
|
||||
* @type Boolean|String|String[]
|
||||
*/
|
||||
function getFieldValue(field, field_type) {
|
||||
field = $(field);
|
||||
switch (field_type) {
|
||||
case 'text':
|
||||
return field.attr('value');
|
||||
case 'checkbox':
|
||||
return field.attr('checked');
|
||||
case 'select':
|
||||
var options = field.attr('options');
|
||||
var i, imax = options.length, items = [];
|
||||
for (i = 0; i < imax; i++) {
|
||||
if (options[i].selected) {
|
||||
items.push(options[i].value);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns values for all fields in fieldsets
|
||||
*/
|
||||
function getAllValues() {
|
||||
var elements = $('fieldset input, fieldset select, fieldset textarea');
|
||||
var values = {};
|
||||
var type, value;
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
type = getFieldType(elements[i]);
|
||||
value = getFieldValue(elements[i], type);
|
||||
if (typeof value != 'undefined') {
|
||||
// we only have single selects, fatten array
|
||||
if (type == 'select') {
|
||||
value = value[0];
|
||||
}
|
||||
values[elements[i].name] = value;
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether field has its default value
|
||||
*
|
||||
* @param {Element} field
|
||||
* @param {String} type
|
||||
* @return boolean
|
||||
*/
|
||||
function checkFieldDefault(field, type) {
|
||||
field = $(field);
|
||||
var field_id = field.attr('id');
|
||||
if (typeof defaultValues[field_id] == 'undefined') {
|
||||
return true;
|
||||
}
|
||||
var isDefault = true;
|
||||
var currentValue = getFieldValue(field, type);
|
||||
if (type != 'select') {
|
||||
isDefault = currentValue == defaultValues[field_id];
|
||||
} else {
|
||||
// compare arrays, will work for our representation of select values
|
||||
if (currentValue.length != defaultValues[field_id].length) {
|
||||
isDefault = false;
|
||||
}
|
||||
else {
|
||||
for (var i = 0; i < currentValue.length; i++) {
|
||||
if (currentValue[i] != defaultValues[field_id][i]) {
|
||||
isDefault = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns element's id prefix
|
||||
* @param {Element} element
|
||||
*/
|
||||
function getIdPrefix(element) {
|
||||
return $(element).attr('id').replace(/[^-]+$/, '');
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Form validation and field operations
|
||||
//
|
||||
|
||||
// form validator assignments
|
||||
var validate = {};
|
||||
|
||||
// form validator list
|
||||
var validators = {
|
||||
// regexp: numeric value
|
||||
_regexp_numeric: /^[0-9]+$/,
|
||||
// regexp: extract parts from PCRE expression
|
||||
_regexp_pcre_extract: /(.)(.*)\1(.*)?/,
|
||||
/**
|
||||
* Validates positive number
|
||||
*
|
||||
* @param {boolean} isKeyUp
|
||||
*/
|
||||
validate_positive_number: function (isKeyUp) {
|
||||
if (isKeyUp && this.value == '') {
|
||||
return true;
|
||||
}
|
||||
var result = this.value != '0' && validators._regexp_numeric.test(this.value);
|
||||
return result ? true : PMA_messages['error_nan_p'];
|
||||
},
|
||||
/**
|
||||
* Validates non-negative number
|
||||
*
|
||||
* @param {boolean} isKeyUp
|
||||
*/
|
||||
validate_non_negative_number: function (isKeyUp) {
|
||||
if (isKeyUp && this.value == '') {
|
||||
return true;
|
||||
}
|
||||
var result = validators._regexp_numeric.test(this.value);
|
||||
return result ? true : PMA_messages['error_nan_nneg'];
|
||||
},
|
||||
/**
|
||||
* Validates port number
|
||||
*
|
||||
* @param {boolean} isKeyUp
|
||||
*/
|
||||
validate_port_number: function(isKeyUp) {
|
||||
if (this.value == '') {
|
||||
return true;
|
||||
}
|
||||
var result = validators._regexp_numeric.test(this.value) && this.value != '0';
|
||||
return result && this.value <= 65535 ? true : PMA_messages['error_incorrect_port'];
|
||||
},
|
||||
/**
|
||||
* Validates value according to given regular expression
|
||||
*
|
||||
* @param {boolean} isKeyUp
|
||||
* @param {string} regexp
|
||||
*/
|
||||
validate_by_regex: function(isKeyUp, regexp) {
|
||||
if (isKeyUp && this.value == '') {
|
||||
return true;
|
||||
}
|
||||
// convert PCRE regexp
|
||||
var parts = regexp.match(validators._regexp_pcre_extract);
|
||||
var valid = this.value.match(new RegExp(parts[2], parts[3])) != null;
|
||||
return valid ? true : PMA_messages['error_invalid_value'];
|
||||
},
|
||||
/**
|
||||
* Validates upper bound for numeric inputs
|
||||
*
|
||||
* @param {boolean} isKeyUp
|
||||
* @param {int} max_value
|
||||
*/
|
||||
validate_upper_bound: function(isKeyUp, max_value) {
|
||||
var val = parseInt(this.value);
|
||||
if (isNaN(val)) {
|
||||
return true;
|
||||
}
|
||||
return val <= max_value ? true : PMA_messages['error_value_lte'].replace('%s', max_value);
|
||||
},
|
||||
// field validators
|
||||
_field: {
|
||||
},
|
||||
// fieldset validators
|
||||
_fieldset: {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Registers validator for given field
|
||||
*
|
||||
* @param {String} id field id
|
||||
* @param {String} type validator (key in validators object)
|
||||
* @param {boolean} onKeyUp whether fire on key up
|
||||
* @param {Array} params validation function parameters
|
||||
*/
|
||||
function validateField(id, type, onKeyUp, params) {
|
||||
if (typeof validators[type] == 'undefined') {
|
||||
return;
|
||||
}
|
||||
if (typeof validate[id] == 'undefined') {
|
||||
validate[id] = [];
|
||||
}
|
||||
validate[id].push([type, params, onKeyUp]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns valdiation functions associated with form field
|
||||
*
|
||||
* @param {String} field_id form field id
|
||||
* @param {boolean} onKeyUpOnly see validateField
|
||||
* @type Array
|
||||
* @return array of [function, paramseters to be passed to function]
|
||||
*/
|
||||
function getFieldValidators(field_id, onKeyUpOnly) {
|
||||
// look for field bound validator
|
||||
var name = field_id.match(/[^-]+$/)[0];
|
||||
if (typeof validators._field[name] != 'undefined') {
|
||||
return [[validators._field[name], null]];
|
||||
}
|
||||
|
||||
// look for registered validators
|
||||
var functions = [];
|
||||
if (typeof validate[field_id] != 'undefined') {
|
||||
// validate[field_id]: array of [type, params, onKeyUp]
|
||||
for (var i = 0, imax = validate[field_id].length; i < imax; i++) {
|
||||
if (onKeyUpOnly && !validate[field_id][i][2]) {
|
||||
continue;
|
||||
}
|
||||
functions.push([validators[validate[field_id][i][0]], validate[field_id][i][1]]);
|
||||
}
|
||||
}
|
||||
|
||||
return functions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays errors for given form fields
|
||||
*
|
||||
* WARNING: created DOM elements must be identical with the ones made by
|
||||
* display_input() in FormDisplay.tpl.php!
|
||||
*
|
||||
* @param {Object} error_list list of errors in the form {field id: error array}
|
||||
*/
|
||||
function displayErrors(error_list) {
|
||||
for (var field_id in error_list) {
|
||||
var errors = error_list[field_id];
|
||||
var field = $('#'+field_id);
|
||||
var isFieldset = field.attr('tagName') == 'FIELDSET';
|
||||
var errorCnt = isFieldset
|
||||
? field.find('dl.errors')
|
||||
: field.siblings('.inline_errors');
|
||||
|
||||
// remove empty errors (used to clear error list)
|
||||
errors = $.grep(errors, function(item) {
|
||||
return item != '';
|
||||
});
|
||||
|
||||
// CSS error class
|
||||
if (!isFieldset) {
|
||||
// checkboxes uses parent <span> for marking
|
||||
var fieldMarker = (field.attr('type') == 'checkbox') ? field.parent() : field;
|
||||
fieldMarker[errors.length ? 'addClass' : 'removeClass']('field-error');
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
// if error container doesn't exist, create it
|
||||
if (errorCnt.length == 0) {
|
||||
if (isFieldset) {
|
||||
errorCnt = $('<dl class="errors" />');
|
||||
field.find('table').before(errorCnt);
|
||||
} else {
|
||||
errorCnt = $('<dl class="inline_errors" />');
|
||||
field.closest('td').append(errorCnt);
|
||||
}
|
||||
}
|
||||
|
||||
var html = '';
|
||||
for (var i = 0, imax = errors.length; i < imax; i++) {
|
||||
html += '<dd>' + errors[i] + '</dd>';
|
||||
}
|
||||
errorCnt.html(html);
|
||||
} else if (errorCnt !== null) {
|
||||
// remove useless error container
|
||||
errorCnt.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates fieldset and puts errors in 'errors' object
|
||||
*
|
||||
* @param {Element} fieldset
|
||||
* @param {boolean} isKeyUp
|
||||
* @param {Object} errors
|
||||
*/
|
||||
function validate_fieldset(fieldset, isKeyUp, errors) {
|
||||
fieldset = $(fieldset);
|
||||
if (fieldset.length && typeof validators._fieldset[fieldset.attr('id')] != 'undefined') {
|
||||
var fieldset_errors = validators._fieldset[fieldset.attr('id')].apply(fieldset[0], [isKeyUp]);
|
||||
for (var field_id in fieldset_errors) {
|
||||
if (typeof errors[field_id] == 'undefined') {
|
||||
errors[field_id] = [];
|
||||
}
|
||||
if (typeof fieldset_errors[field_id] == 'string') {
|
||||
fieldset_errors[field_id] = [fieldset_errors[field_id]];
|
||||
}
|
||||
$.merge(errors[field_id], fieldset_errors[field_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates form field and puts errors in 'errors' object
|
||||
*
|
||||
* @param {Element} field
|
||||
* @param {boolean} isKeyUp
|
||||
* @param {Object} errors
|
||||
*/
|
||||
function validate_field(field, isKeyUp, errors) {
|
||||
field = $(field);
|
||||
var field_id = field.attr('id');
|
||||
errors[field_id] = [];
|
||||
var functions = getFieldValidators(field_id, isKeyUp);
|
||||
for (var i = 0; i < functions.length; i++) {
|
||||
var args = functions[i][1] != null
|
||||
? functions[i][1].slice(0)
|
||||
: [];
|
||||
args.unshift(isKeyUp);
|
||||
var result = functions[i][0].apply(field[0], args);
|
||||
if (result !== true) {
|
||||
if (typeof result == 'string') {
|
||||
result = [result];
|
||||
}
|
||||
$.merge(errors[field_id], result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates form field and parent fieldset
|
||||
*
|
||||
* @param {Element} field
|
||||
* @param {boolean} isKeyUp
|
||||
*/
|
||||
function validate_field_and_fieldset(field, isKeyUp) {
|
||||
field = $(field);
|
||||
var errors = {};
|
||||
validate_field(field, isKeyUp, errors);
|
||||
validate_fieldset(field.closest('fieldset'), isKeyUp, errors);
|
||||
displayErrors(errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks field depending on its value (system default or custom)
|
||||
*
|
||||
* @param {Element} field
|
||||
*/
|
||||
function markField(field) {
|
||||
field = $(field);
|
||||
var type = getFieldType(field);
|
||||
var isDefault = checkFieldDefault(field, type);
|
||||
|
||||
// checkboxes uses parent <span> for marking
|
||||
var fieldMarker = (type == 'checkbox') ? field.parent() : field;
|
||||
setRestoreDefaultBtn(field, !isDefault);
|
||||
fieldMarker[isDefault ? 'removeClass' : 'addClass']('custom');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the "restore default value" button
|
||||
*
|
||||
* @param {Element} field
|
||||
* @param {boolean} display
|
||||
*/
|
||||
function setRestoreDefaultBtn(field, display) {
|
||||
var el = $(field).closest('td').find('.restore-default img');
|
||||
el[display ? 'show' : 'hide']();
|
||||
}
|
||||
|
||||
$(function() {
|
||||
// register validators and mark custom values
|
||||
var elements = $('input[id], select[id], textarea[id]');
|
||||
$('input[id], select[id], textarea[id]').each(function(){
|
||||
markField(this);
|
||||
var el = $(this);
|
||||
el.bind('change', function() {
|
||||
validate_field_and_fieldset(this, false);
|
||||
markField(this);
|
||||
});
|
||||
var tagName = el.attr('tagName');
|
||||
// text fields can be validated after each change
|
||||
if (tagName == 'INPUT' && el.attr('type') == 'text') {
|
||||
el.keyup(function() {
|
||||
validate_field_and_fieldset(el, true);
|
||||
markField(el);
|
||||
});
|
||||
}
|
||||
// disable textarea spellcheck
|
||||
if (tagName == 'TEXTAREA') {
|
||||
el.attr('spellcheck', false);
|
||||
}
|
||||
});
|
||||
|
||||
// check whether we've refreshed a page and browser remembered modified
|
||||
// form values
|
||||
var check_page_refresh = $('#check_page_refresh');
|
||||
if (check_page_refresh.length == 0 || check_page_refresh.val() == '1') {
|
||||
// run all field validators
|
||||
var errors = {};
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
validate_field(elements[i], false, errors);
|
||||
}
|
||||
// run all fieldset validators
|
||||
$('fieldset').each(function(){
|
||||
validate_fieldset(this, false, errors);
|
||||
});
|
||||
|
||||
displayErrors(errors);
|
||||
} else if (check_page_refresh) {
|
||||
check_page_refresh.val('1');
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// END: Form validation and field operations
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Tabbed forms
|
||||
//
|
||||
|
||||
/**
|
||||
* Sets active tab
|
||||
*
|
||||
* @param {String} tab_id
|
||||
*/
|
||||
function setTab(tab_id) {
|
||||
$('.tabs a').removeClass('active').filter('[href=' + tab_id + ']').addClass('active');
|
||||
$('.tabs_contents fieldset').hide().filter(tab_id).show();
|
||||
location.hash = 'tab_' + tab_id.substr(1);
|
||||
$('.config-form input[name=tab_hash]').val(location.hash);
|
||||
}
|
||||
|
||||
$(function() {
|
||||
var tabs = $('.tabs');
|
||||
if (!tabs.length) {
|
||||
return;
|
||||
}
|
||||
// add tabs events and activate one tab (the first one or indicated by location hash)
|
||||
tabs.find('a')
|
||||
.click(function(e) {
|
||||
e.preventDefault();
|
||||
setTab($(this).attr('href'));
|
||||
})
|
||||
.filter(':first')
|
||||
.addClass('active');
|
||||
$('.tabs_contents fieldset').hide().filter(':first').show();
|
||||
|
||||
// tab links handling, check each 200ms
|
||||
// (works with history in FF, further browser support here would be an overkill)
|
||||
var prev_hash;
|
||||
var tab_check_fnc = function() {
|
||||
if (location.hash != prev_hash) {
|
||||
prev_hash = location.hash;
|
||||
if (location.hash.match(/^#tab_.+/) && $('#' + location.hash.substr(5)).length) {
|
||||
setTab('#' + location.hash.substr(5));
|
||||
}
|
||||
}
|
||||
};
|
||||
tab_check_fnc();
|
||||
setInterval(tab_check_fnc, 200);
|
||||
});
|
||||
|
||||
//
|
||||
// END: Tabbed forms
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Form reset buttons
|
||||
//
|
||||
|
||||
$(function() {
|
||||
$('input[type=button][name=submit_reset]').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]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
// END: Form reset buttons
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// "Restore default" and "set value" buttons
|
||||
//
|
||||
|
||||
/**
|
||||
* Restores field's default value
|
||||
*
|
||||
* @param {String} field_id
|
||||
*/
|
||||
function restoreField(field_id) {
|
||||
var field = $('#'+field_id);
|
||||
if (field.length == 0 || defaultValues[field_id] == undefined) {
|
||||
return;
|
||||
}
|
||||
setFieldValue(field, getFieldType(field), defaultValues[field_id]);
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$('.tabs_contents')
|
||||
.delegate('.restore-default, .set-value', 'mouseenter', function(){$(this).css('opacity', 1)})
|
||||
.delegate('.restore-default, .set-value', 'mouseleave', function(){$(this).css('opacity', 0.25)})
|
||||
.delegate('.restore-default, .set-value', 'click', function(e) {
|
||||
e.preventDefault();
|
||||
var href = $(this).attr('href');
|
||||
var field_sel;
|
||||
if ($(this).hasClass('restore-default')) {
|
||||
field_sel = href;
|
||||
restoreField(field_sel.substr(1));
|
||||
} else {
|
||||
field_sel = href.match(/^[^=]+/)[0];
|
||||
var value = href.match(/=(.+)$/)[1];
|
||||
setFieldValue($(field_sel), 'text', value);
|
||||
}
|
||||
$(field_sel).trigger('change');
|
||||
})
|
||||
.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
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// User preferences import/export
|
||||
//
|
||||
|
||||
$(function() {
|
||||
offerPrefsAutoimport();
|
||||
var radios = $('#import_local_storage, #export_local_storage');
|
||||
if (!radios.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// enable JavaScript dependent fields
|
||||
radios
|
||||
.attr('disabled', false)
|
||||
.add('#export_text_file, #import_text_file')
|
||||
.click(function(){
|
||||
var enable_id = $(this).attr('id');
|
||||
var disable_id = enable_id.match(/local_storage$/)
|
||||
? enable_id.replace(/local_storage$/, 'text_file')
|
||||
: enable_id.replace(/text_file$/, 'local_storage');
|
||||
$('#opts_'+disable_id).addClass('disabled').find('input').attr('disabled', true);
|
||||
$('#opts_'+enable_id).removeClass('disabled').find('input').attr('disabled', false);
|
||||
});
|
||||
|
||||
// detect localStorage state
|
||||
var ls_supported = window.localStorage || false;
|
||||
var ls_exists = ls_supported ? (window.localStorage['config'] || false) : false;
|
||||
$('.localStorage-'+(ls_supported ? 'un' : '')+'supported').hide();
|
||||
$('.localStorage-'+(ls_exists ? 'empty' : 'exists')).hide();
|
||||
if (ls_exists) {
|
||||
updatePrefsDate();
|
||||
}
|
||||
$('form.prefs-form').change(function(){
|
||||
var form = $(this);
|
||||
var disabled = false;
|
||||
if (!ls_supported) {
|
||||
disabled = form.find('input[type=radio][value$=local_storage]').attr('checked');
|
||||
} else if (!ls_exists && form.attr('name') == 'prefs_import'
|
||||
&& $('#import_local_storage')[0].checked) {
|
||||
disabled = true;
|
||||
}
|
||||
form.find('input[type=submit]').attr('disabled', disabled);
|
||||
}).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']);
|
||||
}
|
||||
});
|
||||
|
||||
$('.click-hide-message').live('click', function(){
|
||||
var div = $(this);
|
||||
div.hide().parent('.group').css('height', '');
|
||||
div.next('form').show();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Saves user preferences to localStorage
|
||||
*
|
||||
* @param {Element} form
|
||||
*/
|
||||
function savePrefsToLocalStorage(form)
|
||||
{
|
||||
form = $(form);
|
||||
var submit = form.find('input[type=submit]');
|
||||
submit.attr('disabled', true);
|
||||
$.ajax({
|
||||
url: 'prefs_manage.php',
|
||||
cache: false,
|
||||
type: 'POST',
|
||||
data: {
|
||||
token: form.find('input[name=token]').val(),
|
||||
submit_get_json: true
|
||||
},
|
||||
success: function(response) {
|
||||
window.localStorage['config'] = response.prefs;
|
||||
window.localStorage['config_mtime'] = response.mtime;
|
||||
window.localStorage['config_mtime_local'] = (new Date()).toUTCString();
|
||||
updatePrefsDate();
|
||||
$('.localStorage-empty').hide();
|
||||
$('.localStorage-exists').show();
|
||||
var group = form.parent('.group');
|
||||
group.css('height', group.height() + 'px');
|
||||
form.hide('fast');
|
||||
form.prev('.click-hide-message').show('fast');
|
||||
},
|
||||
complete: function() {
|
||||
submit.attr('disabled', false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates preferences timestamp in Import form
|
||||
*/
|
||||
function updatePrefsDate()
|
||||
{
|
||||
var d = new Date(window.localStorage['config_mtime_local']);
|
||||
var msg = PMA_messages['strSavedOn'].replace('@DATE@', formatDate(d));
|
||||
$('#opts_import_local_storage .localStorage-exists').html(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns date formatted as YYYY-MM-DD HH:II
|
||||
*
|
||||
* @param {Date} d
|
||||
*/
|
||||
function formatDate(d)
|
||||
{
|
||||
return d.getFullYear() + '-'
|
||||
+ (d.getMonth() < 10 ? '0'+d.getMonth() : d.getMonth())
|
||||
+ '-' + (d.getDate() < 10 ? '0'+d.getDate() : d.getDate())
|
||||
+ ' ' + (d.getHours() < 10 ? '0'+d.getHours() : d.getHours())
|
||||
+ ':' + (d.getMinutes() < 10 ? '0'+d.getMinutes() : d.getMinutes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares message which informs that localStorage preferences are available and can be imported
|
||||
*/
|
||||
function offerPrefsAutoimport()
|
||||
{
|
||||
var has_config = (window.localStorage || false) && (window.localStorage['config'] || false);
|
||||
var cnt = $('#prefs_autoload');
|
||||
if (!cnt.length || !has_config) {
|
||||
return;
|
||||
}
|
||||
cnt.find('a').click(function(e) {
|
||||
e.preventDefault();
|
||||
var a = $(this);
|
||||
if (a.attr('href') == '#no') {
|
||||
cnt.remove();
|
||||
$.post('main.php', {
|
||||
token: cnt.find('input[name=token]').val(),
|
||||
prefs_autoload: 'hide'});
|
||||
return;
|
||||
}
|
||||
cnt.find('input[name=json]').val(window.localStorage['config']);
|
||||
cnt.find('form').submit();
|
||||
});
|
||||
cnt.show();
|
||||
}
|
||||
|
||||
//
|
||||
// END: User preferences import/export
|
||||
// ------------------------------------------------------------------
|
150
js/functions.js
150
js/functions.js
@@ -1400,7 +1400,7 @@ function getElement(e,f){
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the WYSIWYG-PDF scratchboard after changes have been made
|
||||
* Refresh the WYSIWYG scratchboard after changes have been made
|
||||
*/
|
||||
function refreshDragOption(e) {
|
||||
var elm = $('#' + e);
|
||||
@@ -1410,13 +1410,16 @@ function refreshDragOption(e) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh/resize the WYSIWYG-PDF scratchboard
|
||||
* Refresh/resize the WYSIWYG scratchboard
|
||||
*/
|
||||
function refreshLayout() {
|
||||
var elm = $('#pdflayout')
|
||||
var orientation = $('#orientation_opt').val();
|
||||
var paper = $('#paper_opt').val();
|
||||
|
||||
if($('#paper_opt').length==1){
|
||||
var paper = $('#paper_opt').val();
|
||||
}else{
|
||||
var paper = 'A4';
|
||||
}
|
||||
if (orientation == 'P') {
|
||||
posa = 'x';
|
||||
posb = 'y';
|
||||
@@ -1429,7 +1432,7 @@ function refreshLayout() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Show/hide the WYSIWYG-PDF scratchboard
|
||||
* Show/hide the WYSIWYG scratchboard
|
||||
*/
|
||||
function ToggleDragDrop(e) {
|
||||
var elm = $('#' + e);
|
||||
@@ -1706,6 +1709,47 @@ $(document).ready(function(){
|
||||
insertQuery(evt.target.id);
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#export_type").change(function(){
|
||||
if($("#export_type").val()=='svg'){
|
||||
$("#show_grid_opt").attr("disabled","disabled");
|
||||
$("#orientation_opt").attr("disabled","disabled");
|
||||
$("#with_doc").attr("disabled","disabled");
|
||||
$("#show_table_dim_opt").removeAttr("disabled");
|
||||
$("#all_table_same_wide").removeAttr("disabled");
|
||||
$("#paper_opt").removeAttr("disabled","disabled");
|
||||
$("#show_color_opt").removeAttr("disabled","disabled");
|
||||
//$(this).css("background-color","yellow");
|
||||
}else if($("#export_type").val()=='dia'){
|
||||
$("#show_grid_opt").attr("disabled","disabled");
|
||||
$("#with_doc").attr("disabled","disabled");
|
||||
$("#show_table_dim_opt").attr("disabled","disabled");
|
||||
$("#all_table_same_wide").attr("disabled","disabled");
|
||||
$("#paper_opt").removeAttr("disabled","disabled");
|
||||
$("#show_color_opt").removeAttr("disabled","disabled");
|
||||
$("#orientation_opt").removeAttr("disabled","disabled");
|
||||
}else if($("#export_type").val()=='eps'){
|
||||
$("#show_grid_opt").attr("disabled","disabled");
|
||||
$("#orientation_opt").removeAttr("disabled");
|
||||
$("#with_doc").attr("disabled","disabled");
|
||||
$("#show_table_dim_opt").attr("disabled","disabled");
|
||||
$("#all_table_same_wide").attr("disabled","disabled");
|
||||
$("#paper_opt").attr("disabled","disabled");
|
||||
$("#show_color_opt").attr("disabled","disabled");
|
||||
|
||||
}else if($("#export_type").val()=='pdf'){
|
||||
$("#show_grid_opt").removeAttr("disabled");
|
||||
$("#orientation_opt").removeAttr("disabled");
|
||||
$("#with_doc").removeAttr("disabled","disabled");
|
||||
$("#show_table_dim_opt").removeAttr("disabled","disabled");
|
||||
$("#all_table_same_wide").removeAttr("disabled","disabled");
|
||||
$("#paper_opt").removeAttr("disabled","disabled");
|
||||
$("#show_color_opt").removeAttr("disabled","disabled");
|
||||
}else{
|
||||
// nothing
|
||||
}
|
||||
});
|
||||
|
||||
$('#sqlquery').focus();
|
||||
if ($('#input_username')) {
|
||||
if ($('#input_username').val() == '') {
|
||||
@@ -2455,3 +2499,99 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function menuResize()
|
||||
{
|
||||
var cnt = $('#topmenu');
|
||||
var wmax = cnt.width() - 5; // 5 px margin for jumping menu in Chrome
|
||||
var submenu = cnt.find('.submenu');
|
||||
var submenu_w = submenu.outerWidth(true);
|
||||
var submenu_ul = submenu.find('ul');
|
||||
var li = cnt.find('> li');
|
||||
var li2 = submenu_ul.find('li');
|
||||
var more_shown = li2.length > 0;
|
||||
var w = more_shown ? submenu_w : 0;
|
||||
|
||||
// hide menu items
|
||||
var hide_start = 0;
|
||||
for (var i = 0; i < li.length-1; i++) { // li.length-1: skip .submenu element
|
||||
var el = $(li[i]);
|
||||
var el_width = el.outerWidth(true);
|
||||
el.data('width', el_width);
|
||||
w += el_width;
|
||||
if (w > wmax) {
|
||||
w -= el_width;
|
||||
if (w + submenu_w < wmax) {
|
||||
hide_start = i;
|
||||
} else {
|
||||
hide_start = i-1;
|
||||
w -= $(li[i-1]).data('width');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hide_start > 0) {
|
||||
for (var i = hide_start; i < li.length-1; i++) {
|
||||
$(li[i])[more_shown ? 'prependTo' : 'appendTo'](submenu_ul);
|
||||
}
|
||||
submenu.show();
|
||||
} else if (more_shown) {
|
||||
w -= submenu_w;
|
||||
// nothing hidden, maybe something can be restored
|
||||
for (var i = 0; i < li2.length; i++) {
|
||||
//console.log(li2[i], submenu_w);
|
||||
w += $(li2[i]).data('width');
|
||||
// item fits or (it is the last item and it would fit if More got removed)
|
||||
if (w+submenu_w < wmax || (i == li2.length-1 && w < wmax)) {
|
||||
$(li2[i]).insertBefore(submenu);
|
||||
if (i == li2.length-1) {
|
||||
submenu.hide();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (submenu.find('.tabactive').length) {
|
||||
submenu.addClass('active').find('> a').removeClass('tab').addClass('tabactive');
|
||||
} else {
|
||||
submenu.removeClass('active').find('> a').addClass('tab').removeClass('tabactive');
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
var topmenu = $('#topmenu');
|
||||
if (topmenu.length == 0) {
|
||||
return;
|
||||
}
|
||||
// create submenu container
|
||||
var link = $('<a />', {href: '#', 'class': 'tab'})
|
||||
.text(PMA_messages['strMore'])
|
||||
.click(function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
var img = topmenu.find('li:first-child img');
|
||||
if (img.length) {
|
||||
img.clone().attr('src', img.attr('src').replace(/\/[^\/]+$/, '/b_more.png')).prependTo(link);
|
||||
}
|
||||
var submenu = $('<li />', {'class': 'submenu'})
|
||||
.append(link)
|
||||
.append($('<ul />'))
|
||||
.mouseenter(function() {
|
||||
if ($(this).find('ul .tabactive').length == 0) {
|
||||
$(this).addClass('submenuhover').find('> a').addClass('tabactive');
|
||||
}
|
||||
})
|
||||
.mouseleave(function() {
|
||||
if ($(this).find('ul .tabactive').length == 0) {
|
||||
$(this).removeClass('submenuhover').find('> a').removeClass('tabactive');
|
||||
}
|
||||
})
|
||||
.hide();
|
||||
topmenu.append(submenu);
|
||||
|
||||
// populate submenu and register resize event
|
||||
$(window).resize(menuResize);
|
||||
menuResize();
|
||||
});
|
||||
|
@@ -106,6 +106,9 @@ $js_messages['strGeneratePassword'] = __('Generate password');
|
||||
$js_messages['strGenerate'] = __('Generate');
|
||||
$js_messages['strChangePassword'] = __('Change Password');
|
||||
|
||||
/* navigation tabs */
|
||||
$js_messages['strMore'] = __('More');
|
||||
|
||||
echo "var PMA_messages = new Array();\n";
|
||||
foreach ($js_messages as $name => $js_message) {
|
||||
PMA_printJsValue("PMA_messages['" . $name . "']", $js_message);
|
||||
|
164
js/pMap.js
Normal file
164
js/pMap.js
Normal file
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* Holds the definition and the creation of the imageMap object
|
||||
* @author Martynas Mickevicius <mmartynas@gmail.com>
|
||||
* @package phpMyAdmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* responsible for showing tooltips above the image chart
|
||||
*/
|
||||
var imageMap = {
|
||||
'mouseMoved': function(event, cont) {
|
||||
// return if no imageMap set
|
||||
// this can happen if server has no json
|
||||
if (!this.imageMap) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get mouse coordinated relative to image
|
||||
var mouseX = event.pageX - cont.offsetLeft;
|
||||
var mouseY = event.pageY - cont.offsetTop;
|
||||
|
||||
//console.log("X: " + mouseX + ", Y: " + mouseY);
|
||||
|
||||
/* Check if we are flying over a map zone
|
||||
* Lets use the following method to check if a given
|
||||
* point is in any convex polygon.
|
||||
* http://www.programmingforums.org/post168124-3.html
|
||||
*/
|
||||
var found = false;
|
||||
for (var key = 0; key < this.imageMap.length; key++)
|
||||
{
|
||||
var seriesName = this.imageMap[key]['n'];
|
||||
var seriesValue = this.imageMap[key]['v'];
|
||||
|
||||
var signSum = 0;
|
||||
for (var i = 0; i < this.imageMap[key]['p'].length; i++)
|
||||
{
|
||||
var index1;
|
||||
var index2;
|
||||
|
||||
if (i == this.imageMap[key]['p'].length - 1)
|
||||
{
|
||||
index1 = i;
|
||||
index2 = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
index1 = i;
|
||||
index2 = i+1;
|
||||
}
|
||||
var result = this.getDeterminant(
|
||||
this.imageMap[key]['p'][index1][0],
|
||||
this.imageMap[key]['p'][index1][1],
|
||||
this.imageMap[key]['p'][index2][0],
|
||||
this.imageMap[key]['p'][index2][1],
|
||||
mouseX,
|
||||
mouseY
|
||||
);
|
||||
if (result > 0) { signSum += 1; } else { signSum += -1; }
|
||||
}
|
||||
|
||||
if (Math.abs(signSum) == this.imageMap[key]['p'].length)
|
||||
{
|
||||
found = true;
|
||||
if (this.currentKey != key)
|
||||
{
|
||||
this.tooltip.show();
|
||||
this.tooltip.title(seriesName);
|
||||
this.tooltip.text(seriesValue);
|
||||
this.currentKey = key;
|
||||
}
|
||||
this.tooltip.move(mouseX + 20, mouseY + 20);
|
||||
}
|
||||
}
|
||||
if (!found && this.currentKey != -1 )
|
||||
{
|
||||
this.tooltip.hide();
|
||||
this.currentKey = -1;
|
||||
}
|
||||
},
|
||||
|
||||
'getDeterminant': function (X1, Y1, X2, Y2, X3, Y3) {
|
||||
return (X2*Y3 - X3*Y2) - (X1*Y3 - X3*Y1) + (X1*Y2 - X2*Y1);
|
||||
},
|
||||
|
||||
'loadImageMap': function(map) {
|
||||
this.imageMap = JSON.parse(map);
|
||||
for (key in this.imageMap)
|
||||
{
|
||||
// FIXME
|
||||
// without this loop image map does not work
|
||||
// on IE8 in the status page
|
||||
}
|
||||
},
|
||||
|
||||
'init': function() {
|
||||
this.tooltip.init();
|
||||
|
||||
$("div#chart").bind('mousemove',function(e) {
|
||||
imageMap.mouseMoved(e, this);
|
||||
});
|
||||
|
||||
this.tooltip.attach("div#chart");
|
||||
|
||||
this.currentKey = -1;
|
||||
},
|
||||
|
||||
'tooltip': {
|
||||
'init': function () {
|
||||
this.el = $('<div></div>');
|
||||
this.el.css('position', 'absolute');
|
||||
this.el.css('font-family', 'tahoma');
|
||||
this.el.css('background-color', '#373737');
|
||||
this.el.css('color', '#BEBEBE');
|
||||
this.el.css('padding', '3px');
|
||||
|
||||
var title = $('<p></p>');
|
||||
title.attr('id', 'title');
|
||||
title.css('margin', '0px');
|
||||
title.css('padding', '3px');
|
||||
title.css('background-color', '#606060');
|
||||
title.css('text-align', 'center');
|
||||
title.html('Title');
|
||||
this.el.append(title);
|
||||
|
||||
var text = $('<p></p>');
|
||||
text.attr('id', 'text');
|
||||
text.css('margin', '0');
|
||||
text.html('Text');
|
||||
this.el.append(text);
|
||||
|
||||
this.hide();
|
||||
},
|
||||
|
||||
'attach': function (element) {
|
||||
$(element).prepend(this.el);
|
||||
},
|
||||
|
||||
'move': function (x, y) {
|
||||
this.el.css('margin-left', x);
|
||||
this.el.css('margin-top', y);
|
||||
},
|
||||
|
||||
'hide': function () {
|
||||
this.el.css('display', 'none');
|
||||
},
|
||||
|
||||
'show': function () {
|
||||
this.el.css('display', 'block');
|
||||
},
|
||||
|
||||
'title': function (title) {
|
||||
this.el.find("p#title").html(title);
|
||||
},
|
||||
|
||||
'text': function (text) {
|
||||
this.el.find("p#text").html(text.replace(/;/g, "<br />"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
imageMap.init();
|
||||
});
|
Reference in New Issue
Block a user