/*! jquery-dateformat 01-08-2019 */ //https://github.com/phstc/jquery-dateFormat var DateFormat = {}; !function (e) { var I = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], O = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], v = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], w = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], a = { Jan: "01", Feb: "02", Mar: "03", Apr: "04", May: "05", Jun: "06", Jul: "07", Aug: "08", Sep: "09", Oct: "10", Nov: "11", Dec: "12" }, u = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.?\d{0,3}[Z\-+]?(\d{2}:?\d{2})?/; DateFormat.format = function () { function o(e) { return a[e] || e } function i(e) { var a, r, t, n, s, o = e, i = ""; return -1 !== o.indexOf(".") && (o = (n = o.split("."))[0], i = n[n.length - 1]), 3 <= (s = o.split(":")).length ? (a = s[0], r = s[1], t = s[2].replace(/\s.+/, "").replace(/[a-z]/gi, ""), { time: o = o.replace(/\s.+/, "").replace(/[a-z]/gi, ""), hour: a, minute: r, second: t, millis: i }) : { time: "", hour: "", minute: "", second: "", millis: "" } } function D(e, a) { for (var r = a - String(e).length, t = 0; t < r; t++)e = "0" + e; return e } return { parseDate: function (e) { var a, r, t = { date: null, year: null, month: null, dayOfMonth: null, dayOfWeek: null, time: null }; if ("number" == typeof e) return this.parseDate(new Date(e)); if ("function" == typeof e.getFullYear) t.year = String(e.getFullYear()), t.month = String(e.getMonth() + 1), t.dayOfMonth = String(e.getDate()), t.time = i(e.toTimeString() + "." + e.getMilliseconds()); else if (-1 != e.search(u)) a = e.split(/[T\+-]/), t.year = a[0], t.month = a[1], t.dayOfMonth = a[2], t.time = i(a[3].split(".")[0]); else switch (6 === (a = e.split(" ")).length && isNaN(a[5]) && (a[a.length] = "()"), a.length) { case 6: t.year = a[5], t.month = o(a[1]), t.dayOfMonth = a[2], t.time = i(a[3]); break; case 2: r = a[0].split("-"), t.year = r[0], t.month = r[1], t.dayOfMonth = r[2], t.time = i(a[1]); break; case 7: case 9: case 10: t.year = a[3]; var n = parseInt(a[1]), s = parseInt(a[2]); n && !s ? (t.month = o(a[2]), t.dayOfMonth = a[1]) : (t.month = o(a[1]), t.dayOfMonth = a[2]), t.time = i(a[4]); break; case 1: r = a[0].split(""), t.year = r[0] + r[1] + r[2] + r[3], t.month = r[5] + r[6], t.dayOfMonth = r[8] + r[9], t.time = i(r[13] + r[14] + r[15] + r[16] + r[17] + r[18] + r[19] + r[20]); break; default: return null }return t.time ? t.date = new Date(t.year, t.month - 1, t.dayOfMonth, t.time.hour, t.time.minute, t.time.second, t.time.millis) : t.date = new Date(t.year, t.month - 1, t.dayOfMonth), t.dayOfWeek = String(t.date.getDay()), t }, date: function (a, e) { try { var r = this.parseDate(a); if (null === r) return a; for (var t, n = r.year, s = r.month, o = r.dayOfMonth, i = r.dayOfWeek, u = r.time, c = "", h = "", l = "", d = !1, y = 0; y < e.length; y++) { var m = e.charAt(y), f = e.charAt(y + 1); if (d) "'" == m ? (h += "" === c ? "'" : c, c = "", d = !1) : c += m; else switch (l = "", c += m) { case "ddd": h += (S = i, I[parseInt(S, 10)] || S), c = ""; break; case "dd": if ("d" === f) break; h += D(o, 2), c = ""; break; case "d": if ("d" === f) break; h += parseInt(o, 10), c = ""; break; case "D": h += o = 1 == o || 21 == o || 31 == o ? parseInt(o, 10) + "st" : 2 == o || 22 == o ? parseInt(o, 10) + "nd" : 3 == o || 23 == o ? parseInt(o, 10) + "rd" : parseInt(o, 10) + "th", c = ""; break; case "MMMM": h += (M = s, void 0, g = parseInt(M, 10) - 1, w[g] || M), c = ""; break; case "MMM": if ("M" === f) break; h += (k = s, void 0, p = parseInt(k, 10) - 1, v[p] || k), c = ""; break; case "MM": if ("M" === f) break; h += D(s, 2), c = ""; break; case "M": if ("M" === f) break; h += parseInt(s, 10), c = ""; break; case "y": case "yyy": if ("y" === f) break; h += c, c = ""; break; case "yy": if ("y" === f) break; h += String(n).slice(-2), c = ""; break; case "yyyy": h += n, c = ""; break; case "HH": h += D(u.hour, 2), c = ""; break; case "H": if ("H" === f) break; h += parseInt(u.hour, 10), c = ""; break; case "hh": h += D(t = 0 === parseInt(u.hour, 10) ? 12 : u.hour < 13 ? u.hour : u.hour - 12, 2), c = ""; break; case "h": if ("h" === f) break; t = 0 === parseInt(u.hour, 10) ? 12 : u.hour < 13 ? u.hour : u.hour - 12, h += parseInt(t, 10), c = ""; break; case "mm": h += D(u.minute, 2), c = ""; break; case "m": if ("m" === f) break; h += parseInt(u.minute, 10), c = ""; break; case "ss": h += D(u.second.substring(0, 2), 2), c = ""; break; case "s": if ("s" === f) break; h += parseInt(u.second, 10), c = ""; break; case "S": case "SS": if ("S" === f) break; h += c, c = ""; break; case "SSS": h += D(u.millis.substring(0, 3), 3), c = ""; break; case "a": h += 12 <= u.hour ? "PM" : "AM", c = ""; break; case "p": h += 12 <= u.hour ? "p.m." : "a.m.", c = ""; break; case "E": h += (b = i, O[parseInt(b, 10)] || b), c = ""; break; case "'": c = "", d = !0; break; default: h += m, c = "" } } return h += l } catch (e) { return console && console.log && console.log(e), a } var b, k, p, M, g, S }, prettyDate: function (e) { var a, r, t, n, s; if ("string" != typeof e && "number" != typeof e || (a = new Date(e)), "object" == typeof e && (a = new Date(e.toString())), r = ((new Date).getTime() - a.getTime()) / 1e3, t = Math.abs(r), n = Math.floor(t / 86400), !isNaN(n)) return s = r < 0 ? "from now" : "ago", t < 60 ? 0 <= r ? "just now" : "in a moment" : t < 120 ? "1 minute " + s : t < 3600 ? Math.floor(t / 60) + " minutes " + s : t < 7200 ? "1 hour " + s : t < 86400 ? Math.floor(t / 3600) + " hours " + s : 1 === n ? 0 <= r ? "Yesterday" : "Tomorrow" : n < 7 ? n + " days " + s : 7 === n ? "1 week " + s : n < 31 ? Math.ceil(n / 7) + " weeks " + s : "more than 5 weeks " + s }, toBrowserTimeZone: function (e, a) { return this.date(new Date(e), a || "MM/dd/yyyy HH:mm:ss") } } }() }(); String.prototype.startsWith = function (query) { return new RegExp('^' + query).test(this); }; String.prototype.endsWith = function (needle) { return needle === this.substr(0 - needle.length); }; String.prototype.replaceAll = function (find, replace) { return this.replace(new RegExp(find, 'g'), replace); }; String.prototype.capitaliseFirstLetter = function () { return this.charAt(0).toUpperCase() + this.slice(1); }; window.isAdapted = function () { return ($(this).width() < 640); } $(function () { //Method to check if select has an option in it //$('#ctl').hasOption('a_value'); $.fn.hasOption = function (val) { if ($(this).is('select')) { return $(this).find('option').filter(function () { return $(this).val() === val; }).length !== 0; } else return false; } //Method to add an option to a select //$('#ctl').addOption('Some text to show', 'a_value'); $.fn.addOption = function (txt, val) { if ($(this).is('select') && !$(this).hasOption(val)) { var o = new Option(txt, val); $(this).append(o); } }; //Method to clear all options from a select //$('#ctl').clearOptions(false); $.fn.clearOptions = function (inclFirst) { if ($(this).is('select')) { if (!inclFirst) $(this).find('option:not(:first)').remove(); else $(this).empty(); } }; //Method to add mulitple options to a select //$('#ctl').addOptions(["v1~^~t1", "v2~^~t2"], '~^~'); $.fn.addOptions = function (data, delimiter) { if ($(this).is('select')) { if (delimiter == undefined || delimiter == null) delimiter = '~^~'; var _this = $(this); $.each(data, function (index, value) { var itm = value.split(delimiter); _this.addOption(itm[1], itm[0]); }); } }; //Method to add mulitple options to a select //$('#ctl').addOptions([{"key": "k1", "value": "v1"}, {"key": "k2", "value": "v2"}]); $.fn.addOptionsKeyValue = function (data) { if ($(this).is('select')) { var _this = $(this); $.each(data, function (index, itm) { _this.addOption(itm.value, itm.key); }); } }; //Method to set the selected value on a custom select //$('#ctl').setVal('a_value'); $.fn.setVal = function (val) { if ($(this).is('select')) { $(this).val(val); $(this).next('span.customSelect').find('span.customSelectInner').text($(this).find('option:selected').text()); } }; $.fn.exists = function () { return $(this).length > 0; }; $.fn.scrollTo = function (additionalOffset, oncomplete) { if (additionalOffset == undefined) additionalOffset = 0; $('html,body').animate( { scrollTop: $(this).offset().top - additionalOffset }, 400, oncomplete ); }; $.fn.encHTML = function () { return $(this).html().replace(/&/g, '&').replace(//g, '>'); }; $.fn.decHTML = function () { return $(this).html().replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); }; $.fn.focusEnd = function () { this.focus(); var initVal = $(this).val(); this.val('').val(initVal); return this; } $.fn.hasAttr = function (name) { return this.attr(name) !== undefined; }; $.fn.revertState = function () { var _this = this; setTimeout(function () { _this.each(function () { if ($(_this).hasAttr('data-orig-msg')) { $(_this).prop('disabled', false); if ($(this).is('button') || $(this).is('a')) { $(this).html($(this).attr('data-orig-msg')); } else { $(this).val($(this).attr('data-orig-msg')); } } }); }, 100); }; //Converts querystring to object $.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('&')); }); function isDate(value) { switch (typeof value) { case 'number': return true; case 'string': return !isNaN(Date.parse(value)); case 'object': if (value instanceof Date) { return !isNaN(value.getTime()); } default: return false; } } //Default parameters to make and AJAX call var ajaxParams = { url: 'https://devportal.fuchslubricants.com/api/ajax.asmx/', type: 'post', contentType: 'application/json; charset=utf-8', data: JSON.stringify({}), dataType: 'json', sync: true }; var ajaxParamsAsync = { url: 'https://devportal.fuchslubricants.com/api/ajax-async.ashx?mthd=', type: 'post', contentType: 'application/json; charset=utf-8', data: JSON.stringify({}), dataType: 'json', sync: false, async: true }; function getAjax(method) { var _ajaxParams = JSON.parse(JSON.stringify(ajaxParams)); _ajaxParams.url += method; return _ajaxParams; } function formatJSONResponse(data) { if (data.d.hasOwnProperty('Result')) { data.d = data.d.Result; } data = jQuery.parseJSON(data.d); info = jQuery.parseJSON(data.info); data.info = info; return data; } function configureAJAXParams(mthd, params) { var _ajaxParams = JSON.parse(JSON.stringify(ajaxParams)); _ajaxParams.url += mthd; _ajaxParams.data = JSON.stringify(params); return _ajaxParams; } function configureAJAXParamsAsync(mthd, params) { var _ajaxParamsAsync = JSON.parse(JSON.stringify(ajaxParamsAsync)); _ajaxParamsAsync.url += mthd; _ajaxParamsAsync.data = JSON.stringify(params); return _ajaxParamsAsync; } function getWebControl(ctlName, prms, callback, failCallback) { if (!Array.isArray(prms)) { prms = [prms]; } var _ajaxParams = configureAJAXParams('GetWebControl', { controlName: ctlName, paramss: prms }); $.ajax(_ajaxParams) .done(function (data, textStatus) { data = formatJSONResponse(data); if (data.error == 'none') { if (callback) { callback(data.info.html); } } else { if (failCallback) { failCallback(data.error); } else { showError(data.error); } } }) .fail(function (jqXHR, textStatus, errorThrown) { if (failCallback) { failCallback(errorThrown); } else { showError(errorThrown); } }); } var modalPopUp = (function ($) { var cls = function () { var dfd = $.Deferred(); this.title = arguments[0].title; this.text = arguments[0].text; this.allowClose = arguments[0].allowClose; if (this.allowClose == undefined || this.allowClose == null) { this.allowClose = true; } this.prependTo = arguments[0].prependTo; if (this.prependTo == undefined || this.prependTo == null) { this.prependTo = 'body'; } this.hidden = arguments[0].hidden; if (this.hidden == undefined || this.hidden == null) { this.hidden = false; } var t = new Date().getTime(); this.id = 'modal-popup' + t; var html = '\n'; if (this.prependTo != 'body') { html += '
\n'; $(this.prependTo).prepend(html); } else { $(html).insertBefore('#main-overlay'); } if (this.allowClose) { $('#popup' + t).click(function () { $('#modal-popup' + t).remove(); dfd.resolve({ modal: null }); }); } this.close = dfd.done; return this; } return cls; })(jQuery); var modalConfirm = (function ($) { var cls = function () { var dfd = $.Deferred(); this.title = arguments[0].title; this.text = arguments[0].text; this.prependTo = arguments[0].prependTo; if (this.prependTo == undefined || this.prependTo == null) { this.prependTo = 'body'; } var t = new Date().getTime(); var html = '\n'; if (this.prependTo != 'body') { html += '
\n'; $(this.prependTo).prepend(html); } else { $(html).insertBefore('#main-overlay'); } $('#confirm-no' + t).click(function () { mHideConfirm(t); dfd.reject({ modal: null }); }); $('#confirm-yes' + t).click(function () { mHideConfirm(t); dfd.resolve({ modal: null }); }); this.yes = dfd.done; this.no = dfd.fail; return this; } return cls; })(jQuery); function mHideConfirm(t) { $('#modal-confirm' + t).remove() } var modalOptions = (function ($) { var cls = function () { var dfd = $.Deferred(); this.title = arguments[0].title; this.text = arguments[0].text; this.opt1 = arguments[0].opt1; this.opt2 = arguments[0].opt2; this.opt3 = arguments[0].opt3; if (this.opt3 == undefined || this.opt3 == null) { this.opt3 = 'Cancel'; } this.primarybutton = arguments[0].primarybutton; if (this.primarybutton == undefined || this.primarybutton == null) { this.primarybutton = 'null'; } this.oncancel = arguments[0].oncancel; var _this = this; var t = new Date().getTime(); var html = '\n'; $(html).insertBefore('#main-overlay'); $('#option-opt1' + t).click(function () { mHideOption(t); dfd.resolve({ modal: null }); }); $('#option-opt2' + t).click(function () { mHideOption(t); dfd.reject({ modal: null }); }); $('#option-opt3' + t).click(function () { mHideOption(t); if (_this.oncancel != undefined && _this.oncancel != null) { _this.oncancel(); } }); this.action1 = dfd.done; this.action2 = dfd.fail; return this; } return cls; })(jQuery); function mHideOption(t) { $('#modal-option' + t).remove() } var modalAlert = (function ($) { var cls = function () { var dfd = $.Deferred(); this.title = arguments[0].title; this.text = arguments[0].text; this.prependTo = arguments[0].prependTo; if (this.prependTo == undefined || this.prependTo == null) { this.prependTo = 'body'; } var _this = this; var t = new Date().getTime(); var html = '\n'; if (this.prependTo != 'body') { html += '
\n'; $(this.prependTo).prepend(html); } else { $(html).insertBefore('#main-overlay'); } $('#alert-ok' + t).click(function () { mHideAlert(t); dfd.resolve({ modal: null }); }); this.ok = dfd.done; return this; } return cls; })(jQuery); function mHideAlert(t) { $('#modal-alert' + t).remove() } var modalInput = (function ($) { var cls = function () { var dfd = $.Deferred(); this.title = arguments[0].title; this.text = arguments[0].text; this.label = arguments[0].label; this.prependTo = arguments[0].prependTo; if (this.prependTo == undefined || this.prependTo == null) { this.prependTo = 'body'; } this.hint = arguments[0].hint; if (this.hint == undefined || this.hint == null) { this.hint = ''; } this.default = arguments[0].default; if (this.default == undefined || this.default == null) { this.default = ''; } this.okbutton = arguments[0].okbutton; if (this.okbutton == undefined || this.okbutton == null) { this.okbutton = 'OK'; } this.focus = arguments[0].focus; if (this.focus == undefined || this.focus == null) { this.focus = true; } var t = new Date().getTime(); var html = '\n'; if (this.prependTo != 'body') { html += '
\n'; $(this.prependTo).prepend(html); } else { $(html).insertBefore('#main-overlay'); } if (this.focus) { $('#input-value' + t).focus(); } $('#input-cancel' + t).click(function () { mHideInput(t); dfd.reject({ modal: null }); }); $('#input-ok' + t).click(function () { var value = $('#input-value' + t).val(); mHideInput(t); dfd.resolve({ modal: null, value: value }); }); this.ok = dfd.done; this.cancel = dfd.fail; return this; } return cls; })(jQuery); function mHideInput(t) { $('#modal-input' + t).remove(); } function showAlert(title, msg, callback, prependTo) { new modalAlert({ title: title, text: msg, prependTo: prependTo }) .ok(function () { if (callback) callback(); }); } function showError(msg, callback, prependTo) { showAlert('Error', msg, callback, prependTo); } function showConfirm(title, msg, callbackYes, callbackNo, prependTo) { new modalConfirm({ title: title, text: msg, prependTo: prependTo }) .yes(function () { if (callbackYes) callbackYes(); }) .no(function () { if (callbackNo) callbackNo(); }); } var loaderTimeouts = []; function showLoader(msg, prependTo, delayOf) { if (delayOf == undefined) { delayOf = 500; } var loading = new modalPopUp({ title: 'Loading...', text: msg, allowClose: false, prependTo: prependTo, hidden: true }); var to = setTimeout(function () { $('#' + loading.id).addClass('show'); }, delayOf); loaderTimeouts.push('#' + loading.id + ':' + to); return '#' + loading.id; } function hideLoader(id) { for (var i = loaderTimeouts.length - 1; i >= 0; i--) { var itm = loaderTimeouts[i]; if (itm.startsWith(id)) { clearTimeout(itm.split(':')[1]); loaderTimeouts.splice(i, 1); break; } }; if ($(id).exists()) { $(id).remove(); } } function htmlDecode(encodedString) { return $('
').html(encodedString).text(); } function htmlEncode(decodedString) { return $('
').text(decodedString).html(); } function scrollTo(ele, additionalOffset) { if (additionalOffset == undefined) additionalOffset = 0; $('html,body').animate({ scrollTop: $(ele).offset().top - additionalOffset }); } function validateForm() { $('#fMaster').validate(); } function formIsValid(ele) { if (!ele) return $('#fMaster').valid(); else { var bRet = true; $(ele).find('input, select, textarea').each(function () { if ($(this).attr('type') != 'hidden' && $(this).attr('type') != 'button' && $(this).attr('type') != 'button') { if (!$(this).valid()) { highlightValidator(this); bRet = false; } else { unHighlightValidator(this); //$(this).removeClass('error'); //$(this).next('span.error-msg').hide(300); } } }); return bRet; } } function highlightValidator(element) { $(element).addClass('error'); } function unHighlightValidator(element) { var errElement = $(element).next('span.error-msg'); if (errElement.length < 1) { errElement = $(element).parent().parent().find('span.error-msg') } if (errElement.length > 0) { $(errElement).hide(300, function () { $(element).removeClass('error'); }); } else { $(element).removeClass('error'); } } function errorPlacementValidator(error, element) { var errElement = $(element).next('span.error-msg'); if (errElement.length < 1) { errElement = $(element).parent().parent().find('span.error-msg') } if (errElement.length > 0) { $(errElement).show(300); } return true; } function loadOrderDetailControl(orderID, htmlControlID, modalID) { var loadingOrderDetail = showLoader('Please wait while we load the order details'); var params = ['OrderID:' + orderID]; getWebControl('content/Shared/OrderDetail.ascx', params, function (html) { $(htmlControlID).html(html); hideLoader(loadingOrderDetail); $(modalID).addClass('show'); }, function (error) { hideLoader(loadingOrderDetail); showError(error); } ); } var filterTables = []; function filterLists(searchTerm, dataTags, baseElementSelector) { if (dataTags.length > 0) { var selector = ''; if (baseElementSelector !== undefined && baseElementSelector !== null) { selector = baseElementSelector; } var tableRef = $(selector + '[' + dataTags[0] + ']').closest('table'); if ($(tableRef).closest('div.table-container').next().hasClass('pagination-controls')) { //Paginated table var tableBody = $(tableRef).find('tbody'); if (!$(tableRef).hasAttr('id')) { var tableID = `custom-id-${new Date().getTime().toString()}`; $(tableRef).attr('id', tableID); } //Get the original copy of the children if we don't have one if ($.grep(filterTables, function (itm, idx) { return itm.tableid === $(tableRef).attr('id'); }).length < 1) { filterTables.push({ tableid: $(tableRef).attr('id'), tableref: ($(tableRef)[0]), children: $(tableRef).find('tbody').children() }); } //Use the original list to filter on var filterTable = $.grep(filterTables, function (itm, idx) { return itm.tableid === $(tableRef).attr('id'); })[0]; var foundRows = $.grep(filterTable.children, function (row, idx) { var foundIt = false; for (var i = 0; i < dataTags.length; i++) { if ($(row).attr(dataTags[i].toLowerCase()).includes(searchTerm.toLowerCase())) { foundIt = true; break; } } return foundIt; }); //Clear the table and repopulate $(tableBody).children().remove(); $.each(foundRows, function (idx, row) { $(tableBody).append(row); }); //Reinitialise the paginator var paginator = Object.assign({}, paginatedTables[0]); paginator.reinit(); } else { //Unpaginated table if (searchTerm === '') { $(selector + '[' + dataTags[0] + ']').show(); } else { $(selector + '[' + dataTags[0] + ']').hide(); var delimiter = ''; var subSelector = selector; selector = ''; for (var i = 0; i < dataTags.length; i++) { selector += delimiter + subSelector + '[' + dataTags[i] + '*="' + searchTerm + '"]'; delimiter = ','; } $(selector).show(); } } } } function readFromCookie(cookieName, key) { var value = null; var cookies = document.cookie.split(';') for (var i = 0; i < cookies.length; i++) { if (cookies[i].trim().startsWith(cookieName)) { var values = cookies[i].trim().replace(cookieName + '=', '').split('='); for (var j = 0; j < values.length; j += 2) { if (values[j] == key) { value = values[j + 1]; break; } } } } return value; } function writeToCookie(cookieName, key, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = cookieName + "=" + (key + '=' + value || "") + expires + "; path=/"; } function applyError(ele) { $(ele).addClass('error'); $(ele).next('span.error-msg').show(300); } function clearError(ele) { $(ele).removeClass('error'); $(ele).next('span.error-msg').hide(); } function doOrderedTables() { Array.prototype.slice.call(document.getElementsByClassName('js_sortable-table')).forEach(function (table) { if (!table.hasAttribute('data-sort-applied')) { table.setAttribute('data-sort-applied', '1'); Array.prototype.slice.call(table.querySelectorAll('[data-sort-name]')).forEach(function (anc) { var ascArw = '5'; var descArw = '6'; if (anc.hasAttribute('data-sort-default')) { anc.setAttribute('data-sort-order', 'desc'); anc.innerHTML += ' ' + ascArw; } else { anc.setAttribute('data-sort-order', 'asc'); anc.innerHTML += ' ' + ascArw + descArw; } anc.addEventListener('click', function (e) { e.preventDefault(); var usesPagination = false; var pgnTable = null; if (table.classList.contains('js_paginated-table')) { usesPagination = true; var pgnIdx = paginatedTables.findIndex(function (e) { return e.tableRef.getAttribute('id') === table.getAttribute('id'); }); if (pgnIdx >= 0) { pgnTable = paginatedTables[pgnIdx]; paginatedTables[pgnIdx].destroy(); } } var sortName = this.getAttribute('data-sort-name'); var sortOrder = this.getAttribute('data-sort-order') var attr = 'data-sort-' + sortName; var tbody = table.querySelector('tbody'); var rows = Array.prototype.slice.call(tbody.rows); rows .sort(function (r1, r2) { var r1Attr = r1.getAttribute(attr); var r2Attr = r2.getAttribute(attr); if (!isNaN(r1Attr)) { r1Attr = parseFloat(r1Attr); r2Attr = parseFloat(r2Attr); } if (r1Attr < r2Attr) { return (sortOrder === 'asc' ? -1 : 1); } if (r1Attr > r2Attr) { return (sortOrder === 'asc' ? 1 : -1); } return 0; }) .forEach(function (tr) { tbody.appendChild(tr); }); Array.prototype.slice.call(tbody.parentNode.querySelectorAll('[data-sort-order]')) .forEach(function (_anc) { Array.prototype.slice.call(_anc.querySelectorAll('.js_sortable-order')).forEach(function (orderer) { _anc.removeChild(orderer); }); if (_anc.getAttribute('data-sort-name') === sortName) { if (sortOrder === 'asc') { _anc.setAttribute('data-sort-order', 'desc'); _anc.innerHTML += ' ' + ascArw; } else { _anc.setAttribute('data-sort-order', 'asc'); _anc.innerHTML += ' ' + descArw; } } else { _anc.setAttribute('data-sort-order', 'asc'); _anc.innerHTML += ' ' + ascArw + descArw; } }); if (usesPagination) { new Paginator(pgnTable.tableRef) .init(); } }); }); } }); } function edgeOnlyChecker() { var ua = window.navigator.userAgent; var isIE = /MSIE|Trident/.test(ua); if (isIE) { showAlert('Browser Compatability', 'Unfortunately, Internet Explorer is not supported in this application.

