window.tablelayout = window.tablelayout || {};
jQuery(window).on('load', function () {
'use strict';
/**
*
* @param {jQuery} $secedit_form jQuery object of the section edit form associated with the table
*
* @return {void}
*/
function addPrintButtonToTable($secedit_form) {
var range = $secedit_form.find('input[name="range"]').val();
var target = $secedit_form.closest('form').attr('action');
var layout = $secedit_form.find('input[name="tablelayout"]').val();
var params = [
'do=tablelayout_printtable',
'range=' + encodeURIComponent(range),
'id=' + encodeURIComponent(window.JSINFO.id)
];
if (typeof layout !== 'undefined' && layout.length > 0) {
var json = JSON.parse(layout);
var colwidth = json.colwidth;
params.push('colwidth=' + colwidth);
}
var href = target + '?' + params.join('&');
var $link = jQuery('' + window.LANG.plugins.tablelayout.print + '').attr({
'href': href,
'target': '_blank'
}).addClass('button print');
$secedit_form.closest('div.secedit').append($link);
}
/**
* Add a row for the search fields and filter buttons below the table header
*
* @param {JQuery} $table jQuery-object of the table
* @param {int} numHeaderRows the number of rows in the header of the table
* @param {int} columnCount the number of columns in the table
* @return {JQuery} the searchSortRow object, that has been added to the table
*/
function addSearchSortRow($table, numHeaderRows, columnCount) {
var $searchSortRow = jQuery('
' + '
'.repeat(columnCount) + '
');
var $lastHeaderRow;
if ($table.hasClass('tablelayout_body')) {
$lastHeaderRow = $table.closest('.table').find('table.tablelayout_head tr').last();
$lastHeaderRow.after($searchSortRow);
} else if(numHeaderRows === 0) {
$table.find('tr').first().before($searchSortRow);
} else {
$lastHeaderRow = $table.find('tr').slice(numHeaderRows - 1).first();
$lastHeaderRow.after($searchSortRow);
}
return $searchSortRow;
}
/**
*
* @param {JQuery} $table jQuery-object of the table
* @param {JQuery} $searchSortRow the special row where the sort-buttons will be placed
* @param {int} numHeaderRows the number of rows in the header of the table
*
* @return {void}
*/
function addSortFunctionality($table, $searchSortRow, numHeaderRows) {
var $rowsToBeSorted;
if ($table.hasClass('tablelayout_body')) {
$rowsToBeSorted = $table.find('tr');
} else {
$rowsToBeSorted = $table.find('tr').slice(parseInt(numHeaderRows) + 1);
}
var $tableSortRowCells = $searchSortRow.find('td > div,th > div');
$tableSortRowCells.append(jQuery('