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 = $("