zet-lib 3.0.8 → 3.0.9

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/Form.js CHANGED
@@ -214,6 +214,10 @@ Form.field = (obj) => {
214
214
  displayForm = `${prepend}${inputGroupLeft}<input autocomplete="off" autofocus="" ${disabled} ${readonly} ${additional_attributes} ${tabindex} ${style} type="text" class="form-control number ${obj.class}" ${id} ${name} ${placeholder} ${required} value="${value}" ${htmlOptions}>${inputGroupRight}${information}${append}`;
215
215
  break;
216
216
 
217
+ case "money":
218
+ displayForm = `${prepend}${inputGroupLeft}<input autocomplete="off" autofocus="" ${disabled} ${readonly} ${additional_attributes} ${tabindex} ${style} type="text" class="form-control ${obj.class}" ${id} ${name} ${placeholder} ${required} value="${value}" ${htmlOptions}>${inputGroupRight}${information}${append}`;
219
+ break;
220
+
217
221
  case "integer":
218
222
  displayForm = `${prepend}${inputGroupLeft}<input autocomplete="off" autofocus="" ${disabled} ${readonly} ${additional_attributes} ${tabindex} ${style} type="number" class="form-control ${obj.class}" ${id} ${name} ${placeholder} ${required} value="${value}" ${htmlOptions}>${inputGroupRight}${information}${append}`;
219
223
  break;
package/lib/Model.js CHANGED
@@ -84,6 +84,7 @@ Model.keys = {
84
84
  text: "Text",
85
85
  textarea: "Textarea",
86
86
  checkbox: "Checkbox",
87
+ money: "Money",
87
88
  number: "Amount",
88
89
  integer: "Integer",
89
90
  select: "Select (static) ",
@@ -889,6 +890,147 @@ Model.password = {
889
890
  category: "text",
890
891
  };
891
892
 
893
+ Model.money = {
894
+ properties: [
895
+ "required",
896
+ "unique",
897
+ "tabindex",
898
+ "min",
899
+ "max",
900
+ "hidden",
901
+ "defaultValue",
902
+ "inputGroupLeft",
903
+ "inputGroupRight",
904
+ "digitDecimal",
905
+ "decimalPlaces",
906
+ "thousandSeparator",
907
+ "symbol",
908
+ "information",
909
+ ],
910
+ attributes: ["min", "max"],
911
+ labels: {
912
+ required: "Required",
913
+ unique: "Unique",
914
+ tabindex: "Tab Index",
915
+ min: "Min",
916
+ max: "Max",
917
+ hidden: "Hidden",
918
+ defaultValue: "Default Value",
919
+ inputGroupLeft: "Input Group Left",
920
+ inputGroupRight: "Input Group Right",
921
+ digitDecimal:"Digit Decimal",
922
+ decimalPlaces:"Decimal Places",
923
+ thousandSeparator:"Use 1000 Separator",
924
+ symbol:"Currency Symbol",
925
+ information: "Additional Information",
926
+ },
927
+ defaultValues: {
928
+ required: false,
929
+ unique: false,
930
+ tabindex: 1,
931
+ min: 0,
932
+ max: 0,
933
+ hidden: false,
934
+ defaultValue: null,
935
+ inputGroupLeft: "",
936
+ inputGroupRight: "",
937
+ digitDecimal: 0,
938
+ decimalPlaces:",",
939
+ thousandSeparator:".",
940
+ symbol:"",
941
+ information: "",
942
+ },
943
+ typies: {
944
+ required: {
945
+ tag: "input",
946
+ type: "checkbox",
947
+ },
948
+ tabindex: {
949
+ tag: "input",
950
+ type: "number",
951
+ },
952
+ unique: {
953
+ tag: "input",
954
+ type: "checkbox",
955
+ },
956
+ min: {
957
+ tag: "input",
958
+ type: "number",
959
+ },
960
+ max: {
961
+ tag: "input",
962
+ type: "number",
963
+ },
964
+ hidden: {
965
+ tag: "input",
966
+ type: "checkbox",
967
+ },
968
+ defaultValue: {
969
+ tag: "input",
970
+ type: "number",
971
+ },
972
+ inputGroupLeft: {
973
+ tag: "input",
974
+ type: "text",
975
+ },
976
+ inputGroupRight: {
977
+ tag: "input",
978
+ type: "text",
979
+ },
980
+ digitDecimal: {
981
+ tag: "input",
982
+ type: "number",
983
+ },
984
+ decimalPlaces: {
985
+ tag: "input",
986
+ type: "text",
987
+ },
988
+ thousandSeparator: {
989
+ tag: "input",
990
+ type: "text",
991
+ },
992
+ symbol: {
993
+ tag: "input",
994
+ type: "text",
995
+ },
996
+ information: {
997
+ tag: "textarea",
998
+ type: "",
999
+ class: "",
1000
+ },
1001
+ },
1002
+ comment: (obj = {}) => {
1003
+ return `money`;
1004
+ },
1005
+ sql: (key, MYMODEL, obj = {}) => {
1006
+ const required = !obj.required ? false : true;
1007
+ const digitDecimal = obj.digitDecimal || 0;
1008
+ let defaultValue = "";
1009
+ if (!obj.defaultValue) {
1010
+ defaultValue = ``;
1011
+ } else if (obj.defaultValue == "null") {
1012
+ defaultValue = `ALTER TABLE "${MYMODEL.table}" ALTER COLUMN "${key}" SET DEFAULT NULL;`;
1013
+ } else {
1014
+ defaultValue = `ALTER TABLE "${MYMODEL.table}" ALTER COLUMN "${key}" SET DEFAULT ${obj.defaultValue};`;
1015
+ }
1016
+ const indexing = !obj.unique
1017
+ ? ""
1018
+ : ` ALTER TABLE "${MYMODEL.table}" ADD CONSTRAINT unique_${MYMODEL.table}_${key} UNIQUE (${key});`;
1019
+
1020
+ const addTable = `ALTER TABLE "${MYMODEL.table}" ADD COLUMN "${key}" NUMERIC(15, ${digitDecimal});`;
1021
+ return {
1022
+ defaultValue: defaultValue,
1023
+ column: addTable,
1024
+ index: indexing,
1025
+ foreignKey: "",
1026
+ };
1027
+ },
1028
+ columnType: (obj = {}) => {
1029
+ return `money`;
1030
+ },
1031
+ category: "money",
1032
+ };
1033
+
892
1034
  Model.number = {
893
1035
  properties: [
894
1036
  "required",
@@ -3175,7 +3317,6 @@ Model.html = {
3175
3317
  },
3176
3318
  sql: (key, MYMODEL, obj = {}) => {
3177
3319
  return {
3178
- column: "",
3179
3320
  index: "",
3180
3321
  foreignKey: "",
3181
3322
  };
package/lib/Util.js CHANGED
@@ -660,16 +660,18 @@ Util.toNumber = function (num) {
660
660
  Util.formatNumber = function (num, thousandSeparator = ".") {
661
661
  try {
662
662
  const strValue = String(num);
663
- // Split into integer and decimal parts
664
- const parts = strValue.split(",");
663
+ // Split into integer and decimal parts (input usually has "." as decimal separator)
664
+ const parts = strValue.split(".");
665
665
  // Format integer part with thousand separators
666
666
  const integerPart = parts[0].replace(
667
667
  /\B(?=(\d{3})+(?!\d))/g,
668
668
  thousandSeparator
669
669
  );
670
+ // Determine decimal separator: if thousandSeparator is ".", use ","; otherwise use "."
671
+ let decimalSeparator = thousandSeparator === "." ? "," : ".";
670
672
  // If there's a decimal part, add it back
671
673
  if (parts.length > 1) {
672
- return `${integerPart},${parts[1]}`;
674
+ return `${integerPart}${decimalSeparator}${parts[1]}`;
673
675
  }
674
676
  return integerPart;
675
677
  } catch (e) {