@michalrakus/x-react-web-lib 1.0.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/LICENSE.md +21 -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/XInputTextarea.d.ts +3 -0
- package/XInputTextarea.js +5 -0
- package/gulpfile.js +5 -0
- package/lib/administration/XBrowseMetaBrowse.js +2 -1
- package/lib/administration/XBrowseMetaForm.js +4 -2
- package/lib/administration/XUserBrowse.js +3 -2
- package/lib/administration/XUserForm.js +5 -3
- package/lib/components/SearchTableParams.d.ts +8 -2
- package/lib/components/SourceCodeLinkEntity.js +3 -2
- package/lib/components/XAutoComplete.d.ts +10 -7
- package/lib/components/XAutoComplete.js +37 -41
- package/lib/components/XAutoCompleteBase.d.ts +8 -5
- package/lib/components/XAutoCompleteBase.js +86 -43
- package/lib/components/XAutoCompleteDT.d.ts +33 -0
- package/lib/components/XAutoCompleteDT.js +141 -0
- package/lib/components/XBrowse.js +11 -5
- package/lib/components/XButton.d.ts +3 -1
- package/lib/components/XButton.js +3 -2
- 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/XButtonIconSmall.js +2 -1
- package/lib/components/XChangePasswordForm.js +12 -7
- package/lib/components/XCheckbox.d.ts +8 -10
- package/lib/components/XCheckbox.js +39 -31
- package/lib/components/XCheckboxDT.js +2 -1
- package/lib/components/XDataTable.js +16 -10
- package/lib/components/XDropdown.d.ts +7 -5
- package/lib/components/XDropdown.js +24 -45
- package/lib/components/XDropdownDT.js +10 -5
- package/lib/components/XDropdownDTFilter.js +12 -7
- package/lib/components/XDropdownFormDTFilter.js +12 -7
- package/lib/components/XEditColumnDialog.js +12 -7
- package/lib/components/XErrors.d.ts +1 -0
- package/lib/components/XExportRowsDialog.js +13 -8
- package/lib/components/XFieldChangeEvent.d.ts +11 -0
- package/lib/components/XFieldChangeEvent.js +2 -0
- package/lib/components/XFieldSelector.js +11 -6
- package/lib/components/XFormBase.d.ts +17 -8
- package/lib/components/XFormBase.js +127 -48
- package/lib/components/XFormBaseT.js +3 -1
- package/lib/components/XFormComponent.d.ts +19 -7
- package/lib/components/XFormComponent.js +89 -49
- package/lib/components/XFormComponentDT.d.ts +30 -0
- package/lib/components/XFormComponentDT.js +119 -0
- package/lib/components/XFormDataTable2.d.ts +53 -8
- package/lib/components/XFormDataTable2.js +270 -57
- package/lib/components/XFormFooter.js +2 -1
- package/lib/components/XFormNavigator3.js +18 -7
- package/lib/components/XHolders.js +4 -2
- package/lib/components/XInput.d.ts +13 -0
- package/lib/components/XInput.js +38 -0
- 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 +7 -4
- package/lib/components/XInputDateDT.js +3 -2
- package/lib/components/XInputDecimal.d.ts +9 -2
- package/lib/components/XInputDecimal.js +63 -45
- package/lib/components/XInputDecimalDT.d.ts +10 -8
- package/lib/components/XInputDecimalDT.js +59 -36
- package/lib/components/XInputText.d.ts +7 -11
- package/lib/components/XInputText.js +22 -49
- package/lib/components/XInputTextDT.js +4 -4
- package/lib/components/XInputTextarea.d.ts +18 -0
- package/lib/components/XInputTextarea.js +85 -0
- package/lib/components/XLazyDataTable.d.ts +8 -0
- package/lib/components/XLazyDataTable.js +187 -85
- package/lib/components/XLoginDialog.js +2 -1
- package/lib/components/XLoginForm.js +11 -6
- package/lib/components/XResponseError.js +4 -2
- package/lib/components/XSearchButton.d.ts +8 -7
- package/lib/components/XSearchButton.js +32 -51
- package/lib/components/XSearchButtonDT.js +15 -10
- package/lib/components/XSearchButtonOld.js +13 -8
- package/lib/components/XToOneAssocButton.js +2 -1
- package/lib/components/XUtils.d.ts +13 -1
- package/lib/components/XUtils.js +125 -5
- package/lib/components/XUtilsConversions.d.ts +1 -0
- package/lib/components/XUtilsConversions.js +24 -3
- package/lib/components/XUtilsMetadata.d.ts +4 -1
- package/lib/components/XUtilsMetadata.js +62 -14
- package/lib/components/useXToken.js +1 -1
- package/lib/serverApi/ExportImportParam.d.ts +3 -3
- package/lib/serverApi/FindParam.d.ts +12 -14
- package/lib/serverApi/FindParam.js +14 -0
- package/lib/serverApi/XUtilsCommon.d.ts +1 -0
- package/lib/serverApi/XUtilsCommon.js +6 -2
- package/package.json +24 -25
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,7 +18,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
14
18
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
19
|
if (mod && mod.__esModule) return mod;
|
|
16
20
|
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
22
|
__setModuleDefault(result, mod);
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
@@ -51,11 +55,11 @@ var react_1 = __importStar(require("react"));
|
|
|
51
55
|
var treetable_1 = require("primereact/treetable");
|
|
52
56
|
var column_1 = require("primereact/column");
|
|
53
57
|
var XUtilsMetadata_1 = require("./XUtilsMetadata");
|
|
54
|
-
|
|
58
|
+
var XFieldSelector = function (props) {
|
|
55
59
|
// poznamka: treeNodeList by sme mohli vypocitavat priamo, ale ked pouzijeme useState/useEffect tak sa createTreeNodeList zavola len raz pri vytvoreni komponentu
|
|
56
|
-
var _a = __read(react_1.useState([]), 2), treeNodeList = _a[0], setTreeNodeList = _a[1];
|
|
60
|
+
var _a = __read((0, react_1.useState)([]), 2), treeNodeList = _a[0], setTreeNodeList = _a[1];
|
|
57
61
|
// parameter [] zabezpeci ze sa metoda zavola len po prvom renderingu (a nie po kazdej zmene stavu (zavolani setNieco()))
|
|
58
|
-
react_1.useEffect(function () {
|
|
62
|
+
(0, react_1.useEffect)(function () {
|
|
59
63
|
setTreeNodeList(createTreeNodeList(props.entity, ""));
|
|
60
64
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
61
65
|
var createTreeNodeList = function (entity, keyPrefix) {
|
|
@@ -101,7 +105,8 @@ exports.XFieldSelector = function (props) {
|
|
|
101
105
|
}
|
|
102
106
|
return treeNodeList;
|
|
103
107
|
};
|
|
104
|
-
return (react_1.default.createElement(treetable_1.TreeTable, { value: treeNodeList, selectionMode: "single", selectionKeys: props.selectionField, onSelectionChange: function (e) { return props.onSelectionChange(e.value); }, className: "x-field-treetable p-treetable-sm", scrollable: true, scrollHeight: "20rem" },
|
|
108
|
+
return (react_1.default.createElement(treetable_1.TreeTable, { value: treeNodeList, selectionMode: "single", selectionKeys: props.selectionField, onSelectionChange: function (e) { return props.onSelectionChange(Object.keys(e.value)[0]); }, className: "x-field-treetable p-treetable-sm", scrollable: true, scrollHeight: "20rem" },
|
|
105
109
|
react_1.default.createElement(column_1.Column, { field: "name", header: "Field name", headerStyle: { width: "15.7rem" }, expander: true }),
|
|
106
110
|
react_1.default.createElement(column_1.Column, { field: "type", header: "Type", headerStyle: { width: "9.3rem" } })));
|
|
107
111
|
};
|
|
112
|
+
exports.XFieldSelector = XFieldSelector;
|
|
@@ -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,20 +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;
|
|
45
|
+
addXFormComponent(xFormComponent: XFormComponent<any, any>): void;
|
|
46
|
+
findXFormComponent(field: string): XFormComponent<any, any> | undefined;
|
|
40
47
|
addXFormDataTable(xFormDataTable: XFormDataTable2): void;
|
|
41
48
|
onClickSave(): Promise<void>;
|
|
42
49
|
onClickCancel(): void;
|
|
43
50
|
validateSave(): boolean;
|
|
44
51
|
validateForm(): XErrorMap;
|
|
45
52
|
fieldValidation(): XErrorMap;
|
|
53
|
+
preInitForm(object: XObject, operationType: OperationType.Insert | OperationType.Update): void;
|
|
46
54
|
validate(object: XObject): XErrors;
|
|
47
55
|
preSave(object: XObject): void;
|
|
56
|
+
saveRow(): Promise<any>;
|
|
48
57
|
}
|
|
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
3
3
|
var extendStatics = function (d, b) {
|
|
4
4
|
extendStatics = Object.setPrototypeOf ||
|
|
5
5
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
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");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -38,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
40
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
39
41
|
function step(op) {
|
|
40
42
|
if (f) throw new TypeError("Generator is already executing.");
|
|
41
|
-
while (_) try {
|
|
43
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
42
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;
|
|
43
45
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
44
46
|
switch (op[0]) {
|
|
@@ -90,7 +92,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
90
92
|
exports.XFormBase = exports.Form = void 0;
|
|
91
93
|
var react_1 = require("react");
|
|
92
94
|
var XUtils_1 = require("./XUtils");
|
|
93
|
-
var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
|
|
94
95
|
// class decorator ktory nastavuje property entity (dalo by sa to nastavovat v konstruktore ale decorator je menej ukecany)
|
|
95
96
|
// ma sa pouzivat len na triedach odvodenych od XFormBase - obmedzenie som vsak nevedel nakodit
|
|
96
97
|
// property sa nastavi az po zbehnuti konstruktora
|
|
@@ -142,10 +143,11 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
142
143
|
}
|
|
143
144
|
XFormBase.prototype.componentDidMount = function () {
|
|
144
145
|
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
-
var object;
|
|
146
|
+
var object, operationType;
|
|
146
147
|
return __generator(this, function (_a) {
|
|
147
148
|
switch (_a.label) {
|
|
148
149
|
case 0:
|
|
150
|
+
console.log("volany XFormBase.componentDidMount()");
|
|
149
151
|
// kontrola (musi byt tu, v konstruktore este property nie je nastavena)
|
|
150
152
|
if (this.entity === undefined) {
|
|
151
153
|
throw "XFormBase: Property entity is not defined - use decorator @Form.";
|
|
@@ -153,18 +155,21 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
153
155
|
if (!(this.props.id !== undefined)) return [3 /*break*/, 2];
|
|
154
156
|
return [4 /*yield*/, XUtils_1.XUtils.fetchById(this.entity, Array.from(this.fields), this.props.id)];
|
|
155
157
|
case 1:
|
|
158
|
+
//console.log('XFormBase.componentDidMount ide nacitat objekt');
|
|
159
|
+
//console.log(this.fields);
|
|
156
160
|
object = _a.sent();
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.
|
|
166
|
-
|
|
167
|
-
|
|
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*/];
|
|
168
173
|
}
|
|
169
174
|
});
|
|
170
175
|
});
|
|
@@ -187,26 +192,52 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
187
192
|
XFormBase.prototype.isAddRow = function () {
|
|
188
193
|
return this.props.id === undefined;
|
|
189
194
|
};
|
|
190
|
-
XFormBase.prototype.onFieldChange = function (field, value, error) {
|
|
195
|
+
XFormBase.prototype.onFieldChange = function (field, value, error, onChange, assocObjectChange) {
|
|
191
196
|
var object = this.getXObject();
|
|
192
197
|
object[field] = value;
|
|
193
198
|
var errorMap = this.state.errorMap;
|
|
194
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
|
+
}
|
|
195
204
|
// TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
|
|
196
205
|
this.setState({ object: object, errorMap: errorMap });
|
|
197
206
|
};
|
|
198
|
-
XFormBase.prototype.onTableFieldChange = function (
|
|
207
|
+
XFormBase.prototype.onTableFieldChange = function (rowData, field, value, error, onChange, assocObjectChange) {
|
|
199
208
|
var object = this.getXObject();
|
|
200
|
-
|
|
201
|
-
|
|
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
|
+
}
|
|
202
217
|
// TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
|
|
203
|
-
this.setState({ object: object });
|
|
218
|
+
this.setState({ object: object /*, errorMap: errorMap*/ });
|
|
204
219
|
};
|
|
205
|
-
|
|
220
|
+
/**
|
|
221
|
+
* @deprecated - mal by sa pouzivat onTableFieldChange
|
|
222
|
+
*/
|
|
223
|
+
XFormBase.prototype.onObjectDataChange = function (row, onChange) {
|
|
206
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
|
+
}
|
|
207
230
|
// TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
|
|
208
231
|
this.setState({ object: object });
|
|
209
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
|
+
};
|
|
210
241
|
XFormBase.prototype.onTableAddRow = function (assocField, newRow, dataKey, selectedRow) {
|
|
211
242
|
var object = this.getXObject();
|
|
212
243
|
var rowList = object[assocField];
|
|
@@ -269,18 +300,54 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
269
300
|
// TODO - tu mozno treba setnut funkciu - koli moznej asynchronicite
|
|
270
301
|
this.setState({ object: object });
|
|
271
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
|
+
};
|
|
272
318
|
XFormBase.prototype.addField = function (field) {
|
|
273
319
|
this.fields.add(field);
|
|
274
320
|
};
|
|
275
321
|
XFormBase.prototype.addXFormComponent = function (xFormComponent) {
|
|
276
322
|
this.xFormComponentList.push(xFormComponent);
|
|
277
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
|
+
};
|
|
278
345
|
XFormBase.prototype.addXFormDataTable = function (xFormDataTable) {
|
|
279
346
|
this.xFormDataTableList.push(xFormDataTable);
|
|
280
347
|
};
|
|
281
348
|
XFormBase.prototype.onClickSave = function () {
|
|
282
349
|
return __awaiter(this, void 0, void 0, function () {
|
|
283
|
-
var isAddRow, object,
|
|
350
|
+
var isAddRow, object, e_3;
|
|
284
351
|
return __generator(this, function (_a) {
|
|
285
352
|
switch (_a.label) {
|
|
286
353
|
case 0:
|
|
@@ -305,13 +372,13 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
305
372
|
_a.label = 1;
|
|
306
373
|
case 1:
|
|
307
374
|
_a.trys.push([1, 3, , 4]);
|
|
308
|
-
return [4 /*yield*/,
|
|
375
|
+
return [4 /*yield*/, this.saveRow()];
|
|
309
376
|
case 2:
|
|
310
377
|
object = _a.sent();
|
|
311
378
|
return [3 /*break*/, 4];
|
|
312
379
|
case 3:
|
|
313
|
-
|
|
314
|
-
XUtils_1.XUtils.showErrorMessage("Save row failed.",
|
|
380
|
+
e_3 = _a.sent();
|
|
381
|
+
XUtils_1.XUtils.showErrorMessage("Save row failed.", e_3);
|
|
315
382
|
return [2 /*return*/]; // zostavame vo formulari
|
|
316
383
|
case 4:
|
|
317
384
|
if (this.props.onSaveOrCancel !== undefined) {
|
|
@@ -338,26 +405,23 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
338
405
|
}
|
|
339
406
|
};
|
|
340
407
|
XFormBase.prototype.validateSave = function () {
|
|
341
|
-
var
|
|
408
|
+
var e_4, _a;
|
|
342
409
|
var xErrorMap = this.validateForm();
|
|
343
|
-
// zatial takto
|
|
344
|
-
var msg =
|
|
410
|
+
// zatial takto jednoducho
|
|
411
|
+
var msg = XUtils_1.XUtils.getErrorMessages(xErrorMap);
|
|
345
412
|
try {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
msg += field + ": " + xError.onChange + ", " + xError.onBlur + ", " + xError.form + XUtilsCommon_1.XUtilsCommon.newLine;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
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();
|
|
353
417
|
}
|
|
354
418
|
}
|
|
355
|
-
catch (
|
|
419
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
356
420
|
finally {
|
|
357
421
|
try {
|
|
358
422
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
359
423
|
}
|
|
360
|
-
finally { if (
|
|
424
|
+
finally { if (e_4) throw e_4.error; }
|
|
361
425
|
}
|
|
362
426
|
var ok = true;
|
|
363
427
|
if (msg !== "") {
|
|
@@ -367,7 +431,7 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
367
431
|
return ok;
|
|
368
432
|
};
|
|
369
433
|
XFormBase.prototype.validateForm = function () {
|
|
370
|
-
var
|
|
434
|
+
var e_5, _a;
|
|
371
435
|
var xErrorMap = this.fieldValidation();
|
|
372
436
|
// form validation
|
|
373
437
|
var xErrors = this.validate(this.getXObject());
|
|
@@ -375,23 +439,27 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
375
439
|
for (var _b = __values(Object.entries(xErrors)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
376
440
|
var _d = __read(_c.value, 2), field = _d[0], error = _d[1];
|
|
377
441
|
if (error) {
|
|
378
|
-
|
|
442
|
+
// skusime zistit label
|
|
443
|
+
var xFormComponent = this.findXFormComponent(field);
|
|
444
|
+
var fieldLabel = xFormComponent ? xFormComponent.getLabel() : undefined;
|
|
445
|
+
xErrorMap[field] = __assign(__assign({}, xErrorMap[field]), { form: error, fieldLabel: fieldLabel });
|
|
379
446
|
}
|
|
380
447
|
}
|
|
381
448
|
}
|
|
382
|
-
catch (
|
|
449
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
383
450
|
finally {
|
|
384
451
|
try {
|
|
385
452
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
386
453
|
}
|
|
387
|
-
finally { if (
|
|
454
|
+
finally { if (e_5) throw e_5.error; }
|
|
388
455
|
}
|
|
389
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)
|
|
390
|
-
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 });
|
|
391
459
|
return xErrorMap;
|
|
392
460
|
};
|
|
393
461
|
XFormBase.prototype.fieldValidation = function () {
|
|
394
|
-
var
|
|
462
|
+
var e_6, _a, e_7, _b;
|
|
395
463
|
var xErrorMap = {};
|
|
396
464
|
try {
|
|
397
465
|
for (var _c = __values(this.xFormComponentList), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
@@ -403,28 +471,31 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
403
471
|
}
|
|
404
472
|
}
|
|
405
473
|
}
|
|
406
|
-
catch (
|
|
474
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
407
475
|
finally {
|
|
408
476
|
try {
|
|
409
477
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
410
478
|
}
|
|
411
|
-
finally { if (
|
|
479
|
+
finally { if (e_6) throw e_6.error; }
|
|
412
480
|
}
|
|
413
481
|
try {
|
|
414
482
|
for (var _e = __values(this.xFormDataTableList), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
415
483
|
var xFormDataTable = _f.value;
|
|
416
|
-
|
|
484
|
+
xFormDataTable.validate();
|
|
417
485
|
}
|
|
418
486
|
}
|
|
419
|
-
catch (
|
|
487
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
420
488
|
finally {
|
|
421
489
|
try {
|
|
422
490
|
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
423
491
|
}
|
|
424
|
-
finally { if (
|
|
492
|
+
finally { if (e_7) throw e_7.error; }
|
|
425
493
|
}
|
|
426
494
|
return xErrorMap;
|
|
427
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
|
+
};
|
|
428
499
|
// this method can be overriden in subclass if needed (custom validation)
|
|
429
500
|
XFormBase.prototype.validate = function (object) {
|
|
430
501
|
return {};
|
|
@@ -432,6 +503,14 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
432
503
|
// this method can be overriden in subclass if needed (to modify object before save)
|
|
433
504
|
XFormBase.prototype.preSave = function (object) {
|
|
434
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
|
+
};
|
|
435
514
|
return XFormBase;
|
|
436
515
|
}(react_1.Component));
|
|
437
516
|
exports.XFormBase = XFormBase;
|
|
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
3
3
|
var extendStatics = function (d, b) {
|
|
4
4
|
extendStatics = Object.setPrototypeOf ||
|
|
5
5
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
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");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -1,24 +1,36 @@
|
|
|
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 class XFormComponent<P extends XFormComponentProps
|
|
12
|
-
constructor(props: P);
|
|
13
|
-
|
|
17
|
+
export declare abstract class XFormComponent<T, P extends XFormComponentProps<T>> extends Component<P> {
|
|
18
|
+
protected constructor(props: P);
|
|
19
|
+
abstract getField(): string;
|
|
20
|
+
getValueFromObject(): any;
|
|
21
|
+
onValueChangeBase(value: any, onChange?: FieldOnChange, assocObjectChange?: OperationType): void;
|
|
22
|
+
abstract isNotNull(): boolean;
|
|
23
|
+
isReadOnly(): boolean;
|
|
24
|
+
getLabel(): string;
|
|
25
|
+
getLabelStyle(): React.CSSProperties;
|
|
14
26
|
validate(): {
|
|
15
27
|
field: string;
|
|
16
28
|
xError: XError;
|
|
17
29
|
} | undefined;
|
|
18
30
|
validateOnChange(value: any): string | undefined;
|
|
19
31
|
validateNotNull(value: any): string | undefined;
|
|
20
|
-
checkNotNull(): boolean;
|
|
21
|
-
getValueFromObject(): any;
|
|
22
|
-
getError(): string | undefined;
|
|
23
32
|
getClassNameTooltip(): {};
|
|
33
|
+
getError(): string | undefined;
|
|
34
|
+
callOnChangeFromOnBlur(): void;
|
|
35
|
+
getFilterBase(filter: XFilterProp | undefined): XCustomFilter | undefined;
|
|
24
36
|
}
|