@michalrakus/x-react-web-lib 1.7.3 → 1.9.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 (152) hide show
  1. package/README.md +3 -3
  2. package/gulpfile.js +82 -82
  3. package/lib/administration/XBrowseMetaBrowse.d.ts +2 -2
  4. package/lib/administration/XBrowseMetaBrowse.js +21 -21
  5. package/lib/administration/XBrowseMetaForm.d.ts +5 -5
  6. package/lib/administration/XBrowseMetaForm.js +63 -63
  7. package/lib/administration/XUserBrowse.d.ts +2 -2
  8. package/lib/administration/XUserBrowse.js +88 -87
  9. package/lib/administration/XUserForm.d.ts +9 -9
  10. package/lib/administration/XUserForm.js +195 -194
  11. package/lib/components/SearchTableParams.d.ts +11 -11
  12. package/lib/components/SearchTableParams.js +2 -2
  13. package/lib/components/SourceCodeLinkEntity.d.ts +4 -4
  14. package/lib/components/SourceCodeLinkEntity.js +14 -14
  15. package/lib/components/XAutoComplete.d.ts +36 -36
  16. package/lib/components/XAutoComplete.js +155 -155
  17. package/lib/components/XAutoCompleteBase.d.ts +45 -45
  18. package/lib/components/XAutoCompleteBase.js +371 -371
  19. package/lib/components/XAutoCompleteDT.d.ts +33 -33
  20. package/lib/components/XAutoCompleteDT.js +140 -140
  21. package/lib/components/XBrowse.d.ts +33 -33
  22. package/lib/components/XBrowse.js +360 -360
  23. package/lib/components/XButton.d.ts +9 -9
  24. package/lib/components/XButton.js +13 -13
  25. package/lib/components/XButtonIconMedium.d.ts +9 -9
  26. package/lib/components/XButtonIconMedium.js +13 -13
  27. package/lib/components/XButtonIconNarrow.d.ts +10 -10
  28. package/lib/components/XButtonIconNarrow.js +25 -25
  29. package/lib/components/XButtonIconSmall.d.ts +9 -9
  30. package/lib/components/XButtonIconSmall.js +13 -13
  31. package/lib/components/XCalendar.d.ts +8 -8
  32. package/lib/components/XCalendar.js +27 -27
  33. package/lib/components/XChangePasswordForm.d.ts +5 -5
  34. package/lib/components/XChangePasswordForm.js +160 -160
  35. package/lib/components/XCheckbox.d.ts +8 -8
  36. package/lib/components/XCheckbox.js +57 -57
  37. package/lib/components/XCheckboxDT.d.ts +10 -10
  38. package/lib/components/XCheckboxDT.js +46 -46
  39. package/lib/components/XDataTable.d.ts +11 -11
  40. package/lib/components/XDataTable.js +197 -197
  41. package/lib/components/XDropdown.d.ts +18 -18
  42. package/lib/components/XDropdown.js +57 -57
  43. package/lib/components/XDropdownDT.d.ts +13 -13
  44. package/lib/components/XDropdownDT.js +128 -128
  45. package/lib/components/XDropdownDTFilter.d.ts +7 -7
  46. package/lib/components/XDropdownDTFilter.js +121 -121
  47. package/lib/components/XDropdownForEntity.d.ts +25 -25
  48. package/lib/components/XDropdownForEntity.js +149 -149
  49. package/lib/components/XDropdownFormDTFilter.d.ts +7 -7
  50. package/lib/components/XDropdownFormDTFilter.js +121 -121
  51. package/lib/components/XEditColumnDialog.d.ts +13 -13
  52. package/lib/components/XEditColumnDialog.js +112 -112
  53. package/lib/components/XEnvVars.d.ts +15 -12
  54. package/lib/components/XEnvVars.js +23 -20
  55. package/lib/components/XErrors.d.ts +12 -12
  56. package/lib/components/XErrors.js +2 -2
  57. package/lib/components/XExportRowsDialog.d.ts +15 -15
  58. package/lib/components/XExportRowsDialog.js +184 -184
  59. package/lib/components/XFieldChangeEvent.d.ts +11 -11
  60. package/lib/components/XFieldChangeEvent.js +2 -2
  61. package/lib/components/XFieldSelector.d.ts +7 -7
  62. package/lib/components/XFieldSelector.js +113 -113
  63. package/lib/components/XFormBase.d.ts +59 -59
  64. package/lib/components/XFormBase.js +526 -526
  65. package/lib/components/XFormBaseModif.d.ts +5 -5
  66. package/lib/components/XFormBaseModif.js +33 -33
  67. package/lib/components/XFormBaseT.d.ts +4 -4
  68. package/lib/components/XFormBaseT.js +31 -31
  69. package/lib/components/XFormComponent.d.ts +40 -40
  70. package/lib/components/XFormComponent.js +177 -177
  71. package/lib/components/XFormComponentDT.d.ts +30 -30
  72. package/lib/components/XFormComponentDT.js +145 -145
  73. package/lib/components/XFormDataTable2.d.ts +143 -143
  74. package/lib/components/XFormDataTable2.js +686 -686
  75. package/lib/components/XFormFooter.d.ts +6 -6
  76. package/lib/components/XFormFooter.js +19 -19
  77. package/lib/components/XFormNavigator3.d.ts +12 -12
  78. package/lib/components/XFormNavigator3.js +130 -130
  79. package/lib/components/XHolders.d.ts +7 -7
  80. package/lib/components/XHolders.js +15 -15
  81. package/lib/components/XInput.d.ts +13 -13
  82. package/lib/components/XInput.js +38 -38
  83. package/lib/components/XInputDT.d.ts +11 -11
  84. package/lib/components/XInputDT.js +37 -37
  85. package/lib/components/XInputDate.d.ts +13 -13
  86. package/lib/components/XInputDate.js +63 -63
  87. package/lib/components/XInputDateDT.d.ts +10 -10
  88. package/lib/components/XInputDateDT.js +55 -55
  89. package/lib/components/XInputDecimal.d.ts +15 -15
  90. package/lib/components/XInputDecimal.js +78 -78
  91. package/lib/components/XInputDecimalBase.d.ts +12 -12
  92. package/lib/components/XInputDecimalBase.js +18 -18
  93. package/lib/components/XInputDecimalDT.d.ts +11 -11
  94. package/lib/components/XInputDecimalDT.js +74 -74
  95. package/lib/components/XInputFileList.d.ts +36 -36
  96. package/lib/components/XInputFileList.js +251 -244
  97. package/lib/components/XInputText.d.ts +12 -12
  98. package/lib/components/XInputText.js +69 -69
  99. package/lib/components/XInputTextDT.d.ts +9 -9
  100. package/lib/components/XInputTextDT.js +42 -42
  101. package/lib/components/XInputTextarea.d.ts +18 -18
  102. package/lib/components/XInputTextarea.js +85 -85
  103. package/lib/components/XLazyDataTable.d.ts +78 -78
  104. package/lib/components/XLazyDataTable.js +885 -885
  105. package/lib/components/XLocale.d.ts +26 -26
  106. package/lib/components/XLocale.js +59 -59
  107. package/lib/components/XLoginDialog.d.ts +8 -8
  108. package/lib/components/XLoginDialog.js +21 -21
  109. package/lib/components/XLoginForm.d.ts +7 -7
  110. package/lib/components/XLoginForm.js +128 -128
  111. package/lib/components/XObject.d.ts +3 -3
  112. package/lib/components/XObject.js +2 -2
  113. package/lib/components/XResponseError.d.ts +11 -11
  114. package/lib/components/XResponseError.js +32 -32
  115. package/lib/components/XSearchButton.d.ts +26 -26
  116. package/lib/components/XSearchButton.js +225 -225
  117. package/lib/components/XSearchButtonDT.d.ts +12 -12
  118. package/lib/components/XSearchButtonDT.js +188 -188
  119. package/lib/components/XSearchButtonOld.d.ts +13 -13
  120. package/lib/components/XSearchButtonOld.js +212 -212
  121. package/lib/components/XToOneAssocButton.d.ts +8 -8
  122. package/lib/components/XToOneAssocButton.js +30 -30
  123. package/lib/components/XToken.d.ts +6 -6
  124. package/lib/components/XToken.js +2 -2
  125. package/lib/components/XUtils.d.ts +74 -74
  126. package/lib/components/XUtils.js +627 -627
  127. package/lib/components/XUtilsConversions.d.ts +12 -12
  128. package/lib/components/XUtilsConversions.js +125 -125
  129. package/lib/components/XUtilsMetadata.d.ts +39 -39
  130. package/lib/components/XUtilsMetadata.js +452 -452
  131. package/lib/components/locale/x-en.json +26 -26
  132. package/lib/components/useXToken.d.ts +2 -2
  133. package/lib/components/useXToken.js +44 -44
  134. package/lib/serverApi/ExportImportParam.d.ts +51 -51
  135. package/lib/serverApi/ExportImportParam.js +34 -34
  136. package/lib/serverApi/FindParam.d.ts +34 -34
  137. package/lib/serverApi/FindParam.js +30 -30
  138. package/lib/serverApi/FindResult.d.ts +8 -8
  139. package/lib/serverApi/FindResult.js +2 -2
  140. package/lib/serverApi/XBrowseMetadata.d.ts +19 -19
  141. package/lib/serverApi/XBrowseMetadata.js +2 -2
  142. package/lib/serverApi/XEntityMetadata.d.ts +35 -35
  143. package/lib/serverApi/XEntityMetadata.js +2 -2
  144. package/lib/serverApi/XFileJsonField.d.ts +6 -0
  145. package/lib/serverApi/XFileJsonField.js +2 -0
  146. package/lib/serverApi/XUser.d.ts +8 -7
  147. package/lib/serverApi/XUser.js +2 -2
  148. package/lib/serverApi/XUserAuthenticationIfc.d.ts +9 -9
  149. package/lib/serverApi/XUserAuthenticationIfc.js +2 -2
  150. package/lib/serverApi/XUtilsCommon.d.ts +13 -13
  151. package/lib/serverApi/XUtilsCommon.js +110 -110
  152. package/package.json +1 -1
@@ -1,526 +1,526 @@
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.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;