/**
* Copyright 2003-2020 *
* copyright@slipt.net|copyright@dccollc.com *
* DCCO LLC., The Media Trust Company *
* *
* This is proprietary software. Any unauthorized distribution or *
* modification is strictly forbidden and will be prosecuted to the *
* fullest extent of the law. *
* *
* Front-End Development Team Version 7 *
* *
* Matt Martin 2016 *
*/
function Datatables(prefix,pa,options)
{
this.prefix = prefix;
this.process_action = pa;
this.init_complete = false;
this.row_data = [];
this.options = ( options && typeof options == "object" ) ? options : {};
if ( this.prefix && window.UserPref )
{
this.userPref = new UserPref(this.prefix);
}
};
Datatables.TABLE_DOM_FILTER = '<\"fg-toolbar ui-toolbar ui-widget-header ui-helper-clearfix\"flp<\"clear\">>rt<\"fg-toolbar ui-toolbar ui-widget-header ui-helper-clearfix\"i<\"clear\">>';
Datatables.TABLE_DOM_NO_FILTER = '<\"fg-toolbar ui-toolbar ui-widget-header ui-helper-clearfix\"l<\"clear\">>rt<\"fg-toolbar ui-toolbar ui-widget-header ui-helper-clearfix\"i<\"clear\">>';
Datatables.TABLE_LANGUAGE = { processing: "Loading...", search: "", lengthMenu: "_MENU_ per page", infoEmpty: "_TOTAL_", info: "_START_ to _END_ of _TOTAL_", infoFiltered: "" };
Datatables.prototype.init = function()
{
var dt = this;
if ( !dt.initTable() )
{
// dt.initTable();
$(".datatable_wrapper").show(); //Show the wrapper if there's no table to initialize
}
};
/*
* Initialize a datatable
*/
Datatables.prototype.initTable = function(tableSettings)
{
var dt = this; //Needed to maintain this reference or else datatables will override it
if ( $("table#" + dt.prefix).length )
{
var standardTableSettings = {
order: [[0, "desc"]],
columns: dt.getColumns(dt.prefix),
lengthMenu: [10, 25, 50, 100, 500, 1000, 1500],
//lengthMenu: dt.getLengthMenu(),
pageLength: 25,
//pageLength: dt.getPageLength(),
language: Datatables.TABLE_LANGUAGE,
autoWidth: false,
destroy: true,
serverSide: true,
stateSave: true,
stateDuration: 0,
jQueryUI: true,
searchDelay: 500,
initComplete: function() { dt.initComplete.call(dt); },
drawCallback: function() { dt.drawCallback.call(dt); },
stateSaveCallback: function(settings, data) { dt.saveTableState.call(dt, settings, data); },
stateLoadCallback: function(settings) { return dt.loadTableState.call(dt, settings); },
ajax: function(data, callback, settings)
{
if ( dt.serverParams ) { dt.serverParams.call(this, data); }
dt.serverData.call(dt, data, callback, settings);
},
dom: Datatables.TABLE_DOM_FILTER,
pagingType: "input"
};
tableSettings = this.tableSettings || tableSettings || {};
return dt.table = $("#" + dt.prefix).dataTable($.extend({}, standardTableSettings, tableSettings));
}
return false;
};
Datatables.prototype.getColumns = function(prefix)
{
var columns = [];
var column;
if ( $("#"+prefix).find("th").length )
{
$("#"+prefix).find("th").each(function()
{
if ( $(this).data("mdata") === "NULL" ) return true; // skip column def if mdata='NULL'
column = { orderable: $(this).data("sort"), data: $(this).data("mdata"), className: $(this).attr("class") };
columns.push(column);
});
}
else
{
columns.push({});
}
return columns;
}
/*
* Page length menu options
*/
Datatables.prototype.getLengthMenu = function(array)
{
if ( array && array.length )
{
return array;
}
return [10, 25, 50, 100, 500, 1000];
};
/*
* Default page length
*/
Datatables.prototype.getPageLength = function(integer)
{
if ( integer )
{
return integer;
}
return 25;
};
/*
* Refresh the datatable
*/
Datatables.prototype.refreshTable = function()
{
var table = this instanceof Datatables && this.table ? this.table : $("table.dataTable").dataTable();
if ( table && table.fnDraw )
{
table.fnDraw();
}
};
/*
* Add a placeholder to the search box
*
* To override with custom placeholder:
*
* namespace.addFilterPlaceholder = function()
* {
* Datatables.prototype.addFilterPlaceholder.call(namespace, "Search custom");
* };
*
*/
Datatables.prototype.addFilterPlaceholder = function(placeholder)
{
$("#" + this.prefix + "_wrapper").find(".dataTables_filter input").attr("placeholder", placeholder || this.filterPlaceholder || "Search");
};
Datatables.prototype.positionControls = function()
{
//add positioning to account for search icon
$("#" + this.prefix + "_wrapper .dataTables_filter label").css("position", "relative");
var filter = $("#" + this.prefix + "_wrapper").find(".dataTables_filter");
this.filter = filter.find("input");
$("#main_search").html(filter);
var info = $("#" + this.prefix + "_wrapper").find(".dataTables_info");
$("#main_info").html(info);
var length = $("#" + this.prefix + "_wrapper").find(".dataTables_length");
$("#main_length").html(length);
var paginate = $("#" + this.prefix + "_wrapper").find(".dataTables_paginate");
$("#main_pagination").html(paginate);
//$(".dataTables_paginate").toggle($("table.dataTable").DataTable().page.info().pages > 1);
//pagination buttons
$(".dataTables_paginate span:nth-of-type(1)").addClass("btn").html('');
$(".dataTables_paginate span:nth-of-type(2)").addClass("btn").html('');
$(".dataTables_paginate span:nth-of-type(5)").addClass("btn").html('');
$(".dataTables_paginate span:nth-of-type(6)").addClass("btn").html('');
};
/*
* Init complete callback
*/
Datatables.prototype.initComplete = function()
{
$("#" + this.prefix).before($("#" + this.prefix + "_wrapper [id*=_controls]"));
$("#" + this.prefix + "_wrapper").show();
var sub = GeneralUtility.prototype.getParameterByName("sub_mode");
var colsel = GeneralUtility.prototype.addTableColumnSelector();
this.init_complete = true;
};
/*
* Draw callback
*/
Datatables.prototype.drawCallback = function()
{
if ( !this.init_complete )
{
this.addFilterPlaceholder();
this.positionControls();
var sub = GeneralUtility.prototype.getParameterByName("sub_mode");
}
setTimeout(WebRequest.prototype.rewriteHrefs(), 1);
};
/*
* Server parameters callback
*/
Datatables.prototype.serverParams = function(data)
{
};
/*
* Server data callback
*/
Datatables.prototype.serverData = function(data, callback, settings)
{
let dt = this;
var source = "process_action.php?qgs=1&v=7";
data.auth = GeneralUtility.prototype.getParameterByName("auth");
data.process_action = this.process_action;
let storeRowData = (function (request) {
if (!this.options.store_row_data) {
return;
}
if (typeof request !== 'object' || !request.responseText) {
dt.row_data = {};
} else {
let obj = JSON.parse(request.responseText);
obj.aaData.map(function(data, index) {
if (data.hasOwnProperty('_data')) {
dt.row_data[index] = JSON.parse(data._data);
} else {
dt.row_data[index] = {};
}
});
}
}).bind(this);
settings.jqXHR = WebRequest.prototype.spinWhileActive($.getJSON(source, data, callback), storeRowData);
};
/*
* Save the table state
*/
Datatables.prototype.saveTableState = function(settings, data)
{
if ( !this.userPref )
{
return;
}
if ( this.options.hasOwnProperty("ignore_pref") )
{
var prefs = this.options.ignore_pref;
if ( Array.isArray(prefs) )
{
for (var i=0; i