document.addEventListener("DOMContentLoaded",()=>{
let helpNavElement = $($(".navbar-nav .nav-item").toArray().find(e=>e.innerText.contains("Help")));
if(commonFunctionToCheckNullOrUndefinedHelp(helpNavElement))
{
let anchorElement = helpNavElement.find("a");
if(commonFunctionToCheckNullOrUndefinedHelp(anchorElement))
{
anchorElement.attr("href","#");
$(anchorElement).click(getTheBase64OfFileHelp);
}
}
});
function showPdfInPopupHelp(base64String) {
// Convert Base64 to a Data URL
const fileURL = `data:application/pdf;base64,${base64String}`;
// Create HTML for Popup
const popupHtml = `
`;
// Append to body
document.body.insertAdjacentHTML("beforeend", popupHtml);
}
function getTheBase64OfFileHelp()
{
try
{
const masterRecordId = document.getElementById("helpDocument").value;
if(commonFunctionToCheckNullOrUndefinedHelp(masterRecordId))
{
const masterRecordValue = masterRecordId;
const filter = `_objectid_value eq '${masterRecordValue}'`;
const encodedFilter = encodeURIComponent(filter);
webapi.safeAjax({
type: "GET",
url: `/_api/annotations?$select=annotationid,documentbody&$filter=${encodedFilter}`,
contentType: "application/json",
success: async function (res) {
//debugger;
if(res.value.length>0)
{
showPdfInPopupHelp(res.value[0].documentbody);
}
}
});
}
}
catch(error)
{
commonFunctionForErrorLoggingHelp(error.message,"getTheBase64OfFile");
}
}
function commonFunctionForErrorLoggingHelp(error,functionName)
{
//Include application insights if needed
console.log(`An error occured in function - ${functionName}.\n Error message - ${error.message}`);
}
function commonFunctionToCheckNullOrUndefinedHelp(value,isStringCheck = false)
{
if(isStringCheck)
{
return (value !== null && value !== undefined && value !== "");
}
return (value !== null && value !== undefined);
}