`;
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 < logic.length; i++) {
wizForms.hideAllHideActionFields(logic[i]);
wizForms.loadFieldIDsTreeLogicNodes(logic[i]);
}
},
loadFieldIDsTreeLogicNodes(logicNode) {
let currentFieldID = Wiz(logicNode.fieldID);
// if (logic.index != undefined) {
// currentFieldID.on("change", function (currentFieldID) {
// if (currentFieldID.getValue() == logic.triggerValue){
// triggerTreeNodeActions(actions)
// }
// });
// }
// for (let i = 0; i < logic.actions.length; i++) {
currentFieldID.on("change", function () {
wizForms.triggerTreeNodeActions(currentFieldID, logicNode);
});
// }
},
triggerTreeNodeActions(currentFieldID, currentNode) {
let actionState = true;
let nodeDateObject;
for (let i = 0; i < currentNode.actions.length; i++) {
if (currentFieldID.type == "datePicker" && currentFieldID.getValue().length <= 0) {
continue;
}
if (currentNode.actions[i].condition != undefined) {
nodeDateObject = wizForms.StringHebrewDateConvertToDateObject(currentNode.actions[i].onValue);
switch (currentNode.actions[i].condition) {
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;
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; g < currentFieldID.getValue().length; g++) {
if (currentFieldID.getValue()[g] != currentNode.actions[i].onValue) {
actionState = false;
}
else {
actionState = true;
break;
}
}
} else {
actionState = false;
}
}
}
switch (currentNode.actions[i].actionType) {
case "show":
if (currentNode.actions[i].fieldIDs != undefined) {
for (let j = 0; j < currentNode.actions[i].fieldIDs.length; j++) {
let currentActionFieldID = currentNode.actions[i].fieldIDs[j];
if (actionState != false) {
Wiz(currentActionFieldID.fieldID).show();
}
else {
Wiz(currentActionFieldID.fieldID).setValue("");
Wiz(currentActionFieldID.fieldID).hide();
}
if (currentActionFieldID.actions != undefined) {
wizForms.loadFieldIDsTreeLogicNodes(currentActionFieldID);
}
}
}
break;
case "hide":
if (currentNode.actions[i].fieldIDs != undefined) {
for (let j = 0; j < currentNode.actions[i].fieldIDs.length; j++) {
let currentActionFieldID = currentNode.actions[i].fieldIDs[j];
if (actionState != false) {
Wiz(currentActionFieldID.fieldID).hide();
Wiz(currentActionFieldID.fieldID).setValue("");
}
else {
Wiz(currentActionFieldID.fieldID).show();
}
if (currentActionFieldID.actions != undefined) {
if (currentActionFieldID.actions.length > 0) {
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
}
},
setCustomFooter(...logoLinks) {
/*
Creates a "פותח על ידי שחר" footer at the bottom of the form with custom links. The function can take any amount of links and will
place them in the following fashion:
From right to left and splitting the amount of logos in half on each side
*/
const upperView = $(".upperView")
// Calculate the number of logo links
const numLinks = logoLinks.length;
// Calculate the number of links to be placed before and after the text
const linksBeforeText = Math.floor(numLinks / 2);
const beforeText = logoLinks.slice(0, linksBeforeText).map(link => ``).join('');
const afterText = logoLinks.slice(linksBeforeText).map(link => ``).join('');
const footer = `
${beforeText}
פותח על ידי יחידת שחר
${afterText}
`;
// Append the footer to the upperView
upperView.append(footer);
},
setFooter() {
/*
Sets default "פותח על ידי שחר" logo at the bottom of the form
*/
const upperView = $(".upperView")
const footer = `
פותח על ידי יחידת שחר
`
upperView.append(footer)
},
setCustomHeader(position, ...logoLinks) {
/*
position (param) values:
1. center
2. flex-end
3. flex-start
4. space-around
5. space-between
6. space-evenly
*/
const validPositions = ["center", "flex-end", "flex-start", "space-around", "space-between", "space-evenly"];
const formHeader = $('.formHeader')
const header = logoLinks.map(link => ``).join('');
formHeader.empty()
formHeader.html(header)
if (validPositions.includes(position)) {
// Set the justify-content property based on the chosen position
formHeader.css("justify-content", position);
} else {
// If an invalid position is provided, keep the default justify-content: center
formHeader.css("justify-content", "center");
}
},
setHeader() {
const formHeader = $('.formHeader')
const header = `
`
formHeader.empty()
formHeader.html(header)
},
loadNumericFields() {
/*
Dynamically adds a comma after every 3 digits in the input field. Must have class numeric for the function to work
*/
const numericFields = $('.numeric .textBox input');
numericFields.each(function () {
$(this).on('input', setNumeric);
});
function setNumeric() {
/*
Adds a comma after every 3 digits
*/
var inputValue = $(this).val();
// Remove any existing commas and non-digit characters
var numericValue = inputValue.replace(/[^0-9]/g, '');
// Add commas after every 3 digits
var formattedValue = numericValue.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
$(this).val(formattedValue);
}
},
loadPhoneNumberFields() {
/*
Adds a dash after the first 3 and first 6 digits of a phone number. Must have class 'phone' for the function to work
*/
const phoneFields = $('.phone .textBox input');
phoneFields.each(function () {
$(this).on('input', setPhoneNumber);
});
function setPhoneNumber() {
var inputValue = $(this).val();
var numericValue = inputValue.replace(/[^0-9]/g, '');
var formattedValue = formatAsPhoneNumber(numericValue);
$(this).val(formattedValue);
}
function formatAsPhoneNumber(value) {
if (value.length > 6) {
return value.replace(/(\d{3})(\d{3})(\d{1,4})/, '$1-$2-$3');
} else if (value.length > 3) {
return value.replace(/(\d{3})(\d{1,3})/, '$1-$2');
} else {
return value;
}
}
},
loadNativeDateFields() {
const dateFields = $('.date .textDate input')
const dateTimeFields = $('.datetime .textDate input')
dateFields.each(function () {
replaceDate($(this), 'date');
});
dateTimeFields.each(function () {
replaceDate($(this), 'datetime-local');
});
function replaceDate(elem, type) {
// Create a new input element with updated properties
var newInput = $('', {
'tabindex': elem.attr('tabindex'),
'type': type,
'use': elem.attr('use'),
'id': elem.attr('id'),
'mandatory': elem.attr('mandatory'),
'pdf': elem.attr('pdf'),
'validtype': elem.attr('validtype'),
'validationdata': elem.attr('validationdata'),
'aria-describedby': elem.attr('aria-describedby'),
'fieldid': elem.attr('fieldid'),
'mandatoryoriginalvalue': elem.attr('mandatoryoriginalvalue'),
// Add any other attributes you need to copy
});
// Replace the original input element with the new one
elem.replaceWith(newInput);
}
},
setFieldClass() {
/*
Gives each wiz fields outter div a class and stops on fields with class spacing
Example (Before calling the function):
(After calling the function):
*/
const allWizFields = $('[id^="elemID"]:not([id^="elemIDerr"])').toArray();
for (const field of allWizFields) {
var id = $(field).attr('id')
var type = getFieldType(id)
// Assign type to div
var div;
if (type == "multiFileUpload") {
div = $(field).parent().parent()
}
else {
div = $(field).parent()
}
$(div).addClass(type);
if (type == "checkbox") {
$(field).css('display', '');
}
}
function getFieldType(id) {
var field = $('#' + id)
var children = field.children().toArray()
var type = "noType"
for (var child of children) {
child = $(child)
if (child.hasClass("headlineTitleBig") || child.hasClass("headlineTitle"))
type = "title"
else if (child.hasClass("textBox")) // Add option for השלמה אוטומטית
type = "basic"
else if (child.hasClass("textSelect"))
type = "dropdown"
else if (child.hasClass("textTitle"))
type = "text"
else if (child.hasClass("checkBoxtitle"))
type = "checkbox"
else if (child.hasClass("textRadio"))
type = "radiobutton"
else if (child.hasClass("mu_wrap_upload"))
type = "multiFileUpload"
else if (child.hasClass("fileUpload"))
type = "uploadFile"
else if (child.hasClass("textArea"))
type = "textArea"
else if (child.hasClass("dateSubTitle"))
type = "date"
else if (child.hasClass("timeSubTitle"))
type = "time"
else if (child.hasClass("signatureTextTitle"))
type = "signature"
}
return type
}
},
/* function showDropDownValues(values, fieldid) {
// Hides all dropdown options in values array [string] from being chosen
const field = Wiz(fieldid)
// const dropdownOptions = field.getOptions();
var dropdownOptions = $(`[fieldid="${fieldid}"] .textSelect select option`).toArray() // Shift is to keep "בחירה" option
dropdownOptions.shift()
for (const option of dropdownOptions) {
if (!values.includes(option.text)){
$(option).css('display', 'none');
$(option).addClass("hidden");
}
}
}
function showAllDropDownValues(fieldid) {
// Shows all dropdown options (used to reset the options hidden after calling showAllDropDownValues() function)
const field = Wiz(fieldid)
// const dropdownOptions = field.getOptions();
var dropdownOptions = $(`[fieldid="${fieldid}"] .textSelect select option`).toArray() // Shift is to keep "בחירה" option
dropdownOptions
for (const option of dropdownOptions) {
$(option).css('display', 'block')
$(option).removeClass("hidden")
}
}*/
disable(fieldid) {
Wiz(fieldid).jQueryFieldObject.find('select').attr('disabled', true);
},
enable(fieldid) {
Wiz(fieldid).jQueryFieldObject.find('select').attr('disabled', false);
},
executeAfterHttpRequest (urlmatch, callback) {
let send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function() {
this.addEventListener('readystatechange', function() {
if (this.responseURL.includes(urlmatch) && this.readyState === 4 && this.status === 200) {
setTimeout(() => {
callback(this);
});
}
}, false);
send.apply(this, arguments);
};
},
preFillResponseToJson(request) {
return JSON.parse(JSON.parse(request.response).d)
},
populateFields(fields) {
if (!fields) return;
Object.keys(fields).forEach(key => {
const element = $(`[fieldid='${key}'] .textBox input`);
if (element) {
element.val(fields[key]);
}
})
},
}
//#endregion
class RootField {
constructor(fieldid, children) {
this.fieldid = fieldid;
this.children = children;
}
}
class Field extends RootField {
constructor(fieldid, children, fatherValueToShow) {
super(fieldid, children)
}
}