@michalrakus/x-react-web-lib 1.1.0 → 1.2.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.
- package/FindParam.d.ts +3 -0
- package/FindParam.js +5 -0
- package/XButtonIconNarrow.d.ts +3 -0
- package/XButtonIconNarrow.js +5 -0
- package/XButtonIconSmall.d.ts +3 -0
- package/XButtonIconSmall.js +5 -0
- package/XFieldChangeEvent.d.ts +3 -0
- package/XFieldChangeEvent.js +5 -0
- package/gulpfile.js +4 -0
- package/lib/components/SearchTableParams.d.ts +8 -2
- package/lib/components/XAutoComplete.d.ts +7 -4
- package/lib/components/XAutoComplete.js +21 -6
- package/lib/components/XAutoCompleteBase.d.ts +7 -4
- package/lib/components/XAutoCompleteBase.js +65 -26
- package/lib/components/XAutoCompleteDT.d.ts +33 -0
- package/lib/components/XAutoCompleteDT.js +141 -0
- package/lib/components/XButton.d.ts +3 -1
- package/lib/components/XButton.js +1 -1
- package/lib/components/XButtonIconNarrow.d.ts +10 -0
- package/lib/components/XButtonIconNarrow.js +25 -0
- package/lib/components/XButtonIconSmall.d.ts +3 -1
- package/lib/components/XCheckbox.d.ts +2 -2
- package/lib/components/XDropdown.d.ts +3 -2
- package/lib/components/XDropdown.js +1 -1
- package/lib/components/XFieldChangeEvent.d.ts +11 -0
- package/lib/components/XFieldChangeEvent.js +2 -0
- package/lib/components/XFormBase.d.ts +17 -9
- package/lib/components/XFormBase.js +85 -34
- package/lib/components/XFormComponent.d.ts +11 -3
- package/lib/components/XFormComponent.js +29 -3
- package/lib/components/XFormComponentDT.d.ts +30 -0
- package/lib/components/XFormComponentDT.js +119 -0
- package/lib/components/XFormDataTable2.d.ts +46 -6
- package/lib/components/XFormDataTable2.js +170 -40
- package/lib/components/XInput.d.ts +2 -2
- package/lib/components/XInputDT.d.ts +11 -0
- package/lib/components/XInputDT.js +37 -0
- package/lib/components/XInputDate.d.ts +2 -1
- package/lib/components/XInputDate.js +4 -2
- package/lib/components/XInputDecimal.d.ts +9 -2
- package/lib/components/XInputDecimal.js +62 -45
- package/lib/components/XInputDecimalDT.d.ts +10 -8
- package/lib/components/XInputDecimalDT.js +58 -36
- package/lib/components/XInputText.d.ts +3 -2
- package/lib/components/XInputText.js +7 -1
- package/lib/components/XInputTextarea.d.ts +2 -2
- package/lib/components/XLazyDataTable.d.ts +5 -0
- package/lib/components/XLazyDataTable.js +38 -23
- package/lib/components/XSearchButton.d.ts +6 -4
- package/lib/components/XSearchButton.js +19 -17
- package/lib/components/XSearchButtonDT.js +3 -3
- package/lib/components/XUtils.d.ts +12 -2
- package/lib/components/XUtils.js +94 -1
- package/lib/components/XUtilsConversions.d.ts +1 -0
- package/lib/components/XUtilsConversions.js +14 -1
- package/lib/components/XUtilsMetadata.d.ts +4 -1
- package/lib/components/XUtilsMetadata.js +46 -7
- package/lib/serverApi/FindParam.d.ts +10 -2
- package/lib/serverApi/XUtilsCommon.d.ts +1 -0
- package/lib/serverApi/XUtilsCommon.js +4 -0
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { XFormComponent, XFormComponentProps } from "./XFormComponent";
|
|
3
3
|
import { XAssoc } from "../serverApi/XEntityMetadata";
|
|
4
|
-
|
|
4
|
+
import { XObject } from "./XObject";
|
|
5
|
+
export interface XDropdownProps extends XFormComponentProps<XObject> {
|
|
5
6
|
assocField: string;
|
|
6
7
|
displayField: string;
|
|
7
8
|
}
|
|
8
|
-
export declare class XDropdown extends XFormComponent<XDropdownProps> {
|
|
9
|
+
export declare class XDropdown extends XFormComponent<XObject, XDropdownProps> {
|
|
9
10
|
protected xAssoc: XAssoc;
|
|
10
11
|
state: {
|
|
11
12
|
options: any[];
|
|
@@ -102,7 +102,7 @@ var XDropdown = /** @class */ (function (_super) {
|
|
|
102
102
|
else {
|
|
103
103
|
newValueOrNull = e.target.value;
|
|
104
104
|
}
|
|
105
|
-
this.onValueChangeBase(newValueOrNull);
|
|
105
|
+
this.onValueChangeBase(newValueOrNull, this.props.onChange);
|
|
106
106
|
};
|
|
107
107
|
XDropdown.prototype.componentDidMount = function () {
|
|
108
108
|
this.findOptions(this.props.form.getEntity(), this.props.assocField);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OperationType } from "./XUtils";
|
|
2
|
+
import { XObject } from "./XObject";
|
|
3
|
+
export interface XFieldChangeEvent<M = XObject> {
|
|
4
|
+
object: M;
|
|
5
|
+
assocObjectChange?: OperationType;
|
|
6
|
+
}
|
|
7
|
+
export interface XTableFieldChangeEvent<M = XObject, R = any> {
|
|
8
|
+
object: M;
|
|
9
|
+
tableRow: R;
|
|
10
|
+
assocObjectChange?: OperationType;
|
|
11
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Component } from "react";
|
|
2
2
|
import { XObject } from "./XObject";
|
|
3
3
|
import { OperationType } from "./XUtils";
|
|
4
|
-
import { XFormComponent } from "./XFormComponent";
|
|
5
|
-
import { XFormDataTable2 } from "./XFormDataTable2";
|
|
4
|
+
import { FieldOnChange, XFormComponent } from "./XFormComponent";
|
|
5
|
+
import { TableFieldOnChange, XFormDataTable2, XRowTechData } from "./XFormDataTable2";
|
|
6
6
|
import { XErrorMap, XErrors } from "./XErrors";
|
|
7
|
+
export type XOnSaveOrCancelProp = (object: XObject | null, objectChange: OperationType) => void;
|
|
7
8
|
export interface FormProps {
|
|
8
9
|
id?: number;
|
|
9
10
|
object?: XObject;
|
|
10
|
-
onSaveOrCancel?:
|
|
11
|
+
onSaveOrCancel?: XOnSaveOrCancelProp;
|
|
11
12
|
}
|
|
12
13
|
export declare function Form(entity: string): <T extends new (...args: any[]) => {}>(constructor: T) => {
|
|
13
14
|
new (...args: any[]): {
|
|
@@ -21,7 +22,7 @@ export declare abstract class XFormBase extends Component<FormProps> {
|
|
|
21
22
|
object: XObject | null;
|
|
22
23
|
errorMap: XErrorMap;
|
|
23
24
|
} | any;
|
|
24
|
-
xFormComponentList: Array<XFormComponent<any>>;
|
|
25
|
+
xFormComponentList: Array<XFormComponent<any, any>>;
|
|
25
26
|
xFormDataTableList: Array<XFormDataTable2>;
|
|
26
27
|
constructor(props: FormProps);
|
|
27
28
|
componentDidMount(): Promise<void>;
|
|
@@ -29,21 +30,28 @@ export declare abstract class XFormBase extends Component<FormProps> {
|
|
|
29
30
|
getXObject(): XObject;
|
|
30
31
|
getObject(): any;
|
|
31
32
|
isAddRow(): any;
|
|
32
|
-
onFieldChange(field: string, value: any, error?: string | undefined): void;
|
|
33
|
-
onTableFieldChange(
|
|
34
|
-
|
|
33
|
+
onFieldChange(field: string, value: any, error?: string | undefined, onChange?: FieldOnChange, assocObjectChange?: OperationType): void;
|
|
34
|
+
onTableFieldChange(rowData: any, field: string, value: any, error?: string | undefined, onChange?: TableFieldOnChange, assocObjectChange?: OperationType): void;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated - mal by sa pouzivat onTableFieldChange
|
|
37
|
+
*/
|
|
38
|
+
onObjectDataChange(row?: any, onChange?: TableFieldOnChange): void;
|
|
39
|
+
setStateXForm(): void;
|
|
35
40
|
onTableAddRow(assocField: string, newRow: any, dataKey?: string, selectedRow?: {}): void;
|
|
36
41
|
static getNextRowId(rowList: any[], dataKey: string): number;
|
|
37
42
|
onTableRemoveRow(assocField: string, row: {}): void;
|
|
43
|
+
static getXRowTechData(row: any): XRowTechData;
|
|
38
44
|
addField(field: string): void;
|
|
39
|
-
addXFormComponent(xFormComponent: XFormComponent<any>): void;
|
|
40
|
-
findXFormComponent(field: string): XFormComponent<any> | undefined;
|
|
45
|
+
addXFormComponent(xFormComponent: XFormComponent<any, any>): void;
|
|
46
|
+
findXFormComponent(field: string): XFormComponent<any, any> | undefined;
|
|
41
47
|
addXFormDataTable(xFormDataTable: XFormDataTable2): void;
|
|
42
48
|
onClickSave(): Promise<void>;
|
|
43
49
|
onClickCancel(): void;
|
|
44
50
|
validateSave(): boolean;
|
|
45
51
|
validateForm(): XErrorMap;
|
|
46
52
|
fieldValidation(): XErrorMap;
|
|
53
|
+
preInitForm(object: XObject, operationType: OperationType.Insert | OperationType.Update): void;
|
|
47
54
|
validate(object: XObject): XErrors;
|
|
48
55
|
preSave(object: XObject): void;
|
|
56
|
+
saveRow(): Promise<any>;
|
|
49
57
|
}
|
|
@@ -92,7 +92,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
92
92
|
exports.XFormBase = exports.Form = void 0;
|
|
93
93
|
var react_1 = require("react");
|
|
94
94
|
var XUtils_1 = require("./XUtils");
|
|
95
|
-
var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
|
|
96
95
|
// class decorator ktory nastavuje property entity (dalo by sa to nastavovat v konstruktore ale decorator je menej ukecany)
|
|
97
96
|
// ma sa pouzivat len na triedach odvodenych od XFormBase - obmedzenie som vsak nevedel nakodit
|
|
98
97
|
// property sa nastavi az po zbehnuti konstruktora
|
|
@@ -144,10 +143,11 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
144
143
|
}
|
|
145
144
|
XFormBase.prototype.componentDidMount = function () {
|
|
146
145
|
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
-
var object;
|
|
146
|
+
var object, operationType;
|
|
148
147
|
return __generator(this, function (_a) {
|
|
149
148
|
switch (_a.label) {
|
|
150
149
|
case 0:
|
|
150
|
+
console.log("volany XFormBase.componentDidMount()");
|
|
151
151
|
// kontrola (musi byt tu, v konstruktore este property nie je nastavena)
|
|
152
152
|
if (this.entity === undefined) {
|
|
153
153
|
throw "XFormBase: Property entity is not defined - use decorator @Form.";
|
|
@@ -155,18 +155,21 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
155
155
|
if (!(this.props.id !== undefined)) return [3 /*break*/, 2];
|
|
156
156
|
return [4 /*yield*/, XUtils_1.XUtils.fetchById(this.entity, Array.from(this.fields), this.props.id)];
|
|
157
157
|
case 1:
|
|
158
|
+
//console.log('XFormBase.componentDidMount ide nacitat objekt');
|
|
159
|
+
//console.log(this.fields);
|
|
158
160
|
object = _a.sent();
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.
|
|
168
|
-
|
|
169
|
-
|
|
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 }, function () { return console.log("volany XFormBase.componentDidMount() - callback setState"); });
|
|
172
|
+
return [2 /*return*/];
|
|
170
173
|
}
|
|
171
174
|
});
|
|
172
175
|
});
|
|
@@ -189,26 +192,52 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
189
192
|
XFormBase.prototype.isAddRow = function () {
|
|
190
193
|
return this.props.id === undefined;
|
|
191
194
|
};
|
|
192
|
-
XFormBase.prototype.onFieldChange = function (field, value, error) {
|
|
195
|
+
XFormBase.prototype.onFieldChange = function (field, value, error, onChange, assocObjectChange) {
|
|
193
196
|
var object = this.getXObject();
|
|
194
197
|
object[field] = value;
|
|
195
198
|
var errorMap = this.state.errorMap;
|
|
196
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
|
+
}
|
|
197
204
|
// TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
|
|
198
205
|
this.setState({ object: object, errorMap: errorMap });
|
|
199
206
|
};
|
|
200
|
-
XFormBase.prototype.onTableFieldChange = function (
|
|
207
|
+
XFormBase.prototype.onTableFieldChange = function (rowData, field, value, error, onChange, assocObjectChange) {
|
|
201
208
|
var object = this.getXObject();
|
|
202
|
-
|
|
203
|
-
|
|
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
|
+
}
|
|
204
217
|
// TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
|
|
205
|
-
this.setState({ object: object });
|
|
218
|
+
this.setState({ object: object /*, errorMap: errorMap*/ });
|
|
206
219
|
};
|
|
207
|
-
|
|
220
|
+
/**
|
|
221
|
+
* @deprecated - mal by sa pouzivat onTableFieldChange
|
|
222
|
+
*/
|
|
223
|
+
XFormBase.prototype.onObjectDataChange = function (row, onChange) {
|
|
208
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
|
+
}
|
|
209
230
|
// TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
|
|
210
231
|
this.setState({ object: object });
|
|
211
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
|
+
};
|
|
212
241
|
XFormBase.prototype.onTableAddRow = function (assocField, newRow, dataKey, selectedRow) {
|
|
213
242
|
var object = this.getXObject();
|
|
214
243
|
var rowList = object[assocField];
|
|
@@ -271,6 +300,21 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
271
300
|
// TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
|
|
272
301
|
this.setState({ object: object });
|
|
273
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
|
+
};
|
|
274
318
|
XFormBase.prototype.addField = function (field) {
|
|
275
319
|
this.fields.add(field);
|
|
276
320
|
};
|
|
@@ -328,7 +372,7 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
328
372
|
_a.label = 1;
|
|
329
373
|
case 1:
|
|
330
374
|
_a.trys.push([1, 3, , 4]);
|
|
331
|
-
return [4 /*yield*/,
|
|
375
|
+
return [4 /*yield*/, this.saveRow()];
|
|
332
376
|
case 2:
|
|
333
377
|
object = _a.sent();
|
|
334
378
|
return [3 /*break*/, 4];
|
|
@@ -362,25 +406,20 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
362
406
|
};
|
|
363
407
|
XFormBase.prototype.validateSave = function () {
|
|
364
408
|
var e_4, _a;
|
|
365
|
-
var _b;
|
|
366
409
|
var xErrorMap = this.validateForm();
|
|
367
|
-
// zatial takto
|
|
368
|
-
var msg =
|
|
410
|
+
// zatial takto jednoducho
|
|
411
|
+
var msg = XUtils_1.XUtils.getErrorMessages(xErrorMap);
|
|
369
412
|
try {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
if (errorMessage) {
|
|
375
|
-
msg += "".concat((_b = xError.fieldLabel) !== null && _b !== void 0 ? _b : field, ": ").concat(errorMessage).concat(XUtilsCommon_1.XUtilsCommon.newLine);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
413
|
+
// este spracujeme editovatelne tabulky
|
|
414
|
+
for (var _b = __values(this.xFormDataTableList), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
415
|
+
var xFormDataTable = _c.value;
|
|
416
|
+
msg += xFormDataTable.getErrorMessages();
|
|
378
417
|
}
|
|
379
418
|
}
|
|
380
419
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
381
420
|
finally {
|
|
382
421
|
try {
|
|
383
|
-
if (
|
|
422
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
384
423
|
}
|
|
385
424
|
finally { if (e_4) throw e_4.error; }
|
|
386
425
|
}
|
|
@@ -415,7 +454,8 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
415
454
|
finally { if (e_5) throw e_5.error; }
|
|
416
455
|
}
|
|
417
456
|
// 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)
|
|
418
|
-
this.
|
|
457
|
+
// setujeme aj this.state.object, lebo mohli pribudnut/odbudnut chyby na rowData v editovatelnych tabulkach
|
|
458
|
+
this.setState({ object: this.state.object, errorMap: xErrorMap });
|
|
419
459
|
return xErrorMap;
|
|
420
460
|
};
|
|
421
461
|
XFormBase.prototype.fieldValidation = function () {
|
|
@@ -441,7 +481,7 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
441
481
|
try {
|
|
442
482
|
for (var _e = __values(this.xFormDataTableList), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
443
483
|
var xFormDataTable = _f.value;
|
|
444
|
-
|
|
484
|
+
xFormDataTable.validate();
|
|
445
485
|
}
|
|
446
486
|
}
|
|
447
487
|
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
@@ -453,6 +493,9 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
453
493
|
}
|
|
454
494
|
return xErrorMap;
|
|
455
495
|
};
|
|
496
|
+
// this method can be overriden in subclass if needed (to modify/save object after read from DB and before set into the form)
|
|
497
|
+
XFormBase.prototype.preInitForm = function (object, operationType) {
|
|
498
|
+
};
|
|
456
499
|
// this method can be overriden in subclass if needed (custom validation)
|
|
457
500
|
XFormBase.prototype.validate = function (object) {
|
|
458
501
|
return {};
|
|
@@ -460,6 +503,14 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
460
503
|
// this method can be overriden in subclass if needed (to modify object before save)
|
|
461
504
|
XFormBase.prototype.preSave = function (object) {
|
|
462
505
|
};
|
|
506
|
+
// this method can be overriden in subclass if needed (to use another service then default 'saveRow')
|
|
507
|
+
XFormBase.prototype.saveRow = function () {
|
|
508
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
509
|
+
return __generator(this, function (_a) {
|
|
510
|
+
return [2 /*return*/, XUtils_1.XUtils.fetch('saveRow', { entity: this.getEntity(), object: this.state.object, reload: this.props.onSaveOrCancel !== undefined })];
|
|
511
|
+
});
|
|
512
|
+
});
|
|
513
|
+
};
|
|
463
514
|
return XFormBase;
|
|
464
515
|
}(react_1.Component));
|
|
465
516
|
exports.XFormBase = XFormBase;
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import React, { Component } from "react";
|
|
2
2
|
import { XFormBase } from "./XFormBase";
|
|
3
3
|
import { XError } from "./XErrors";
|
|
4
|
-
|
|
4
|
+
import { OperationType } from "./XUtils";
|
|
5
|
+
import { XFieldChangeEvent } from "./XFieldChangeEvent";
|
|
6
|
+
import { XCustomFilter } from "../serverApi/FindParam";
|
|
7
|
+
export type FieldOnChange = (e: XFieldChangeEvent<any>) => void;
|
|
8
|
+
export type XFilterProp = XCustomFilter | ((object: any) => XCustomFilter | undefined);
|
|
9
|
+
export interface XFormComponentProps<T> {
|
|
5
10
|
form: XFormBase;
|
|
6
11
|
label?: string;
|
|
7
12
|
readOnly?: boolean;
|
|
8
13
|
labelStyle?: React.CSSProperties;
|
|
9
14
|
inline?: boolean;
|
|
15
|
+
onChange?: FieldOnChange;
|
|
10
16
|
}
|
|
11
|
-
export declare abstract class XFormComponent<P extends XFormComponentProps
|
|
17
|
+
export declare abstract class XFormComponent<T, P extends XFormComponentProps<T>> extends Component<P> {
|
|
12
18
|
protected constructor(props: P);
|
|
13
19
|
abstract getField(): string;
|
|
14
20
|
getValueFromObject(): any;
|
|
15
|
-
onValueChangeBase(value: any): void;
|
|
21
|
+
onValueChangeBase(value: any, onChange?: FieldOnChange, assocObjectChange?: OperationType): void;
|
|
16
22
|
abstract isNotNull(): boolean;
|
|
17
23
|
isReadOnly(): boolean;
|
|
18
24
|
getLabel(): string;
|
|
@@ -25,4 +31,6 @@ export declare abstract class XFormComponent<P extends XFormComponentProps> exte
|
|
|
25
31
|
validateNotNull(value: any): string | undefined;
|
|
26
32
|
getClassNameTooltip(): {};
|
|
27
33
|
getError(): string | undefined;
|
|
34
|
+
callOnChangeFromOnBlur(): void;
|
|
35
|
+
getFilterBase(filter: XFilterProp | undefined): XCustomFilter | undefined;
|
|
28
36
|
}
|
|
@@ -42,9 +42,9 @@ var XFormComponent = /** @class */ (function (_super) {
|
|
|
42
42
|
return objectValue;
|
|
43
43
|
};
|
|
44
44
|
// writes value into form.state.object
|
|
45
|
-
XFormComponent.prototype.onValueChangeBase = function (value) {
|
|
45
|
+
XFormComponent.prototype.onValueChangeBase = function (value, onChange, assocObjectChange) {
|
|
46
46
|
var error = this.validateOnChange(value);
|
|
47
|
-
this.props.form.onFieldChange(this.getField(), value, error);
|
|
47
|
+
this.props.form.onFieldChange(this.getField(), value, error, onChange, assocObjectChange);
|
|
48
48
|
};
|
|
49
49
|
XFormComponent.prototype.isReadOnly = function () {
|
|
50
50
|
// tuto do buducna planujeme pridat aj dynamicky readOnly, bude ho treba ukladat do form.state podobne ako sa ukladaju errory do form.state.errorMap
|
|
@@ -116,7 +116,33 @@ var XFormComponent = /** @class */ (function (_super) {
|
|
|
116
116
|
// vrati error message z form.state.errorMap
|
|
117
117
|
XFormComponent.prototype.getError = function () {
|
|
118
118
|
var error = this.props.form.state.errorMap[this.getField()];
|
|
119
|
-
return error ? XUtils_1.XUtils.
|
|
119
|
+
return error ? XUtils_1.XUtils.getErrorMessage(error) : undefined;
|
|
120
|
+
};
|
|
121
|
+
XFormComponent.prototype.callOnChangeFromOnBlur = function () {
|
|
122
|
+
if (this.props.onChange) {
|
|
123
|
+
var object = this.props.form.getXObject();
|
|
124
|
+
// developer v onChange nastavi atributy na object-e
|
|
125
|
+
this.props.onChange({ object: object });
|
|
126
|
+
// rovno zavolame form.setState({...}), nech to nemusi robit developer
|
|
127
|
+
this.props.form.setStateXForm();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
// len pre assoc fieldy sa pouziva
|
|
131
|
+
XFormComponent.prototype.getFilterBase = function (filter) {
|
|
132
|
+
var customFilter = undefined;
|
|
133
|
+
if (typeof filter === 'object') {
|
|
134
|
+
customFilter = filter;
|
|
135
|
+
}
|
|
136
|
+
if (typeof filter === 'function') {
|
|
137
|
+
//const object: XObject = this.props.form.getXObject();
|
|
138
|
+
var object = this.props.form.state.object;
|
|
139
|
+
// zatial zakomentujeme, aby sa zavolal aj pre XAutoComplete (tam zatial nemame k dispozicii object
|
|
140
|
+
// (componentDidMount pre XAutoComplete sa vola skor ako componentDidMount pre XFormBase))
|
|
141
|
+
//if (object) {
|
|
142
|
+
customFilter = filter(object);
|
|
143
|
+
//}
|
|
144
|
+
}
|
|
145
|
+
return customFilter;
|
|
120
146
|
};
|
|
121
147
|
return XFormComponent;
|
|
122
148
|
}(react_1.Component));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { XFormBase } from "./XFormBase";
|
|
2
|
+
import { Component } from "react";
|
|
3
|
+
import { OperationType } from "./XUtils";
|
|
4
|
+
import { XError } from "./XErrors";
|
|
5
|
+
import { XCustomFilter } from "../serverApi/FindParam";
|
|
6
|
+
import { XTableFieldFilterProp, TableFieldOnChange } from "./XFormDataTable2";
|
|
7
|
+
export interface XFormComponentDTProps {
|
|
8
|
+
form: XFormBase;
|
|
9
|
+
entity: string;
|
|
10
|
+
rowData: any;
|
|
11
|
+
readOnly?: boolean;
|
|
12
|
+
onChange?: TableFieldOnChange;
|
|
13
|
+
}
|
|
14
|
+
export declare abstract class XFormComponentDT<P extends XFormComponentDTProps> extends Component<P> {
|
|
15
|
+
protected constructor(props: P);
|
|
16
|
+
abstract getField(): string;
|
|
17
|
+
getValueFromRowData(): any;
|
|
18
|
+
onValueChangeBase(value: any, onChange?: TableFieldOnChange, assocObjectChange?: OperationType): void;
|
|
19
|
+
abstract isNotNull(): boolean;
|
|
20
|
+
isReadOnly(): boolean;
|
|
21
|
+
validate(): {
|
|
22
|
+
field: string;
|
|
23
|
+
xError: XError;
|
|
24
|
+
} | undefined;
|
|
25
|
+
validateOnChange(value: any): string | undefined;
|
|
26
|
+
validateNotNull(value: any): string | undefined;
|
|
27
|
+
getError(): string | undefined;
|
|
28
|
+
callOnChangeFromOnBlur(): void;
|
|
29
|
+
getFilterBase(filter: XTableFieldFilterProp | undefined): XCustomFilter | undefined;
|
|
30
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.XFormComponentDT = void 0;
|
|
19
|
+
var XFormBase_1 = require("./XFormBase");
|
|
20
|
+
var react_1 = require("react");
|
|
21
|
+
var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
|
|
22
|
+
var XUtils_1 = require("./XUtils");
|
|
23
|
+
var XFormComponentDT = /** @class */ (function (_super) {
|
|
24
|
+
__extends(XFormComponentDT, _super);
|
|
25
|
+
function XFormComponentDT(props) {
|
|
26
|
+
var _this = _super.call(this, props) || this;
|
|
27
|
+
XFormBase_1.XFormBase.getXRowTechData(props.rowData).xFormComponentDTList.push(_this);
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
// ******** read and write from/into this.props.rowData ***********
|
|
31
|
+
// reads value from this.props.rowData
|
|
32
|
+
// can be overridden, but this should work for every component
|
|
33
|
+
XFormComponentDT.prototype.getValueFromRowData = function () {
|
|
34
|
+
var rowDataValue = null;
|
|
35
|
+
// test na undefined je tu koli insertu noveho riadku
|
|
36
|
+
if (this.props.rowData !== undefined && this.props.rowData !== null) {
|
|
37
|
+
rowDataValue = XUtilsCommon_1.XUtilsCommon.getValueByPath(this.props.rowData, this.getField());
|
|
38
|
+
// pre istotu dame na null, null je standard
|
|
39
|
+
if (rowDataValue === undefined) {
|
|
40
|
+
rowDataValue = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return rowDataValue;
|
|
44
|
+
};
|
|
45
|
+
// writes value into form.state.object
|
|
46
|
+
XFormComponentDT.prototype.onValueChangeBase = function (value, onChange, assocObjectChange) {
|
|
47
|
+
var error = this.validateOnChange(value);
|
|
48
|
+
this.props.form.onTableFieldChange(this.props.rowData, this.getField(), value, error, onChange, assocObjectChange);
|
|
49
|
+
};
|
|
50
|
+
XFormComponentDT.prototype.isReadOnly = function () {
|
|
51
|
+
// tuto do buducna planujeme pridat aj dynamicky readOnly, bude ho treba ukladat do form.state podobne ako sa ukladaju errory do form.state.errorMap
|
|
52
|
+
return XUtils_1.XUtils.isReadOnly(this.getField(), this.props.readOnly);
|
|
53
|
+
};
|
|
54
|
+
// *********** validation support ************
|
|
55
|
+
// volane po kliknuti na Save
|
|
56
|
+
// vrati (field, XError) ak nezbehne "field validacia", ak zbehne, vrati undefined
|
|
57
|
+
XFormComponentDT.prototype.validate = function () {
|
|
58
|
+
// TODO - FILOZOFICKA OTAZKA - volat validaciu aj ked je field readOnly (this.isReadOnly() === true)? zatial dame ze hej...
|
|
59
|
+
var value = this.getValueFromRowData();
|
|
60
|
+
// not null validacia + custom field validacia volana na onChange
|
|
61
|
+
var errorOnChange = this.validateOnChange(value);
|
|
62
|
+
// custom field validacia volana na onBlur (focus lost)
|
|
63
|
+
// TODO - fieldLabel
|
|
64
|
+
if (errorOnChange) {
|
|
65
|
+
return { field: this.getField(), xError: { onChange: errorOnChange, fieldLabel: undefined } };
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
};
|
|
69
|
+
XFormComponentDT.prototype.validateOnChange = function (value) {
|
|
70
|
+
var error = this.validateNotNull(value);
|
|
71
|
+
if (error) {
|
|
72
|
+
return error;
|
|
73
|
+
}
|
|
74
|
+
// custom field validacia volana na onChange
|
|
75
|
+
// TODO
|
|
76
|
+
return undefined;
|
|
77
|
+
};
|
|
78
|
+
XFormComponentDT.prototype.validateNotNull = function (value) {
|
|
79
|
+
// validacia by mala sediet s metodou getLabel(), kde sa pridava * , preto tu mame aj test !this.isReadOnly() - id fieldy pri inserte nechceme testovat
|
|
80
|
+
// otazka je ci nevypinat validaciu pre readOnly fieldy vzdy (aj ked napr. readOnly vznikne dynamicky)
|
|
81
|
+
if (this.isNotNull() && !this.isReadOnly() && value === null) {
|
|
82
|
+
return "Field is required.";
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
};
|
|
86
|
+
// vrati error message z rowData.errorMap
|
|
87
|
+
XFormComponentDT.prototype.getError = function () {
|
|
88
|
+
var error = XFormBase_1.XFormBase.getXRowTechData(this.props.rowData).errorMap[this.getField()];
|
|
89
|
+
return error ? XUtils_1.XUtils.getErrorMessage(error) : undefined;
|
|
90
|
+
};
|
|
91
|
+
XFormComponentDT.prototype.callOnChangeFromOnBlur = function () {
|
|
92
|
+
if (this.props.onChange) {
|
|
93
|
+
var object = this.props.form.getXObject();
|
|
94
|
+
// developer v onChange nastavi atributy na object-e
|
|
95
|
+
this.props.onChange({ object: object, tableRow: this.props.rowData, assocObjectChange: undefined });
|
|
96
|
+
// rovno zavolame form.setState({...}), nech to nemusi robit developer
|
|
97
|
+
this.props.form.setStateXForm();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
// len pre assoc fieldy sa pouziva, aj to nie pre vsetky
|
|
101
|
+
XFormComponentDT.prototype.getFilterBase = function (filter) {
|
|
102
|
+
var customFilter = undefined;
|
|
103
|
+
if (typeof filter === 'object') {
|
|
104
|
+
customFilter = filter;
|
|
105
|
+
}
|
|
106
|
+
if (typeof filter === 'function') {
|
|
107
|
+
//const object: XObject = this.props.form.getXObject();
|
|
108
|
+
var object = this.props.form.state.object;
|
|
109
|
+
// zatial zakomentujeme, aby sa zavolal aj pre XAutoComplete (tam zatial nemame k dispozicii object
|
|
110
|
+
// (componentDidMount pre XAutoComplete sa vola skor ako componentDidMount pre XFormBase))
|
|
111
|
+
//if (object) {
|
|
112
|
+
customFilter = filter(object, this.props.rowData);
|
|
113
|
+
//}
|
|
114
|
+
}
|
|
115
|
+
return customFilter;
|
|
116
|
+
};
|
|
117
|
+
return XFormComponentDT;
|
|
118
|
+
}(react_1.Component));
|
|
119
|
+
exports.XFormComponentDT = XFormComponentDT;
|