function loadJavaScriptLibrary(sLibrariesName){ for (var sLibraryName of sLibrariesName.split(",").join("|").split(";").join("|").split("|")) { document.getElementsByTagName("head")[0].innerHTML += (""); } } function checkPreviousPage(sAllowUrls, sRedirectUrl = "") { let lsPreviousURL = document.referrer; if (sRedirectUrl.length == 0) sRedirectUrl = lsPreviousURL; if (lsPreviousURL.length != 0 || window.history.length == 0) { if (sAllowUrls.length > 0 && sRedirectUrl.length > 0 && (lsPreviousURL.length > 0 || window.history.length>0)) { if (lsPreviousURL.toLowerCase() != window.location.href.toLowerCase()) { if (lsPreviousURL.substring(lsPreviousURL.length-1) == "/") lsPreviousURL = lsPreviousURL.substring(0,lsPreviousURL.length-1); lsPreviousURL = lsPreviousURL.replace('https://','').replace('http://',''); let liPreviousSize = lsPreviousURL.length; var lbIsCorrect = false; for (let lUrl of sAllowUrls.split(" ").join("|").split(",").join("|").split(";").join("|").split("|")) { let liUrlSize = lUrl.length; if (liPreviousSize >= liUrlSize) if (lsPreviousURL.substring(liPreviousSize-liUrlSize).toLowerCase() == lUrl.toLowerCase() || lsPreviousURL.substring(0, liUrlSize).toLowerCase() == lUrl.toLowerCase()) { lbIsCorrect = true; break; } } if (lbIsCorrect == false) window.location.href = ((sRedirectUrl.substring(0,4).toLowerCase() == "http") ? "": "https://") + sRedirectUrl; return lbIsCorrect; } else { return true; } } else { return true; } } else { window.location.href = "https://" + sRedirectUrl; return false; } } //------------------------------------- // VISIBLE CONTROLS //------------------------------------- function visibleControls(sIDControls, bVisible = true, bAlertError = false) { var sVisible = (bVisible) ? "" : "none"; for (var sIDControl of sIDControls.split(".").join("|").split(",").join("|").split(";").join("|").split("|")) { var oControl = document.getElementById(sIDControl.trim()); if (oControl != null) oControl.style.display = sVisible; else if (bAlertError == true) alert ("No " + sIDControl + " control found."); } } function visibleUnvisibleControls( sIdVisibleControls, sIdUnVisibleControls, bAlertError = false) { visibleControls(sIdVisibleControls, true, bAlertError); visibleControls(sIdUnVisibleControls, false, bAlertError); } function visibleIfValueInSelectOption(sIdSelectControl, sSelectValues, sIdVisiblesControls, bAlertError = false) { visibleControls(sIdVisiblesControls, checkSelectControl(sIdSelectControl,sSelectValues, bAlertError), bAlertError); } //------------------------------------- // SELECT OPTION //------------------------------------- function checkValueInSelectOptionControl(sValueToCheck, sValues, bAlertError = false) { if (typeof sValueToCheck == 'object') var sValueToCheck = sValueToCheck.options[oSelectControl.selectedIndex].value.toUpperCase(); var bResult = false; if (sValueToCheck != null) { sValueToCheck = sValueToCheck.trim(); for (var sValue of sValues.toUpperCase().split(".").join("|").split(",").join("|").split(";").join("|").split("|")) { if (sValueToCheck == sValue.trim()) { bResult = true; break; } } } else { if (bAlertError == true) alert ("No value '" + sValueToCheck + "' found."); } return bResult; } function dispatchEventChangeSelectOption(sIDSelectOption, sAttributeOfIDValue = "value", sAttributeToFilter = "name", sDefaultAttribute = "value", sDefaultValue = "") { let lbReturn = true; if ((lctrlSelectOption = ((typeof sIDSelectOption == 'string' && sIDSelectOption.length > 0) ? document.querySelector(sIDSelectOption) : ((sIDSelectOption != null && typeof sIDSelectOption == 'object') ? sIDSelectOption : null))) != null ) { if (lctrlSelectOption.selectedIndex >= 0 && (lsIDValue = ((sAttributeOfIDValue == "value") ? lctrlSelectOption.options[lctrlSelectOption.selectedIndex].value : lctrlSelectOption.options[lctrlSelectOption.selectedIndex].getAttribute(sAttributeOfIDValue))) != null) { if ((lsFilterName = ((sAttributeToFilter == "name") ? lctrlSelectOption.getAttribute(sAttributeToFilter) : sAttributeToFilter)) != null) { for (let lctrElelement of lctrlSelectOption.closest(".tab, fieldset, form, body").querySelectorAll("select option[" + sAttributeToFilter + "]:last-of-type")) { if (filterSelectOption([lctrElelement.parentNode], lsFilterName, lsIDValue, sDefaultAttribute, sDefaultValue)) lbReturn = false; } } } } return lbReturn; } function visibleSelectOptions(sIDSelectToFilter, sDefaultAttribute = "value", sDefaultValue = "", sAttributeOfIDValue = "value", sAttributeToFilter = "name") { let lbReturn = true; if ((lArraySelectOptionToFilter = ((typeof sIDSelectToFilter == 'string') ? ( (sIDSelectToFilter.length > 0) ? document.querySelectorAll(sIDSelectToFilter) : null) : ((sIDSelectToFilter != null && typeof sIDSelectToFilter == 'object') ? ((["NodeList", "Array"].includes(sIDSelectToFilter.constructor.name)) ? sIDSelectToFilter : [sIDSelectToFilter]) : null))) != null) { for (let lctrlSelectOption of lArraySelectOptionToFilter) { if ((loLastOption = lctrlSelectOption.querySelector("option:not(disabled):last-of-type")) != null) { let lsAttributes = ""; for(let loAttribute of loLastOption.attributes) { if ([sAttributeOfIDValue,"style","id"].includes(loAttribute.getAttribute(sAttributeToFilter)) == false) lsAttributes = ((lsAttributes.length > 0) ? (lsAttributes + ", ") : "") + "select[" + sAttributeToFilter + "='" + loAttribute.getAttribute(sAttributeToFilter) + "'] option[selected]"; } if (lsAttributes.length > 0 ) { let lsFilter = ""; for(let lctrlOption of lctrlSelectOption.closest(".tab, fieldset, form, body").querySelectorAll(lsAttributes)) { if (((sAttributeOfIDValue == "value") ? lctrlOption.value.length : lctrlOption.getAttribute(sAttributeOfIDValue).length) > 0) lsFilter = lsFilter + "[" + lctrlOption.parentNode.getAttribute(sAttributeToFilter) + "='" + ((sAttributeOfIDValue == "value") ? lctrlOption.value : lctrlOption.getAttribute(sAttributeOfIDValue)) + "']"; } if (lsFilter.length > 0 ) { for(let lctrlOption of lctrlSelectOption.querySelectorAll("option" + lsFilter)) lctrlOption.style.display = "inline"; for(let lctrlOption of lctrlSelectOption.querySelectorAll("option:not(" + lsFilter + ")")) lctrlOption.style.display = "none"; if (lctrlSelectOption.options[liCurrentIndex].style.display == "inline") { lctrlSelectOption.selectedIndex = liCurrentIndex; } else if (selectedSelectOption(lctrlSelectOption, sDefaultAttribute,sDefaultValue) == false) lbReturn = false; } } } } } } function filterSelectOption(sIDSelectToFilter, sAttributeToFilter = "", sValueToFilter = "", sDefaultAttribute = "value", sDefaultValue = "") { let lbReturn = true; if ((lArraySelectOptionToFilter = ((typeof sIDSelectToFilter == 'string') ? ( (sIDSelectToFilter.length > 0) ? document.querySelectorAll(sIDSelectToFilter) : null) : ((sIDSelectToFilter != null && typeof sIDSelectToFilter == 'object') ? ((["NodeList", "Array"].includes(sIDSelectToFilter.constructor.name)) ? sIDSelectToFilter : [sIDSelectToFilter]) : null))) != null) { let lsAttribute = "[" + sAttributeToFilter + "='" + sValueToFilter + "']"; for (let lctrElelement of lArraySelectOptionToFilter) { lctrlSelectOptionToFilter = (lctrElelement.nodeName.toUpperCase() == "option") ? lctrElelement.parentNode : lctrElelement; liCurrentIndex = lctrlSelectOptionToFilter.selectedIndex; for(let lctrlOption of lctrlSelectOptionToFilter.querySelectorAll("option" + lsAttribute)) lctrlOption.style.display = "inline"; for(let lctrlOption of lctrlSelectOptionToFilter.querySelectorAll("option:not(" + lsAttribute + ")")) lctrlOption.style.display = "none"; if (lctrlSelectOptionToFilter.options[liCurrentIndex].style.display == "inline") { lctrlSelectOptionToFilter.selectedIndex = liCurrentIndex; } else if (selectedSelectOption(lctrlSelectOptionToFilter, sDefaultAttribute,sDefaultValue) == false) lbReturn = false; } } return lbReturn; } function selectedSelectOption(sIDSelectToFilter, sDefaultAttribute = "value", sDefaultValue = "") { let lbReturn = false; if ((lctrlSelectOption = ((typeof sIDSelectToFilter == 'string' && sIDSelectToFilter.length > 0) ? document.querySelector(sIDSelectToFilter) : ((sIDSelectToFilter != null && typeof sIDSelectToFilter == 'object') ? sIDSelectToFilter : null))) != null ) { liCurrentIndex = lctrlSelectOption.selectedIndex; if (/^[-+]?[0-9]+$/.test(sDefaultAttribute)){ lctrlSelectOption.selectedIndex = parseInt(sDefaultAttribute); } else { if ((lctrlOptionDefault = lctrlSelectOption.querySelector("option[" + sDefaultAttribute + "='" + sDefaultValue + "']")) != null) lctrlSelectOption.selectedIndex = lctrlOptionDefault.index; else if ((lctrlOptionDefault = lctrlSelectOption.querySelector("option:disabled")) != null) lctrlSelectOption.selectedIndex = lctrlOptionDefault.index; else lctrlSelectOption.selectedIndex = 0; } if (lctrlSelectOption.selectedIndex >= 0 || liCurrentIndex != lctrlSelectOption.selectedIndex) lctrlSelectOption.dispatchEvent(new Event('change')); lbReturn = true; } return lbReturn; } function filterValuesOfSelectOption(sIDControlToFilter, sValueToFilter, sAttributeToFilter = "", sSelectedValue = "", iDefaultSelectedIndex = -1, bAlertError = false) { if (typeof sValueToFilter == "object") var sValueToFilter = sValueToFilter.options[sValueToFilter.selectedIndex].value.toUpperCase(); var oSelectControlToFilter = (typeof sIDControlToFilter == "string") ? document.getElementById(sIDControlToFilter.trim()) : sIDControlToFilter; if (oSelectControlToFilter != undefined || oSelectControlToFilter != null) { if (sValueToFilter != undefined && sValueToFilter.length > 0) { sValueToFilter = sValueToFilter.trim().toUpperCase(); var sActualSelectedValue = (oSelectControlToFilter.selectedIndex != -1) ? ((oSelectControlToFilter.options[oSelectControlToFilter.selectedIndex].value.length > 0) ? oSelectControlToFilter.options[oSelectControlToFilter.selectedIndex].value : sSelectedValue) : sSelectedValue; var bOptionVisible = false; var liIndexVisible = iDefaultSelectedIndex; for (var iOptionCounter = 0; iOptionCounter < oSelectControlToFilter.options.length; ++iOptionCounter) { bOptionVisible = oSelectControlToFilter.options[iOptionCounter].value.length == 0 || ((sAttributeToFilter == "" && oSelectControlToFilter.options[iOptionCounter].value.toUpperCase() == sValueToFilter) || (sAttributeToFilter != "" && oSelectControlToFilter.options[iOptionCounter].getAttribute(sAttributeToFilter) != null && oSelectControlToFilter.options[iOptionCounter].getAttribute(sAttributeToFilter).toUpperCase() == sValueToFilter)); oSelectControlToFilter.options[iOptionCounter].style.display = (bOptionVisible) ? "block" : "none"; if (bOptionVisible == true && sActualSelectedValue.length > 0) { if (oSelectControlToFilter.options[iOptionCounter].value == sSelectedValue) { liIndexVisible = iOptionCounter; sActualSelectedValue = ""; } else { if (oSelectControlToFilter.options[iOptionCounter].value == sActualSelectedValue) { liIndexVisible = iOptionCounter; sActualSelectedValue = sSelectedValue; } } } } oSelectControlToFilter.selectedIndex = liIndexVisible; if (oSelectControlToFilter.options[oSelectControlToFilter.selectedIndex].value.length > 0) oSelectControlToFilter.dispatchEvent(new Event('change')); } } else { if (bAlertError == true) alert ("No " + sValueToCheck + " control found."); } } // sRegularExpresion Filter Countries [^:]*: function formatSelectOptionControl(sIDControlToFomat, sSelectedValue, bSeletedText = true, sRegularExpresionText = "", sRegularExpresionValue = "", sDefaultText = "Choose a item") { var oSelectControlToFormat = (typeof sIDControlToFomat == "string") ? document.getElementById(sIDControlToFomat.trim()) : sIDControlToFomat; if ((oSelectControlToFormat != undefined || oSelectControlToFormat != null) && oSelectControlToFormat.options.length > 0) { var liIndexVisible = -1; if (oSelectControlToFormat.options[0].value.length == 0) { liIndexVisible = 0; if (oSelectControlToFormat.options[0].text.length == 0) { oSelectControlToFormat.options[0].text = sDefaultText; oSelectControlToFormat.options[0].setAttribute("label",sDefaultText); oSelectControlToFormat.options[0].setAttribute("disabled",true); } } var oregText = (sRegularExpresionText.length > 0) ? new RegExp(sRegularExpresionText) : undefined; var oregValue = (sRegularExpresionValue.length > 0) ? new RegExp(sRegularExpresionValue) : undefined; var oOptionProcesed = undefined; sSelectedValue = sSelectedValue.toUpperCase(); for (var iOptionCounter = 0; iOptionCounter < oSelectControlToFormat.options.length; ++iOptionCounter) { oOptionProcesed = oSelectControlToFormat.options[iOptionCounter]; if (oregText != undefined) oOptionProcesed.text = oOptionProcesed.text.replace(oregText,"").trim(); if (oregValue != undefined) oOptionProcesed.value = oOptionProcesed.value.replace(oregValue,"").trim(); if (sSelectedValue.length > 0) { if (bSeletedText == true) { if (oOptionProcesed.text.toUpperCase() == sSelectedValue.toUpperCase()) { liIndexVisible = iOptionCounter; bSeletedText = ""; } } else { if (oOptionProcesed.value.toUpperCase() == sSelectedValue.toUpperCase()) { liIndexVisible = iOptionCounter; bSeletedText = ""; } } } } oSelectControlToFormat.selectedIndex = liIndexVisible; if (liIndexVisible >= 0 && oSelectControlToFormat.options[liIndexVisible].value.length > 0) oSelectControlToFormat.dispatchEvent(new Event('change')); } } function defaultSelectOption(sIDquerySelectorControls, sDefaultValue = "", sDefaultField = "value") { let lColSelectOptionsRef = (typeof sIDquerySelectorControls == 'string') ? document.querySelectorAll(sIDquerySelectorControls) : (["NodeList", "Array"].includes(sIDquerySelectorControls.constructor.name)) ? sIDquerySelectorControls : [sIDquerySelectorControls]; for (let lcrtSelectOption of lColSelectOptionsRef) { let loDefaultOption = lcrtSelectOption.parentNode.querySelector("option[" + sDefaultField + "='" + sDefaultValue + "']"); if (loDefaultOption != null) loDefaultOption.parentNode.selectedIndex = loDefaultOption.index; } return (lColSelectOptionsRef.length > 0) } function visibleFieldInSelectOption(sIDquerySelectorControls, sFilterValue, sFilterField = "value", bVisible = true, sDefaultValue = "", sDefaultField = "value") { if(bVisible == true){ $("#cts_plate_type").prop( "disabled", true ); $('#cts_plate_type').append(''); return visibleItemsInSelectOption(sIDquerySelectorControls, "option[" + sFilterField + " = '" + sFilterValue + "']", bVisible, sDefaultValue, sDefaultField); } else { $("#cts_plate_type option[cts_code='0']").remove(); if ($("#cts_plate_type").prop( "disabled") == true) defaultSelectOption(sIDquerySelectorControls, sDefaultValue, sDefaultField); $("#cts_plate_type").prop( "disabled", false ); } } function visibleItemsInSelectOption(sIDquerySelectorControls, sFilterCondition, bVisible = true, sDefaultValue = "", sDefaultField = "value") { let lColSelectOptionsRef = (typeof sIDquerySelectorControls == 'string') ? document.querySelectorAll(sIDquerySelectorControls.split(',').join(' ' + sFilterCondition + ',') + ' ' + sFilterCondition) : (["NodeList", "Array"].includes(sIDquerySelectorControls.constructor.name)) ? sIDquerySelectorControls : [sIDquerySelectorControls]; for (let lcrtSelectOption of lColSelectOptionsRef) { lcrtSelectOption.style.display = ((bVisible == true) ? "block" : "none"); if (bVisible == false && lcrtSelectOption.index == lcrtSelectOption.parentNode.selectedIndex) defaultSelectOption(lcrtSelectOption, sDefaultValue, sDefaultField); } return lColSelectOptionsRef.length; } function validateFirstOption(sIDPanel, sDefaultText = "• Choose a item •") { var loPanelControl = (typeof sIDPanel == "string") ? document.getElementById(sIDPanel.trim()) : sIDPanel; if (loPanelControl != null) { var loAllSelectOptionControl = loPanelControl.querySelectorAll("select"); if (loAllSelectOptionControl != null && loAllSelectOptionControl != undefined && loAllSelectOptionControl.length > 0) { for (var loSelectOptionControl of loAllSelectOptionControl) { if (loSelectOptionControl.options.length > 0 && loSelectOptionControl.options[0].getAttribute("label") != null && loSelectOptionControl.options[0].getAttribute("label").trim().length == 0) { var loLabels = loPanelControl.querySelectorAll("label[for='" + loSelectOptionControl.id + "']"); var lsNewText = sDefaultText; if (sDefaultText == "• Choose a item •") lsNewText = (loLabels != null && loLabels.length > 0 && loLabels[0].innerHTML.trim().length > 0) ? loLabels[0].innerHTML.trim().toLowerCase() : sDefaultText; loSelectOptionControl.options[0].setAttribute("label", "• Choose a " + lsNewText + " •"); loSelectOptionControl.options[0].disabled = true; } } } return true; } else { return false; } } //------------------------------------- // LOCAL STORAGE //------------------------------------- function setLocalStorage(sIDControls, bClearStorage = true) { if (bClearStorage) localStorage.clear(); for (var sIDControl of sIDControls.split(".").join("|").split(",").join("|").split(";").join("|").split("|")) { var oControl = document.getElementById(sIDControl.trim()); if (oControl != null && oControl.style.display != "none" && oControl.parentNode.style.display != "none") localStorage.setItem(oControl.name, oControl.value); } } function getLocalStorage(sIDControls, bClearStorage = true) { for (var sIDControl of sIDControls.split(".").join("|").split(",").join("|").split(";").join("|").split("|")) { var oControl = document.getElementById(sIDControl.trim()); if (oControl != null) { var sValue = localStorage.getItem(oControl.name); if (sValue != null) oControl.value = sValue; } } if (bClearStorage) localStorage.clear(); } function setPanelLocalStorage(sIDPanel, bClearStorage = true, sNodeSelection = "input,select", bAlertError = false) { setLocalStorage(getControlsNamesInPanel(sIDPanel, sNodeSelection,",", bAlertError), bClearStorage); } function getPanelLocalStorage(sIDPanel, bClearStorage = true, sNodeSelection = "input,select", bAlertError = false) { getLocalStorage(getControlsNamesInPanel(sIDPanel, sNodeSelection,",", bAlertError), bClearStorage); } //------------------------------------- // Required Controls //------------------------------------- function reqUnreqControls( sIDRequiredControls, sIdUnrequiredControls, sControlIndetifier = "#", bAlertError = false) { reqControls(sIdUnrequiredControls, false, sControlIndetifier, bAlertError); return reqControls(sIDRequiredControls, true, sControlIndetifier, bAlertError); } function reqControls(sIDControls, bEnabled = true, sControlIndetifier = "#", bAlertError = false) { var lbValidate = true; for (var loControl of document.querySelectorAll(sControlIndetifier + sIDControls.split(".").join("|").split(",").join("|").split(";").join("|").split(" ").join("").split("|").join(", " + sControlIndetifier))) { if (loControl != null) { loControl.required = (loControl.style.display == "none" || loControl.parentNode.style.display == "none") ? false : bEnabled; if (lbValidate == true && loControl.required == true) lbValidate = loControl.checkValidity(); } else if (bAlertError == true) alert (sIDControl); } return lbValidate; } function reqUnreqPanel(sIDRequiredPanel, sIDUnrequiredPanel, sNodeSelection = "input,select", bAlertError = false) { reqPanel(sIDUnrequiredPanel, sNodeSelection, false, true, bAlertError); return reqPanel(sIDRequiredPanel, sNodeSelection, true, true, bAlertError); } function reqPanel(sIDPanel, sNodeSelection = "input,select", bEnabled = true, bWithout_Submit = true, bAlertError = false) { var lbValidate = true; for (var loControl of getControlsObjectInPanel(sIDPanel, sNodeSelection, bAlertError)) { if ((bWithout_Submit == false || (loControl.type != "submit" && loControl.type != "button")) && loControl.id.length> 0 || loControl.class != "Captcha-check-container") { if (loControl != null) { loControl.required = (loControl.style.display == "none" || loControl.parentNode.style.display == "none") ? false : bEnabled; if (lbValidate == true && loControl.required == true) lbValidate = loControl.checkValidity(); } else if (bAlertError == true) alert (sIDControl); } } return lbValidate; } function requiredControls(sIDquerySelectorControls, bIsRequired = true, successFunction = undefined, sIDquerySelectorInputs = "input:not([type='submit'],[type='reset'],[type='hidden'])") { let lbAllInputsAreValids = true; let lColInputssRef = (typeof sIDquerySelectorControls == 'object') ? ( (["FORM", "FIELDSET", "DIV", "BODY"].includes(sIDquerySelectorControls.nodeName.toUpperCase())) ? sIDquerySelectorControls.querySelectorAll(sIDquerySelectorInputs) : [sIDquerySelectorControls] ) : ( document.querySelectorAll ((sIDquerySelectorControls != undefined && sIDquerySelectorControls != null && (typeof sIDquerySelectorControls == "string" && sIDquerySelectorControls.length > 0) ) ? sIDquerySelectorControls : sIDquerySelectorInputs) ); for (let loControl of lColInputssRef) { let lbCheckIsRequired = (loControl.style.display == "none" || loControl.parentNode.style.display == "none") ? false : bIsRequired; loControl.required = lbCheckIsRequired; if (lbAllInputsAreValids == true && lbCheckIsRequired == true) lbAllInputsAreValids = loControl.checkValidity(); } if (lbAllInputsAreValids == true && successFunction != undefined) successFunction.call(); return lbAllInputsAreValids; } function requiredUnrequiredControls( sIDquerySelectorRequiredControls, sIDquerySelectorUnrequiredControls, successFunction = undefined, sIDquerySelectorInputs = "input:not([type='submit'],[type='reset'],[type='hidden'],[type='button']), select") { if (requiredControls(sIDquerySelectorUnrequiredControls, false, undefined, sIDquerySelectorInputs) == true) return requiredControls(sIDquerySelectorRequiredControls, true, successFunction, sIDquerySelectorInputs); else return false; } function requiredUnrequiredPanel( sIDquerySelectorRequiredPanel, sIDquerySelectorUnrequiredPanel, successFunction = undefined, sIDquerySelectorInputs = "input:not([type='submit'],[type='reset'],[type='hidden'],[type='button']), select") { if (typeof sIDquerySelectorRequiredPanel == 'string') sIDquerySelectorRequiredPanel = sIDquerySelectorRequiredPanel + " " + sIDquerySelectorInputs.split(', ').join(', ' + sIDquerySelectorRequiredPanel + ' '); if (typeof sIDquerySelectorUnrequiredPanel == 'string') sIDquerySelectorUnrequiredPanel = sIDquerySelectorUnrequiredPanel + " " + sIDquerySelectorInputs.split(', ').join(', ' + sIDquerySelectorUnrequiredPanel + ' '); if (requiredControls(sIDquerySelectorUnrequiredPanel, false, undefined, sIDquerySelectorInputs) == true) return requiredControls(sIDquerySelectorRequiredPanel, true, successFunction, sIDquerySelectorInputs); else return true; } //------------------------------------- // Get Controls in Panels //------------------------------------- function getControlsObjectInPanel(sPanelID, sNodeSelection = "input,select", bAlertError = false) { var loNodesArrayResult = undefined; if (typeof sPanelID == "string") loSelectedControl = (typeof sPanelID == "string") ? document.getElementById(sPanelID): sPanelID; if (loSelectedControl != undefined && loSelectedControl != null) loNodesArrayResult = loSelectedControl.querySelectorAll(sNodeSelection.split(".").join(",").split(";").join(",").split("|").join(",")); else if (bAlertError) alert ("No " + sIDControl + " panel control found."); return loNodesArrayResult; } function getControlsNamesInPanel(sPanelID, sNodeSelection = "input,select", sSeparator = ",", bWithout_Submit = true, bAlertError = false) { var loNodesArray = getControlsObjectInPanel(sPanelID, sNodeSelection, bAlertError); if (loNodesArray != undefined && loNodesArray.length > 0) { var lsStringResult = loNodesArray[0].id; for(var iNodeCounter = 1; iNodeCounter < loNodesArray.length; iNodeCounter++) if ((bWithout_Submit == false || (loNodesArray[iNodeCounter].type != "submit" && loNodesArray[iNodeCounter].type != "button")) && loNodesArray[iNodeCounter].id.length> 0) lsStringResult = lsStringResult + sSeparator + loNodesArray[iNodeCounter].id; return lsStringResult; } else { return ""; } } //------------------------------------- // Get Controls values //------------------------------------- function getControlValue(sIDControl) { var oValue = document.getElementById(sIDControl); return oValue.textContent || oValue.innerText; } function getControlsValues(sPanelControlsID, sDireccionURLReenvio, sNodeSelection = "input,select", bAlertError = false) { var loNodesArray = getControlsObjectInPanel(sPanelControlsID, sNodeSelection, bAlertError); var htmlValues = "
"; } //------------------------------------- // Check Controls values //------------------------------------- function checkValidityDocument() { var lbDocumentCorrectValidate = true; for(var oControlRequired of document.querySelectorAll("[required]")) if (oControlRequired.checkValidity() == false) { lbDocumentCorrectValidate = false; break; } return lbDocumentCorrectValidate; } function initCheckEmail(sIDEmailControl, sDefaultMessage = "The e-mail format is not correct") { var loEmailControl = (typeof sIDEmailControl == "string") ? document.getElementById(sIDEmailControl.trim()) : sIDEmailControl; if (loEmailControl != null) { loEmailControl.setAttribute("pattern", "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{1,63}$"); loEmailControl.setAttribute("title", sDefaultMessage); if (loEmailControl.tagName.toLowerCase() == "input" && loEmailControl.type != "email") loEmailControl.type = "email"; } } //------------------------------------------ // Strings Functions //------------------------------------------ function AddCharacterLeft(sControlID, sCharacter, iMaxLength = -1) { var loControlRef = (typeof sControlID == "string") ? document.getElementById(sControlID.trim()) : sControlID; iMaxLength = (iMaxLength == -1) ? loControlRef.maxLength: iMaxLength if (loControlRef.value != undefined && loControlRef.value.length > 0 && iMaxLength != undefined && iMaxLength >= 0) loControlRef.value = loControlRef.value.padStart(iMaxLength, sCharacter); } function AddCharacterRight(sControlID, sCharacter, iMaxLength = -1) { var loControlRef = (typeof sControlID == "string") ? document.getElementById(sControlID.trim()) : sControlID; iMaxLength = (iMaxLength == -1) ? loControlRef.maxLength: iMaxLength if (loControlRef.value != undefined && loControlRef.value.length > 0 && iMaxLength != undefined && iMaxLength >= 0) loControlRef.value = loControlRef.value.padEnd(iMaxLength, sCharacter); } //------------------------------------------ // Tab-Functions //------------------------------------------ function MoveToPanel(iAdvance, lastFunction = undefined, sIdSelector = ".tab", sIdPreviousButton = "#previous", sIdNextButton = "#next", sNextButtonCaption = "Next", sIdLastButtonCaption = "Submmit") { let lbReturn = false; if ((lctrlCurrentPanel = document.querySelector(sIdSelector + "[number][style*='block']")) != null) lbReturn = showPanel(parseInt(lctrlCurrentPanel.getAttribute("number")) + iAdvance, lastFunction, sIdSelector, sIdPreviousButton, sIdNextButton, sNextButtonCaption, sIdLastButtonCaption); return lbReturn; } function showPanel(iNumberOfPanel = 1, lastFunction = undefined, sIdSelector = ".tab", sIdPreviousButton = "#previous", sIdNextButton = "#next", sNextButtonCaption = "Next", sIdLastButtonCaption = "Submmit") { let lbReturn = false; var lArrayTabs = document.querySelectorAll(sIdSelector + "[number]"); if ((lctrlCurrent = document.querySelector(sIdSelector + "[number][style*='block']")) == null || ((liCurrentNumberTab = parseInt(lctrlCurrent.getAttribute("number"))) != iNumberOfPanel && (liCurrentNumberTab > iNumberOfPanel || checkPanel(lctrlCurrent) == true))) { if (iNumberOfPanel > lArrayTabs.length && lastFunction != undefined) { lastFunction.call(); lbReturn = true; } else { iNumberOfPanel = ((iNumberOfPanel < 1) ? 1 :((iNumberOfPanel > lArrayTabs.length) ? lArrayTabs.length: iNumberOfPanel)); if ( (lcrtlPreviousButton = ((typeof sIdPreviousButton == 'string') ? ( (sIdPreviousButton.length > 0) ? document.querySelector(sIdPreviousButton) : null) : ((sIdPreviousButton != null && typeof sIdPreviousButton == 'object') ? sIdPreviousButton : null))) != null) lcrtlPreviousButton.style.display = ((iNumberOfPanel == 1) ? "none" : "inline"); if ((lcrtlNextButton = ((typeof sIdNextButton == 'string') ? ( (sIdNextButton.length > 0) ? document.querySelector(sIdNextButton) : null) : ((sIdNextButton != null && typeof sIdNextButton == 'object') ? sIdNextButton : null))) != null) { lcrtlNextButton.value = ((iNumberOfPanel == lArrayTabs.length && lastFunction != undefined) ? sIdLastButtonCaption : sNextButtonCaption); lcrtlNextButton.innerHTML = lcrtlNextButton.value; lcrtlNextButton.style.display = ((iNumberOfPanel == lArrayTabs.length && lastFunction == undefined) ? "none" : "inline"); } for (var lctrlTab of lArrayTabs) lctrlTab.style.display = (iNumberOfPanel == parseInt(lctrlTab.getAttribute("number"))) ? "block" : "none"; lbReturn = true; } } return lbReturn; } function checkPanel(IDPanel, IDInputs = "input[required], input[pattern]") { let lbCheckCorrect = true; if ((lctrlPanel = ((typeof IDPanel == 'string') ? ( (IDPanel.length > 0) ? document.querySelector(IDPanel) : null) : ((IDPanel != null && typeof IDPanel == 'object') ? IDPanel : null))) != null) { for (let lcrtInput of lctrlPanel.querySelectorAll(IDInputs)) { if(lcrtInput.checkValidity() == false && lbCheckCorrect == true) lbCheckCorrect = false; } } return lbCheckCorrect; } function checkInput(IDInput, oExternalValues = undefined, sErrorMensaje = "", checkIDPanel = undefined, errorIfExist = true, IDctrWarning = ".alert", sAttributeName = "title") { let lbCheckCorrect = true; if (typeof oExternalValues == 'object') { console.log(oExternalValues["@odata.context"] + ": " + oExternalValues.value.length); lbCheckCorrect = (oExternalValues.value.length > 0) ? !errorIfExist : errorIfExist; } if ((lctrlInput = ((typeof IDInput == 'string') ? ( (IDInput.length > 0) ? document.querySelector(IDInput) : null) : ((IDInput != null && typeof IDInput == 'object') ? IDInput : null))) != null && lctrlInput.nodeName.toUpperCase() == "INPUT") { let lbIsVisible = (lctrlInput.closest("[style*='display: none'], [style*='opacity: 0']") == null); let lsInternalMessage = lctrlInput.validationMessage; if (lsInternalMessage == "AJAXquery") { lbCheckCorrect = false; } else { lctrlInput.setCustomValidity(""); if(lbIsVisible == true && lbCheckCorrect == true && lctrlInput.checkValidity() == false) { lbCheckCorrect = false; if (lctrlInput.value.trim().length > 0) { if (sErrorMessage.length == 0) { sErrorMessage = lctrlInput.getAttribute(sAttributeName); if (sErrorMessage == null || (typeof sErrorMessage == 'string' && sErrorMessage.length == 0)) sErrorMessage = lsInternalMessage; } } else { sErrorMessage = ""; } } lctrlInput.setCustomValidity((lbCheckCorrect == true) ? "" : sErrorMessage); } if ((lcrtlAlert = ((typeof IDctrWarning == 'string') ? ( (IDctrWarning.length > 0) ? document.querySelector(IDctrWarning) : null) : ((IDctrWarning != null && typeof IDctrWarning == 'object') ? IDctrWarning : null))) != null) { if (lbCheckCorrect == false && sErrorMessage != null && typeof sErrorMessage == 'string' && sErrorMessage.length > 0) { if (lcrtlAlert.style.display == "none") { lcrtlAlert.style.display = "block"; lcrtlAlert.innerHTML = sErrorMessage; } } else { if (checkIDPanel == undefined) { lcrtlAlert.style.display = "none"; lcrtlAlert.innerHTML = ""; } else { checkPanel(checkIDPanel); } } } } return lbCheckCorrect; } ////////// function validateInput(ctrlInputData, sErrorMensaje = "{title}", successFunction = undefined, ctrlShowMessage = ".alert", bcheckIfNoVisible = false, sLastErrorMessageAttribute = "LastErrorMessage") { let lbCheckCorrect = false; if ((lctrlInputData = ((typeof ctrlInputData == 'string') ? ( (ctrlInputData.length > 0) ? document.querySelector(ctrlInputData) : null) : ((ctrlInputData != null && typeof ctrlInputData == 'object') ? ctrlInputData : null))) != null && ctrlInputData.nodeName.toUpperCase() == "INPUT") { if ( bcheckIfNoVisible == true || (lctrlInputData.style.display != 'none' && lctrlInputData.style.opacity != '0' && (lctrlInputData.closest("[style*='display: none'], [style*='opacity: 0']") == null))) { let lsLastErrorMessageAttribute = lctrlInputData.getAttribute(sLastErrorMessageAttribute); let lbcheckError = (lsLastErrorMessageAttribute != null && lsLastErrorMessageAttribute.length >= 0) ?((sErrorMensaje.length > 0) ? (sErrorMensaje == lsLastErrorMessageAttribute) : true) : true; if (lbcheckError == true) { lctrlInputData.setCustomValidity(""); let lsShowMessage = ""; if(lctrlInputData.checkValidity() == true) { if (successFunction != undefined) successFunction.call(); lbCheckCorrect = true; } else { lctrlInputData.setCustomValidity((lsShowMessage = sErrorMensaje)); } lctrlInputData.setAttribute(sLastErrorMessageAttribute, lsShowMessage); if ((lcrtlShowMessage = document.querySelector(ctrlShowMessage)) != null) { let lsLastErrorTag = lcrtlShowMessage.getAttribute(sLastErrorMessageAttribute); lbcheckError = (lsLastErrorTag != null && lsLastErrorTag.length >= 0) ? (sErrorMensaje == lsLastErrorTag) : true; if (lbcheckError == true) { lcrtlShowMessage.setAttribute(sLastErrorMessageAttribute, lsShowMessage); lcrtlShowMessage.style.display = (lsShowMessage.length > 0) ? "block" : "none"; lcrtlShowMessage.innerHTML = getStringFromControl(lctrlInputData, lsShowMessage); } } } } } return lbCheckCorrect; } function getStringFromControl(ctrlSource, sStringTemplate) { if ((lctrlSource = ((typeof ctrlSource == 'string') ? ( (ctrlSource.length > 0) ? document.querySelector(ctrlSource) : null) : ((ctrlSource != null && typeof ctrlSource == 'object') ? ctrlSource : null))) != null && (typeof sStringTemplate == "string" && sStringTemplate.length > 0 && sStringTemplate.indexOf('{') >= 0)) { let lsResult = ""; for (let lsAttribute of sStringTemplate.split('}')) { if ((liPositionEnd = lsAttribute.indexOf("{")) >= 0) { lsAttributeValue = lctrlSource.getAttribute(lsAttribute.split('{')[1]); lsResult = lsResult + ((liPositionEnd == 0) ? "" : lsAttribute.substring(0, liPositionEnd)) + ((lsAttributeValue != null && lsAttributeValue.length > 0) ? lsAttributeValue : "") } else { lsResult = lsResult + lsAttribute; } } return lsResult; } else return sStringTemplate; } function getStringFromControlInPanel(sStringTemplate, IDPanelOfControl = undefined) { if (sStringTemplate != undefined && sStringTemplate != null && typeof sStringTemplate == "string" && sStringTemplate.length > 0) { if (sStringTemplate.indexOf('{') >= 0) { let lsResult = ""; if ((lctrlPanel = ((typeof IDPanelOfControl == 'string') ? ( (IDPanelOfControl.length > 0) ? document.querySelector(IDPanelOfControl) : document) : ((IDPanelOfControl != null && typeof IDPanelOfControl == 'object') ? ((["FORM", "FIELDSET", "DIV", "BODY"].includes(IDPanelOfControl.nodeName.toUpperCase())) ? IDPanelOfControl : IDPanelOfControl.closest("fieldset, form, body, .tab,.ModalPopUp")) : document))) == null) lctrlPanel = document; for (let lsControl of sStringTemplate.split('}')) { if ((liPositionEnd = lsControl.indexOf("{")) >= 0) { lsControlData = lsControl.split('{')[1]; if ((liPositionDataEnd = lsControlData.indexOf("|")) >= 0) { if (lsControlData.substring(liPositionDataEnd + 1).toLowerCase() == "text") lsValue = lctrlPanel.querySelector(lsControlData.substring(0, liPositionDataEnd)).text; else lsValue = lctrlPanel.querySelector(lsControlData.substring(0, liPositionDataEnd)).getAttribute(lsControlData.substring(liPositionDataEnd + 1)); } else { loNewControl = lctrlPanel.querySelector(lsControlData); if (loNewControl.type != undefined && loNewControl.type.toLowerCase() == "date") lsValue = loNewControl.valueAsDate.toLocaleDateString("en"); else lsValue = loNewControl.value; } lsResult = lsResult + lsControl.substring(0, liPositionEnd) + lsValue; } else { lsResult = lsResult + lsControl; } } return lsResult; } else return sStringTemplate; } else return ""; } function addRowToTable(IDTable, sHTMLRow, IDPanelOfControl = undefined, IDRequiredControls = undefined, bAddKey = true, bAddRemoveButton = false) { let lbReturn = false; if (typeof sHTMLRow == "string" && sHTMLRow.length >0) { if (IDRequiredControls == undefined || requiredControls(IDRequiredControls) == true) { if ((lctrlTable = ((typeof IDTable == 'string') ? ( (IDTable.length > 0) ? document.querySelector(IDTable) : null) : ((IDTable != null && typeof IDTable == 'object') ? IDTable : null))) != null) { let lsKey = ""; if (IDRequiredControls != undefined || bAddKey == true) { lsKey = createKey(IDRequiredControls); lsKey = (lctrlTable.querySelectorAll("tr[key='" + lsKey + "']").length == 0) ? lsKey : ""; } if (lsKey.length > 0) { lsProcessedHTMLRow = getStringFromControlInPanel(sHTMLRow, IDPanelOfControl); if (lsProcessedHTMLRow.toLowerCase().indexOf("