zet-lib 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/zRoute.js +81 -31
- package/package.json +1 -1
package/lib/zRoute.js
CHANGED
|
@@ -4801,6 +4801,29 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4801
4801
|
let relationsWithKeys = relations ? relations[keys] : {};
|
|
4802
4802
|
let dropdownMultis = [];
|
|
4803
4803
|
|
|
4804
|
+
scriptForm += `function sanitizeUndefinedAttributes($scope) {
|
|
4805
|
+
$scope = $scope || $(document);
|
|
4806
|
+
$scope.find("input, textarea, select").each(function () {
|
|
4807
|
+
const $el = $(this);
|
|
4808
|
+
const badString = (x) =>
|
|
4809
|
+
typeof x === "string" && (x.trim().toLowerCase() === "undefined" || x.trim().toLowerCase() === "null");
|
|
4810
|
+
|
|
4811
|
+
// Only act if the attribute EXISTS and is an actual "undefined"/"null" string.
|
|
4812
|
+
// Many elements legitimately have no "value" attribute (e.g. textarea uses textContent).
|
|
4813
|
+
const hasValueAttr = $el[0] && $el[0].hasAttribute && $el[0].hasAttribute("value");
|
|
4814
|
+
const attrValue = hasValueAttr ? $el.attr("value") : null;
|
|
4815
|
+
if (hasValueAttr && badString(attrValue)) {
|
|
4816
|
+
$el.removeAttr("value");
|
|
4817
|
+
if ($el.is("input,textarea")) $el.val("");
|
|
4818
|
+
}
|
|
4819
|
+
|
|
4820
|
+
const dataT = $el.attr("data-t");
|
|
4821
|
+
if (badString(dataT)) {
|
|
4822
|
+
$el.removeAttr("data-t");
|
|
4823
|
+
}
|
|
4824
|
+
});
|
|
4825
|
+
}${Util.newLine}`
|
|
4826
|
+
|
|
4804
4827
|
for (let qq in MODEL_TABLE.widgets) {
|
|
4805
4828
|
//check if have dropdown_multi
|
|
4806
4829
|
if (MODEL_TABLE.widgets[qq].name == "dropdown_multi") {
|
|
@@ -4869,56 +4892,83 @@ $("#body-${keys}>tr").each(function (index, tr) {
|
|
|
4869
4892
|
|
|
4870
4893
|
}); ${Util.newLine}};${Util.newLine}`;
|
|
4871
4894
|
|
|
4872
|
-
scriptForm += `
|
|
4895
|
+
scriptForm += `
|
|
4896
|
+
$('#add${keys}').on('click',function(){
|
|
4873
4897
|
append${keys}(append${keys}Max, (data) => $('#body-${keys}').append(data));
|
|
4874
4898
|
append${keys}Max++;
|
|
4875
4899
|
${keys}Handler();
|
|
4900
|
+
sanitizeUndefinedAttributes($("#body-${keys}"));
|
|
4876
4901
|
}); ${Util.newLine}`;
|
|
4877
4902
|
scriptForm += `function set${keys}value(index,myobj) {
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4903
|
+
for(var key in myobj){
|
|
4904
|
+
const $el = $(".${subname}_" + key).eq(index);
|
|
4905
|
+
let v = myobj[key];
|
|
4906
|
+
if (
|
|
4907
|
+
v === undefined ||
|
|
4908
|
+
v === null ||
|
|
4909
|
+
(typeof v === "string" && (v.trim().toLowerCase() === "undefined" || v.trim().toLowerCase() === "null"))
|
|
4910
|
+
) {
|
|
4911
|
+
v = "";
|
|
4912
|
+
}
|
|
4913
|
+
const setInputValue = (val) => {
|
|
4914
|
+
const next = val ?? "";
|
|
4915
|
+
$el.val(next);
|
|
4916
|
+
if (next === "") {
|
|
4917
|
+
$el.removeAttr("value");
|
|
4918
|
+
$el.removeAttr("data-t");
|
|
4919
|
+
} else {
|
|
4920
|
+
$el.attr("value", next);
|
|
4921
|
+
$el.attr("data-t", next);
|
|
4922
|
+
}
|
|
4923
|
+
};
|
|
4924
|
+
|
|
4925
|
+
if ($el.attr("type") == "checkbox") {
|
|
4926
|
+
const checked = v == 1 || v === true || v === "1" || v === "true";
|
|
4927
|
+
$el.prop("checked", checked);
|
|
4928
|
+
setInputValue(checked ? 1 : "");
|
|
4929
|
+
} else if ($(".${subname}_" + key).eq(index).attr("type") == "file") {
|
|
4930
|
+
var myimg = v ? v : '';
|
|
4931
|
+
var pathName = "/uploads/${MYMODEL.table}/${keys}/";
|
|
4932
|
+
if (myimg) {
|
|
4933
|
+
var filename = filenamex = pathName + myimg;
|
|
4934
|
+
if (!myimg.match(/\\.(jpg|jpeg|png|gif|svg|jiff|avif)$/i)) {
|
|
4935
|
+
filename = "/img/file.png";
|
|
4936
|
+
}
|
|
4937
|
+
$(".${subname}_" + key).eq(index).closest("TD").find("img").attr("src", filename).addClass("boxy");
|
|
4938
|
+
$(".${subname}_" + key).eq(index).closest("TD").append('<a href="' + filenamex + '" target="_blank" style="font-size: 12px">' + myimg + '</a>');
|
|
4939
|
+
}
|
|
4940
|
+
} else if ($(".${subname}_" + key).eq(index).hasClass("dropdown-multi")) {
|
|
4941
|
+
var dropdownsData = '';
|
|
4942
|
+
var mydropdowns = myobj[key] || [];
|
|
4943
|
+
mydropdowns.map((item, i) => {
|
|
4944
|
+
var text = ${dropdownMultis[0]}Object[item];
|
|
4945
|
+
dropdownsData += "<span class='span"+key+"' > "+(i+1)+". <input type='hidden' name='${MYMODEL.table}[${keys}]["+index+"]["+key+"]["+i+"]' value='"+item+"' /> " + text +" <img class='tabler-icons icons-filter-danger pull-right' src='/assets/icons/trash-filled.svg' onclick='$(this).closest(\`span\`).remove();' title='Delete' /> <br></span>";
|
|
4946
|
+
});
|
|
4947
|
+
$(".${subname}_" + key).eq(index).closest("TD").find("#dropdownboxparameter_income").html(dropdownsData);
|
|
4948
|
+
} else {
|
|
4949
|
+
setInputValue(v);
|
|
4907
4950
|
}
|
|
4951
|
+
|
|
4952
|
+
}
|
|
4953
|
+
}
|
|
4908
4954
|
`;
|
|
4909
4955
|
|
|
4910
4956
|
scriptForm += `function build${keys}form(index, myobj) {
|
|
4911
4957
|
append${keys}(index, (data) => {
|
|
4912
4958
|
$("#body-${keys}").append(data);
|
|
4913
4959
|
${keys}Handler();
|
|
4960
|
+
sanitizeUndefinedAttributes($("#body-${keys}"));
|
|
4914
4961
|
setTimeout(function () {
|
|
4915
4962
|
set${keys}value(index,myobj);
|
|
4963
|
+
sanitizeUndefinedAttributes($("#body-${keys}"));
|
|
4916
4964
|
},500);
|
|
4917
4965
|
append${keys}Max = index + 1;
|
|
4918
4966
|
});
|
|
4919
4967
|
}
|
|
4920
4968
|
`;
|
|
4921
4969
|
|
|
4970
|
+
scriptForm += `$(function () {sanitizeUndefinedAttributes($("#body-${keys}"));});`
|
|
4971
|
+
|
|
4922
4972
|
break;
|
|
4923
4973
|
|
|
4924
4974
|
case "ide_editor":
|
|
@@ -6620,4 +6670,4 @@ zRoute.tableBody = (
|
|
|
6620
6670
|
}
|
|
6621
6671
|
return html;
|
|
6622
6672
|
};
|
|
6623
|
-
module.exports = zRoute;
|
|
6673
|
+
module.exports = zRoute;
|