@michalrakus/x-react-web-lib 1.8.0 → 1.10.0

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.
Files changed (162) hide show
  1. package/README.md +3 -3
  2. package/XInputInterval.d.ts +3 -0
  3. package/XInputInterval.js +5 -0
  4. package/XInputIntervalBase.d.ts +3 -0
  5. package/XInputIntervalBase.js +5 -0
  6. package/gulpfile.js +84 -82
  7. package/lib/administration/XBrowseMetaBrowse.d.ts +2 -2
  8. package/lib/administration/XBrowseMetaBrowse.js +21 -21
  9. package/lib/administration/XBrowseMetaForm.d.ts +5 -5
  10. package/lib/administration/XBrowseMetaForm.js +63 -63
  11. package/lib/administration/XUserBrowse.d.ts +2 -2
  12. package/lib/administration/XUserBrowse.js +88 -87
  13. package/lib/administration/XUserForm.d.ts +9 -9
  14. package/lib/administration/XUserForm.js +195 -194
  15. package/lib/components/SearchTableParams.d.ts +11 -11
  16. package/lib/components/SearchTableParams.js +2 -2
  17. package/lib/components/SourceCodeLinkEntity.d.ts +4 -4
  18. package/lib/components/SourceCodeLinkEntity.js +14 -14
  19. package/lib/components/XAutoComplete.d.ts +36 -36
  20. package/lib/components/XAutoComplete.js +155 -155
  21. package/lib/components/XAutoCompleteBase.d.ts +45 -45
  22. package/lib/components/XAutoCompleteBase.js +371 -371
  23. package/lib/components/XAutoCompleteDT.d.ts +33 -33
  24. package/lib/components/XAutoCompleteDT.js +140 -140
  25. package/lib/components/XBrowse.d.ts +33 -33
  26. package/lib/components/XBrowse.js +360 -360
  27. package/lib/components/XButton.d.ts +9 -9
  28. package/lib/components/XButton.js +13 -13
  29. package/lib/components/XButtonIconMedium.d.ts +9 -9
  30. package/lib/components/XButtonIconMedium.js +13 -13
  31. package/lib/components/XButtonIconNarrow.d.ts +10 -10
  32. package/lib/components/XButtonIconNarrow.js +25 -25
  33. package/lib/components/XButtonIconSmall.d.ts +9 -9
  34. package/lib/components/XButtonIconSmall.js +13 -13
  35. package/lib/components/XCalendar.d.ts +9 -8
  36. package/lib/components/XCalendar.js +27 -27
  37. package/lib/components/XChangePasswordForm.d.ts +5 -5
  38. package/lib/components/XChangePasswordForm.js +160 -160
  39. package/lib/components/XCheckbox.d.ts +8 -8
  40. package/lib/components/XCheckbox.js +57 -57
  41. package/lib/components/XCheckboxDT.d.ts +10 -10
  42. package/lib/components/XCheckboxDT.js +46 -46
  43. package/lib/components/XDataTable.d.ts +11 -11
  44. package/lib/components/XDataTable.js +197 -197
  45. package/lib/components/XDropdown.d.ts +18 -18
  46. package/lib/components/XDropdown.js +57 -57
  47. package/lib/components/XDropdownDT.d.ts +16 -13
  48. package/lib/components/XDropdownDT.js +135 -128
  49. package/lib/components/XDropdownDTFilter.d.ts +7 -7
  50. package/lib/components/XDropdownDTFilter.js +121 -121
  51. package/lib/components/XDropdownForEntity.d.ts +26 -25
  52. package/lib/components/XDropdownForEntity.js +151 -149
  53. package/lib/components/XDropdownFormDTFilter.d.ts +7 -7
  54. package/lib/components/XDropdownFormDTFilter.js +121 -121
  55. package/lib/components/XEditColumnDialog.d.ts +13 -13
  56. package/lib/components/XEditColumnDialog.js +112 -112
  57. package/lib/components/XEnvVars.d.ts +15 -12
  58. package/lib/components/XEnvVars.js +23 -20
  59. package/lib/components/XErrors.d.ts +12 -12
  60. package/lib/components/XErrors.js +2 -2
  61. package/lib/components/XExportRowsDialog.d.ts +15 -15
  62. package/lib/components/XExportRowsDialog.js +184 -184
  63. package/lib/components/XFieldChangeEvent.d.ts +11 -11
  64. package/lib/components/XFieldChangeEvent.js +2 -2
  65. package/lib/components/XFieldSelector.d.ts +7 -7
  66. package/lib/components/XFieldSelector.js +113 -113
  67. package/lib/components/XFormBase.d.ts +68 -59
  68. package/lib/components/XFormBase.js +613 -526
  69. package/lib/components/XFormBaseModif.d.ts +5 -5
  70. package/lib/components/XFormBaseModif.js +33 -33
  71. package/lib/components/XFormBaseT.d.ts +4 -4
  72. package/lib/components/XFormBaseT.js +31 -31
  73. package/lib/components/XFormComponent.d.ts +40 -40
  74. package/lib/components/XFormComponent.js +177 -177
  75. package/lib/components/XFormComponentDT.d.ts +30 -30
  76. package/lib/components/XFormComponentDT.js +145 -145
  77. package/lib/components/XFormDataTable2.d.ts +144 -143
  78. package/lib/components/XFormDataTable2.js +679 -686
  79. package/lib/components/XFormFooter.d.ts +6 -6
  80. package/lib/components/XFormFooter.js +19 -19
  81. package/lib/components/XFormNavigator3.d.ts +12 -12
  82. package/lib/components/XFormNavigator3.js +130 -130
  83. package/lib/components/XHolders.d.ts +7 -7
  84. package/lib/components/XHolders.js +15 -15
  85. package/lib/components/XInput.d.ts +13 -13
  86. package/lib/components/XInput.js +38 -38
  87. package/lib/components/XInputDT.d.ts +11 -11
  88. package/lib/components/XInputDT.js +37 -37
  89. package/lib/components/XInputDate.d.ts +13 -13
  90. package/lib/components/XInputDate.js +63 -63
  91. package/lib/components/XInputDateDT.d.ts +10 -10
  92. package/lib/components/XInputDateDT.js +55 -55
  93. package/lib/components/XInputDecimal.d.ts +15 -15
  94. package/lib/components/XInputDecimal.js +78 -78
  95. package/lib/components/XInputDecimalBase.d.ts +12 -12
  96. package/lib/components/XInputDecimalBase.js +18 -18
  97. package/lib/components/XInputDecimalDT.d.ts +11 -11
  98. package/lib/components/XInputDecimalDT.js +74 -74
  99. package/lib/components/XInputFileList.d.ts +36 -36
  100. package/lib/components/XInputFileList.js +251 -251
  101. package/lib/components/XInputInterval.d.ts +14 -0
  102. package/lib/components/XInputInterval.js +56 -0
  103. package/lib/components/XInputIntervalBase.d.ts +10 -0
  104. package/lib/components/XInputIntervalBase.js +97 -0
  105. package/lib/components/XInputIntervalDT.d.ts +11 -0
  106. package/lib/components/XInputIntervalDT.js +43 -0
  107. package/lib/components/XInputText.d.ts +12 -12
  108. package/lib/components/XInputText.js +69 -69
  109. package/lib/components/XInputTextDT.d.ts +9 -9
  110. package/lib/components/XInputTextDT.js +42 -42
  111. package/lib/components/XInputTextarea.d.ts +18 -18
  112. package/lib/components/XInputTextarea.js +85 -85
  113. package/lib/components/XLazyDataTable.d.ts +78 -78
  114. package/lib/components/XLazyDataTable.js +899 -885
  115. package/lib/components/XLocale.d.ts +26 -26
  116. package/lib/components/XLocale.js +59 -59
  117. package/lib/components/XLoginDialog.d.ts +8 -8
  118. package/lib/components/XLoginDialog.js +21 -21
  119. package/lib/components/XLoginForm.d.ts +7 -7
  120. package/lib/components/XLoginForm.js +128 -128
  121. package/lib/components/XObject.d.ts +3 -3
  122. package/lib/components/XObject.js +2 -2
  123. package/lib/components/XResponseError.d.ts +11 -11
  124. package/lib/components/XResponseError.js +32 -32
  125. package/lib/components/XSearchButton.d.ts +26 -26
  126. package/lib/components/XSearchButton.js +225 -225
  127. package/lib/components/XSearchButtonDT.d.ts +12 -12
  128. package/lib/components/XSearchButtonDT.js +188 -188
  129. package/lib/components/XSearchButtonOld.d.ts +13 -13
  130. package/lib/components/XSearchButtonOld.js +212 -212
  131. package/lib/components/XToOneAssocButton.d.ts +8 -8
  132. package/lib/components/XToOneAssocButton.js +30 -30
  133. package/lib/components/XToken.d.ts +6 -6
  134. package/lib/components/XToken.js +2 -2
  135. package/lib/components/XUtils.d.ts +84 -74
  136. package/lib/components/XUtils.js +664 -627
  137. package/lib/components/XUtilsConversions.d.ts +15 -12
  138. package/lib/components/XUtilsConversions.js +177 -125
  139. package/lib/components/XUtilsMetadata.d.ts +39 -39
  140. package/lib/components/XUtilsMetadata.js +452 -452
  141. package/lib/components/locale/x-en.json +26 -26
  142. package/lib/components/useXToken.d.ts +2 -2
  143. package/lib/components/useXToken.js +44 -44
  144. package/lib/serverApi/ExportImportParam.d.ts +51 -51
  145. package/lib/serverApi/ExportImportParam.js +34 -34
  146. package/lib/serverApi/FindParam.d.ts +35 -34
  147. package/lib/serverApi/FindParam.js +30 -30
  148. package/lib/serverApi/FindResult.d.ts +8 -8
  149. package/lib/serverApi/FindResult.js +2 -2
  150. package/lib/serverApi/XBrowseMetadata.d.ts +19 -19
  151. package/lib/serverApi/XBrowseMetadata.js +2 -2
  152. package/lib/serverApi/XEntityMetadata.d.ts +35 -35
  153. package/lib/serverApi/XEntityMetadata.js +2 -2
  154. package/lib/serverApi/XFileJsonField.d.ts +6 -6
  155. package/lib/serverApi/XFileJsonField.js +2 -2
  156. package/lib/serverApi/XUser.d.ts +8 -7
  157. package/lib/serverApi/XUser.js +2 -2
  158. package/lib/serverApi/XUserAuthenticationIfc.d.ts +9 -9
  159. package/lib/serverApi/XUserAuthenticationIfc.js +2 -2
  160. package/lib/serverApi/XUtilsCommon.d.ts +14 -13
  161. package/lib/serverApi/XUtilsCommon.js +180 -110
  162. package/package.json +1 -1
