function Wiz(query) { return wizForms.getFieldByFieldID(query); } const wizForms = { getFieldByFieldID(fieldid) { var fieldIDs = []; var jQueryObjects = wizForms.getFieldsjQueryObjectsByFieldID(fieldid); $.each(jQueryObjects, function (i, currentObject) { fieldIDs.push(wizForms.jQueryObjectToWizObject(currentObject, fieldid)); }); if (fieldIDs.length > 1) return fieldIDs; else return fieldIDs[0]; }, jQueryObjectToWizObject(jQueryObject, fieldid) { var fieldType = wizForms.getFieldIDTypeByjQueryObject($(jQueryObject)); return { jQueryFieldObject: $(jQueryObject), fieldID: fieldid, type: fieldType, setValue(value) { wizForms.setFieldValueByType(this, value); }, getValue() { return wizForms.getFieldValueByType(this); }, getTextValue() { return wizForms.getFieldTextValueByType(this); }, hide() { if(fieldType == "multiFileUpload"){ $(jQueryObject).parent().parent().css("display", "none"); } else if ($(jQueryObject).hasClass("checkBoxtitle")) { $(jQueryObject).css("display", "none"); } else { $(jQueryObject).parent().css("display", "none"); } }, show() { if(fieldType == "multiFileUpload"){ $(jQueryObject).parent().parent().css("display", "inline-block"); } else if ($(jQueryObject).hasClass("checkBoxtitle")) { $(jQueryObject).css("display", "inline-block"); } else { $(jQueryObject).parent().css("display", "inline-block"); } }, setErrorMessage(errMsg) { $(jQueryObject).parent().find(".validError").text(errMsg); }, on(onType,onFunction){ switch(fieldType){ case "select": $(jQueryObject).find("select").on(onType,onFunction); break; case "textBox": $(jQueryObject).find("input").on(onType,onFunction); break; case "radio": $(jQueryObject).find("input").on(onType,onFunction); break; case "datePicker": $(jQueryObject).find("input").on(onType,onFunction); break; case "checkBox": $(jQueryObject).find("input").on(onType,onFunction); break; } }, getDateObject(){ return wizForms.StringHebrewDateConvertToDateObject(wizForms.getFieldValueByType(this)); }, getFiles(){ return wizForms.getFilesAmount(fieldid); } } }, getFilesAmount(fieldid){ let files = []; let currentFilesArray; wizForms.getFieldsjQueryObjectsByFieldID(fieldid).parent().find(".mu_wrap_upload input").each(function(){ currentFilesArray=$(this)[0].files; for(let i=0;i 0) hideNestedFields(child) hideElems(child.fieldid) } } }, getFieldValueByType(wizObject) { switch (wizObject.type) { case "textBox": return wizObject.jQueryFieldObject.find("input").val(); case "select": return wizObject.jQueryFieldObject.find("select :selected").val(); case "textArea": return wizObject.jQueryFieldObject.find("textArea").val(); case "checkBox": var selectOptions = []; var options = $(wizObject.jQueryFieldObject.find(`input:checked`)); $.each(options, function (i, currentOption) { selectOptions.push(currentOption.value); }) return selectOptions; case "radio": return $(wizObject.jQueryFieldObject).find(`input:checked`).val(); case "datePicker": return wizObject.jQueryFieldObject.find("input").val(); } }, getFieldTextValueByType(wizObject) { switch (wizObject.type) { case "textBox": return wizObject.jQueryFieldObject.find("input").text(); case "select": return wizObject.jQueryFieldObject.find("select :selected").text(); case "textArea": return wizObject.jQueryFieldObject.find("textArea").text(); } }, getFieldIDTypeByjQueryObject(jQueryObject) { // jQueryObject=$(jQueryObject); if (jQueryObject.hasClass("textBox")) { return "textBox"; } if (jQueryObject.hasClass("textDate")) { return "datePicker"; } if (jQueryObject.hasClass("textRadio")) { return "radio"; } if (jQueryObject.children().hasClass("checkBoxtitle")) { return "checkBox"; } if (jQueryObject.hasClass("textSelect")) { return "select"; } if (jQueryObject.hasClass("textArea")) { return "textArea"; } if (jQueryObject.hasClass("headlineTitle")) { return "title"; } if (jQueryObject.parent().find(".mu_wrap_upload").length>0) { return "multiFileUpload"; } }, getFieldsjQueryObjectsByFieldID(fieldid) { var currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textBox`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textDate`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textRadio`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textTitle`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textSelect`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textArea`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .headlineTitle`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}']`); if (currentFields.length >= 1) return currentFields; else return null; }, //#region MandatoryFields loadMandatoryFieldCheckup() { wizForms.addStarToMandatoryFields(); wizForms.changeNextBTNToDiv(); wizForms.changeNextBTNOnClickToCheckMandatoryFields(); }, addStarToMandatoryFields() { let currentField; $(`.mandatory`).each(function () { if($(this).attr("fieldid")!=undefined){ currentField = Wiz($(this).attr("fieldid")); }else{ currentField = Wiz($($(this).children()[0]).attr("fieldid")); } if(currentField.type!="multiFileUpload"){ $(this).find("[class*='Title']:not('[for]')").prepend(`*`); } else{ $(this).find(".textTitle").prepend(`*`); } }); }, changeNextBTNOnClickToCheckMandatoryFields() { let currentOnClick = ""; $(".nextBTN").each(function () { currentOnClick = $(this).attr("onclick").replace(";return false;", ""); if (currentOnClick.includes('checkMandatoryFields()') != true) { $(this).attr("onclick", `wizForms.checkMandatoryFields( "${currentOnClick}" )`); } }); }, changeNextBTNToDiv() { $(".nextBTN").each(function () { wizForms.changeElementType("nextBTN", "div") }); }, checkMandatoryFields(onSuccessFunction) { let currentFieldID = ""; let currentField; let allMandatoryFieldsFilled = true; //mandatory for normal fields $(`[id='page${currentPage}'] .mandatory`).not("[style*='display: none;']").each(function () { if($(this).attr("fieldid")!=undefined){ currentFieldID = $(this).attr("fieldid"); currentField = Wiz(currentFieldID); if(currentField.type!="multiFileUpload"){ if (currentField.getValue() == undefined || currentField.getValue().length <= 0) { currentField.setErrorMessage("זהו שדה חובה"); allMandatoryFieldsFilled = false; } } } }); //mandatory for multiUploadFiles fields $(`[id='page${currentPage}'] .mandatory`).not("[style*='display: none;']").find("[fieldid]").find(".mu_wrap_upload").each(function () { currentFieldID = $(this).parent().attr("fieldid"); currentField = Wiz(currentFieldID); if(currentField.type == "multiFileUpload" ){ if(currentField.getFiles().length<=0){ currentField.setErrorMessage("זהו שדה חובה"); allMandatoryFieldsFilled = false; } } //else if (currentField.getValue() == undefined || currentField.getValue().length <= 0) { // currentField.setErrorMessage("זהו שדה חובה"); //allMandatoryFieldsFilled = false; // } }); if (allMandatoryFieldsFilled == true) { eval(onSuccessFunction); } }, changeElementType(classTo, transformTo) { var attrs = {}; $.each($(`.${classTo}`)[0].attributes, function (idx, attr) { attrs[attr.nodeName] = attr.nodeValue; }); $(`.${classTo}`).replaceWith(function () { return $(`<${transformTo}/>`, attrs).append($(this).contents()); }); }, //#endregion //#region LimitFileUploads, limitFileUploads() { wizForms.checkFilesOnUpload(); wizForms.checkFilesOnRemove(); wizForms.displayUploadStats(); }, limitUploadSettings: { "allowedFileTypes": ["jpeg", "jpg", "png", "docx", "tif", "tiff", "bmp", "pdf", "pptx"], "maxMBAllowed": 10, "maxFilesAllowed": 10, uploadInfomration: { "currentFilesAmount": 0, "currentMBUploaded": 0 }, "reachedMaxFilesMessage": "שים לב! גודל הקבצים המצורפים עולה מגבלת הכמות של 10 קבצים ולכן לא ניתן לשלוח את הטופס", "reachedMaxMBMessage": "שים לב! גודל הקבצים המצורפים עולה על 10MB לכן לא ניתן לשלוח את הטופס", "bannedFileTypeMBMessage": "ניתן לצרף רק קבצים בפורמטים הבאים: .jpg .jpeg .pdf .doc .docx .png .tiff .bmp" }, checkFilesOnUpload() { var uploadFields = $("[fieldid*='upload']"); var currentSize = 0; var totalSize = 0; $(uploadFields).each(function () { $(this).find("input").attr("onChange", ""); $(this).on("change", function () { var validFileType = false; var file = $(this)[0].files; if (file.length > 0 && file != undefined) { var fileName = file[0].name; var fileExtension = fileName.split(".").pop().toLowerCase(); let fileSizeInMB = (file[0].size) / (1024 * 1024); totalSize = 0; currentSize = 0; if ((fileSizeInMB + wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded) > wizForms.limitUploadSettings.maxMBAllowed) { alert(wizForms.limitUploadSettings.reachedMaxMBMessage); $(this).val("") return; } for (let i = 0; i < wizForms.limitUploadSettings.allowedFileTypes.length; i++) { if (fileExtension == wizForms.limitUploadSettings.allowedFileTypes[i]) { validFileType = true; } } if (validFileType == true) { addMultiFile(this); for (var i = 0; i < this.files.length; i++) { currentSize = this.files[i].size; currentSize /= 1024 * 1024; totalSize += currentSize; wizForms.limitUploadSettings.uploadInfomration.currentFilesAmount++; } wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded += totalSize; wizForms.checkFilesOnRemove(); wizForms.checkLimits(); wizForms.displayUploadStats(); } else { alert(wizForms.limitUploadSettings.bannedFileTypeMBMessage); $(this).val("") } } }); }); }, checkFilesOnRemove() { var uploadedFiles = $("[id^='upload_prev']"); var currentSize = 0; $(uploadedFiles).each(function () { $(this).children().each(function () { var currnetButton = $(this).find("input"); $(currnetButton).attr("onclick", ""); $(currnetButton).unbind(); $(currnetButton).on("click", function () { var currentInputId = $(this).parent().attr("name"); currentSize = $("#" + currentInputId)[0].files[0].size; currentSize /= 1024 * 1024; wizForms.limitUploadSettings.uploadInfomration.currentFilesAmount--; wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded -= currentSize; wizForms.checkLimits(); removeFile(this) wizForms.displayUploadStats(); }); }) }); }, checkLimits() { var disableUpload = false; console.log(wizForms.limitUploadSettings.uploadInfomration); if (wizForms.limitUploadSettings.uploadInfomration.currentFilesAmount >= wizForms.limitUploadSettings.maxFilesAllowed || wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded >= wizForms.limitUploadSettings.maxMBAllowed) { setTimeout(function () { $("[id^='fileToUpload']").attr("disabled", "true"); if (currentPage >= $("[id^='page']").length) { $("#finishForm").hide(); } }, 100); if (wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded >= wizForms.limitUploadSettings.maxMBAllowed) { alert(wizForms.limitUploadSettings.reachedMaxMBMessage); } } else { setTimeout(function () { $("[id^='fileToUpload']").removeAttr("disabled"); if (currentPage >= $("[id^='page']").length) { $("#finishForm").show(); } }, 100); } }, displayUploadStats() { $("[fieldid='upSummary']").html(`
כמות טפסים מצורפים היא ${wizForms.limitUploadSettings.uploadInfomration.currentFilesAmount}
גודל קבצים מצורפים: MB ${wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded.toFixed(2)}
`); }, //#endregion //#region RenderTable loadTable(textFieldid, table, usingHeaders) { let idsToAppendFields = []; let htmlTable = ``; let currentFieldSection; let startingTableRow = 1; if (usingHeaders != false) { htmlTable += ` `; for (let i = 0; i < table[0].length; i++) { htmlTable += `` } htmlTable += ` `; } else { startingTableRow = 0; } for (let j = startingTableRow; j < table.length; j++) { htmlTable += ` `; for (let z = 0; z < table[j].length; z++) { if (z <= 0) { htmlTable += ``; } else { htmlTable += ``; idsToAppendFields.push({ fieldID: table[j][z], ID: `#${textFieldid}_${j}_${z}` }) } } htmlTable += ` `; } htmlTable += `
${table[0][i]}
${table[j][z]}
`; wizForms.getFieldsjQueryObjectsByFieldID(textFieldid).append(htmlTable); for (let w = 0; w < idsToAppendFields.length; w++) { let fieldSection = wizForms.getFieldsjQueryObjectsByFieldID(idsToAppendFields[w].fieldID); if (fieldSection != undefined) { fieldSection.parent().find("span").hide() currentFieldSection = fieldSection.parent().parent(); currentFieldSection.appendTo(idsToAppendFields[w].ID); } } }, //#endregion //#region FieldIDsTreeLogic loadFieldIDsTreeLogic(logic){ for(let i=0;i": if(currentFieldID.type=="datePicker"){ if (currentFieldID.getDateObject() > nodeDateObject) { actionState = true; } else { actionState = false; } } else{ if (currentFieldID.getValue() > currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } break; case "<": if(currentFieldID.type=="datePicker"){ if (currentFieldID.getDateObject() < nodeDateObject) { actionState = true; } else { actionState = false; } } else{ if (currentFieldID.getValue() < currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } break; case "<=": if(currentFieldID.type=="datePicker"){ if (currentFieldID.getDateObject() <= nodeDateObject) { actionState = true; } else { actionState = false; } } else{ if (currentFieldID.getValue() <= currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } break; case ">=": if(currentFieldID.type=="datePicker"){ if (currentFieldID.getDateObject() >= nodeDateObject) { actionState = true; } else { actionState = false; } } else{ if (currentFieldID.getValue() >= currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } break; } } else{ if(currentFieldID.type != "checkBox"){ if (currentFieldID.getValue() == currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } else{ if(currentFieldID.getValue().length>0){ for(let g=0;g0){ wizForms.loadFieldIDsTreeLogicNodes(currentActionFieldID); } } } } break; case "function": if(actionState!=false){ let currentActionFieldID = currentNode.actions[i]; eval(currentActionFieldID.function); if(currentActionFieldID.actions!=undefined){ if(currentActionFieldID.actions.length>0){ wizForms.loadFieldIDsTreeLogic(currentActionFieldID); } } } break; } } }, hideAllHideActionFields(currentNode){ for (let i = 0; i < currentNode.actions.length; i++) { switch (currentNode.actions[i].actionType) { case "hide": for (let j = 0; j < currentNode.actions[i].fieldIDs.length; j++) { let currentActionFieldID = currentNode.actions[i].fieldIDs[j]; Wiz(currentActionFieldID.fieldID).hide(); if(currentActionFieldID.actions!=undefined){ if(currentActionFieldID.actions.length>0){ wizForms.hideAllHideActionFields(currentActionFieldID); } } } break; case "show": for (let j = 0; j < currentNode.actions[i].fieldIDs.length; j++) { let currentActionFieldID = currentNode.actions[i].fieldIDs[j]; Wiz(currentActionFieldID.fieldID).hide(); if(currentActionFieldID.actions!=undefined){ if(currentActionFieldID.actions.length>0){ wizForms.hideAllHideActionFields(currentActionFieldID); } } } break; } } }, StringHebrewDateConvertToDateObject(inputDate) { const parts = inputDate.split('/'); if (parts.length === 3) { const swappedDate = `${parts[1]}/${parts[0]}/${parts[2]}`; return new Date(swappedDate); } else { return null; // Invalid input format } } //#endregion } class RootField { constructor(fieldid, children) { this.fieldid = fieldid; this.children = children; } } class Field extends RootField { constructor(fieldid, children, fatherValueToShow) { super(fieldid, children) } }