EnVisageOnline/Main-RMO/Source/EnVisage/Scripts/main.js

385 lines
13 KiB
JavaScript

var _lockers = 0;
function increaseLockers() {
if (_lockers < 0)
_lockers = 0;
_lockers++;
}
function decreaseLockers() {
if (_lockers > 0)
_lockers--;
if (_lockers < 0)
_lockers = 0;
}
function canUnblockUI() {
return _lockers === 0;
}
function isUIBlocked() {
return _lockers > 0;
}
function showErrorModal(title, message) {
var modal = $("#modal-error");
if (modal != null) {
var divTitle = $("#modal-error .modal-title");
if (divTitle != null)
divTitle.text(title);
var divMessage = $("#modal-error .modal-body");
if (divMessage != null) {
divMessage.text($.trim(message));
if (divMessage.text().length > 0) {
$("#modal-error").modal();
}
}
}
}
function enableElement(obj, enable) {
if (enable) {
$(obj).removeAttr('disabled');
} else {
$(obj).attr('disabled', 'disabled');
}
}
function blockUI() {
increaseLockers();
$.blockUI({ message: "<div class='spinner2'>Loading...</div>", ignoreIfBlocked: true });
}
function unblockUI() {
decreaseLockers();
if (canUnblockUI())
$.unblockUI();
}
(function ($) {
$.validator.unobtrusive.parseDynamicContent = function (selector) {
//use the normal unobstrusive.parse method
$.validator.unobtrusive.parse(selector);
//get the relevant form
var form = $(selector).first().closest('form');
//get the collections of unobstrusive validators, and jquery validators
//and compare the two
var unobtrusiveValidation = form.data('unobtrusiveValidation');
var validator = form.validate();
$.each(unobtrusiveValidation.options.rules, function (elname, elrules) {
if (validator.settings.rules[elname] == undefined) {
var args = {};
$.extend(args, elrules);
args.messages = unobtrusiveValidation.options.messages[elname];
//edit:use quoted strings for the name selector
$(form).find("[name='" + elname + "']").rules("add", args);
} else {
$.each(elrules, function (rulename, data) {
if (validator.settings.rules[elname][rulename] == undefined) {
var args = {};
args[rulename] = data;
args.messages = unobtrusiveValidation.options.messages[elname];
//edit:use quoted strings for the name selector
$(form).find("[name='" + elname + "']").rules("add", args);
}
});
}
});
};
})($);
(function ($) {
$.QueryString = (function (a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i) {
var p = a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
})($);
Number.prototype.formatNumber = function (c, d, t) {
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : d,
t = t == undefined ? "," : t,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
Number.prototype.formatDuration = function () {
var result = this;
if (this > 0) { // get years
}
if (this > 0) { // get days
}
if (this > 0) { // get hours
}
return result;
};
function union(arr1, arr2) {
var result = new Array();
var fa = (arr1 || []);
for (var i = 0; i < fa.length; i++) {
if (result.indexOf(fa[i]) < 0)
result.push(fa[i]);
}
var sa = (arr2 || []);
for (var i = 0; i < sa.length; i++) {
if (result.indexOf(sa[i]) < 0)
result.push(sa[i]);
}
return result;
};
function binarySearch(ar, x, left, right, searchIndex4Insert) {
if (!ar || !$.isArray(ar))
throw 'ar is not array!';
if (left > right || ar.length <= 0)
return -1;
var mid = Math.floor((left + right) / 2);
if (mid == ar.length) {
return searchIndex4Insert === true ? ar.length : -1;
}
if (ar[mid] == x)
return mid;
if (searchIndex4Insert === true) {
var prev = (ar[mid - 1] || Number.MIN_VALUE);
var next = (ar[mid + 1] || Number.MAX_VALUE);
if (prev == x)
return mid - 1;
if (next == x)
return mid + 1;
if (prev < x && x < ar[mid])
return mid;
if (ar[mid] < x && x < next)
return mid + 1;
}
if (ar[mid] < x)
return binarySearch(ar, x, mid + 1, right, searchIndex4Insert);
if (ar[mid] > x)
return binarySearch(ar, x, left, mid - 1, searchIndex4Insert);
};
/*
* Generate a random uuid.
*
* USAGE: Math.uuid(length, radix)
* length - the desired number of characters
* radix - the number of allowable values for each character.
*
* EXAMPLES:
* // No arguments - returns RFC4122, version 4 ID
* >>> Math.uuid()
* "92329D39-6F5C-4520-ABFC-AAB64544E172"
*
* // One argument - returns ID of the specified length
* >>> Math.uuid(15) // 15 character ID (default base=62)
* "VcydxgltxrVZSTV"
*
* // Two arguments - returns ID of the specified length, and radix. (Radix must be <= 62)
* >>> Math.uuid(8, 2) // 8 character ID (base=2)
* "01001010"
* >>> Math.uuid(8, 10) // 8 character ID (base=10)
* "47473046"
* >>> Math.uuid(8, 16) // 8 character ID (base=16)
* "098F4D35"
*/
Math.uuid = (function () {
// Private array of chars to use
var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
return function (len, radix) {
var chars = CHARS, uuid = [], rnd = Math.random;
radix = radix || chars.length;
if (len) {
// Compact form
for (var i = 0; i < len; i++) uuid[i] = chars[0 | rnd() * radix];
} else {
// rfc4122, version 4 form
var r;
// rfc4122 requires these characters
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
// Fill in random data. At i==19 set the high bits of clock sequence as
// per rfc4122, sec. 4.1.5
for (var i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | rnd() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];
}
}
}
return uuid.join('');
};
})();
function initMainJS() {
$("select").on("select2-focus", function (e) {
$(".minicolors-panel").css('display', 'none');
$(".datepicker-dropdown").css('display', 'none');
});
}
function setDropdownProps(button, dropdown, liHeight) {
var clientid = $(dropdown)[0].id;
var rows = $("#" + clientid + " li").length;
if (rows > 3)
rows = rows - 1;
var menumax = rows * liHeight;
if (rows >= 2)
menumax = menumax + 15;
dropdown.css('overflow', 'hidden');
var curmaxheight = 300;
var totalMaxheight = 400;
var menumax_keep = menumax;
var y = $(window.top).height();
var bOffset = button.offset().top - window.pageYOffset;
var y1 = bOffset + button.outerHeight();
var dropDownLeft = button.offset().left - window.pageXOffset;
var dropDownTop = bOffset + button.outerHeight();
var sc1 = y - y1;
if (curmaxheight + dropDownTop > window.innerHeight)
sc1 = bOffset;
if (menumax > sc1)
menumax = (sc1 - 50);
if (menumax > totalMaxheight)
menumax = totalMaxheight;
var direction = 'bottom';
if (menumax + dropDownTop > window.innerHeight) {
if (menumax_keep < menumax)
dropDownTop = (bOffset - menumax_keep);
else
dropDownTop = (bOffset - menumax);
direction = 'top'
}
if (menumax < menumax_keep) {
var delta = menumax_keep - menumax
if (delta > 25)
dropdown.css('overflow', 'auto');
if (curmaxheight > menumax) {
menumax = curmaxheight;
}
}
if (direction === 'top') {
dropdown.css('max-height', menumax + "px");
if (menumax < curmaxheight)
menumaxdph = $(dropdown).outerHeight();
dropDownTop = (bOffset - menumax);
} else {
dropdown.css('max-height', menumax + "px");
}
dropdown.css('position', 'fixed');
dropdown.css('top', dropDownTop + "px");
dropdown.css('left', dropDownLeft + "px");
dropdown.css('z-index', '499');
}
jQuery.getScrollBarWidthHeight = function () {
var inner = $('<p></p>').css({
'width': '100%',
'height': '100%'
});
var outer = $('<div></div>').css({
'position': 'absolute',
'width': '100px',
'height': '100px',
'top': '0',
'left': '0',
'visibility': 'hidden',
'overflow': 'hidden'
}).append(inner);
$(document.body).append(outer);
var w1 = inner.width(), h1 = inner.height();
outer.css('overflow', 'scroll');
var w2 = inner.width(), h2 = inner.height();
if (w1 == w2 && outer[0].clientWidth) {
w2 = outer[0].clientWidth;
}
if (h1 == h2 && outer[0].clientHeight) {
h2 = outer[0].clientHeight;
}
outer.detach();
var pixelRatioMultiplier = 1.00;
//AG: I've commented out the lines below because window.devicePixelRatio is a bad practice to determine the zoom although it works
//correctly on the desktop browsers - this supposed to show HIDPI screens and will not work correctly on tablets and phones and probably HIDPI desktop screens as well
//if (window.devicePixelRatio != null && window.devicePixelRatio != 0)
// pixelRatioMultiplier = window.devicePixelRatio.toFixed(2);
return [Math.round((w1 - w2) * pixelRatioMultiplier), Math.round((h1 - h2) * pixelRatioMultiplier)];
};
initMainJS();
Object.size = function (obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
var _bigColorPalette = ["#FFFF00", "#1CE6FF", "#FF34FF", "#FF4A46", "#008941", "#006FA6", "#A30059",
"#FFDBE5", "#7A4900", "#0000A6", "#63FFAC", "#B79762", "#004D43", "#8FB0FF", "#997D87",
"#5A0007", "#809693", "#92896B", "#1B4400", "#4FC601", "#3B5DFF", "#4A3B53", "#FF2F80",
"#61615A", "#BA0900", "#6B7900", "#00C2A0", "#FFAA92", "#FF90C9", "#B903AA", "#D16100",
"#DDEFFF", "#000035", "#7B4F4B", "#A1C299", "#300018", "#0AA6D8", "#013349", "#00846F",
"#372101", "#FFB500", "#C2FFED", "#A079BF", "#CC0744", "#C0B9B2", "#C2FF99", "#001E09",
"#00489C", "#6F0062", "#0CBD66", "#EEC3FF", "#456D75", "#B77B68", "#7A87A1", "#788D66",
"#885578", "#FAD09F", "#FF8A9A", "#D157A0", "#BEC459", "#456648", "#0086ED", "#886F4C",
"#34362D", "#B4A8BD", "#00A6AA", "#452C2C", "#636375", "#A3C8C9", "#FF913F", "#938A81",
"#575329", "#00FECF", "#B05B6F", "#8CD0FF", "#3B9700", "#04F757", "#C8A1A1", "#1E6E00",
"#7900D7", "#A77500", "#6367A9", "#A05837", "#6B002C", "#772600", "#D790FF", "#9B9700",
"#549E79", "#FFF69F", "#201625", "#72418F", "#BC23FF", "#99ADC0", "#3A2465", "#922329",
"#5B4534", "#FDE8DC", "#404E55", "#0089A3", "#CB7E98", "#A4E804", "#324E72", "#6A3A4C",
"#83AB58", "#001C1E", "#D1F7CE", "#004B28", "#C8D0F6", "#A3A489", "#806C66", "#222800",
"#BF5650", "#E83000", "#66796D", "#DA007C", "#FF1A59", "#8ADBB4", "#1E0200", "#5B4E51",
"#C895C5", "#320033", "#FF6832", "#66E1D3", "#CFCDAC", "#D0AC94", "#7ED379", "#012C58",
"#7A7BFF", "#D68E01", "#353339", "#78AFA1", "#FEB2C6", "#75797C", "#837393", "#943A4D",
"#B5F4FF", "#D2DCD5", "#9556BD", "#6A714A", "#001325", "#02525F", "#0AA3F7", "#E98176",
"#DBD5DD", "#5EBCD1", "#3D4F44", "#7E6405", "#02684E", "#962B75", "#8D8546", "#9695C5",
"#E773CE", "#D86A78", "#3E89BE", "#CA834E", "#518A87", "#5B113C", "#55813B", "#E704C4",
"#00005F", "#A97399", "#4B8160", "#59738A", "#FF5DA7", "#F7C9BF", "#643127", "#513A01",
"#6B94AA", "#51A058", "#A45B02", "#1D1702", "#E20027", "#E7AB63", "#4C6001", "#9C6966",
"#64547B", "#97979E", "#006A66", "#391406", "#F4D749", "#0045D2", "#006C31", "#DDB6D0",
"#7C6571", "#9FB2A4", "#00D891", "#15A08A", "#BC65E9", "#000000", "#C6DC99", "#203B3C",
"#671190", "#6B3A64", "#F5E1FF", "#FFA0F2", "#CCAA35", "#374527", "#8BB400", "#797868",
"#C6005A", "#3B000A", "#C86240", "#29607C", "#402334", "#7D5A44", "#CCB87C", "#B88183",
"#AA5199", "#B5D6C3", "#A38469", "#9F94F0", "#A74571", "#B894A6", "#71BB8C", "#00B433",
"#789EC9", "#6D80BA", "#953F00", "#5EFF03", "#E4FFFC", "#1BE177", "#BCB1E5", "#76912F",
"#003109", "#0060CD", "#D20096", "#895563", "#29201D", "#5B3213", "#A76F42", "#89412E",
"#1A3A2A", "#494B5A", "#A88C85", "#F4ABAA", "#A3F3AB", "#00C6C8", "#EA8B66", "#958A9F",
"#BDC9D2", "#9FA064", "#BE4700", "#658188", "#83A485", "#453C23", "#47675D", "#3A3F00",
"#061203", "#DFFB71", "#868E7E", "#98D058", "#6C8F7D", "#D7BFC2", "#3C3E6E", "#D83D66",
"#2F5D9B", "#6C5E46", "#D25B88", "#5B656C", "#00B57F", "#545C46", "#866097", "#365D25",
"#252F99", "#00CCFF", "#674E60", "#FC009C"];