`];
for (a in e.roles)
if (e.roles.hasOwnProperty(a)) {
const t = `fld-${c.lastID}-roles-${a}`,
o = {
type: "checkbox",
name: "roles[]",
value: a,
id: t,
className: "roles-field"
};
s.includes(a) && (o.checked = "checked"), r.push(``)
} r.push("
");
const o = {
first: d.a.get("roles"),
second: d.a.get("limitRole"),
content: r.join("")
};
return M("access", t, o)
},
other: () => M("other", t, {
first: d.a.get("enableOther"),
second: d.a.get("enableOtherMsg")
}),
options: () => function (e) {
const {
type: t,
values: r
} = e;
let o;
const n = [O("a", d.a.get("addOption"), {
className: "add add-opt"
})],
i = [O("label", d.a.get("selectOptions"), {
className: "false-label"
})],
l = e.multiple || "checkbox-group" === t,
a = e => {
const t = d.a.get("optionCount", e);
return {
selected: !1,
label: t,
value: Object(p.n)(t)
}
};
if (r && r.length) o = r.map(e => Object.assign({}, {
selected: !1
}, e));
else {
let e = [1, 2, 3];
["checkbox-group", "checkbox"].includes(t) && (e = [1]), o = e.map(a);
const r = o[0];
r.hasOwnProperty("selected") && "radio-group" !== t && (r.selected = !0)
}
const s = O("div", n, {
className: "option-actions"
}),
c = O("ol", o.map((e, r) => {
const o = m.a.opts.onAddOption(e, {
type: t,
index: r,
isMultiple: l
});
return Y(o, l)
}), {
className: "sortable-options"
}),
u = O("div", [c, s], {
className: "sortable-options-wrap"
});
return i.push(u), O("div", i, {
className: "form-group field-options"
}).outerHTML
}(t),
requireValidOption: () => M("requireValidOption", t, {
first: " ",
second: d.a.get("requireValidOption")
}),
multiple: () => {
const e = {
default: {
first: "Multiple",
second: "set multiple attribute"
},
file: {
first: d.a.get("multipleFiles"),
second: d.a.get("allowMultipleFiles")
},
select: {
first: " ",
second: d.a.get("selectionsMessage")
}
};
return M("multiple", t, e[r] || e.default)
}
};
let a;
const s = void 0 !== t.role ? t.role.split(",") : [];
["min", "max", "step"].forEach(e => {
l[e] = () => U(e, t)
});
const u = ["name", "className"];
if (Object.keys(i).forEach(t => {
const a = i[t],
s = [!0],
c = e.disabledAttrs.includes(a);
if (e.typeUserDisabledAttrs[r]) {
const t = e.typeUserDisabledAttrs[r];
s.push(!t.includes(a))
}
if (n.definition.hasOwnProperty("defaultAttrs")) {
const e = Object.keys(n.definition.defaultAttrs);
s.push(!e.includes(a))
}
if (e.typeUserAttrs[r]) {
const t = Object.keys(e.typeUserAttrs[r]);
s.push(!t.includes(a))
}
c && !u.includes(a) && s.push(!1), s.every(Boolean) && o.push(l[a](c))
}), n.definition.hasOwnProperty("defaultAttrs")) {
const e = R(n.definition.defaultAttrs, t);
o.push(e)
}
if (e.typeUserAttrs[r]) {
const n = R(e.typeUserAttrs[r], t);
o.push(n)
}
return o.join("")
};
function B(e) {
return [
["array", ({
options: e
}) => !!e],
["boolean", ({
type: e
}) => "checkbox" === e],
[typeof e.value, () => !0]
].find(t => t[1](e))[0] || "string"
}
function F(e, t) {
return e.subtype && e.subtype === t
}
function R(e, t) {
const r = [],
o = {
array: P,
string: I,
number: U,
boolean: (e, r) => {
let o = !1;
return "checkbox" === e.type ? o = Boolean(!!r.hasOwnProperty("value") && r.value) : t.hasOwnProperty(e) ? o = t[e] : (r.hasOwnProperty("value") || r.hasOwnProperty("checked")) && (o = r.value || r.checked || !1), M(e, A(A({}, r), {}, {
[e]: o
}), {
first: r.label
})
}
};
for (const i in e)
if (e.hasOwnProperty(i)) {
const l = B(e[i]);
if ("undefined" !== l) {
const a = d.a.get(i),
s = e[i],
c = s.value || "";
s.value = t[i] || s.value || "", s.label && (n[i] = Array.isArray(s.label) ? d.a.get(...s.label) || s.label[0] : s.label), o[l] && r.push(o[l](i, s)), n[i] = a, s.value = c
} else {
if ("undefined" !== l || !F(t, i)) continue;
r.push(R(e[i], t))
}
} return r.join("")
}
function I(e, t) {
const {
class: r,
className: o
} = t, i = x(t, ["class", "className"]);
let l = {
id: e + "-" + c.lastID,
title: i.description || i.label || e.toUpperCase(),
name: e,
type: i.type || "text",
className: ["fld-" + e, (r || o || "").trim()],
value: i.value || ""
};
const a = `${a}${`
${(()=>{if("textarea"===l.type){const e=l.value;return delete l.value,`
`}function P(e,t){const{multiple:r,options:o,label:i,value:l,class:a,className:s}=t,u=x(t,["multiple","options","label","value","class","className"]),f=Object.keys(o).map(e=>{const t={value:e},r=o[e],n=Array.isArray(r)?d.a.get(...r)||r[0]:r;return(Array.isArray(l)?l.includes(e):e===l)&&(t.selected=null),O("option",n,t)}),p={id:`
$ {
e
} - $ {
c.lastID
}
`,title:u.description||i||e.toUpperCase(),name:e,className:`
fld - $ {
e
}
form - control $ {
a || s || ""
}
`.trim()};r&&(p.multiple=!0);const m=` < label
for = "${p.id}" > $ {
n[e]
} < /label>`;Object.keys(u).forEach((function(e){p[e]=u[e]}));return`
`
}
const M = (e, t, r = {}) => {
const o = t => O("label", t, {
for: `${e}-${c.lastID}`
}).outerHTML,
n = {
type: "checkbox",
className: "fld-" + e,
name: e,
id: `${e}-${c.lastID}`
};
t[e] && (n.checked = !0);
const i = [];
let l = [O("input", null, n).outerHTML];
return r.first && i.push(o(r.first)), r.second && l.push(" ", o(r.second)), r.content && l.push(r.content), l = O("div", l, {
className: "input-wrap"
}).outerHTML, O("div", i.concat(l), {
className: `form-group ${e}-wrap`
}).outerHTML
}, z = e => {
let t = "";
"undefined" === e && (e = "default");
const r = `
`;
return t += g.input({
value: e || "default",
type: "hidden",
className: "btn-style"
}).outerHTML, t += '
', m.d.btn.forEach(r => {
const o = ["btn-xs", "btn", "btn-" + r];
e === r && o.push("selected");
const n = O("button", d.a.get("styles.btn." + r), {
value: r,
type: "button",
className: o.join(" ")
}).outerHTML;
t += n
}), t += "
", t = O("div", [r, t], {
className: "form-group style-wrap"
}), t.outerHTML
}, U = (e, t) => {
const {
class: r,
className: o,
value: n
} = t, i = x(t, ["class", "className", "value"])[e] || n, l = d.a.get(e) || e, a = {
type: "number",
value: i,
name: e,
placeholder: d.a.get("placeholder." + e),
className: `fld-${e} form-control ${r||o||""}`.trim(),
id: `${e}-${c.lastID}`
}, s = g.input(Object(p.A)(a)).outerHTML;
return O("div", [`
`, `
${s}
`], {
className: `form-group ${e}-wrap`
}).outerHTML
}, H = (e, t, r) => {
const o = r.map((r, o) => {
let i = Object.assign({
label: `${n.option} ${o}`,
value: void 0
}, r);
return r.value === t[e] && (i.selected = !0), i = Object(p.A)(i), O("option", i.label, i)
}),
i = {
id: e + "-" + c.lastID,
name: e,
className: `fld-${e} form-control`
},
l = d.a.get(e) || Object(p.d)(e) || "",
a = O("label", l, {
for: i.id
}),
s = O("select", o, i),
u = O("div", s, {
className: "input-wrap"
});
return O("div", [a, u], {
className: `form-group ${i.name}-wrap`
}).outerHTML
}, Q = (t, r, o = !1) => {
const n = ["paragraph"];
let i = r[t] || "",
l = d.a.get(t);
"label" === t && (n.includes(r.type) ? l = d.a.get("content") : i = Object(p.u)(i));
const a = d.a.get("placeholders." + t) || "";
let s = "";
if (![].some(e => !0 === e)) {
const n = {
name: t,
placeholder: a,
className: `fld-${t} form-control`,
id: `${t}-${c.lastID}`
},
d = O("label", l, {
for: n.id
}).outerHTML;
"label" !== t || e.disableHTMLLabels ? (n.value = i, n.type = "text", s += `
`) : (n.contenteditable = !0, s += O("div", i, n).outerHTML);
const u = `
${s}
`;
let f = o ? "none" : "block";
"value" === t && (f = r.subtype && "quill" === r.subtype && "none"), s = O("div", [d, u], {
className: `form-group ${t}-wrap`,
style: "display: " + f
})
}
return s.outerHTML
}, V = e => {
const {
type: t
} = e, r = [];
let o = "";
return ["header", "paragraph", "button"].includes(t) && r.push(!0), r.some(e => !0 === e) || (o = M("required", e, {
first: d.a.get("required")
})), o
}, W = function (t, i = !0) {
c.lastID = g.incrementId(c.lastID);
const l = t.type || "text";
let a = t.label || (i ? n.get(l) || d.a.get("label") : "");
"hidden" === l && (a = `${d.a.get(l)}: ${t.name}`);
const s = e.disabledFieldButtons[l] || t.disabledFieldButtons;
let u = [O("a", null, {
type: "remove",
id: "del_" + c.lastID,
className: `del-button btn ${w.a}cancel delete-confirm`,
title: d.a.get("removeMessage")
}), O("a", null, {
type: "edit",
id: c.lastID + "-edit",
className: `toggle-form btn ${w.a}pencil`,
title: d.a.get("hide")
}), O("a", null, {
type: "copy",
id: c.lastID + "-copy",
className: `copy-button btn ${w.a}copy`,
title: d.a.get("copyButtonTooltip")
})];
s && Array.isArray(s) && (u = u.filter(e => !s.includes(e.type)));
const f = [O("div", u, {
className: "field-actions"
})];
f.push(O("label", Object(p.u)(a), {
className: "field-label"
})), f.push(O("span", " *", {
className: "required-asterisk",
style: t.required ? "display:inline" : ""
}));
const m = {
className: "tooltip-element",
tooltip: t.description,
style: t.description ? "display:inline-block" : "display:none"
};
f.push(O("span", "?", m)), f.push(O("div", "", {
className: "prev-holder"
}));
const h = O("div", [T(t), O("a", d.a.get("close"), {
className: "close-field"
})], {
className: "form-elements"
}),
y = O("div", h, {
id: c.lastID + "-holder",
className: "frm-holder",
dataFieldId: c.lastID
});
o.currentEditPanel = y, f.push(y);
const v = O("li", f, {
class: l + "-field form-field",
type: l,
id: c.lastID
}),
x = r(v);
x.data("fieldData", {
attrs: t
}), void 0 !== g.stopIndex ? r("> li", b.stage).eq(g.stopIndex).before(x) : q.append(x), r(".sortable-options", x).sortable({
update: () => g.updatePreview(x)
}), g.updatePreview(x), e.typeUserEvents[l] && e.typeUserEvents[l].onadd && e.typeUserEvents[l].onadd(v), i && (e.editOnAdd && (g.closeAllEdit(), g.toggleEdit(c.lastID, !1)), v.scrollIntoView && e.scrollToFieldOnAdd && v.scrollIntoView({
behavior: "smooth"
}))
}, Y = function (e, t) {
const r = {
selected: t ? "checkbox" : "radio"
},
o = {
boolean: (e, t) => {
const o = {
value: e,
type: r[t] || "checkbox"
};
return e && (o.checked = !!e), ["input", null, o]
},
number: e => ["input", null, {
value: e,
type: "number"
}],
string: (e, t) => ["input", null, {
value: e,
type: "text",
placeholder: d.a.get("placeholder." + t) || ""
}],
array: e => ["select", e.map(({
label: e,
value: t
}) => O("option", e, {
value: t
}))],
object: e => {
let {
tag: t,
content: r
} = e;
return [t, r, x(e, ["tag", "content"])]
}
};
e = A(A({}, {
selected: !1,
label: "",
value: ""
}), e);
const n = Object.entries(e).map(([e, t]) => {
const r = Object(p.k)(t),
[n, i, l] = o[r](t, e),
a = `option-${e} option-attr`;
return l["data-attr"] = e, l.className = l.className ? `${l.className} ${a}` : a, O(n, i, l)
}),
i = {
className: `remove btn ${w.a}cancel`,
title: d.a.get("removeMessage")
};
return n.push(O("a", null, i)), O("li", n).outerHTML
}, X = [".form-elements input", ".form-elements select", ".form-elements textarea"].join(", "); q.on("change blur keyup click", X, i()(e => {
if (e) {
if ([({
type: e,
target: t
}) => "keyup" === e && "className" === t.name].some(t => t(e))) return !1;
g.updatePreview(r(e.target).closest(".form-field")), g.save.call(g)
}
}, 333, {
leading: !1
})), q.on("click touchstart", ".remove", t => {
const o = r(t.target).parents(".form-field:eq(0)"),
n = o[0],
i = n.getAttribute("type"),
l = r(t.target.parentElement);
t.preventDefault();
n.querySelector(".sortable-options").childNodes.length <= 2 && !i.includes("checkbox") ? e.notify.error("Error: " + d.a.get("minOptionMessage")) : l.slideUp("250", () => {
l.remove(), g.updatePreview(o), g.save.call(g)
})
}), q.on("touchstart", "input", e => {
const t = r(this);
if (!0 === e.handled) return !1;
if ("checkbox" === t.attr("type")) t.trigger("click");
else {
t.focus();
const e = t.val();
t.val(e)
}
}), q.on("click touchstart", ".toggle-form, .close-field", (function (e) {
if (e.stopPropagation(), e.preventDefault(), !0 === e.handled) return !1; {
const t = r(e.target).parents(".form-field:eq(0)").attr("id");
g.toggleEdit(t), e.handled = !0
}
})), q.on("dblclick", "li.form-field", e => {
if (!["select", "input", "label"].includes(e.target.tagName.toLowerCase()) && "true" !== e.target.contentEditable && (e.stopPropagation(), e.preventDefault(), !0 !== e.handled)) {
const t = "li" == e.target.tagName ? r(e.target).attr("id") : r(e.target).closest("li.form-field").attr("id");
g.toggleEdit(t), e.handled = !0
}
}), q.on("change", '[name="subtype"]', e => {
const t = r(e.target).closest("li.form-field");
r(".value-wrap", t).toggle("quill" !== e.target.value)
});
if (q.on("change", [".prev-holder input", ".prev-holder select", ".prev-holder textarea"].join(", "), e => {
let t;
if (e.target.classList.contains("other-option")) return;
const r = Object(p.e)(e.target, ".form-field");
if (["select", "checkbox-group", "radio-group"].includes(r.type)) {
const o = r.getElementsByClassName("option-value");
"select" === r.type ? Object(p.i)(o, t => {
o[t].parentElement.childNodes[0].checked = e.target.value === o[t].value
}) : (t = document.getElementsByName(e.target.name), Object(p.i)(t, e => {
o[e].parentElement.childNodes[0].checked = t[e].checked
}))
} else {
const t = document.getElementById("value-" + r.id);
t && (t.value = e.target.value)
}
g.save.call(g)
}), Object(p.a)(b.stage, "keyup change", ({
target: e
}) => {
if (!e.classList.contains("fld-label")) return;
const t = e.value || e.innerHTML;
Object(p.e)(e, ".form-field").querySelector(".field-label").innerHTML = Object(p.u)(t)
}), q.on("keyup", "input.error", ({
target: e
}) => r(e).removeClass("error")), q.on("keyup", 'input[name="description"]', (function (e) {
const t = r(e.target).parents(".form-field:eq(0)"),
o = r(".tooltip-element", t),
n = r(e.target).val();
if ("" !== n)
if (o.length) o.attr("tooltip", n).css("display", "inline-block");
else {
const e = `
?`;
r(".field-label", t).after(e)
}
else o.length && o.css("display", "none")
})), q.on("change", ".fld-multiple", e => {
const t = e.target.checked ? "checkbox" : "radio",
o = r(".option-selected", r(e.target).closest(".form-elements"));
return o.each(e => o[e].type = t), t
}), q.on("blur", "input.fld-name", (function (e) {
e.target.value = Object(p.x)(e.target.value), "" === e.target.value ? r(e.target).addClass("field-error").attr("placeholder", d.a.get("cannotBeEmpty")) : r(e.target).removeClass("field-error")
})), q.on("blur", "input.fld-maxlength", e => {
e.target.value = Object(p.j)(e.target.value)
}), q.on("click touchstart", `.${w.a}copy`, (function (t) {
t.preventDefault();
const o = r(t.target).parent().parent("li"),
n = function (t) {
c.lastID = g.incrementId(c.lastID);
const o = t.attr("id"),
n = t.attr("type"),
i = n + "-" + (new Date).getTime(),
l = t.clone();
return r(".fld-name", l).val(i), l.find("[id]").each((e, t) => {
t.id = t.id.replace(o, c.lastID)
}), l.find("[for]").each((e, t) => {
const r = t.getAttribute("for").replace(o, c.lastID);
t.setAttribute("for", r)
}), l.attr("id", c.lastID), l.attr("name", i), l.addClass("cloned"), r(".sortable-options", l).sortable(), e.typeUserEvents[n] && e.typeUserEvents[n].onclone && e.typeUserEvents[n].onclone(l[0]), l
}(o);
n.insertAfter(o), g.updatePreview(n), g.save.call(g)
})), q.on("click touchstart", ".delete-confirm", t => {
t.preventDefault();
const o = t.target.getBoundingClientRect(),
n = document.body.getBoundingClientRect(),
i = {
pageX: o.left + o.width / 2,
pageY: o.top - n.top - 12
},
l = r(t.target).parents(".form-field:eq(0)").attr("id"),
a = r(document.getElementById(l));
if (document.addEventListener("modalClosed", (function () {
a.removeClass("deleting")
}), !1), e.fieldRemoveWarn) {
const e = O("h3", d.a.get("warning")),
t = O("p", d.a.get("fieldRemoveWarning"));
g.confirm([e, t], () => g.removeField(l), i), a.addClass("deleting")
} else g.removeField(l)
}), q.on("click", ".style-wrap button", e => {
const t = r(e.target),
o = t.closest(".form-elements"),
n = t.val(),
i = r(".btn-style", o);
i.val(n), t.siblings(".btn").removeClass("selected"), t.addClass("selected"), g.updatePreview(i.closest(".form-field")), g.save()
}), q.on("click", ".fld-required", e => {
r(e.target).closest(".form-field").find(".required-asterisk").toggle()
}), q.on("click", "input.fld-access", (function (e) {
const t = r(e.target).closest(".form-field").find(".available-roles"),
o = r(e.target);
t.slideToggle(250, (function () {
o.is(":checked") || r("input[type=checkbox]", t).removeAttr("checked")
}))
})), q.on("click", ".add-opt", (function (e) {
e.preventDefault();
const t = r(e.target).closest(".form-field").attr("type"),
o = r(e.target).closest(".field-options"),
n = r('[name="multiple"]', o),
i = r(".option-selected:eq(0)", o);
let l = !1;
l = n.length ? n.prop("checked") : "checkbox" === i.attr("type");
const a = r(".sortable-options", o),
s = m.a.opts.onAddOption({
selected: !1,
label: "",
value: ""
}, {
type: t,
index: a.children().length,
isMultiple: l
});
a.append(Y(s, l))
})), q.on("mouseover mouseout", ".remove, .del-button", e => r(e.target).closest("li").toggleClass("delete")), D(), e.disableInjectedStyle) {
const e = document.getElementsByClassName("formBuilder-injected-style");
Object(p.i)(e, t => Object(l.f)(e[t]))
}
return document.dispatchEvent(u.a.loaded), o.actions = {
getFieldTypes: t => t ? Object(p.y)(j.getRegistered(), e.disableFields) : j.getRegistered(),
clearFields: e => g.removeAllFields(b.stage, e),
showData: g.showData.bind(g),
save: e => {
const t = g.save(e),
r = window.JSON.parse(t);
return m.a.opts.onSave(r), r
},
addField: (e, t) => {
g.stopIndex = c.formData.length ? t : void 0, L(e)
},
removeField: g.removeField.bind(g),
getData: g.getFormData.bind(g),
setData: e => {
g.stopIndex = void 0, g.removeAllFields(b.stage, !1), D(e)
},
setLang: e => {
d.a.setCurrent.call(d.a, e).then(() => {
b.stage.dataset.content = d.a.get("getStarted"), j.init(), b.empty(b.formActions), g.formActionButtons().forEach(e => b.formActions.appendChild(e))
})
},
showDialog: g.dialog.bind(g),
toggleFieldEdit: e => {
(Array.isArray(e) ? e : [e]).forEach(e => {
["number", "string"].includes(typeof e) && ("number" == typeof e ? e = b.stage.children[e].id : /^frmb-/.test(e) || (e = b.stage.querySelector(e).id), g.toggleEdit(e))
})
},
toggleAllFieldEdit: () => {
Object(p.i)(b.stage.children, e => {
g.toggleEdit(b.stage.children[e].id)
})
},
closeAllFieldEdit: g.closeAllEdit.bind(g),
getCurrentFieldId: () => c.lastID
}, b.onRender(b.controls, () => {
const t = setTimeout(() => {
b.stage.style.minHeight = b.controls.clientHeight + "px", e.stickyControls.enable && g.stickyControls(q), clearTimeout(t)
}, 0)
}), o
}, q = {
init: (e, t) => {
const r = jQuery.extend({}, m.c, e, !0),
{
i18n: o
} = r,
n = x(r, ["i18n"]);
m.a.opts = n;
const i = jQuery.extend({}, m.b, o, !0);
return q.instance = {
actions: {
getFieldTypes: null,
addField: null,
clearFields: null,
closeAllFieldEdit: null,
getData: null,
removeField: null,
save: null,
setData: null,
setLang: null,
showData: null,
showDialog: null,
toggleAllFieldEdit: null,
toggleFieldEdit: null,
getCurrentFieldId: null
},
markup: p.q,
get formData() {
return q.instance.actions.getData && q.instance.actions.getData("json")
},
promise: new Promise((function (e, r) {
d.a.init(i).then(() => {
t.each(e => {
const r = new k(n, t[e], jQuery);
jQuery(t[e]).data("formBuilder", r), Object.assign(q, r.actions, {
markup: p.q
}), q.instance.actions = r.actions
}), delete q.instance.promise, e(q.instance)
}).catch(e => {
r(e), n.notify.error(e)
})
}))
}, q.instance
}
};
jQuery.fn.formBuilder = function (e = {}, ...t) {
if (!("string" == typeof e)) {
const t = q.init(e, this);
return Object.assign(q, t), t
}
if (q[e]) return "function" == typeof q[e] ? q[e].apply(this, t) : q[e]
}
}])
}(jQuery);