';
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.strAffectedRows +
'
' + response.sql_data[i].matched_rows + '';
if (i < len - 1) {
dialogContent += '
';
}
}
} else {
dialogContent += response.message;
}
dialogContent += '
';
var $dialogContent = $(dialogContent);
var modal = $('#simulateDmlModal');
modal.modal('show');
modal.find('.modal-body').first().html($dialogContent);
modal.on('shown.bs.modal', function () {
Functions.highlightSql(modal);
});
} else {
Functions.ajaxShowMessage(response.error);
}
},
error: function () {
Functions.ajaxShowMessage(Messages.strErrorProcessingRequest);
}
});
});
/**
* Handles multi submits of results browsing page such as edit, delete and export
*/
$('body').on('click', 'form[name="resultsForm"].ajax button[name="submit_mult"], form[name="resultsForm"].ajax input[name="submit_mult"]', function (e) {
e.preventDefault();
var $button = $(this);
var action = $button.val();
var $form = $button.closest('form');
var argsep = CommonParams.get('arg_separator');
var submitData = $form.serialize() + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true' + argsep;
Functions.ajaxShowMessage();
AJAX.source = $form;
var url;
if (action === 'edit') {
submitData = submitData + argsep + 'default_action=update';
url = 'index.php?route=/table/change/rows';
} else if (action === 'copy') {
submitData = submitData + argsep + 'default_action=insert';
url = 'index.php?route=/table/change/rows';
} else if (action === 'export') {
url = 'index.php?route=/table/export/rows';
} else if (action === 'delete') {
url = 'index.php?route=/table/delete/confirm';
} else {
return;
}
$.post(url, submitData, AJAX.responseHandler);
});
$(document).on('submit', '.maxRowsForm', function () {
var unlimNumRows = $(this).find('input[name="unlim_num_rows"]').val();
var maxRowsCheck = Functions.checkFormElementInRange(
this,
'session_max_rows',
Messages.strNotValidRowNumber,
1
);
var posCheck = Functions.checkFormElementInRange(
this,
'pos',
Messages.strNotValidRowNumber,
0,
unlimNumRows > 0 ? unlimNumRows - 1 : null
);
return maxRowsCheck && posCheck;
});
$('#insertBtn').on('click', function () {
Functions.insertValueQuery();
});
$('#view_as').on('click', function () {
Functions.selectContent(this, sqlBoxLocked, true);
});
$('#sqlquery').on('click', function () {
if ($(this).data('textarea-auto-select') === true) {
Functions.selectContent(this, sqlBoxLocked, true);
}
});
}); // end $()
/**
* Starting from some th, change the class of all td under it.
* If isAddClass is specified, it will be used to determine whether to add or remove the class.
*
* @param $thisTh
* @param {string} newClass
* @param isAddClass
*/
Sql.changeClassForColumn = function ($thisTh, newClass, isAddClass) {
// index 0 is the th containing the big T
var thIndex = $thisTh.index();
var hasBigT = $thisTh.closest('tr').children().first().hasClass('column_action');
// .eq() is zero-based
if (hasBigT) {
thIndex--;
}
var $table = $thisTh.parents('.table_results');
if (! $table.length) {
$table = $thisTh.parents('table').siblings('.table_results');
}
var $tds = $table.find('tbody tr').find('td.data').eq(thIndex);
if (isAddClass === undefined) {
$tds.toggleClass(newClass);
} else {
$tds.toggleClass(newClass, isAddClass);
}
};
/**
* Handles browse foreign values modal dialog
*
* @param {object} $thisA reference to the browse foreign value link
*/
Sql.browseForeignDialog = function ($thisA) {
var formId = '#browse_foreign_form';
var showAllId = '#foreign_showAll';
var tableId = '#browse_foreign_table';
var filterId = '#input_foreign_filter';
var $dialog = null;
var argSep = CommonParams.get('arg_separator');
var params = $thisA.getPostData();
params += argSep + 'ajax_request=true';
$.post($thisA.attr('href'), params, function (data) {
// Creates browse foreign value dialog
$dialog = $('').append(data.message).dialog({
classes: {
'ui-dialog-titlebar-close': 'btn-close'
},
title: Messages.strBrowseForeignValues,
width: Math.min($(window).width() - 100, 700),
maxHeight: $(window).height() - 100,
dialogClass: 'browse_foreign_modal',
close: function () {
// 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'));
// Unchecks the Ignore checkbox for the current row
$input.trigger('change');
$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 (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 (node) {
if (node.children.length > 0) {
return node.children[0].innerHTML;
} else {
return node.innerHTML;
}
}
});
};
AJAX.registerOnload('sql.js', function () {
Sql.makeProfilingChart();
Sql.initProfilingTables();
});