';
if (response.sql_data) {
var len = response.sql_data.length;
for (var i = 0; i < len; i++) {
dialogContent += '
' + Messages.strSQLQuery + '' + response.sql_data[i].sql_query + Messages.strMatchedRows + '
' + response.sql_data[i].matched_rows + '';
if (i < len - 1) {
dialogContent += '
';
}
}
} else {
dialogContent += response.message;
}
dialogContent += '
';
var $dialogContent = $(dialogContent);
var buttonOptions = {};
buttonOptions[Messages.strClose] = function () {
$(this).dialog('close');
};
$('').append(data.message).dialog({
title: Messages.strBrowseForeignValues,
width: Math.min($(window).width() - 100, 700),
maxHeight: $(window).height() - 100,
dialogClass: 'browse_foreign_modal',
close: function close() {
// remove event handlers attached to elements related to dialog
$(tableId).off('click', 'td a.foreign_value');
$(formId).off('click', showAllId);
$(formId).off('submit'); // remove dialog itself
$(this).remove();
},
modal: true
});
}).done(function () {
var showAll = false;
$(tableId).on('click', 'td a.foreign_value', function (e) {
e.preventDefault();
var $input = $thisA.prev('input[type=text]'); // Check if input exists or get CEdit edit_box
if ($input.length === 0) {
$input = $thisA.closest('.edit_area').prev('.edit_box');
} // Set selected value as input value
$input.val($(this).data('key'));
$dialog.dialog('close');
});
$(formId).on('click', showAllId, function () {
showAll = true;
});
$(formId).on('submit', function (e) {
e.preventDefault(); // if filter value is not equal to old value
// then reset page number to 1
if ($(filterId).val() !== $(filterId).data('old')) {
$(formId).find('select[name=pos]').val('0');
}
var postParams = $(this).serializeArray(); // if showAll button was clicked to submit form then
// add showAll button parameter to form
if (showAll) {
postParams.push({
name: $(showAllId).attr('name'),
value: $(showAllId).val()
});
} // updates values in dialog
$.post($(this).attr('action') + '&ajax_request=1', postParams, function (data) {
var $obj = $('
').html(data.message);
$(formId).html($obj.find(formId).html());
$(tableId).html($obj.find(tableId).html());
});
showAll = false;
});
});
};
/**
* Get the auto saved query key
* @return {String}
*/
Sql.getAutoSavedKey = function () {
var db = $('input[name="db"]').val();
var table = $('input[name="table"]').val();
var key = db;
if (table !== undefined) {
key += '.' + table;
}
return 'autoSavedSql_' + key;
};
Sql.checkSavedQuery = function () {
var key = Sql.getAutoSavedKey();
if (isStorageSupported('localStorage') && typeof window.localStorage.getItem(key) === 'string') {
Functions.ajaxShowMessage(Messages.strPreviousSaveQuery);
} else if (Cookies.get(key)) {
Functions.ajaxShowMessage(Messages.strPreviousSaveQuery);
}
};
AJAX.registerOnload('sql.js', function () {
$('body').on('click', 'a.browse_foreign', function (e) {
e.preventDefault();
Sql.browseForeignDialog($(this));
});
/**
* vertical column highlighting in horizontal mode when hovering over the column header
*/
$(document).on('mouseenter', 'th.column_heading.pointer', function () {
Sql.changeClassForColumn($(this), 'hover', true);
});
$(document).on('mouseleave', 'th.column_heading.pointer', function () {
Sql.changeClassForColumn($(this), 'hover', false);
});
/**
* vertical column marking in horizontal mode when clicking the column header
*/
$(document).on('click', 'th.column_heading.marker', function () {
Sql.changeClassForColumn($(this), 'marked');
});
/**
* create resizable table
*/
$('.sqlqueryresults').trigger('makegrid');
/**
* Check if there is any saved query
*/
if (codeMirrorEditor || document.sqlform) {
Sql.checkSavedQuery();
}
});
/**
* Profiling Chart
*/
Sql.makeProfilingChart = function () {
if ($('#profilingchart').length === 0 || $('#profilingchart').html().length !== 0 || !$.jqplot || !$.jqplot.Highlighter || !$.jqplot.PieRenderer) {
return;
}
var data = [];
$.each(JSON.parse($('#profilingChartData').html()), function (key, value) {
data.push([key, parseFloat(value)]);
}); // Remove chart and data divs contents
$('#profilingchart').html('').show();
$('#profilingChartData').html('');
Functions.createProfilingChart('profilingchart', data);
};
/**
* initialize profiling data tables
*/
Sql.initProfilingTables = function () {
if (!$.tablesorter) {
return;
} // Added to allow two direction sorting
$('#profiletable').find('thead th').off('click mousedown');
$('#profiletable').tablesorter({
widgets: ['zebra'],
sortList: [[0, 0]],
textExtraction: function textExtraction(node) {
if (node.children.length > 0) {
return node.children[0].innerHTML;
} else {
return node.innerHTML;
}
}
}); // Added to allow two direction sorting
$('#profilesummarytable').find('thead th').off('click mousedown');
$('#profilesummarytable').tablesorter({
widgets: ['zebra'],
sortList: [[1, 1]],
textExtraction: function textExtraction(node) {
if (node.children.length > 0) {
return node.children[0].innerHTML;
} else {
return node.innerHTML;
}
}
});
};
AJAX.registerOnload('sql.js', function () {
Sql.makeProfilingChart();
Sql.initProfilingTables();
});
/**
* Polyfill to make table headers sticky.
*/
var elements = $('.sticky');
Stickyfill.add(elements);