/* $LastChangedRevision$
* General JS used for the d2s.lib
* (C)door2solution software gmbh
*/
/****************************** UTIL START **********************************************/
var UTIL = {};
UTIL.debug = function (msg) {
if (window.console) {
console.log(msg);
} else {
alert(msg);
}
};
UTIL.tableSort = function () {
$('table.sortable th.sort').click(function (e) {
e.stopPropagation();
$elem = $(this);
$arrow = $elem.children("img");
var arrow_up = "/e4s/images/list/sort_up.gif";
var arrow_down = "/e4s/images/list/sort_down.gif";
var table = $(this).parents('table').eq(0);
var rows = table.find('tr:gt(0)').toArray().sort(comparer($(this).index()));
this.asc = !this.asc;
if (!this.asc) {
rows = rows.reverse();
}
for (var i = 0; i < rows.length; i++) {
table.append(rows[i]);
}
if ($elem.hasClass("asc")) {
$elem.removeClass("asc");
$elem.addClass("desc");
$arrow.attr("src", arrow_up);
} else if ($elem.hasClass("desc")) {
$elem.removeClass("desc");
$elem.addClass("asc");
$arrow.attr("src", arrow_down);
} else {
$('table.sortable th.sort').find("img").remove();
$('table.sortable th.sort').removeClass("asc").removeClass("desc");
$(this).append("");
$elem.addClass("asc");
}
});
function comparer(index) {
return function (a, b) {
var valA = getCellValue(a, index),
valB = getCellValue(b, index);
return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB
: valA.localeCompare(valB)
}
}
function getCellValue(row, index) {
return $(row).children('td').eq(index).html()
}
};
UTIL.getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(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 : sParameterName[1];
}
}
};
/* FIXED TABLE HEADER */
UTIL.moveScroll = function (tableID, divID, offset) {
$div = $(("#" + divID));
var scroll = $div.scrollTop();
var offsetTop = $div.offset().top;
$table = $(("#" + tableID));
var anchor_top = $table.offset().top;
var width = $table.width() + offset;
var anchor_bottom = $("#bottom_anchor").offset().top;
var height = $(("#" + tableID + " th")).height();
if (true) {
clone_table = $("#clone");
if (clone_table.length == 0) {
clone_table = $(("#" + tableID)).clone();
clone_table.attr('id', 'clone');
clone_table.css({
position: 'fixed',
'pointer-events': 'none',
top: offsetTop,
'width': width,
'background-color': 'transparent'
});
clone_table.width($table.width());
$(("#" + divID)).append(clone_table);
$("#clone").find('tbody').css({
visibility: 'collapse'
/*display: 'none'*/
});
$("#clone").find('tfoot').css({
visibility: 'collapse',
display: 'none'
});
$("#clone thead").css({
visibility: 'visible',
'pointer-events': 'auto'
});
}
} else {
$("#clone").remove();
}
};
UTIL.reload = function () {
document.location.reload();
};
UTIL.loadModule = function (callback) {
try {
callback();
} catch (e) {
try {
//console.log(e);
} catch (ex) {
}
}
};
UTIL.addGoogleAnalytics = function (code) {
if (code && code != '') {
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', cod, 'auto');
ga('send', 'pageview');
} else {
console.log("Code " + code + " not valid!");
}
};
/****************************** UTIL END ************************************************/
/****************************** TREE START **********************************************/
var TREE = {};
TREE.refreshTreeFrame = function (fname, win, node) {
var refreshed = false;
if (win.name == fname) {
var tmp = win.frames;
var i;
for (i = 0; i < tmp.length; i++) {
if (tmp[i].name == 'TREE') {
tmp[i].e4sRefreshNode(node);
refreshed = true;
}
}
}
if (!refreshed && win.parent != null && win.name != '') {
this.refreshTreeFrame(fname, win.parent, node);
}
};
TREE.test = function (alias, txt) {
var now = new Date();
var urlAction = '/d2p/d2p';
urlAction += '?ALIAS=' + alias;
urlAction += '&E4S_TRE_OBJ=MAINMENU';
//urlAction += '&E4S_TRE_NOD=' + node;
urlAction += '&E4S_TRE_TGT=MAINCONTENT';
urlAction += '&E4S_TRE_TXT=' + escape(txt).replace('+', '%2B');
urlAction += '&TIM=' + now.getTime();
parent.MAINCONTENT.location = urlAction;
};
/****************************** TREE END ************************************************/
/****************************** AJAX START **********************************************/
var AJAX = {};
AJAX.getJSON = function (url, dataid, data, callback) {
var params = {ALIAS: "9905", DATA: dataid};
if (data != null && data != '') {
$.extend(params, data);
}
$.ajax({
method: "GET",
url: url,
data: params
})
.done(function (msg) {
return callback($.parseJSON(msg));
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log("ajax call failed (" + errorThrown + ")");
});
};
AJAX.getDataAndAddContent = function (url, dataid, target, pid, pvalue) {
var params = {ALIAS: "9905", DATA: dataid};
var data = null;
if (pid != null && pid != '') {
data = {dataid: pvalue};
}
if (data != null && data != '') {
$.extend(params, data);
}
$(target).html("Please Wait!");
$.ajax({
method: "GET",
url: url,
data: params
})
.done(function (msg) {
$(target).html(msg);
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log("ajax call failed (" + errorThrown + ")");
});
};
AJAX.printPdf = function (requestUrl) {
var ret = {};
ret.finalize = function (fun) {
ret.finalizeFunction = fun;
return ret;
};
ret.timeout = function (fun) {
ret.timeoutFunction = fun;
return ret;
};
ret.fail = function (fun) {
ret.failFunction = fun;
return ret;
};
ret.success = function (fun, preventDefault) {
ret.successFunction = fun;
ret.preventDefault = preventDefault;
return ret;
};
ret.jqXHR = $.getJSON(requestUrl, function (data) {
if (data.timeout) {
console.error("timeout", this);
if (ret.timeoutFunction) {
ret.timeoutFunction(ret);
}
return;
}
if (data.error) {
console.error("error while processing print request:", data.error, this);
if (data.stackTrace) {
console.error(data.stackTrace);
}
if (ret.failFunction) {
ret.failFunction(ret);
}
return;
}
if (data.url) {
if (!ret.preventDefault) {
window.open(data.url);
}
if (ret.successFunction) {
ret.successFunction(ret, data);
}
} else {
console.error("error on server side no url and no error", this);
}
});
ret.jqXHR.fail(function (jqXHR, textStatus, errorThrown) {
console.error("error while sending print request:", textStatus, errorThrown, jqXHR);
if (ret.failFunction) {
ret.failFunction(ret);
}
});
ret.jqXHR.always(function () {
if (ret.finalizeFunction) {
ret.finalizeFunction(ret);
}
});
return ret;
};
/****************************** AJAX END ************************************************/
/****************************** HTML START **********************************************/
var HTML = {};
/****************************** HTML END ************************************************/
/****************************** BOOTSTRAP START *****************************************/
var BOOTSTRAP = {};
BOOTSTRAP.openModal = function (id) {
BOOTSTRAP.modal(id, "");
};
BOOTSTRAP.closeModal = function (id) {
BOOTSTRAP.modal(id, "close");
};
BOOTSTRAP.modal = function (id, mode) {
try {
if (id != null && id != '') {
if (id.toString().indexOf("#") < 0) {
id = "#" + id;
}
if (mode != null && mode != '') {
$(id).modal(mode);
} else {
$(id).modal();
}
} else {
console.log("id empty or null");
}
} catch (e) {
alert(e);
}
};
/****************************** BOOTSTRAP END *******************************************/
/* Float Label Pattern Plugin for Bootstrap 3.1.0 by Travis Wilson
**************************************************/
(function ($) {
$.fn.floatLabels = function (options) {
// Settings
var self = this;
var settings = $.extend({}, options);
// Event Handlers
function registerEventHandlers() {
self.on('input keyup change', 'input, textarea', function () {
actions.swapLabels(this);
});
}
// Actions
var actions = {
initialize: function () {
self.each(function () {
var $this = $(this);
var $label = $this.children('label');
var $field = $this.find('input,textarea').first();
if ($this.children().first().is('label')) {
$this.children().first().remove();
$this.append($label);
}
var placeholderText = ($field.attr('placeholder') && $field.attr(
'placeholder') != $label.text()) ? $field.attr('placeholder')
: $label.text();
$label.data('placeholder-text', placeholderText);
$label.data('original-text', $label.text());
if ($field.val() == '') {
$field.addClass('empty')
}
});
},
swapLabels: function (field) {
var $field = $(field);
var $label = $(field).siblings('label').first();
var isEmpty = Boolean($field.val());
if (isEmpty) {
$field.removeClass('empty');
$label.text($label.data('original-text'));
} else {
$field.addClass('empty');
$label.text($label.data('placeholder-text'));
}
}
};
// Initialization
function init() {
registerEventHandlers();
actions.initialize();
self.each(function () {
actions.swapLabels($(this).find('input,textarea').first());
});
}
init();
return this;
};
$(function () {
UTIL.loadModule(function () {
$('.float-label-control').floatLabels();
});
UTIL.loadModule(function () {
$('[data-toggle="popover"]').popover();
});
UTIL.loadModule(function () {
$('SELECT.searchable').select2({
dropdownAutoWidth: true,
width: 'initial'
});
});
UTIL.loadModule(function () {
var nSort = [];
$('table.useDatatable thead th').each(function (index, value) {
if (!$(value).hasClass("sortable")) {
nSort.push(index);
}
});
$('table.useDatatable').DataTable({
"order": [[0, "desc"]],
"bStateSave": true,
"columnDefs": [{
"targets": nSort,
"orderable": false
}],
language: {
'decimal': '',
'emptyTable': '',
'info': '',
'infoEmpty': '',
'infoFiltered': '',
'infoPostFix': '',
'thousands': ',',
'lengthMenu': '',
'loadingRecords': '',
'processing': '',
'search': '',
'zeroRecords': '',
'paginate': {
'first': '',
'last': '',
'next': '',
'previous': '',
},
'aria': {
'sortAscending': 'activate to sort column ascending',
'sortDescending': 'activate to sort column descending',
},
}
}
);
});
});
})(jQuery);
function refreshSelect2() {
$('SELECT.searchable').trigger("change");
}
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
};
}
var isMarking = false;
var X_OFFSET = 0;
function temp_d2z_handleMouseDownEvent(evt) {
if (document.forms[0].elements["ACTION"].value === "CROP") {
isMarking = true;
evt.preventDefault();
var parentOffset = $(this).parent().offset();
var relX = evt.pageX - parentOffset.left;
var relY = evt.pageY - parentOffset.top;
pos.xStart = relX + X_OFFSET;
pos.yStart = relY;
$('#ID_IMAP').append("