const changeButtonColor = (buttonPath, color) => {
document.querySelector(buttonPath).style.border = `1px solid ${color}`;
document
.querySelectorAll(`${buttonPath} svg path`)
.forEach((item) => (item.style.stroke = color));
};
const getApiLink = () => {
if (
window.location.origin.includes("localhost") ||
window.location.origin.includes("file") ||
window.location.origin.includes("127.0.0.1")
) {
return "http://localhost";
} else {
return window.location.origin;
}
};
const getWSLink = () => {
if (
window.location.origin.includes("localhost") ||
window.location.origin.includes("file")
) {
return "ws://localhost:8080";
} else {
return "ws://13.201.227.120:8088";
}
};
const createAlertMessage = (
elemClass,
result,
message = "Something Went Wrong",
type,
show_error = false
) => {
const errorElem = document.querySelector(`.${elemClass}`);
errorElem.innerHTML = "";
const messageElem = document.createElement("alert-element");
messageElem.setAttribute(
"data-message",
`${result ? result.message || result.status : message}
${
result?.error && show_error ? result.error : ""
}`
);
messageElem.setAttribute(
"data-type",
type || result?.success ? "info" : "error"
);
messageElem.setAttribute(
"data-isclose",
show_error && result?.error ? "false" : "true"
);
messageElem.setAttribute("data-container-class", elemClass);
errorElem.appendChild(messageElem);
};
const startLoader = (elemClass) => {
const holderElem = document.querySelector(`.${elemClass}`);
holderElem.innerHTML = "";
const loaderElem = document.createElement("loader-element");
holderElem.appendChild(loaderElem);
};
const endLoader = (elemClass) => {
const holderElem = document.querySelector(`.${elemClass}`);
holderElem.innerHTML = "";
};
const setTimer = (viewElemClass, resendButtonClass, timeInSec = 60) => {
const countdown = document.querySelector(`.${viewElemClass}`);
const btn = document.querySelector(`.${resendButtonClass}`);
btn.classList.add("_disabled");
const interval = window.setInterval(() => {
if (timeInSec > 0) timeInSec--;
countdown.innerHTML = "in (" + timeInSec + " sec)";
if (timeInSec <= 0) {
btn.classList.remove("_disabled");
countdown.innerHTML = "";
clearInterval(interval);
}
}, 1000);
return interval;
};
const setMessage = (targetElemClass, message) => {
const elem = document.querySelector(`.${targetElemClass}`);
elem.innerHTML = "";
const messageElem = document.createElement("message-element");
messageElem.setAttribute("data-message", message);
elem.appendChild(messageElem);
};
const updateFieldValues = (json, section) => {
if (section == "shareholder") {
Object.keys(json).forEach((shareholder_id) => {
const fields = json[shareholder_id]?.fields;
const files = json[shareholder_id]?.files;
if (fields) {
Object.keys(fields).forEach((field) => {
if (field != "Uid" && field != "Holding") {
const elem = document.getElementById(
`${section}#${shareholder_id}_${field}`
);
updateValue(elem, json[shareholder_id].fields[field]);
}
});
}
if (files) {
Object.keys(files).forEach((field) => {
renderFiles(
null,
`${section}#${shareholder_id}_${field}`,
files[field]
);
});
}
});
} else {
if (json["fields"]) {
Object.keys(json.fields).forEach((field) => {
const elem = document.getElementById(`${section}_${field}`);
updateValue(elem, json.fields[field]);
});
}
if (json["files"]) {
Object.keys(json.files).forEach((field) => {
renderFiles(null, `${section}_${field}`, json.files[field]);
});
}
}
};
const updateValue = (elem, val) => {
if (elem.classList.contains("__radio")) {
const radioInputs = elem.querySelectorAll("input");
radioInputs.forEach((radioInput) => {
if (radioInput.getAttribute("data-radio") == `radio${val}`) {
radioInput.checked = true;
}
});
} else if (elem.classList.contains("__checkbox")) {
elem.checked = val == "1";
} else if (elem.classList.contains("__select")) {
elem.value = val || "not-selected";
} else if (elem.classList.contains("__button")) {
if (val == "1") {
linkSentButtonChange(elem);
}
} else {
if (elem.id == "companyDetails_DateOfInc") {
const diff = differenceInYearsAndMonths(val);
const vantageValue =
diff.years != undefined && diff.months != undefined
? `${diff.years} Year ${diff.months} Month`
: "";
document.querySelector("#companyDetails_BusinessVantage").value =
vantageValue;
} else if (elem.id.includes("shareholder#") && elem.id.includes("_Dob")) {
const diff = differenceInYearsAndMonths(val);
const age = isNaN(diff.years) ? "" : diff.years;
const id = elem.id.split("_")[0];
if (document.getElementById(`${id}_Age`))
document.getElementById(`${id}_Age`).value = age;
}
elem.value = val;
}
};
const linkSentButtonChange = (elem) => {
elem.classList.add("_disabled");
elem.querySelector("._button_icon").src = "../../assets/images/tick.png";
elem.querySelector(".button__container").style.backgroundColor =
"transparent";
elem.querySelector(".button__container").style.color = "#00A2AD";
elem.querySelector("._button_font").innerHTML = "Link Sent";
elem.querySelector(".button__container").style.cursor = "not-allowed";
if (elem.id == "financialData_IsItrLinkSent") {
document.querySelector("#financialData_ItrAcqPhoneNumber").readOnly = true;
document.querySelector("#financialData_ItrAcqCompanyEmail").readOnly = true;
}
if (elem.id == "financialData_IsGstLinkSent") {
document.querySelector("#financialData_GstAcqPhoneNumber").readOnly = true;
document.querySelector("#financialData_GstAcqCompanyEmail").readOnly = true;
}
};
function renderFiles(elem, id, files) {
const filelist = document.getElementById(`filelist_${id.replace("#", "__")}`);
filelist.innerHTML = "";
Array.from(files).forEach((file, index) => {
const fileItem = document.createElement("div");
fileItem.classList.add("fileupload__fileitem");
fileItem.innerHTML = `