/* */
/* Copyright 2003-2016 */
/* 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 */
/* */
function GeneralUtility(auth_key)
{
this.auth_key = auth_key;
};
var Blow;
GeneralUtility.prototype.init = function() {
var gen_util = this;
$(document).off( 'click', '.dtColumns span').on( 'click', '.dtColumns span', function (e) {
e.preventDefault();
if ($(e.target).hasClass("no-hide"))
return;
var tables = $(e.target).parents('.dtColumns').siblings('.dataTable').DataTable();
var column = tables.column( $(e.target).attr('data-index') );
var columnNbr = parseInt($(e.target).attr('data-index'));
if (isNaN(columnNbr))
return;
column.visible( ! column.visible() );
$(e.target).parents('.dtColumns').siblings('.dataTable').find('.cookie-by-company td:nth-child(' + (parseInt($(e.target).attr('data-index'))+1).toString() + ')').toggle();
$(".dom_inserted_row").each( function(idx,row) {
let cell = row.cells[columnNbr];
$(cell).toggle();
}
);
$(this).toggleClass('hid');
});
}
GeneralUtility.prototype.addTableColumnSelector = function() {
$('table').each(function() {
if ($.fn.dataTable.fnIsDataTable(this) && $(this).siblings('.dtColumns').length == 0 && $('.deck_header').length == 0) {
let strCols = '
';
$(this).parents('.dataTables_wrapper').prepend(strCols);
$('.dtColumns > div > span').find('span').remove();
$('.dtColumns > div > span > div').contents().unwrap();
strCols = null;
}
});
}
GeneralUtility.prototype.getParameterByName = function (name, url)
{
if ( !url ) { url = window.location.href; }
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^]*)|&|#|$)"), results = regex.exec(url);
if ( !results ) { return null; }
if ( !results[2] ) { return ''; }
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
GeneralUtility.prototype.hideClickOffEvent = function(elem)
{
$('body').bind('click', function(event)
{
if ( $("#"+elem).is(":visible") && !$(event.target).is("#"+elem+", a") && !$(event.target).closest("#"+elem).length )
{
$("#"+elem).hide();
$("body").unbind("click");
}
});
}
//move/position controls for pages
GeneralUtility.prototype.movePageControls = function()
{
var utility = this;
if ( $("#page_timeframe").length && $("#page_timeframe").children().length )
{
$("#main_timeframe > span").html("").append($("#page_timeframe select"));
utility.setDatepicker("start_date input", "yy-mm-dd");
utility.setDatepicker("end_date input", "yy-mm-dd");
}
}
//page timeframe control configuration
GeneralUtility.prototype.timeframeConfig = function(table,prop)
{
var utility = this;
$("#main_timeframe select").change(function()
{
if ( $(this).val() == "custom" )
{
$("#main_custom_dates").css("display","table-cell");
utility.sendCustomDates(table,prop);
}
else
{
$("#main_custom_dates").css("display","none");
$("#start_date input, #end_date input").val("");
if ( prop ) { prop.save($(this).val()); } /************** NEED TO ADD THIS IN AND UPDATE EVERY FILE THAT USES timeframeConfig() ***************/
table.refreshTable();
}
});
}
GeneralUtility.prototype.getTimeframeValue = function()
{
if ( $("#main_timeframe select").val() )
{
var obj = {};
if ( $("#main_timeframe select").val() == "custom" )
{
obj.custom_start = $("#start_date input").val();
obj.custom_end = $("#end_date input").val();
if ( !$.isEmptyObject(obj) ) { return obj; }
}
else
{
obj.timeframe = $("#main_timeframe select").val();
return obj;
}
}
}
GeneralUtility.prototype.getUrlParameter = function(sParam)
{
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
}
GeneralUtility.prototype.sendCustomDates = function(table,prop)
{
if ($('input#sub_mode').val() != "data_compliance_cookies") {
$("#end_date + button").click(function()
{
if ( $("#start_date input") != "" && $("#end_date input") != "" )
{
var time_obj = {};
time_obj.value = "custom";
time_obj.start = $("#start_date input").val();
time_obj.end = $("#end_date input").val();
if ( prop ) { prop.save(time_obj); }
table.refreshTable();
}
});
} else {
return true;
}
}
GeneralUtility.prototype.setDatepicker = function(elem, format)
{
if ( format ) { var date_format = format; }
$("#"+elem).datepicker({ dateFormat: date_format });
}
GeneralUtility.prototype.exploreExpandClick = function(event)
{
if ( $(event.target).hasClass("ico-down") )
{
event.stopPropagation();
event.preventDefault();
$(event.target).parents(".expand").click();
return false;
}
else
{
if ( $(event.target).siblings(".expand_list").css("display") == "none" )
{
var posV = 0;
var wOption = 0;
var wList = 0;
$(".expand_list").css("display","none");
/*
if ( $(window).height() - $(event.target).offset().top - $(event.target).outerHeight() + $(window).scrollTop() - $(event.target).siblings(".expand_list").outerHeight() > 0 )
{
posV = $(event.target).parent().outerHeight() - 5;
}
else
{
posV = -$(event.target).siblings(".expand_list").outerHeight() + 5;
}
*/
$(event.target).siblings(".expand_list").css({"display" : "inline-block"});
$(event.target).siblings(".expand_list").find("div").each(function()
{
if ($(this).outerWidth() > wOption) { wOption = $(this).outerWidth(); }
});
wList = $(event.target).parent().find(".expand").width();
wList = "-" + wList + "px";
$(event.target).siblings(".expand_list").css({"width" : wOption});
event.stopPropagation();
$(document).one('click', function(event)
{
$(".expand_list").css({"display" : "none"});
});
}
else
{
$(event.target).siblings(".expand_list").css("display","none");
}
return false;
}
}
GeneralUtility.prototype.toggleMenu = function(e, container)
{
e.preventDefault();
e.stopPropagation();
$(container + ' nav').toggleClass('on');
$(document).one('click', function closeMenu (e) {
if($(container + ' nav div').has(e.target).length === 0){
$(container + ' nav').removeClass('on');
} else {
$(document).one('click', closeMenu);
}
});
}
GeneralUtility.prototype.toggleSplitMenu = function(e)
{
e.stopPropagation();
$(e.target).siblings(".btn_drop").toggleClass("on");
$(document).one('click', function()
{
$(".btn_drop").removeClass("on");
});
}
GeneralUtility.prototype.tableFlexCC = function(offset_sel, offset_col)
{
var utility = this;
var ccIds = $.map($(".call_chain"), function(n, i){
return "#" + n.id;
});
$.each( ccIds, function( i, ccId ){
utility.tableFlex(offset_sel, offset_col, ccId);
});
}
GeneralUtility.prototype.tableFlex = function(offset_sel, offset_col, scope)
{
var utility = this;
if (typeof scope === 'undefined') { scope = ""; }
if ( $(scope + " .table-flex")[0] )
{
var scr = 0, tbl = 0, flx = [], pos = [], diff = 0, cut = 0, cols = 1;
flx[1] = 0;
pos[1] = $(scope + " .table-flex:not([class*='flex-col'])").eq(0).parents("td").index();
for (i = 2; i < 20; i++)
{
if ( $(scope + " .flex-col-" + i).length )
{
pos[i] = $(scope + " .flex-col-" + i).eq(0).parents("td").index();
flx[i] = 0;
cols++;
}
else
{
break;
}
}
$(scope + " .table-flex").css("max-width","");
if ( offset_sel == ".cc_tier" )
{
$("table" + scope + ":has('.table-flex') tr th:nth-child(n+7)").css("min-width","27px");
$("table" + scope + ":has('.table-flex') tr td:nth-child(n+7)").css("min-width","27px");
}
scr = $(window).width();
if ($("body").height() > $(window).height()) { scr = scr - 17; }
if ($("#side_bar").length) { scr = scr - $("#side_bar").innerWidth(); }
if ($("#dialog_dashboard_item").length) { scr = scr - ($(window).width()*.08); }
if ($("#malware_alert_dialog").length) { scr = scr - 200; }
tbl = $("table" + scope + ":has('.table-flex')").width();
$(scope + " .table-flex:not([class*='flex-col'])").each(function( ) {
if ( $(this).width() > flx[1] ) { flx[1] = $(this).width() }
if ( $(this).attr("title") == undefined ) { $(this).attr("title", $(this).text()); }
});
for (i = 2; i < flx.length; i++)
{
$(scope + " .table-flex.flex-col-" + i).each(function( )
{
if ( $(this).width() > flx[i] ) { flx[i] = $(this).width() - 20; }
if ( $(this).attr("title") == undefined ) { $(this).attr("title", $(this).text()); }
});
}
if (typeof offset_sel === 'undefined')
{
offset_sel = 0;
offset_col = 0;
}
if ( tbl > scr )
{
var flxAll = 0;
var diffLeft = 0;
for (i = 1; i < flx.length; i++) {
flxAll += flx[i];
}
diff = parseInt(tbl - scr);
if ( diff < flxAll )
{
diffLeft = diff;
for (i = 1; i < flx.length; i++)
{
if (diffLeft > 0)
{
if (flx[i] > diffLeft && (flx[i] - diffLeft) > 50) {
cut = parseInt(diffLeft);
} else if (flx[i] < diffLeft) {
cut = parseInt(flx[i] - 50);
} else {
cut = parseInt(flx[i] - diffLeft);
}
diffLeft = diffLeft - parseInt(cut) + 21;
cut = flx[i] - cut;
cut += "px";
if (i == 1)
{
$(scope + " .table-flex:not([class*='flex-col'])").each(function()
{
if ( i === offset_col )
{
cut_offset = parseInt(cut) - ($(this).siblings(offset_sel).width() * parseInt($(this).siblings(offset_sel).data("tier")));
cut_offset = cut_offset - 40 + "px";
$(this).css("max-width",cut_offset);
}
else
{
$(this).css("max-width",cut);
$(this).parents("table").find("th").eq(pos[i]).css({"width":"unset","max-width":cut});
$(this).parents("table").find("th").eq(pos[i]).children("div").css({"max-width":cut, "overflow":"hidden", "text-overflow":"ellipsis", "margin-right":"0"});
}
});
}
else
{
$(scope + " .table-flex.flex-col-" + i).each(function()
{
if ( i === offset_col )
{
cut_offset = parseInt(cut) - ($(this).siblings(offset_sel).width() * parseInt($(this).siblings(offset_sel).data("tier")));
$(this).css("max-width",cut_offset);
}
else
{
$(this).css("max-width",cut);
$(this).parents("table").find("th").eq(pos[i]).css({"width":"unset","max-width":cut});
$(this).parents("table").find("th").eq(pos[i]).children("div").css({"max-width":cut, "overflow":"hidden", "text-overflow":"ellipsis", "margin-right":"0"});
}
});
}
//diffLeft = diffLeft - flx[i] + parseInt(cut);
}
}
}
else
{
$(scope + " .table-flex").css("max-width","50px");
}
}
}
}
GeneralUtility.prototype.debouncer = function(func, timeout)
{
var timeoutID , timeout = timeout || 200;
return function()
{
var scope = this, args = arguments;
clearTimeout( timeoutID );
timeoutID = setTimeout( function()
{
func.apply( scope , Array.prototype.slice.call( args ) );
}, timeout );
}
}
//adjust height of main_content div
GeneralUtility.prototype.adjustContentHeight = function()
{
var avail = $(window).height() - $('#fixed_wrapper').height() - $('#main_footer').height();
avail += "px";
$("#main_content").css("min-height",avail);
}
//"expand" table row (create new row underneath click event row to show additional data/info)
GeneralUtility.prototype.clickExpandRow = function (event, func)
{
var table = $(event.target).parents("table").attr("id");
$(".expanded_row").remove();
//hide explore drop down
$(event.target).parents(".expand_list").css("display", "none");
var tr = $(event.target).parents("tr")[0];
//$(event.target).removeClass("open");
$(tr).after(" |
");
var data_obj = {};
$.extend(data_obj, event.target.dataset);
var expand_row_callback = function(html)
{
if ( html )
{
$('.expanded_row td').html("").html(html);
if ( (func) && ( typeof (func) == "function" ) )
func();
}
}
page.request.getRender(data_obj.pa, data_obj, expand_row_callback);
}
GeneralUtility.prototype.clickExpandRowTop = function(event, id, func)
{
var table = id;
$(".expanded_row").remove();
//hide explore drop down
$(event.target).parents(".expand_list").css("display", "none");
var tr = $("#"+table+" tbody").children("tr")[0];
//$(event.target).removeClass("open");
$(tr).before(" |
");
var data_obj = {};
$.extend(data_obj, event.target.dataset);
var expand_row_callback = function(html)
{
if ( html )
{
$('.expanded_row td').html("").html(html);
if ( (func) && ( typeof (func) == "function" ) )
func();
}
}
page.request.getRender(data_obj.pa, data_obj, expand_row_callback);
}
GeneralUtility.prototype.closeExpandRow = function(event)
{
$(event.target).parents(".expanded_row").remove();
}
//used for displaying post response message for dataTable row - single processing action from Explore drop down menu (pausing, disabling, etc.)
GeneralUtility.prototype.expandRowResponseMessage = function(elem)
{
var table = $(elem).parents("table").attr("id");
$(".expanded_row").remove();
//hide explore drop down
$(elem).parents(".expand_list").css("display", "none");
var tr = $(elem).parents("tr")[0];
//$(event.target).removeClass("open");
$(tr).after(" |
");
}
//original function: "configureAutoComplete_withHiddenField" Vidit Agarwal 2015
GeneralUtility.prototype.autoCompleteHiddenField = function(params)
{
//params: inputField, hiddenField_id, authKey, type, delay_msec, minChars, autoSubmit, callback, filters, allow_csv, extras (array)
//console.log(params);
inputField = $('#'+params.inputField);
hiddenField = $('#'+params.hiddenField_id);
type = params.type;
delay_msec = params.delay_msec;
minChars = params.minChars;
autoSubmit = params.autoSubmit;
callback = params.callback;
filters = params.filters;
allow_csv = params.allow_csv;
extras = params.extras;
if ( hiddenField.length < 0 ) { return; }
if ( allow_csv != true ) { allow_csv = false; }
$( inputField ).autocomplete(
{
delay: delay_msec,
select: function(event, ui)
{
if ( allow_csv )
{
//manipulate visible values
var display_terms = $(this).val().split( /\s*,\s*/ );
display_terms.pop();
display_terms.push( ui.item.label );
$(this).val( display_terms.join( ", " ) );
//manipulate hidden values
var hidden_terms = hiddenField.val().split( /\s*,\s*/ );
var last_hidden_item = hidden_terms.pop();
if (last_hidden_item != '')
{
hidden_terms.push(last_hidden_item);
}
hidden_terms.push( ui.item.value );
hiddenField.val(hidden_terms.join( "," ));
}
else
{
hiddenField.val(ui.item.value);
$(this).val(ui.item.label);
}
if ( autoSubmit == 1 || autoSubmit == true) { hiddenField.closest("form").submit(); }
if ( callback != undefined && callback != null) { callback(inputField, ui.item, hiddenField); }
return false;
},
search: function()
{
var this_term = $(this).val();
if ( allow_csv ) { this_term = extractLast( this.value ); }
else { hiddenField.val(''); }
if ( this_term.length < minChars ) { return false; }
},
source: function(request, response)
{
var this_term = request['term'];
if ( allow_csv ) { this_term = extractLast(this_term); }
var obj = params;
obj.term = this_term;
page.request.getData("autocomplete_list-v7", obj, response);
// GeneralUtility.prototype.blowItUp();
},
focus: function(event, ui) {
return false;
},
response: function(event, ui)
{
//console.log(event);
Blow = ui;
}
});
}
GeneralUtility.prototype.bindUserPref = function(select, pref, eventType)
{
eventType = eventType || "change";
$(function()
{
$(select).off(eventType + ".statesave").on(eventType + ".statesave", function()
{
pref.save($(this).val());
});
});
};
GeneralUtility.prototype.bindTimeframeUserPref = function(pref, eventType)
{
this.bindUserPref.call(this, "#main_timeframe select, #page_timeframe select", pref, eventType);
};
//These methods should be available statically
for ( var methodName in GeneralUtility.prototype )
{
GeneralUtility[methodName] = GeneralUtility.prototype[methodName];
}
//select/deselect all checkboxes
GeneralUtility.prototype.toggleAllCheckboxes = function(elem, boxes)
{
$(elem).change(function()
{
if ( $(elem).is(":checked") )
{
$("."+boxes).each(function()
{
$(this).prop("checked",true);
});
}
else
{
$("."+boxes).each(function()
{
$(this).prop("checked",false);
});
}
});
}
GeneralUtility.prototype.init();