When you click OK, this page will opended in Edge for you.', function () { window.open("microsoft-edge:" + window.location.href); }); } } function setTableCheckboxToggler(headerCheckboxSelector, itemCheckboxSelector) { $(headerCheckboxSelector).on('click', function () { var loader = showLoader('Please wait a moment while we toggle the selections. It\'s quite a large list'); var checked = $(headerCheckboxSelector).prop('checked'); $(headerCheckboxSelector).closest('table').find('input[type=checkbox][id^="' + itemCheckboxSelector + '"]').each(function (idx, itm) { if ( ($(itm).prop('checked') && !checked) || (!$(itm).prop('checked') && checked) ) { $(itm).trigger('click'); } }); hideLoader(loader); }); } function isLocalStorageAvailable() { var test = 'test'; try { localStorage.setItem(test, test); localStorage.removeItem(test); return true; } catch (e) { return false; } } function Buffer(callback, frequency) { this.frequency = (frequency == undefined || frequency == null ? 500 : frequency); this.tasks = []; this.taskIsRunning = false; this.notificationIncludeError = false; this.notificationErrorMessage = ''; this.itemKey = window.location.href.replace('#ROOT_PATH#', '').split('.aspx')[0].replace('/', '_'); //this.itemKey = window.location.href.substring(window.location.href.indexOf('content/')).split('.aspx')[0].replace('/', '_'); // enable this for local testing this.debug = false; this.requeueOnFail = false; //if a task fails, this will requeue it so it definitely goes in. this.idempotentRequests = false; //this will not handle idempotency itself, but will only remove the task once confirmation is received. this.needsLocalStorage = false; this.consecutiveErrors = 0; this.stopAfterErrors = 5; //stops the process after X amount this.restartAfter = 30000; //starts again after X amount. this.resolvedCallback = null; //Will be executed if the task was a success this.rejectedCallback = null; //Will be executed if the task was a failure var runner = null; this.append = function (task) { var data = null; if (isLocalStorageAvailable()) { if (localStorage.getItem(this.itemKey)) data = JSON.parse(localStorage.getItem(this.itemKey)); else data = JSON.parse('[]'); data.push(task); localStorage.setItem(this.itemKey, JSON.stringify(data)); if (this.debug) { console.log('[Buffer] data: ', data); } } else { if (!this.needsLocalStorage) { this.tasks.push(task); } else { console.error('[Buffer]', 'Error adding a new task. NeedsLocalStorage is set to true but local storage is not available', task); showError('Local Storage is not available on this device and is required by this site to function properly. Please contact your IT administrator. Any work will be lost.'); } } if (this.debug) { console.log('[Buffer] Task appended', task, this.tasks); } }; this.start = function () { if (this.debug) { console.log('[Buffer] Starting...'); } var _this = this; _this.consecutiveErrors = 0; runner = setInterval(function () { if (_this.debug) { console.log('[Buffer] Task is', _this.state()); } var data = null; if (isLocalStorageAvailable()) { data = JSON.parse(localStorage.getItem(_this.itemKey)); } if (!_this.taskIsRunning) { _this.taskIsRunning = true; if (_this.tasks.length > 0 || (data != null && data.length > 0)) { var task = null; if (data != null) { var data = JSON.parse(localStorage.getItem(_this.itemKey)); task = _this.idempotentRequests ? data[0] : data.shift(); localStorage.setItem(_this.itemKey, JSON.stringify(data)); if (_this.debug) { console.log('[Buffer] Data: ', data); } if (_this.debug) { console.log('[Buffer] Task: ', task); } } else { if (!_this.needsLocalStorage) task = _this.idempotentRequests ? _this.tasks[0] : _this.tasks.shift(); else { console.error('[Buffer]', 'Error when processing task. NeedsLocalStorage is set to true but local storage is not available', task); showError('Local Storage is not available on this device and is required by this site to function properly. Please contact your IT administrator. Any work will be lost.') } } if (_this.debug) { console.log('[Buffer] Calling callback', task); } callback(task) .then(function (response) { if (_this.idempotentRequests) { if (isLocalStorageAvailable()) { var data = JSON.parse(localStorage.getItem(_this.itemKey)); data.shift(); localStorage.setItem(_this.itemKey, JSON.stringify(data)); } else { _this.tasks.shift(); } } this.consecutiveErrors = 0; if (_this.debug) { console.log('[Buffer] Callback complete', response); } if (_this.resolvedCallback) { if (_this.debug) { console.log('[Buffer] Calling resolvedCallback'); } _this.resolvedCallback(response); } _this.taskIsRunning = false; }) .catch(function (err) { console.error('[Buffer]', err, task); _this.consecutiveErrors += 1; if (_this.consecutiveErrors >= _this.stopAfterErrors) { _this.stop(); setTimeout(function () { _this.start(); }, _this.restartAfter) } if (_this.requeueOnFail && !_this.idempotentRequests) _this.append(task); if (_this.notificationErrorMessage !== '') { addNotification(_this.notificationErrorMessage + (_this.notificationIncludeError ? '
' + err : '')); } if (_this.rejectedCallback) { if (_this.debug) { console.log('[Buffer] Calling rejectedCallback'); } _this.rejectedCallback(err); } _this.taskIsRunning = false; }); } else { _this.taskIsRunning = false; } } }, this.frequency); if (this.debug) { console.log('[Buffer] Started'); } }; this.stop = function (clearBuffer) { clearBuffer = (clearBuffer == undefined || clearBuffer == null ? false : clearBuffer); if (runner !== null) { clearInterval(runner); runner = null; if (this.debug) { console.log('[Buffer] Stopped'); } } if (clearBuffer) { this.tasks = []; if (isLocalStorageAvailable()) { localStorage.setItem(this.itemKey, JSON.stringify(this.tasks)); } if (this.debug) { console.log('[Buffer] Cleared'); } } }; this.state = function () { return (runner === null ? 'stopped' : (this.taskIsRunning ? 'running' : 'waiting')); }; this.numTasks = function () { if (isLocalStorageAvailable()) { var data = localStorage.getItem(this.itemKey); return (data === null ? 0 : JSON.parse(data).length); } else { return this.tasks.length; } }; } function downloadFile(fetchURL, fileName, errTitle, errMsg, useLoader, loadMsg, callback) { var downloading = (useLoader ? showLoader(loadMsg) : null); fetch(fetchURL) .then(resp => resp.blob()) .then(blob => { const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.style.display = 'none'; a.href = url; a.download = fileName; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); a.remove(); if (downloading !== null) { hideLoader(downloading); } if (callback) { callback(fetchURL, fileName); } }) .catch(() => { hideLoader(downloading); showAlert(errTitle, errMsg); }); } function uploadFiles(file, name, id, path, callback) { var fileReader = new FileReader(); fileReader.onload = function () { var loadingItem = $('#loadingImage-' + id).clone(); $('#file-buttons-' + id).append($(loadingItem)); $(loadingItem).show(300); var readerData = fileReader.result.split(','); if (readerData.length > 0) readerData = readerData[1]; else readerData = ''; var _ajaxParams = getAjax('UploadFile'); _ajaxParams.data = JSON.stringify({ fileStorePath: path, fileName: name, data: readerData, time: Date.now().toString() }); $.ajax(_ajaxParams) .done(function (data, textStatus, jqXHR) { var obj = JSON.parse(data.d); $('#file-buttons-' + id).append(JSON.parse(obj.info).control); var file = JSON.parse(obj.info).file; var folder = JSON.parse(obj.info).folder; if (callback) window[callback](folder, file); }) .fail(function (jqXHR, textStatus, errorThrown) { showError(errorThrown); }) .always(function () { $(loadingItem).remove(); }) } fileReader.readAsDataURL(file); } function deleteFile(button, callbackYes, callbackNo) { var fileName = $(button).attr('data-filename'); var filePath = $(button).attr('data-filePath'); var modal = $(button).closest('.modal'); showConfirm('Delete File', 'Are you sure you want to delete this file?', function () { var _ajaxParams = getAjax('DeleteFile'); _ajaxParams.data = JSON.stringify({ fileStorePath: filePath, fileName: fileName, time: Date.now().toString() }); $.ajax(_ajaxParams) .done(function (data, textStatus, jqXHR) { $(button).parent().hide(300); setTimeout(function () { $(button).parent().remove(); if (callbackYes) { window[callbackYes](button, filePath, fileName); } }, 300); }) .fail(function (jqXHR, textStatus, errorThrown) { alert(errorThrown); }); }, function () { if (callbackNo) { window[callbackNo](button, filePath, fileName); } }, modal.length == 0 ? 'body' : modal); }; var paginatedTables = []; function Paginator(tableRef) { this.tableRef = tableRef; this.numRows = 0; this.numRowsRounded = 0; this.startOnPage = 1; this.currentPage = 0; this.showRowsPerPage = true; this.rowsPerPage = 10; this.numPages = 0; this.rootCssClass = ''; this.rowsPerPageCssClass = ''; this.pageListCssClass = ''; this.scrollToTop = true; this.clearTableRowsOnChangeEvents = true; this.rowsPerPageChanged = null; this.pageChanged = null; this.init = function () { var _this = this; if (this.numRows === 0) { this.numRows = $(tableRef).find('tbody').children().length; } this.currentPage = this.startOnPage; this.calculateNumPages(); this.filterTable(false); var paginationDiv = $('
', { class: `pagination-controls${(this.rootCssClass !== '' ? ` ${this.rootCssClass}` : '')}` }); if (this.showRowsPerPage) { var select = $('