const F5_Common = (function () { return function () { var me = this; //need to send in the actual view grids you want this to affect as there can be MANY diffent types of view grids on the form, i.e. every lookup modal has a .view-grid on it me.initialiseDocumentSubgrids = function(viewGrid){ if (!viewGrid.parent().parent().has(".documentDisclaimer").length >0){ viewGrid.parent().parent().prepend("
Opening any of the documents listed here will download them to your device. As some information may be confidential please ensure you delete the files from your Download folder and Trash/Bin once they are no longer needed.

"); } var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; var myObserver = new MutationObserver (F5Common.docRowAddedHandler); var obsConfig = { childList: true, characterData: true, attributes: true, subtree: true }; for (var j = 0; j < viewGrid.length; j++){ myObserver.observe(viewGrid[j],obsConfig); } } me.docRowAddedHandler = function(mutationRecords){ mutationRecords.forEach ( function (mutation) { var mt = mutation.type; if (mt === 'childList') { if(mutation.addedNodes.length === 1 && mutation.addedNodes[0].nodeName === "TBODY"){ var trs = $(mutation.addedNodes[0]).find("tr"); $(mutation.addedNodes[0]).find("tr").each(function(index){ var row = $(this); var CRSMDocumentID = $(this).data("id"); if (!"fus_crsmdocument" == $(this).data("entity")) return; var viewUrl = F5Common.getDocumentUrl(CRSMDocumentID); $(this).find(".details-link").attr("href",viewUrl).attr("target","_blank").off("click"); console.log("detail links: " + $(this).find(".details-link").length); }); } } }); } me.getDocumentUrl = function(documentid) { var url = window.location.origin + "/fusion5webapi?operation=getDocumentUrl&documentid=" + documentid; var result = null; $.get({ url: url, async: false }, function (document) { result = document; }).always(function () { }); return "/_entity/sharepointdocumentlocation/" + result.id + "/7b138792-1090-45b6-9241-8f8d96d8c372?file=" + result.name; } me.addFutureDateValidator = function (controlToValidate, errorMessage) { me.removeValidator(controlToValidate); $("#" + controlToValidate).next().data("DateTimePicker").minDate(moment()); var dateValidator = document.createElement('span'); dateValidator.style.display = "none"; dateValidator.id = "RequiredFieldValidator" + controlToValidate; dateValidator.controltovalidate = controlToValidate; dateValidator.evaluationfunction = function () { var returnValue = true; //set default value as true //get dates var today = new Date(); var compareDate = $("#" + controlToValidate).val(); if (compareDate == "") return true; //we can handle required date validation elsewhere. var compareDateValue = new Date(compareDate); if (today > compareDateValue) { //setup custom validation message this.errormessage = "" + errorMessage + ""; returnValue = false; } return returnValue; }; // Add the validator to the page validators array: Page_Validators.push(dateValidator); // Wire up the click event handler of the validation summary link $("a[href='#" + controlToValidate + "_label']").on("click", function () { scrollToAndFocus(controlToValidate + '_label', controlToValidate); }); } me.addInstructionsBeforeField = function (fieldName, html, id) { if (id == null) id = fieldName + "Instructions"; var row = $("#" + fieldName).closest("tr"); var insertHtml = $("").append($("", { class: "clearfix cell form-control-cell" }).append(html)); row.before(insertHtml); } me.addInstructionsAfterField = function (fieldName, html, id) { if (id == null) id = fieldName + "Instructions"; var row = $("#" + fieldName).closest("tr"); var insertHtml = $("").append($("", { class: "clearfix cell form-control-cell" }).append(html)); row.after(insertHtml); } me.addInstructionsAfterLabel = function (fieldName, html) { var div = $("
", { style:"clear:both"}).append(html); $("#" + fieldName + "_Label,#" + fieldName + "_label").after(div); } me.addSectionInstructions = function (sectionname, instructions) { var tableSelector = "table[data-name='" + sectionname + "']"; var table = $(tableSelector); var instrRow = $("").append($("", { class: "clearfix cell form-control-cell" }).append($("

", { class: "section-instructions", text: instructions }))); table.prepend(instrRow); } me.addSectionInstructionsHtml = function (sectionname, html) { var tableSelector = "table[data-name='" + sectionname + "']"; var table = $(tableSelector); var instrRow = $("").append($("", { class: "clearfix cell form-control-cell" }).append(html)); table.prepend(instrRow); } me.addLookupValidator = function (fieldName, fieldLabel) { me.removeValidator(fieldName); if (typeof (Page_Validators) == 'undefined') return; // Create new validator $("#" + fieldName + "_label").parent().addClass("required"); var newValidator = document.createElement('span'); newValidator.style.display = "none"; newValidator.id = "RequiredFieldValidator" + fieldName; newValidator.controltovalidate = fieldName; newValidator.errormessage = "" + fieldLabel + " is a required field."; newValidator.validationGroup = ""; newValidator.initialvalue = ""; newValidator.evaluationfunction = function () { var value = $("#" + fieldName).val(); if (value == null || value == "") { return false; } else { return true; } }; // Add the new validator to the page validators array: Page_Validators.push(newValidator); // Wire-up the click event handler of the validation summary link $("a[href='#" + fieldName + "_label']").on("click", function () { scrollToAndFocus(fieldName + '_label', fieldName); }); } me.addValidator = function (fieldName, fieldLabel) { me.removeValidator(fieldName); if (typeof (Page_Validators) == 'undefined') return; // Create new validator $("#" + fieldName + "_label").parent().addClass("required"); var newValidator = document.createElement('span'); newValidator.style.display = "none"; newValidator.id = "RequiredFieldValidator" + fieldName; newValidator.controltovalidate = fieldName; newValidator.errormessage = "" + fieldLabel + " is a required field."; newValidator.validationGroup = ""; newValidator.initialvalue = ""; newValidator.evaluationfunction = function () { var value = $("#" + fieldName).val(); if (value == null || value == "") { return false; } else { return true; } }; // Add the new validator to the page validators array: Page_Validators.push(newValidator); // Wire-up the click event handler of the validation summary link $("a[href='#" + fieldName + "_label']").on("click", function () { scrollToAndFocus(fieldName + '_label', fieldName); }); } me.addCustomValidator = function (fieldName, errorMessage,scrollToId,focusId,callback) { var newValidator = document.createElement('span'); newValidator.style.display = "none"; newValidator.id = "RequiredFieldValidator" + fieldName; newValidator.controltovalidate = fieldName; newValidator.errormessage = "" + errorMessage + ""; newValidator.validationGroup = ""; newValidator.initialvalue = ""; newValidator.evaluationfunction = callback; // Add the new validator to the page validators array: Page_Validators.push(newValidator); } me.addSubGridValidator = function (subGridName, minRecords, errorMessage, maxRecords) { me.removeSubGridValidator(subGridName); if (typeof (Page_Validators) == 'undefined') return; $("#" + subGridName).closest("td").find(".info").addClass("required"); // Create new validator var newValidator = document.createElement('span'); newValidator.style.display = "none"; newValidator.id = "RequiredFieldValidator" + subGridName; newValidator.controltovalidate = subGridName; newValidator.errormessage = "" + errorMessage + ""; newValidator.validationGroup = ""; newValidator.initialvalue = ""; newValidator.evaluationfunction = function () { var noOfRecords = $("#" + subGridName + " table tbody tr").length; if (noOfRecords < minRecords || noOfRecords > maxRecords) { return false; } else { return true; } }; // Add the new validator to the page validators array: Page_Validators.push(newValidator); // Wire-up the click event handler of the validation summary link // $("a[href='#" + subGridName + "_label']").on("click", function () { // scrollToAndFocus(subGridName, subGridName); // }); } me.addCheckBoxValidator = function (fieldName, fieldLabel) { me.removeValidator(fieldName); if (typeof (Page_Validators) == 'undefined') return; // Create new validator $("#" + fieldName + "_label").parent().addClass("required"); var newValidator = document.createElement('span'); newValidator.style.display = "none"; newValidator.id = "RequiredFieldValidator" + fieldName; newValidator.controltovalidate = fieldName; newValidator.errormessage = "Check: " + fieldLabel + "."; newValidator.validationGroup = ""; newValidator.initialvalue = ""; newValidator.evaluationfunction = function () { var isChecked = $("#" + fieldName).is(":checked"); if (isChecked == true) { return true; } else { return false; } }; // Add the new validator to the page validators array: Page_Validators.push(newValidator); // Wire-up the click event handler of the validation summary link $("a[href='#" + fieldName + "_label']").on("click", function () { scrollToAndFocus(fieldName + '_label', fieldName); }); } me.addRadioValidator = function (fieldName, fieldLabel) { me.removeValidator(fieldName); if (typeof (Page_Validators) == 'undefined') return; // Create new validator $("#" + fieldName + "_label").parent().addClass("required"); var newValidator = document.createElement('span'); newValidator.style.display = "none"; newValidator.id = "RequiredFieldValidator" + fieldName; newValidator.controltovalidate = fieldName; newValidator.errormessage = "Check: " + fieldLabel + "."; newValidator.validationGroup = ""; newValidator.initialvalue = ""; newValidator.evaluationfunction = function () { var isChosen = $("input[name$='" + fieldName + "']:checked").length > 0; if (isChosen == true) { return true; } else { return false; } }; // Add the new validator to the page validators array: Page_Validators.push(newValidator); // Wire-up the click event handler of the validation summary link $("a[href='#" + fieldName + "_label']").on("click", function () { scrollToAndFocus(fieldName + '_label', fieldName); }); } me.removeSubGridValidator = function (subGridName) { if (typeof (Page_Validators) == 'undefined') return; if ($('#' + subGridName) != undefined) { $("#" + subGridName).closest("td").find(".info").removeClass("required"); me.removeValidator(subGridName); } } me.removeValidator = function (fieldName) { if (typeof (Page_Validators) == 'undefined') return; if ($('#' + fieldName) != undefined) { $("#" + fieldName + "_label").parent().removeClass('required'); $('#' + fieldName).prop('required', false); for (i = 0; i < Page_Validators.length; i++) { if (Page_Validators[i].id == 'RequiredFieldValidator' + fieldName) { // Remove the current field�s �Required� validator from �Page_Validators� array Page_Validators.splice(i, 1); } } } } me.showSections = function (sectionList) { var count = sectionList.length; for (i_ss = 0; i_ss < count; i_ss++) { var fieldString = "fieldset[aria-label='" + sectionList[i_ss] + "']"; $(fieldString).show(); } } me.hideSections = function (sectionList) { var count = sectionList.length; for (i_hs = 0; i_hs < count; i_hs++) { var fieldString = "fieldset[aria-label='" + sectionList[i_hs] + "']"; $(fieldString).hide(); } } me.removeValidators = function (validatorList) { var count = validatorList.length; for (i_rv = 0; i_rv < count; i_rv++) { me.removeValidator(validatorList[i_rv]); } } me.getContactDetails = function (contactid) { var url = window.location.origin + "/fusion5webapi?operation=getContactDetails&contactid=" + contactid; var result = null; $.get({ url: url, async: false }, function (contact) { result = contact; }).always(function () { }); return result; } me.clearTextFields = function (fieldList) { var count = fieldList.length; for (i_ctf = 0; i_ctf < count; i_ctf++) { $("#" + fieldList[i_ctf]).val(""); } } me.hideFields = function (fieldList) { var count = fieldList.length; for (i_hf = 0; i_hf < count; i_hf++) { $("#" + fieldList[i_hf]).closest("tr").hide(); } } me.showFields = function (fieldList) { var count = fieldList.length; for (i_sf = 0; i_sf < count; i_sf++) { $("#" + fieldList[i_sf]).closest("tr").show(); } } me.disableLookups = function (fieldList) { var count = fieldList.length; for (i_dl = 0; i_dl < count; i_dl++) { me.disableLookupFields([$("#" + fieldList[i_dl])]); } } me.enableLookups = function (fieldList) { var count = fieldList.length; for (i_el = 0; i_el < count; i_el++) { $("#" + fieldList[i_el]).parent().find('.input-group-btn').show(); } } me.enableDateTimeFields = function (fieldList) { var count = fieldList.length; for (i_edtf = 0; i_edtf < count; i_edtf++) { $("#" + fieldList[i_edtf]).next().data("DateTimePicker").enable(); } } me.disableDateTimeFields = function (fieldList) { var count = fieldList.length; for (i_ddtf = 0; i_ddtf < count; i_ddtf++) { $("#" + fieldList[i_ddtf]).next().data("DateTimePicker").disable(); } } me.enableFields = function (fieldList) { var count = fieldList.length; for (ecf = 0; ecf < count; ecf++) { $("#" + fieldList[ecf]).enable(true) } } me.disableFields = function (fieldList) { var count = fieldList.length; for (i_dcf = 0; i_dcf < count; i_dcf++) { $("#" + fieldList[i_dcf]).enable(false); } } me.disableLookupFields = function (fieldList) { var count = fieldList.length; for (dlf = 0; dlf < count; dlf++) { $("#" + fieldList[dlf]).parent().removeClass("input-group").find('.input-group-btn').hide(); } $(".text-muted").css("color", "transparent"); } me.enableLookupFields = function (fieldList) { var count = fieldList.length; for (elf = 0; elf < count; elf++) { $("#" + fieldList[elf]).parent().addClass("input-group").find('.input-group-btn').show() } } me.disableRadioButtonFields = function (fieldList) { var count = fieldList.length; for (drbf = 0; drbf < count; drbf++) { $('#' + fieldList[drbf] + ' input:radio:not(:checked)').attr('disabled', true); } } me.enableRadioButtonFields = function (fieldList) { var count = fieldList.length; for (erbf = 0; erbf < count; erbf++) { $('#' + fieldList[erbf] + ' input:radio:not(:checked)').attr('disabled', false); } } me.clearRadioButtonFields = function (fieldList) { var count = fieldList.length; for (erbf = 0; erbf < count; erbf++) { $('#' + fieldList[erbf] + ' input:radio:checked').prop('checked', false);; } } me.disablePicklistFields = function (fieldList) { var count = fieldList.length; for (dplf = 0; dplf < count; dplf++) { //can't disbale them as on postback value will be set to first item in list usual Empty string. //need t instead create a readonly textbox with the required text and show that in place of select let readOnlyInput = $("#ro_" + fieldList[dplf]); if(readOnlyInput.length === 0){ let select = $("#" + fieldList[dplf]); let selectedText = $("#" + fieldList[dplf] + " option:selected").text(); readOnlyInput = $("", { id:"ro_" + fieldList[dplf], class: "text form-control", readonly:true}); readOnlyInput.val(selectedText); select.before(readOnlyInput); select.hide(); } } } me.enablePicklistFields = function (fieldList) { var count = fieldList.length; for (eplf = 0; eplf < count; eplf++) { let select = $("#" + fieldList[dplf]); let readOnlyInput = $("#ro_" + fieldList[dplf]); readOnlyInput.remove(); select.show(); } } me.getUrlParameter = function getUrlParameter(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 typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } return false; } me.addModalForm = function (modalId, modalTitle) { var modalSection = $("

", { id: modalId, "aria-hidden": "true", "aria-label": " Modal Form", class: "modal fade modal-form modal-form-details", "data-backdrop": "static", role: "dialog", tabindex: "-1", style: "display: none;" }); $("body").prepend(modalSection); var modalDialog = $("
", { class: "modal-lg modal-dialog" }); modalSection.append(modalDialog); var modalContent = $("
", { class: "modal-content" }); modalDialog.append(modalContent); var modalHeader = $("
", { class: "modal-header" }); modalContent.append(modalHeader); var closeButton = $("