@@ -1,526 +1,613 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- var __values = (this && this.__values) || function(o) {
65
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
66
- if (m) return m.call(o);
67
- if (o && typeof o.length === "number") return {
68
- next: function () {
69
- if (o && i >= o.length) o = void 0;
70
- return { value: o && o[i++], done: !o };
71
- }
72
- };
73
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
74
- };
75
- var __read = (this && this.__read) || function (o, n) {
76
- var m = typeof Symbol === "function" && o[Symbol.iterator];
77
- if (!m) return o;
78
- var i = m.call(o), r, ar = [], e;
79
- try {
80
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
81
- }
82
- catch (error) { e = { error: error }; }
83
- finally {
84
- try {
85
- if (r && !r.done && (m = i["return"])) m.call(i);
86
- }
87
- finally { if (e) throw e.error; }
88
- }
89
- return ar;
90
- };
91
- Object.defineProperty(exports, "__esModule", { value: true });
92
- exports.XFormBase = exports.Form = void 0;
93
- var react_1 = require("react");
94
- var XUtils_1 = require("./XUtils");
95
- // class decorator ktory nastavuje property entity (dalo by sa to nastavovat v konstruktore ale decorator je menej ukecany)
96
- // ma sa pouzivat len na triedach odvodenych od XFormBase - obmedzenie som vsak nevedel nakodit
97
- // property sa nastavi az po zbehnuti konstruktora
98
- // pozor - decorator je vykopirovany do projektoveho suboru XLibItems.ts, lebo ked je umiestneny tu tak nefunguje pre class-y v projekte!
99
- function Form(entity) {
100
- // sem (mozno) moze prist registracia formu-u
101
- return function (constructor) {
102
- return /** @class */ (function (_super) {
103
- __extends(class_1, _super);
104
- function class_1() {
105
- var _this = _super !== null && _super.apply(this, arguments) || this;
106
- _this.entity = entity;
107
- return _this;
108
- }
109
- return class_1;
110
- }(constructor));
111
- };
112
- }
113
- exports.Form = Form;
114
- var XFormBase = /** @class */ (function (_super) {
115
- __extends(XFormBase, _super);
116
- function XFormBase(props) {
117
- var _this = _super.call(this, props) || this;
118
- // check
119
- if (props.id !== undefined && props.object !== undefined) {
120
- throw "Form cannot have both props id and object defined. Only one of them can be defined.";
121
- }
122
- //this.entity = props.entity; - nastavuje sa cez decorator @Form
123
- var object = null;
124
- if (props.id === undefined) {
125
- // add row operation
126
- if (props.object !== undefined) {
127
- object = props.object;
128
- }
129
- else {
130
- object = {}; // empty new object
131
- }
132
- }
133
- _this.fields = new Set();
134
- _this.state = {
135
- object: object,
136
- errorMap: {}
137
- };
138
- _this.xFormComponentList = [];
139
- _this.xFormDataTableList = [];
140
- _this.onClickSave = _this.onClickSave.bind(_this);
141
- _this.onClickCancel = _this.onClickCancel.bind(_this);
142
- return _this;
143
- }
144
- XFormBase.prototype.componentDidMount = function () {
145
- return __awaiter(this, void 0, void 0, function () {
146
- var object, operationType;
147
- return __generator(this, function (_a) {
148
- switch (_a.label) {
149
- case 0:
150
- //console.log("volany XFormBase.componentDidMount()");
151
- // kontrola (musi byt tu, v konstruktore este property nie je nastavena)
152
- if (this.entity === undefined) {
153
- throw "XFormBase: Property entity is not defined - use decorator @Form.";
154
- }
155
- if (!(this.props.id !== undefined)) return [3 /*break*/, 2];
156
- return [4 /*yield*/, XUtils_1.XUtils.fetchById(this.entity, Array.from(this.fields), this.props.id)];
157
- case 1:
158
- //console.log('XFormBase.componentDidMount ide nacitat objekt');
159
- //console.log(this.fields);
160
- object = _a.sent();
161
- operationType = XUtils_1.OperationType.Update;
162
- return [3 /*break*/, 3];
163
- case 2:
164
- // add new row
165
- object = this.state.object;
166
- operationType = XUtils_1.OperationType.Insert;
167
- _a.label = 3;
168
- case 3:
169
- this.preInitForm(object, operationType);
170
- //console.log("volany XFormBase.componentDidMount() - ideme setnut object");
171
- this.setState({ object: object } /*, () => console.log("volany XFormBase.componentDidMount() - callback setState")*/);
172
- return [2 /*return*/];
173
- }
174
- });
175
- });
176
- };
177
- XFormBase.prototype.getEntity = function () {
178
- if (this.entity === undefined) {
179
- throw "Entity is undefined";
180
- }
181
- return this.entity;
182
- };
183
- XFormBase.prototype.getXObject = function () {
184
- if (this.state.object === null) {
185
- throw "XFormBase: this.state.object is null";
186
- }
187
- return this.state.object;
188
- };
189
- XFormBase.prototype.getObject = function () {
190
- return this.getXObject();
191
- };
192
- XFormBase.prototype.isAddRow = function () {
193
- return this.props.id === undefined;
194
- };
195
- XFormBase.prototype.onFieldChange = function (field, value, error, onChange, assocObjectChange) {
196
- var object = this.getXObject();
197
- object[field] = value;
198
- var errorMap = this.state.errorMap;
199
- errorMap[field] = __assign(__assign({}, errorMap[field]), { onChange: error });
200
- // tu zavolame onChange komponentu - object uz ma zapisanu zmenenu hodnotu, onChange nasledne zmeni dalsie hodnoty a nasledne sa zavola setState
201
- if (onChange) {
202
- onChange({ object: object, assocObjectChange: assocObjectChange });
203
- }
204
- // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
205
- this.setState({ object: object, errorMap: errorMap });
206
- };
207
- XFormBase.prototype.onTableFieldChange = function (rowData, field, value, error, onChange, assocObjectChange) {
208
- var object = this.getXObject();
209
- rowData[field] = value;
210
- // nastavime error do rowData do tech fieldu
211
- var errorMap = XFormBase.getXRowTechData(rowData).errorMap;
212
- errorMap[field] = __assign(__assign({}, errorMap[field]), { onChange: error });
213
- // tu zavolame onChange komponentu - object uz ma zapisanu zmenenu hodnotu, onChange nasledne zmeni dalsie hodnoty a nasledne sa zavola setState
214
- if (onChange) {
215
- onChange({ object: object, tableRow: rowData, assocObjectChange: assocObjectChange });
216
- }
217
- // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
218
- this.setState({ object: object /*, errorMap: errorMap*/ });
219
- };
220
- /**
221
- * @deprecated - mal by sa pouzivat onTableFieldChange
222
- */
223
- XFormBase.prototype.onObjectDataChange = function (row, onChange) {
224
- var object = this.state.object;
225
- // tu zavolame onChange komponentu - object uz ma zapisanu zmenenu hodnotu, onChange nasledne zmeni dalsie hodnoty a nasledne sa zavola setState
226
- if (onChange) {
227
- // TODO - assocObjectChange dorobit
228
- onChange({ object: object, tableRow: row, assocObjectChange: undefined });
229
- }
230
- // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
231
- this.setState({ object: object });
232
- };
233
- // lepsi nazov ako onObjectDataChange
234
- // ak niekto zmenil this.state.object alebo this.state.errorMap, zmena sa prejavi vo formulari
235
- // pouzivame napr. po zavolani onChange na XInputText
236
- XFormBase.prototype.setStateXForm = function () {
237
- // TODO - je to ok ze object menime takto?
238
- // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
239
- this.setState({ object: this.state.object, errorMap: this.state.errorMap });
240
- };
241
- XFormBase.prototype.onTableAddRow = function (assocField, newRow, dataKey, selectedRow) {
242
- var object = this.getXObject();
243
- var rowList = object[assocField];
244
- // ak vieme id-cko a id-cko nie je vyplnene, tak ho vygenerujeme (predpokladame ze id-cko je vzdy number)
245
- // id-cka potrebujeme, lebo by nam bez nich nekorektne fungovala tabulka
246
- // asi cistejsie by bolo citat id-cka zo sekvencie z DB, ale MySql nema sekvencie na styl Oracle
247
- if (dataKey !== undefined) {
248
- var newRowId = newRow[dataKey];
249
- if (newRowId === undefined || newRowId === null) {
250
- newRow[dataKey] = XFormBase.getNextRowId(rowList, dataKey);
251
- newRow.__x_generatedRowId = true; // specialny priznak, ze sme vygenerovali id-cko - pred insertom do DB toto id-cko vynullujeme aby sa vygenerovalo realne id-cko
252
- }
253
- }
254
- var index = undefined;
255
- if (selectedRow !== undefined) {
256
- var selectedRowIndex = rowList.indexOf(selectedRow);
257
- if (selectedRowIndex > -1) {
258
- index = selectedRowIndex + 1;
259
- }
260
- }
261
- if (index !== undefined) {
262
- rowList.splice(index, 0, newRow);
263
- }
264
- else {
265
- rowList.push(newRow); // na koniec
266
- }
267
- // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
268
- this.setState({ object: object });
269
- };
270
- XFormBase.getNextRowId = function (rowList, dataKey) {
271
- var e_1, _a;
272
- var maxId = 0;
273
- try {
274
- for (var rowList_1 = __values(rowList), rowList_1_1 = rowList_1.next(); !rowList_1_1.done; rowList_1_1 = rowList_1.next()) {
275
- var row = rowList_1_1.value;
276
- var id = row[dataKey];
277
- if (id > maxId) {
278
- maxId = id;
279
- }
280
- }
281
- }
282
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
283
- finally {
284
- try {
285
- if (rowList_1_1 && !rowList_1_1.done && (_a = rowList_1.return)) _a.call(rowList_1);
286
- }
287
- finally { if (e_1) throw e_1.error; }
288
- }
289
- return maxId + 1;
290
- };
291
- XFormBase.prototype.onTableRemoveRow = function (assocField, row) {
292
- var object = this.getXObject();
293
- var rowList = object[assocField];
294
- // poznamka: indexOf pri vyhladavani pouziva strict equality (===), 2 objekty su rovnake len ak porovnavame 2 smerniky na totozny objekt
295
- var index = rowList.indexOf(row);
296
- if (index === -1) {
297
- throw "Unexpected error - element 'row' not found in 'rowList'";
298
- }
299
- rowList.splice(index, 1);
300
- // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
301
- this.setState({ object: object });
302
- };
303
- // tato metoda (aj vsetky ostatne metody precujuce s row-mi) by mali byt skor na XFormDataTable2 (ta pozna "assocField" (OneToMany asociaciu))
304
- XFormBase.getXRowTechData = function (row) {
305
- // ak este nemame rowTechData, tak ho vytvorime
306
- if (row.__x_rowTechData === undefined) {
307
- // field '__x_rowTechData' vytvorime takymto specialnym sposobom, aby mal "enumerable: false", tympadom ho JSON.stringify nezaserializuje
308
- // pri posielani objektu formulara na backend (pozor, zaroven sa neda tento field iterovat cez in operator a pod.)
309
- var xRowTechData = { xFormComponentDTList: [], errorMap: {} };
310
- Object.defineProperty(row, '__x_rowTechData', {
311
- value: xRowTechData,
312
- writable: false,
313
- enumerable: false
314
- });
315
- }
316
- return row.__x_rowTechData;
317
- };
318
- XFormBase.prototype.addField = function (field) {
319
- this.fields.add(field);
320
- };
321
- XFormBase.prototype.addXFormComponent = function (xFormComponent) {
322
- this.xFormComponentList.push(xFormComponent);
323
- };
324
- XFormBase.prototype.findXFormComponent = function (field) {
325
- var e_2, _a;
326
- try {
327
- // TODO - vytvorit mapu (field, ref(xFormComponent)), bude to rychlejsie
328
- // vytvorit len mapu (a list zrusit) je problem - mozme mat pre jeden field viacero (napr. asociacnych) componentov
329
- for (var _b = __values(this.xFormComponentList), _c = _b.next(); !_c.done; _c = _b.next()) {
330
- var xFormComponent = _c.value;
331
- if (xFormComponent.getField() === field) {
332
- return xFormComponent;
333
- }
334
- }
335
- }
336
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
337
- finally {
338
- try {
339
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
340
- }
341
- finally { if (e_2) throw e_2.error; }
342
- }
343
- return undefined;
344
- };
345
- XFormBase.prototype.addXFormDataTable = function (xFormDataTable) {
346
- this.xFormDataTableList.push(xFormDataTable);
347
- };
348
- XFormBase.prototype.formReadOnlyBase = function (field) {
349
- // TODO - bude this.state.object vzdycky !== undefined?
350
- return this.formReadOnly(this.state.object, field);
351
- };
352
- XFormBase.prototype.onClickSave = function () {
353
- return __awaiter(this, void 0, void 0, function () {
354
- var isAddRow, object, e_3;
355
- return __generator(this, function (_a) {
356
- switch (_a.label) {
357
- case 0:
358
- //console.log("zavolany onClickSave");
359
- if (!this.validateSave()) {
360
- return [2 /*return*/];
361
- }
362
- // docasne na testovanie
363
- // const object: T | null = this.state.object;
364
- // if (object !== null) {
365
- // const carDate = object['carDatetime'];
366
- // if (carDate !== undefined && carDate !== null) {
367
- // //(object as XObject)['carDate'] = dateFormat(carDate, 'yyyy-mm-dd');
368
- // console.log(dateFormat(carDate, 'yyyy-mm-dd HH:MM:ss'))
369
- // console.log(carDate.getHours());
370
- // console.log(carDate.getMinutes());
371
- // console.log(carDate.getSeconds());
372
- // }
373
- // }
374
- this.preSave(this.state.object);
375
- isAddRow = this.isAddRow();
376
- _a.label = 1;
377
- case 1:
378
- _a.trys.push([1, 3, , 4]);
379
- return [4 /*yield*/, this.saveRow()];
380
- case 2:
381
- object = _a.sent();
382
- return [3 /*break*/, 4];
383
- case 3:
384
- e_3 = _a.sent();
385
- XUtils_1.XUtils.showErrorMessage("Save row failed.", e_3);
386
- return [2 /*return*/]; // zostavame vo formulari
387
- case 4:
388
- if (this.props.onSaveOrCancel !== undefined) {
389
- // formular je zobrazeny v dialogu
390
- this.props.onSaveOrCancel(object, isAddRow ? XUtils_1.OperationType.Insert : XUtils_1.OperationType.Update);
391
- }
392
- else {
393
- this.props.openForm(null); // standardny rezim; save zbehol, ideme naspet do browsu
394
- }
395
- return [2 /*return*/];
396
- }
397
- });
398
- });
399
- };
400
- XFormBase.prototype.onClickCancel = function () {
401
- if (this.props.onSaveOrCancel !== undefined) {
402
- this.props.onSaveOrCancel(null, XUtils_1.OperationType.None); // formular je zobrazeny v dialogu
403
- }
404
- else {
405
- // standardny rezim
406
- // openForm pridavame automaticky v XFormNavigator2 pri renderovani komponentu
407
- // null - vrati sa do predchadzajuceho formularu, z ktoreho bol otvoreny
408
- this.props.openForm(null);
409
- }
410
- };
411
- XFormBase.prototype.validateSave = function () {
412
- var e_4, _a;
413
- var xErrorMap = this.validateForm();
414
- // zatial takto jednoducho
415
- var msg = XUtils_1.XUtils.getErrorMessages(xErrorMap);
416
- try {
417
- // este spracujeme editovatelne tabulky
418
- for (var _b = __values(this.xFormDataTableList), _c = _b.next(); !_c.done; _c = _b.next()) {
419
- var xFormDataTable = _c.value;
420
- msg += xFormDataTable.getErrorMessages();
421
- }
422
- }
423
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
424
- finally {
425
- try {
426
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
427
- }
428
- finally { if (e_4) throw e_4.error; }
429
- }
430
- var ok = true;
431
- if (msg !== "") {
432
- alert(msg);
433
- ok = false;
434
- }
435
- return ok;
436
- };
437
- XFormBase.prototype.validateForm = function () {
438
- var e_5, _a;
439
- var xErrorMap = this.fieldValidation();
440
- // form validation
441
- var xErrors = this.validate(this.getXObject());
442
- try {
443
- for (var _b = __values(Object.entries(xErrors)), _c = _b.next(); !_c.done; _c = _b.next()) {
444
- var _d = __read(_c.value, 2), field = _d[0], error = _d[1];
445
- if (error) {
446
- // skusime zistit label
447
- var xFormComponent = this.findXFormComponent(field);
448
- var fieldLabel = xFormComponent ? xFormComponent.getLabel() : undefined;
449
- xErrorMap[field] = __assign(__assign({}, xErrorMap[field]), { form: error, fieldLabel: fieldLabel });
450
- }
451
- }
452
- }
453
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
454
- finally {
455
- try {
456
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
457
- }
458
- finally { if (e_5) throw e_5.error; }
459
- }
460
- // TODO - optimalizacia - netreba setovat stav ak by sme sli prec z formulara (ak by zbehla validacia aj save a isli by sme naspet do browsu)
461
- // setujeme aj this.state.object, lebo mohli pribudnut/odbudnut chyby na rowData v editovatelnych tabulkach
462
- this.setState({ object: this.state.object, errorMap: xErrorMap });
463
- return xErrorMap;
464
- };
465
- XFormBase.prototype.fieldValidation = function () {
466
- var e_6, _a, e_7, _b;
467
- var xErrorMap = {};
468
- try {
469
- for (var _c = __values(this.xFormComponentList), _d = _c.next(); !_d.done; _d = _c.next()) {
470
- var xFormComponent = _d.value;
471
- var errorItem = xFormComponent.validate();
472
- if (errorItem) {
473
- //console.log("Mame field = " + errorItem.field);
474
- xErrorMap[errorItem.field] = errorItem.xError;
475
- }
476
- }
477
- }
478
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
479
- finally {
480
- try {
481
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
482
- }
483
- finally { if (e_6) throw e_6.error; }
484
- }
485
- try {
486
- for (var _e = __values(this.xFormDataTableList), _f = _e.next(); !_f.done; _f = _e.next()) {
487
- var xFormDataTable = _f.value;
488
- xFormDataTable.validate();
489
- }
490
- }
491
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
492
- finally {
493
- try {
494
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
495
- }
496
- finally { if (e_7) throw e_7.error; }
497
- }
498
- return xErrorMap;
499
- };
500
- // this method can be overriden in subclass if needed
501
- // (the purpose is to put the whole form to read only mode (maybe with exception a few fields))
502
- // if returns true for the param "field", then the field is read only, otherwise the property readOnly of the XInput* is processed
503
- XFormBase.prototype.formReadOnly = function (object, field) {
504
- return false;
505
- };
506
- // this method can be overriden in subclass if needed (to modify/save object after read from DB and before set into the form)
507
- XFormBase.prototype.preInitForm = function (object, operationType) {
508
- };
509
- // this method can be overriden in subclass if needed (custom validation)
510
- XFormBase.prototype.validate = function (object) {
511
- return {};
512
- };
513
- // this method can be overriden in subclass if needed (to modify object before save)
514
- XFormBase.prototype.preSave = function (object) {
515
- };
516
- // this method can be overriden in subclass if needed (to use another service then default 'saveRow')
517
- XFormBase.prototype.saveRow = function () {
518
- return __awaiter(this, void 0, void 0, function () {
519
- return __generator(this, function (_a) {
520
- return [2 /*return*/, XUtils_1.XUtils.fetch('saveRow', { entity: this.getEntity(), object: this.state.object, reload: this.props.onSaveOrCancel !== undefined })];
521
- });
522
- });
523
- };
524
- return XFormBase;
525
- }(react_1.Component));
526
- exports.XFormBase = XFormBase;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __values = (this && this.__values) || function(o) {
65
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
66
+ if (m) return m.call(o);
67
+ if (o && typeof o.length === "number") return {
68
+ next: function () {
69
+ if (o && i >= o.length) o = void 0;
70
+ return { value: o && o[i++], done: !o };
71
+ }
72
+ };
73
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
74
+ };
75
+ var __read = (this && this.__read) || function (o, n) {
76
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
77
+ if (!m) return o;
78
+ var i = m.call(o), r, ar = [], e;
79
+ try {
80
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
81
+ }
82
+ catch (error) { e = { error: error }; }
83
+ finally {
84
+ try {
85
+ if (r && !r.done && (m = i["return"])) m.call(i);
86
+ }
87
+ finally { if (e) throw e.error; }
88
+ }
89
+ return ar;
90
+ };
91
+ Object.defineProperty(exports, "__esModule", { value: true });
92
+ exports.XFormBase = exports.Form = void 0;
93
+ var react_1 = require("react");
94
+ var XUtils_1 = require("./XUtils");
95
+ // class decorator ktory nastavuje property entity (dalo by sa to nastavovat v konstruktore ale decorator je menej ukecany)
96
+ // ma sa pouzivat len na triedach odvodenych od XFormBase - obmedzenie som vsak nevedel nakodit
97
+ // property sa nastavi az po zbehnuti konstruktora
98
+ // pozor - decorator je vykopirovany do projektoveho suboru XLibItems.ts, lebo ked je umiestneny tu tak nefunguje pre class-y v projekte!
99
+ function Form(entity) {
100
+ // sem (mozno) moze prist registracia formu-u
101
+ return function (constructor) {
102
+ return /** @class */ (function (_super) {
103
+ __extends(class_1, _super);
104
+ function class_1() {
105
+ var _this = _super !== null && _super.apply(this, arguments) || this;
106
+ _this.entity = entity;
107
+ return _this;
108
+ }
109
+ return class_1;
110
+ }(constructor));
111
+ };
112
+ }
113
+ exports.Form = Form;
114
+ var XFormBase = /** @class */ (function (_super) {
115
+ __extends(XFormBase, _super);
116
+ function XFormBase(props) {
117
+ var _this = _super.call(this, props) || this;
118
+ // check
119
+ if (props.id !== undefined && props.object !== undefined) {
120
+ throw "Form cannot have both props id and object defined. Only one of them can be defined.";
121
+ }
122
+ //this.entity = props.entity; - nastavuje sa cez decorator @Form
123
+ var object = null;
124
+ if (props.id === undefined) {
125
+ // add row operation
126
+ if (props.object !== undefined) {
127
+ object = props.object;
128
+ }
129
+ else {
130
+ object = {}; // empty new object
131
+ }
132
+ }
133
+ _this.fields = new Set();
134
+ _this.state = {
135
+ object: object,
136
+ errorMap: {}
137
+ };
138
+ _this.xFormComponentList = [];
139
+ _this.xFormDataTableList = [];
140
+ _this.assocToValidateList = [];
141
+ _this.assocToSortList = [];
142
+ _this.onClickSave = _this.onClickSave.bind(_this);
143
+ _this.onClickCancel = _this.onClickCancel.bind(_this);
144
+ return _this;
145
+ }
146
+ XFormBase.prototype.componentDidMount = function () {
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ var object, operationType, _a, _b, assocToSort, assocRowList;
149
+ var e_1, _c;
150
+ return __generator(this, function (_d) {
151
+ switch (_d.label) {
152
+ case 0:
153
+ //console.log("volany XFormBase.componentDidMount()");
154
+ // kontrola (musi byt tu, v konstruktore este property nie je nastavena)
155
+ if (this.entity === undefined) {
156
+ throw "XFormBase: Property entity is not defined - use decorator @Form.";
157
+ }
158
+ if (!(this.props.id !== undefined)) return [3 /*break*/, 2];
159
+ return [4 /*yield*/, XUtils_1.XUtils.fetchById(this.entity, Array.from(this.fields), this.props.id)];
160
+ case 1:
161
+ //console.log('XFormBase.componentDidMount ide nacitat objekt');
162
+ //console.log(this.fields);
163
+ object = _d.sent();
164
+ operationType = XUtils_1.OperationType.Update;
165
+ try {
166
+ // sortovanie, aby sme nemuseli sortovat v DB (neviem co je efektivnejsie)
167
+ for (_a = __values(this.assocToSortList), _b = _a.next(); !_b.done; _b = _a.next()) {
168
+ assocToSort = _b.value;
169
+ assocRowList = object[assocToSort.assoc];
170
+ if (assocRowList) {
171
+ object[assocToSort.assoc] = XUtils_1.XUtils.arraySort(assocRowList, assocToSort.sortField);
172
+ }
173
+ }
174
+ }
175
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
176
+ finally {
177
+ try {
178
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
179
+ }
180
+ finally { if (e_1) throw e_1.error; }
181
+ }
182
+ return [3 /*break*/, 3];
183
+ case 2:
184
+ // add new row
185
+ object = this.state.object;
186
+ operationType = XUtils_1.OperationType.Insert;
187
+ _d.label = 3;
188
+ case 3:
189
+ this.preInitForm(object, operationType);
190
+ //console.log("volany XFormBase.componentDidMount() - ideme setnut object");
191
+ this.setState({ object: object } /*, () => console.log("volany XFormBase.componentDidMount() - callback setState")*/);
192
+ return [2 /*return*/];
193
+ }
194
+ });
195
+ });
196
+ };
197
+ XFormBase.prototype.getEntity = function () {
198
+ if (this.entity === undefined) {
199
+ throw "Entity is undefined";
200
+ }
201
+ return this.entity;
202
+ };
203
+ XFormBase.prototype.getXObject = function () {
204
+ if (this.state.object === null) {
205
+ throw "XFormBase: this.state.object is null";
206
+ }
207
+ return this.state.object;
208
+ };
209
+ XFormBase.prototype.getObject = function () {
210
+ return this.getXObject();
211
+ };
212
+ XFormBase.prototype.isAddRow = function () {
213
+ return this.props.id === undefined;
214
+ };
215
+ XFormBase.prototype.onFieldChange = function (field, value, error, onChange, assocObjectChange) {
216
+ var object = this.getXObject();
217
+ object[field] = value;
218
+ var errorMap = this.state.errorMap;
219
+ errorMap[field] = __assign(__assign({}, errorMap[field]), { onChange: error });
220
+ // tu zavolame onChange komponentu - object uz ma zapisanu zmenenu hodnotu, onChange nasledne zmeni dalsie hodnoty a nasledne sa zavola setState
221
+ if (onChange) {
222
+ onChange({ object: object, assocObjectChange: assocObjectChange });
223
+ }
224
+ // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
225
+ this.setState({ object: object, errorMap: errorMap });
226
+ };
227
+ XFormBase.prototype.onTableFieldChange = function (rowData, field, value, error, onChange, assocObjectChange) {
228
+ var object = this.getXObject();
229
+ rowData[field] = value;
230
+ // nastavime error do rowData do tech fieldu
231
+ var errorMap = XFormBase.getXRowTechData(rowData).errorMap;
232
+ errorMap[field] = __assign(__assign({}, errorMap[field]), { onChange: error });
233
+ // tu zavolame onChange komponentu - object uz ma zapisanu zmenenu hodnotu, onChange nasledne zmeni dalsie hodnoty a nasledne sa zavola setState
234
+ if (onChange) {
235
+ onChange({ object: object, tableRow: rowData, assocObjectChange: assocObjectChange });
236
+ }
237
+ // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
238
+ this.setState({ object: object /*, errorMap: errorMap*/ });
239
+ };
240
+ /**
241
+ * @deprecated - mal by sa pouzivat onTableFieldChange
242
+ */
243
+ XFormBase.prototype.onObjectDataChange = function (row, onChange) {
244
+ var object = this.state.object;
245
+ // tu zavolame onChange komponentu - object uz ma zapisanu zmenenu hodnotu, onChange nasledne zmeni dalsie hodnoty a nasledne sa zavola setState
246
+ if (onChange) {
247
+ // TODO - assocObjectChange dorobit
248
+ onChange({ object: object, tableRow: row, assocObjectChange: undefined });
249
+ }
250
+ // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
251
+ this.setState({ object: object });
252
+ };
253
+ // lepsi nazov ako onObjectDataChange
254
+ // ak niekto zmenil this.state.object alebo this.state.errorMap, zmena sa prejavi vo formulari
255
+ // pouzivame napr. po zavolani onChange na XInputText
256
+ XFormBase.prototype.setStateXForm = function () {
257
+ // TODO - je to ok ze object menime takto?
258
+ // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
259
+ this.setState({ object: this.state.object, errorMap: this.state.errorMap });
260
+ };
261
+ XFormBase.prototype.onTableAddRow = function (assocField, newRow, dataKey, selectedRow) {
262
+ var object = this.getXObject();
263
+ var rowList = object[assocField];
264
+ // ak vieme id-cko a id-cko nie je vyplnene, tak ho vygenerujeme (predpokladame ze id-cko je vzdy number)
265
+ // id-cka potrebujeme, lebo by nam bez nich nekorektne fungovala tabulka
266
+ // asi cistejsie by bolo citat id-cka zo sekvencie z DB, ale MySql nema sekvencie na styl Oracle
267
+ if (dataKey !== undefined) {
268
+ var newRowId = newRow[dataKey];
269
+ if (newRowId === undefined || newRowId === null) {
270
+ newRow[dataKey] = XFormBase.getNextRowId(rowList, dataKey);
271
+ newRow.__x_generatedRowId = true; // specialny priznak, ze sme vygenerovali id-cko - pred insertom do DB toto id-cko vynullujeme aby sa vygenerovalo realne id-cko
272
+ }
273
+ }
274
+ var index = undefined;
275
+ if (selectedRow !== undefined) {
276
+ var selectedRowIndex = rowList.indexOf(selectedRow);
277
+ if (selectedRowIndex > -1) {
278
+ index = selectedRowIndex + 1;
279
+ }
280
+ }
281
+ if (index !== undefined) {
282
+ rowList.splice(index, 0, newRow);
283
+ }
284
+ else {
285
+ rowList.push(newRow); // na koniec
286
+ }
287
+ // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
288
+ this.setState({ object: object });
289
+ };
290
+ XFormBase.getNextRowId = function (rowList, dataKey) {
291
+ var e_2, _a;
292
+ var maxId = 0;
293
+ try {
294
+ for (var rowList_1 = __values(rowList), rowList_1_1 = rowList_1.next(); !rowList_1_1.done; rowList_1_1 = rowList_1.next()) {
295
+ var row = rowList_1_1.value;
296
+ var id = row[dataKey];
297
+ if (id > maxId) {
298
+ maxId = id;
299
+ }
300
+ }
301
+ }
302
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
303
+ finally {
304
+ try {
305
+ if (rowList_1_1 && !rowList_1_1.done && (_a = rowList_1.return)) _a.call(rowList_1);
306
+ }
307
+ finally { if (e_2) throw e_2.error; }
308
+ }
309
+ return maxId + 1;
310
+ };
311
+ XFormBase.prototype.onTableRemoveRow = function (assocField, row) {
312
+ var object = this.getXObject();
313
+ var rowList = object[assocField];
314
+ // poznamka: indexOf pri vyhladavani pouziva strict equality (===), 2 objekty su rovnake len ak porovnavame 2 smerniky na totozny objekt
315
+ var index = rowList.indexOf(row);
316
+ if (index === -1) {
317
+ throw "Unexpected error - element 'row' not found in 'rowList'";
318
+ }
319
+ rowList.splice(index, 1);
320
+ // TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
321
+ this.setState({ object: object });
322
+ };
323
+ XFormBase.getXRowTechData = function (row) {
324
+ // ak este nemame rowTechData, tak ho vytvorime
325
+ if (row.__x_rowTechData === undefined) {
326
+ // field '__x_rowTechData' vytvorime takymto specialnym sposobom, aby mal "enumerable: false", tympadom ho JSON.stringify nezaserializuje
327
+ // pri posielani objektu formulara na backend (pozor, zaroven sa neda tento field iterovat cez in operator a pod.)
328
+ var xRowTechData = { xFormComponentDTList: [], errorMap: {} };
329
+ Object.defineProperty(row, '__x_rowTechData', {
330
+ value: xRowTechData,
331
+ writable: false,
332
+ enumerable: false
333
+ });
334
+ }
335
+ return row.__x_rowTechData;
336
+ };
337
+ XFormBase.prototype.addField = function (field) {
338
+ this.fields.add(field);
339
+ };
340
+ XFormBase.prototype.addXFormComponent = function (xFormComponent) {
341
+ this.xFormComponentList.push(xFormComponent);
342
+ };
343
+ XFormBase.prototype.findXFormComponent = function (field) {
344
+ var e_3, _a;
345
+ try {
346
+ // TODO - vytvorit mapu (field, ref(xFormComponent)), bude to rychlejsie
347
+ // vytvorit len mapu (a list zrusit) je problem - mozme mat pre jeden field viacero (napr. asociacnych) componentov
348
+ for (var _b = __values(this.xFormComponentList), _c = _b.next(); !_c.done; _c = _b.next()) {
349
+ var xFormComponent = _c.value;
350
+ if (xFormComponent.getField() === field) {
351
+ return xFormComponent;
352
+ }
353
+ }
354
+ }
355
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
356
+ finally {
357
+ try {
358
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
359
+ }
360
+ finally { if (e_3) throw e_3.error; }
361
+ }
362
+ return undefined;
363
+ };
364
+ XFormBase.prototype.addXFormDataTable = function (xFormDataTable) {
365
+ this.xFormDataTableList.push(xFormDataTable);
366
+ };
367
+ XFormBase.prototype.addAssocToValidate = function (oneToManyAssoc) {
368
+ this.assocToValidateList.push(oneToManyAssoc);
369
+ };
370
+ XFormBase.prototype.addAssocToSort = function (oneToManyAssoc, sortField) {
371
+ this.assocToSortList.push({ assoc: oneToManyAssoc, sortField: sortField });
372
+ };
373
+ XFormBase.prototype.formReadOnlyBase = function (field) {
374
+ // TODO - bude this.state.object vzdycky !== undefined?
375
+ return this.formReadOnly(this.state.object, field);
376
+ };
377
+ XFormBase.prototype.onClickSave = function () {
378
+ return __awaiter(this, void 0, void 0, function () {
379
+ var isAddRow, object, e_4;
380
+ return __generator(this, function (_a) {
381
+ switch (_a.label) {
382
+ case 0:
383
+ //console.log("zavolany onClickSave");
384
+ if (!this.validateSave()) {
385
+ return [2 /*return*/];
386
+ }
387
+ // docasne na testovanie
388
+ // const object: T | null = this.state.object;
389
+ // if (object !== null) {
390
+ // const carDate = object['carDatetime'];
391
+ // if (carDate !== undefined && carDate !== null) {
392
+ // //(object as XObject)['carDate'] = dateFormat(carDate, 'yyyy-mm-dd');
393
+ // console.log(dateFormat(carDate, 'yyyy-mm-dd HH:MM:ss'))
394
+ // console.log(carDate.getHours());
395
+ // console.log(carDate.getMinutes());
396
+ // console.log(carDate.getSeconds());
397
+ // }
398
+ // }
399
+ this.preSave(this.state.object);
400
+ isAddRow = this.isAddRow();
401
+ _a.label = 1;
402
+ case 1:
403
+ _a.trys.push([1, 3, , 4]);
404
+ return [4 /*yield*/, this.saveRow()];
405
+ case 2:
406
+ object = _a.sent();
407
+ return [3 /*break*/, 4];
408
+ case 3:
409
+ e_4 = _a.sent();
410
+ XUtils_1.XUtils.showErrorMessage("Save row failed.", e_4);
411
+ return [2 /*return*/]; // zostavame vo formulari
412
+ case 4:
413
+ if (this.props.onSaveOrCancel !== undefined) {
414
+ // formular je zobrazeny v dialogu
415
+ this.props.onSaveOrCancel(object, isAddRow ? XUtils_1.OperationType.Insert : XUtils_1.OperationType.Update);
416
+ }
417
+ else {
418
+ this.props.openForm(null); // standardny rezim; save zbehol, ideme naspet do browsu
419
+ }
420
+ return [2 /*return*/];
421
+ }
422
+ });
423
+ });
424
+ };
425
+ XFormBase.prototype.onClickCancel = function () {
426
+ if (this.props.onSaveOrCancel !== undefined) {
427
+ this.props.onSaveOrCancel(null, XUtils_1.OperationType.None); // formular je zobrazeny v dialogu
428
+ }
429
+ else {
430
+ // standardny rezim
431
+ // openForm pridavame automaticky v XFormNavigator2 pri renderovani komponentu
432
+ // null - vrati sa do predchadzajuceho formularu, z ktoreho bol otvoreny
433
+ this.props.openForm(null);
434
+ }
435
+ };
436
+ XFormBase.prototype.validateSave = function () {
437
+ var e_5, _a, e_6, _b;
438
+ var xErrorMap = this.validateForm();
439
+ // zatial takto jednoducho
440
+ var msg = XUtils_1.XUtils.getErrorMessages(xErrorMap);
441
+ try {
442
+ // este spracujeme editovatelne tabulky
443
+ for (var _c = __values(this.xFormDataTableList), _d = _c.next(); !_d.done; _d = _c.next()) {
444
+ var xFormDataTable = _d.value;
445
+ //msg += xFormDataTable.getErrorMessages();
446
+ msg += this.getErrorMessagesForAssoc(xFormDataTable.props.assocField);
447
+ }
448
+ }
449
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
450
+ finally {
451
+ try {
452
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
453
+ }
454
+ finally { if (e_5) throw e_5.error; }
455
+ }
456
+ try {
457
+ // este spracujeme oneToMany asociacie, ktore boli explicitne uvedene, ze ich treba validovat
458
+ // (validaciu treba nakodit vo formulari, zavolat z metody validate() a ukoncit zavolanim XFormBase.saveErrorsIntoXRowTechData)
459
+ for (var _e = __values(this.assocToValidateList), _f = _e.next(); !_f.done; _f = _e.next()) {
460
+ var assocToValidate = _f.value;
461
+ msg += this.getErrorMessagesForAssoc(assocToValidate);
462
+ }
463
+ }
464
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
465
+ finally {
466
+ try {
467
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
468
+ }
469
+ finally { if (e_6) throw e_6.error; }
470
+ }
471
+ var ok = true;
472
+ if (msg !== "") {
473
+ alert(msg);
474
+ ok = false;
475
+ }
476
+ return ok;
477
+ };
478
+ XFormBase.prototype.validateForm = function () {
479
+ var e_7, _a;
480
+ var xErrorMap = this.fieldValidation();
481
+ // form validation
482
+ var xErrors = this.validate(this.getXObject());
483
+ try {
484
+ for (var _b = __values(Object.entries(xErrors)), _c = _b.next(); !_c.done; _c = _b.next()) {
485
+ var _d = __read(_c.value, 2), field = _d[0], error = _d[1];
486
+ if (error) {
487
+ // skusime zistit label
488
+ var xFormComponent = this.findXFormComponent(field);
489
+ var fieldLabel = xFormComponent ? xFormComponent.getLabel() : undefined;
490
+ xErrorMap[field] = __assign(__assign({}, xErrorMap[field]), { form: error, fieldLabel: fieldLabel });
491
+ }
492
+ }
493
+ }
494
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
495
+ finally {
496
+ try {
497
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
498
+ }
499
+ finally { if (e_7) throw e_7.error; }
500
+ }
501
+ // TODO - optimalizacia - netreba setovat stav ak by sme sli prec z formulara (ak by zbehla validacia aj save a isli by sme naspet do browsu)
502
+ // setujeme aj this.state.object, lebo mohli pribudnut/odbudnut chyby na rowData v editovatelnych tabulkach
503
+ this.setState({ object: this.state.object, errorMap: xErrorMap });
504
+ return xErrorMap;
505
+ };
506
+ XFormBase.prototype.fieldValidation = function () {
507
+ var e_8, _a, e_9, _b;
508
+ var xErrorMap = {};
509
+ try {
510
+ for (var _c = __values(this.xFormComponentList), _d = _c.next(); !_d.done; _d = _c.next()) {
511
+ var xFormComponent = _d.value;
512
+ var errorItem = xFormComponent.validate();
513
+ if (errorItem) {
514
+ //console.log("Mame field = " + errorItem.field);
515
+ xErrorMap[errorItem.field] = errorItem.xError;
516
+ }
517
+ }
518
+ }
519
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
520
+ finally {
521
+ try {
522
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
523
+ }
524
+ finally { if (e_8) throw e_8.error; }
525
+ }
526
+ try {
527
+ for (var _e = __values(this.xFormDataTableList), _f = _e.next(); !_f.done; _f = _e.next()) {
528
+ var xFormDataTable = _f.value;
529
+ xFormDataTable.validate();
530
+ }
531
+ }
532
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
533
+ finally {
534
+ try {
535
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
536
+ }
537
+ finally { if (e_9) throw e_9.error; }
538
+ }
539
+ return xErrorMap;
540
+ };
541
+ XFormBase.prototype.getErrorMessagesForAssoc = function (oneToManyAssoc) {
542
+ var e_10, _a;
543
+ var msg = "";
544
+ var object = this.getXObject();
545
+ var rowList = object[oneToManyAssoc];
546
+ if (!Array.isArray(rowList)) {
547
+ throw "Array for the assoc ".concat(oneToManyAssoc, " not found in the form object");
548
+ }
549
+ try {
550
+ for (var rowList_2 = __values(rowList), rowList_2_1 = rowList_2.next(); !rowList_2_1.done; rowList_2_1 = rowList_2.next()) {
551
+ var row = rowList_2_1.value;
552
+ var xRowTechData = XFormBase.getXRowTechData(row);
553
+ msg += XUtils_1.XUtils.getErrorMessages(xRowTechData.errorMap);
554
+ }
555
+ }
556
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
557
+ finally {
558
+ try {
559
+ if (rowList_2_1 && !rowList_2_1.done && (_a = rowList_2.return)) _a.call(rowList_2);
560
+ }
561
+ finally { if (e_10) throw e_10.error; }
562
+ }
563
+ return msg;
564
+ };
565
+ // can be called from AppForm in case of custom validation on oneToMany assoc
566
+ XFormBase.saveErrorsIntoXRowTechData = function (row, xErrors) {
567
+ var e_11, _a;
568
+ var xErrorMap = {};
569
+ try {
570
+ for (var _b = __values(Object.entries(xErrors)), _c = _b.next(); !_c.done; _c = _b.next()) {
571
+ var _d = __read(_c.value, 2), field = _d[0], error = _d[1];
572
+ if (error) {
573
+ xErrorMap[field] = { form: error };
574
+ }
575
+ }
576
+ }
577
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
578
+ finally {
579
+ try {
580
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
581
+ }
582
+ finally { if (e_11) throw e_11.error; }
583
+ }
584
+ var xRowTechData = XFormBase.getXRowTechData(row);
585
+ xRowTechData.errorMap = xErrorMap;
586
+ };
587
+ // this method can be overriden in subclass if needed
588
+ // (the purpose is to put the whole form to read only mode (maybe with exception a few fields))
589
+ // if returns true for the param "field", then the field is read only, otherwise the property readOnly of the XInput* is processed
590
+ XFormBase.prototype.formReadOnly = function (object, field) {
591
+ return false;
592
+ };
593
+ // this method can be overriden in subclass if needed (to modify/save object after read from DB and before set into the form)
594
+ XFormBase.prototype.preInitForm = function (object, operationType) {
595
+ };
596
+ // this method can be overriden in subclass if needed (custom validation)
597
+ XFormBase.prototype.validate = function (object) {
598
+ return {};
599
+ };
600
+ // this method can be overriden in subclass if needed (to modify object before save)
601
+ XFormBase.prototype.preSave = function (object) {
602
+ };
603
+ // this method can be overriden in subclass if needed (to use another service then default 'saveRow')
604
+ XFormBase.prototype.saveRow = function () {
605
+ return __awaiter(this, void 0, void 0, function () {
606
+ return __generator(this, function (_a) {
607
+ return [2 /*return*/, XUtils_1.XUtils.fetch('saveRow', { entity: this.getEntity(), object: this.state.object, reload: this.props.onSaveOrCancel !== undefined })];
608
+ });
609
+ });
610
+ };
611
+ return XFormBase;
612
+ }(react_1.Component));
613
+ exports.XFormBase = XFormBase;