"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } var utils = function () { var module = {}; module.isMobile = function () { return $(window).width() < 800; }; module.isIe = function () { if (window.document.documentMode) { return true; } return false; }; var env; if (window.location.host.indexOf("localtest") == 0) { env = "dev"; } else if (window.location.host.indexOf("localhost") == 0) { env = "chris"; } else if (window.location.host.includes("qa.providertraining")) { env = "qa"; } else if (window.location.host == "app.takecarenm.org") { env = "prod"; } module.env = function () { return env; }; module.dohConsentForm = "b7086dc0-1ce7-4b9e-b1d7-7bb5f581ba6f"; module.serviceUrl = function () { return { "dev": "http://localtest.me:3000", "chris": "https://qa.providertraining.doh.rtsclients.com/api", "qa": "/api", "prod": "/api" }[env]; }; module.domain = function () { return { "dev": "qa.providertraining.doh.rtsclients.com", "qa": "qa.providertraining.doh.rtsclients.com", "chris": "qa.providertraining.doh.rtsclients.com", "prod": "prod.providertraining.doh.rtsclients.com" }[env]; }; module.scrollToInvalid = function (selector) { if ($(".invalid").length) { if (selector == "no-container") { $([document.documentElement, document.body]).animate({ scrollTop: $(".invalid").eq(0).offset().top - 20 }); } else { selector = selector || ".main-content"; var container = $(selector); container.animate({ scrollTop: $(".invalid").eq(0).offset().top - container.offset().top + container.scrollTop() - 40 }); } } }; module.basicValidate = function (selector, scrollContainer) { var container = $(selector); var valid = true; container.find("input:required").each(function (i, e) { var input = $(e); var type = input.attr("type"); var val = input.val(); if (type == "number" || type == "text" || type == "tel" || type == "email" || type == "password" || type == "date") { if (val.length == 0) { input.addClass("invalid").attr("title", "Please enter a value."); valid = false; } else { input.removeClass("invalid").attr("title", null); } if (!input.hasClass("invalid")) { if (type == "tel") { if (val.replace(/\D/g, '').length != 10) { input.addClass("invalid").attr("title", "Please enter a valid phone number."); valid = false; } else { input.removeClass("invalid").attr("title", null); } } if (type == "number" && input.attr("min")) { if (val < input.attr("min")) { input.addClass("invalid").attr("title", "Number must be greater than " + input.attr("min")); valid = false; } else { input.removeClass("invalid").attr("title", null); } } if (type == "email" && !$(e).hasClass("login")) { var re = /\S+@\S+\.\S+/; if (!re.test(val)) { input.addClass("invalid").attr("title", "Please enter a valid email address."); valid = false; } else { input.removeClass("invalid").attr("title", null); } } if (type == "password" && !$(e).hasClass("login")) { if (val.length < 6) { input.addClass("invalid").attr("title", "Password must be at least six characters."); valid = false; } else { input.removeClass("invalid").attr("title", null); } } if (type == "text" && $(e).hasClass("zip")) { if (val.replace(/\D/g, '').length < 5) { input.addClass("invalid").attr("title", "Please enter a valid zip code."); valid = false; } else { input.removeClass("invalid").attr("title", null); } } if (type == "text" && $(e).hasClass("ssn")) { if (val.replace(/\D/g, '').length != 9) { input.addClass("invalid").attr("title", "Please enter a valid SSN."); valid = false; } else { input.removeClass("invalid").attr("title", null); } } if (type == "text" && $(e).hasClass("alpha-only")) { if (val.search(/[^a-z\s]/i) !== -1) { input.addClass("invalid").attr("title", "Please enter only alphabetical characters."); valid = false; } else { input.removeClass("invalid").attr("title", null); } } if (type == "text" && $(e).hasClass("k-input") && $(e).data('role') == "datepicker") { if ($(e).hasClass("new-validate")) { var date = $(e).data("kendoDatePicker").value(); if (!date) { $(e).parent().addClass('invalid').attr("title", "Please enter a valid date in MM/DD/YYYY format or click the calendar icon to select a date."); valid = false; } else { $(e).parent().removeClass('invalid').attr("title", null); } } else { try { var parts = val.split("/"); var dateValid = true; if (parts.length != 3) { dateValid = false; } var nums = parts.join(""); if (nums.replace(/\D/g, '').length < nums.length) { dateValid = false; } var part1 = parseInt(parts[0].replace(/\D/g, '')); if (part1 > 12 || part1 < 1) { dateValid = false; } var part2 = parseInt(parts[1].replace(/\D/g, '')); if (part2 > 31 || part2 < 1) { dateValid = false; } var part3 = parseInt(parts[2].replace(/\D/g, '')); if (part3 > 2022 || part3 < 1900) { dateValid = false; } if (dateValid) { $(e).parent().removeClass('invalid').attr("title", null); } else { $(e).parent().addClass('invalid').attr("title", "Please enter a valid date in MM/DD/YYYY format"); valid = false; } } catch (ex) { $(e).parent().addClass('invalid').attr("title", "Please enter a valid date in MM/DD/YYYY format"); valid = false; } } } if (type == "text" && $(e).hasClass("k-input") && $(e).data('role') == "datetimepicker") { try { if ($(e).data("kendoDateTimePicker").value() != null) { $(e).parent().removeClass('invalid').attr("title", null); } else { $(e).parent().addClass('invalid').attr("title", "Please use the datepicker to select a date"); valid = false; } } catch (ex) { $(e).parent().addClass('invalid').attr("title", "Please use the datepicker to select a date"); valid = false; } } if (type == "text" && $(e).hasClass("k-input") && $(e).data('role') == "timepicker") { try { if ($(e).data("kendoTimePicker").value() != null) { $(e).parent().removeClass('invalid').attr("title", null); } else { $(e).parent().addClass('invalid').attr("title", "Please click the clock icon to select a time."); valid = false; } } catch (ex) { $(e).parent().addClass('invalid').attr("title", "Please click the clock icon to select a time."); valid = false; } } } } if (type == "radio") { var name = input.attr("name"); if ($("input[name=" + name + "]:checked").length == 0) { input.parent().addClass("invalid").attr("title", "Please select an option."); valid = false; } else { input.parent().removeClass("invalid").attr("title", null); } } if (type == "checkbox") { var name = input.attr("name"); if ($("input[name=" + name + "]:checked").length == 0) { input.parent().addClass("invalid").attr("title", "Please select an option."); valid = false; } else { input.parent().removeClass("invalid").attr("title", null); } } if (type == "file") { var files = input[0].files; if (!files.length) { input.addClass("invalid").attr("title", "Please add a file."); valid = false; } else { input.removeClass("invalid").attr("title", null); } } }); container.find("input:not(.invalid)").each(function (i, e) { var element = $(e); if (element.is(":required")) { var confirm = $("#confirm-" + element.attr("id") + ":not(.invalid)"); if (confirm.length && confirm.is(":required")) { if (element.val() != confirm.val()) { element.addClass("invalid").attr("title", "Values do not match."); confirm.addClass("invalid").attr("title", "Values do not match."); valid = false; } else { element.removeClass("invalid").attr("title", null); confirm.removeClass("invalid").attr("title", null); } } } }); container.find("select:required").each(function (i, e) { var input = $(e); var val = input.val(); if (val == null || val.length == 0) { if ($(this).data("select2")) { $(this).data("select2")["$container"].addClass('invalid').attr("title", "Please select an option."); } else if ($(this).data("kendoMultiSelect")) { $(this).closest(".k-multiselect").addClass('invalid').attr("title", "Please select an option."); } else if ($(this).data("kendoDropDownList")) { $(this).closest(".k-dropdown").addClass('invalid').attr("title", "Please select an option."); } else { input.addClass("invalid").attr("title", "Please select an option."); } valid = false; } else { if ($(this).data("select2")) { $(this).data("select2")["$container"].removeClass('invalid').attr("title", null); } else if ($(this).data("kendoDropDownList")) { $(this).closest(".k-dropdown").removeClass("invalid").attr("title", null); } else { input.removeClass("invalid").attr("title", null); } } }); container.find("textarea:required").each(function (i, e) { var input = $(e); var val = input.val(); if (val.length == 0) { input.addClass("invalid").attr("title", "Please fill out the textarea."); valid = false; } else { input.removeClass("invalid").attr("title", null); } }); container.find(".signature.required").each(function (i, e) { if (!$(e).jSignature("getData", "native").length) { valid = false; $(e).addClass("invalid").attr("title", "Please sign here."); } else { $(e).removeClass("invalid").attr("title", null); } }); if (container.data("kendoTooltip")) { container.data("kendoTooltip").destroy(); } container.kendoTooltip({ filter: ".invalid" }); module.scrollToInvalid(scrollContainer || container); module.uuid = function () { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : r & 0x3 | 0x8; return v.toString(16); }); }; return valid; }; Date.prototype.toDateInputValue = function () { var local = new Date(this); local.setMinutes(this.getMinutes() - this.getTimezoneOffset()); return local.toJSON().slice(0, 10); }; module.dateStringToInput = function (str) { try { var parts = str.split("/"); return parts[2] + "-" + parts[0].padStart(2, "0") + "-" + parts[1].padStart(2, "0"); } catch (e) { return null; } }; module.downloadCsv = function (name, data) { var csv = Papa.unparse(data); var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); if (navigator.msSaveBlob) { // IE 10+ navigator.msSaveBlob(blob, name); } else { var link = document.createElement("a"); if (link.download !== undefined) { // feature detection // Browsers that support HTML5 download attribute var url = URL.createObjectURL(blob); link.setAttribute("href", url); link.setAttribute("download", name); link.style.visibility = 'hidden'; document.body.appendChild(link); link.click(); document.body.removeChild(link); } } }; module.dateInputToString = function (str) { var parts = str.split("-"); var result = parts[1].padStart(2, "0") + "/" + parts[2].padStart(2, "0") + "/" + parts[0]; if (result.startsWith("0")) { result = result.substring(1); } return result; }; module.convert24HourTime = function (time) { var hours = parseInt(time.split(":")[0]); var minutes = time.split(":")[1]; var suffix = hours >= 12 ? "PM" : "AM"; hours = (hours + 11) % 12 + 1 + ":" + minutes + " " + suffix; return hours; }; module.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, ' ')); }; Number.prototype.withCommas = function () { try { var numString = this.toString(); if (numString.includes(".")) { return numString.split(".")[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "." + numString.split(".")[1]; } return this.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } catch (e) { return ""; } }; module.phoneFormat = function (input) { if (!input) { return ""; } input = input.replace(/\D/g, ''); input = input.substring(0, 10); var size = input.length; if (size == 0) { input = input; } else if (size < 4) { input = '(' + input; } else if (size < 7) { input = '(' + input.substring(0, 3) + ') ' + input.substring(3, 6); } else { input = '(' + input.substring(0, 3) + ') ' + input.substring(3, 6) + ' - ' + input.substring(6, 10); } return input; }; module.notify = function (message, className) { $("#notification").getKendoNotification().show(message, className || "success"); }; function setPrefilter() { $.ajaxPrefilter(function (options, originalOptions, jqXHR) { if (!(options.data instanceof File) && !(options.data instanceof FormData)) { if (typeof session != "undefined" && session.getAuthTokenGUID()) { originalOptions.data = originalOptions.data || {}; originalOptions.data.authTokenGUID = session.getAuthTokenGUID(); } options.data = $.param(originalOptions.data); } }); } module.loading = function () { var module = {}; function set() { $('body').append('
'); $('head').append('