@michalrakus/x-react-web-lib 1.1.0 → 1.3.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 +8 -4
- package/lib/components/XAutoCompleteBase.js +68 -27
- package/lib/components/XAutoCompleteDT.d.ts +33 -0
- package/lib/components/XAutoCompleteDT.js +140 -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 +5 -3
- package/lib/components/XExportRowsDialog.js +2 -2
- package/lib/components/XFieldChangeEvent.d.ts +11 -0
- package/lib/components/XFieldChangeEvent.js +2 -0
- package/lib/components/XFormBase.d.ts +19 -9
- package/lib/components/XFormBase.js +95 -34
- package/lib/components/XFormComponent.d.ts +13 -4
- package/lib/components/XFormComponent.js +57 -5
- package/lib/components/XFormComponentDT.d.ts +30 -0
- package/lib/components/XFormComponentDT.js +145 -0
- package/lib/components/XFormDataTable2.d.ts +48 -7
- package/lib/components/XFormDataTable2.js +208 -45
- 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 +5 -3
- 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 +39 -24
- 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/ExportImportParam.d.ts +2 -0
- 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,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { XInput, XInputProps } from "./XInput";
|
|
3
|
-
export declare class XCheckbox extends XInput<XInputProps
|
|
4
|
-
constructor(props: XInputProps);
|
|
3
|
+
export declare class XCheckbox extends XInput<boolean, XInputProps<boolean>> {
|
|
4
|
+
constructor(props: XInputProps<boolean>);
|
|
5
5
|
getValue(): boolean | null;
|
|
6
6
|
onValueChange(e: any): void;
|
|
7
7
|
render(): JSX.Element;
|
|
@@ -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);
|
|
@@ -125,12 +125,14 @@ var XDropdown = /** @class */ (function (_super) {
|
|
|
125
125
|
XDropdown.prototype.render = function () {
|
|
126
126
|
// TODO - pridat cez generikum typ objektu v Dropdown-e (ak sa da)
|
|
127
127
|
var options = this.state.options;
|
|
128
|
-
// TODO - readOnly
|
|
128
|
+
// TODO - mozno by nebolo od veci pouzivat InputText ak readOnly === true (chybala by len sipka (rozbalovac)) a dalo by sa copy-paste-ovat
|
|
129
|
+
// propertiesy na Dropdown-e: readOnly vyseduje, disabled znemoznuje vyber polozky
|
|
130
|
+
var readOnly = this.isReadOnly();
|
|
129
131
|
// Dropdown setuje do atributu object.assocField asociovany objekt zo zoznamu objektov ktore ziskame podla asociacie
|
|
130
132
|
// appendTo={document.body} appenduje overlay panel na element body - eliminuje "skakanie" formularu na mobile pri kliknuti na dropdown
|
|
131
133
|
return (react_1.default.createElement("div", { className: "field grid" },
|
|
132
134
|
react_1.default.createElement("label", { htmlFor: this.props.assocField, className: "col-fixed", style: this.getLabelStyle() }, this.getLabel()),
|
|
133
|
-
react_1.default.createElement(dropdown_1.Dropdown, __assign({ appendTo: document.body, id: this.props.assocField, optionLabel: this.props.displayField, value: this.getValue(), options: options, onChange: this.onValueChange }, this.getClassNameTooltip()))));
|
|
135
|
+
react_1.default.createElement(dropdown_1.Dropdown, __assign({ appendTo: document.body, id: this.props.assocField, optionLabel: this.props.displayField, value: this.getValue(), options: options, onChange: this.onValueChange, readOnly: readOnly, disabled: readOnly }, this.getClassNameTooltip()))));
|
|
134
136
|
};
|
|
135
137
|
return XDropdown;
|
|
136
138
|
}(XFormComponent_1.XFormComponent));
|
|
@@ -52,13 +52,13 @@ var XUtilsConversions_1 = require("./XUtilsConversions");
|
|
|
52
52
|
var XExportRowsDialog = function (props) {
|
|
53
53
|
var _a;
|
|
54
54
|
var _b = __read((0, react_1.useState)(ExportImportParam_1.ExportType.Csv), 2), exportType = _b[0], setExportType = _b[1];
|
|
55
|
-
var _c = __read((0, react_1.useState)(
|
|
55
|
+
var _c = __read((0, react_1.useState)(true), 2), createHeaderLine = _c[0], setCreateHeaderLine = _c[1];
|
|
56
56
|
var _d = __read((0, react_1.useState)(ExportImportParam_1.CsvSeparator.Semicolon), 2), csvSeparator = _d[0], setCsvSeparator = _d[1];
|
|
57
57
|
var _e = __read((0, react_1.useState)(ExportImportParam_1.CsvDecimalFormat.Comma), 2), decimalFormat = _e[0], setDecimalFormat = _e[1];
|
|
58
58
|
// bez tejto metody by pri opetovnom otvoreni dialogu ponechal povodne hodnoty
|
|
59
59
|
var onShow = function () {
|
|
60
60
|
setExportType(ExportImportParam_1.ExportType.Csv);
|
|
61
|
-
setCreateHeaderLine(
|
|
61
|
+
setCreateHeaderLine(true); // excel hadze hlasky koli prvemu riadku header-ov
|
|
62
62
|
setCsvSeparator(ExportImportParam_1.CsvSeparator.Semicolon);
|
|
63
63
|
setDecimalFormat(ExportImportParam_1.CsvDecimalFormat.Comma);
|
|
64
64
|
};
|
|
@@ -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,30 @@ 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;
|
|
48
|
+
formReadOnlyBase(field: string): boolean;
|
|
42
49
|
onClickSave(): Promise<void>;
|
|
43
50
|
onClickCancel(): void;
|
|
44
51
|
validateSave(): boolean;
|
|
45
52
|
validateForm(): XErrorMap;
|
|
46
53
|
fieldValidation(): XErrorMap;
|
|
54
|
+
formReadOnly(object: XObject, field: string): boolean;
|
|
55
|
+
preInitForm(object: XObject, operationType: OperationType.Insert | OperationType.Update): void;
|
|
47
56
|
validate(object: XObject): XErrors;
|
|
48
57
|
preSave(object: XObject): void;
|
|
58
|
+
saveRow(): Promise<any>;
|
|
49
59
|
}
|
|
@@ -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
|
};
|
|
@@ -301,6 +345,10 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
301
345
|
XFormBase.prototype.addXFormDataTable = function (xFormDataTable) {
|
|
302
346
|
this.xFormDataTableList.push(xFormDataTable);
|
|
303
347
|
};
|
|
348
|
+
XFormBase.prototype.formReadOnlyBase = function (field) {
|
|
349
|
+
// TODO - bude this.state.object vzdycky !== undefined?
|
|
350
|
+
return this.formReadOnly(this.state.object, field);
|
|
351
|
+
};
|
|
304
352
|
XFormBase.prototype.onClickSave = function () {
|
|
305
353
|
return __awaiter(this, void 0, void 0, function () {
|
|
306
354
|
var isAddRow, object, e_3;
|
|
@@ -328,7 +376,7 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
328
376
|
_a.label = 1;
|
|
329
377
|
case 1:
|
|
330
378
|
_a.trys.push([1, 3, , 4]);
|
|
331
|
-
return [4 /*yield*/,
|
|
379
|
+
return [4 /*yield*/, this.saveRow()];
|
|
332
380
|
case 2:
|
|
333
381
|
object = _a.sent();
|
|
334
382
|
return [3 /*break*/, 4];
|
|
@@ -362,25 +410,20 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
362
410
|
};
|
|
363
411
|
XFormBase.prototype.validateSave = function () {
|
|
364
412
|
var e_4, _a;
|
|
365
|
-
var _b;
|
|
366
413
|
var xErrorMap = this.validateForm();
|
|
367
|
-
// zatial takto
|
|
368
|
-
var msg =
|
|
414
|
+
// zatial takto jednoducho
|
|
415
|
+
var msg = XUtils_1.XUtils.getErrorMessages(xErrorMap);
|
|
369
416
|
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
|
-
}
|
|
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();
|
|
378
421
|
}
|
|
379
422
|
}
|
|
380
423
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
381
424
|
finally {
|
|
382
425
|
try {
|
|
383
|
-
if (
|
|
426
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
384
427
|
}
|
|
385
428
|
finally { if (e_4) throw e_4.error; }
|
|
386
429
|
}
|
|
@@ -415,7 +458,8 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
415
458
|
finally { if (e_5) throw e_5.error; }
|
|
416
459
|
}
|
|
417
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)
|
|
418
|
-
this.
|
|
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 });
|
|
419
463
|
return xErrorMap;
|
|
420
464
|
};
|
|
421
465
|
XFormBase.prototype.fieldValidation = function () {
|
|
@@ -441,7 +485,7 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
441
485
|
try {
|
|
442
486
|
for (var _e = __values(this.xFormDataTableList), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
443
487
|
var xFormDataTable = _f.value;
|
|
444
|
-
|
|
488
|
+
xFormDataTable.validate();
|
|
445
489
|
}
|
|
446
490
|
}
|
|
447
491
|
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
@@ -453,6 +497,15 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
453
497
|
}
|
|
454
498
|
return xErrorMap;
|
|
455
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
|
+
};
|
|
456
509
|
// this method can be overriden in subclass if needed (custom validation)
|
|
457
510
|
XFormBase.prototype.validate = function (object) {
|
|
458
511
|
return {};
|
|
@@ -460,6 +513,14 @@ var XFormBase = /** @class */ (function (_super) {
|
|
|
460
513
|
// this method can be overriden in subclass if needed (to modify object before save)
|
|
461
514
|
XFormBase.prototype.preSave = function (object) {
|
|
462
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
|
+
};
|
|
463
524
|
return XFormBase;
|
|
464
525
|
}(react_1.Component));
|
|
465
526
|
exports.XFormBase = XFormBase;
|
|
@@ -1,18 +1,25 @@
|
|
|
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 XReadOnlyProp = boolean | ((object: any) => boolean);
|
|
9
|
+
export type XFilterProp = XCustomFilter | ((object: any) => XCustomFilter | undefined);
|
|
10
|
+
export interface XFormComponentProps<T> {
|
|
5
11
|
form: XFormBase;
|
|
6
12
|
label?: string;
|
|
7
|
-
readOnly?:
|
|
13
|
+
readOnly?: XReadOnlyProp;
|
|
8
14
|
labelStyle?: React.CSSProperties;
|
|
9
15
|
inline?: boolean;
|
|
16
|
+
onChange?: FieldOnChange;
|
|
10
17
|
}
|
|
11
|
-
export declare abstract class XFormComponent<P extends XFormComponentProps
|
|
18
|
+
export declare abstract class XFormComponent<T, P extends XFormComponentProps<T>> extends Component<P> {
|
|
12
19
|
protected constructor(props: P);
|
|
13
20
|
abstract getField(): string;
|
|
14
21
|
getValueFromObject(): any;
|
|
15
|
-
onValueChangeBase(value: any): void;
|
|
22
|
+
onValueChangeBase(value: any, onChange?: FieldOnChange, assocObjectChange?: OperationType): void;
|
|
16
23
|
abstract isNotNull(): boolean;
|
|
17
24
|
isReadOnly(): boolean;
|
|
18
25
|
getLabel(): string;
|
|
@@ -25,4 +32,6 @@ export declare abstract class XFormComponent<P extends XFormComponentProps> exte
|
|
|
25
32
|
validateNotNull(value: any): string | undefined;
|
|
26
33
|
getClassNameTooltip(): {};
|
|
27
34
|
getError(): string | undefined;
|
|
35
|
+
callOnChangeFromOnBlur(): void;
|
|
36
|
+
getFilterBase(filter: XFilterProp | undefined): XCustomFilter | undefined;
|
|
28
37
|
}
|
|
@@ -42,13 +42,39 @@ 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
|
-
|
|
51
|
-
|
|
50
|
+
var readOnly;
|
|
51
|
+
if (!XUtilsCommon_1.XUtilsCommon.isSingleField(this.getField())) {
|
|
52
|
+
// if the length of field is 2 or more, then readOnly
|
|
53
|
+
readOnly = true;
|
|
54
|
+
}
|
|
55
|
+
// the purpose of formReadOnly is to put the whole form to read only mode,
|
|
56
|
+
// that's why the formReadOnly has higher prio then property this.props.readOnly
|
|
57
|
+
else if (this.props.form.formReadOnlyBase(this.getField())) {
|
|
58
|
+
readOnly = true;
|
|
59
|
+
}
|
|
60
|
+
else if (typeof this.props.readOnly === 'boolean') {
|
|
61
|
+
readOnly = this.props.readOnly;
|
|
62
|
+
}
|
|
63
|
+
else if (typeof this.props.readOnly === 'function') {
|
|
64
|
+
// TODO - tazko povedat ci niekedy bude object === null (asi ano vid metodu getFilterBase)
|
|
65
|
+
var object = this.props.form.state.object;
|
|
66
|
+
if (object) {
|
|
67
|
+
readOnly = this.props.readOnly(this.props.form.getXObject());
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
readOnly = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// readOnly is undefined
|
|
75
|
+
readOnly = false;
|
|
76
|
+
}
|
|
77
|
+
return readOnly;
|
|
52
78
|
};
|
|
53
79
|
XFormComponent.prototype.getLabel = function () {
|
|
54
80
|
var _a;
|
|
@@ -116,7 +142,33 @@ var XFormComponent = /** @class */ (function (_super) {
|
|
|
116
142
|
// vrati error message z form.state.errorMap
|
|
117
143
|
XFormComponent.prototype.getError = function () {
|
|
118
144
|
var error = this.props.form.state.errorMap[this.getField()];
|
|
119
|
-
return error ? XUtils_1.XUtils.
|
|
145
|
+
return error ? XUtils_1.XUtils.getErrorMessage(error) : undefined;
|
|
146
|
+
};
|
|
147
|
+
XFormComponent.prototype.callOnChangeFromOnBlur = function () {
|
|
148
|
+
if (this.props.onChange) {
|
|
149
|
+
var object = this.props.form.getXObject();
|
|
150
|
+
// developer v onChange nastavi atributy na object-e
|
|
151
|
+
this.props.onChange({ object: object });
|
|
152
|
+
// rovno zavolame form.setState({...}), nech to nemusi robit developer
|
|
153
|
+
this.props.form.setStateXForm();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
// len pre assoc fieldy sa pouziva
|
|
157
|
+
XFormComponent.prototype.getFilterBase = function (filter) {
|
|
158
|
+
var customFilter = undefined;
|
|
159
|
+
if (typeof filter === 'object') {
|
|
160
|
+
customFilter = filter;
|
|
161
|
+
}
|
|
162
|
+
if (typeof filter === 'function') {
|
|
163
|
+
//const object: XObject = this.props.form.getXObject();
|
|
164
|
+
var object = this.props.form.state.object;
|
|
165
|
+
// zatial zakomentujeme, aby sa zavolal aj pre XAutoComplete (tam zatial nemame k dispozicii object
|
|
166
|
+
// (componentDidMount pre XAutoComplete sa vola skor ako componentDidMount pre XFormBase))
|
|
167
|
+
//if (object) {
|
|
168
|
+
customFilter = filter(object);
|
|
169
|
+
//}
|
|
170
|
+
}
|
|
171
|
+
return customFilter;
|
|
120
172
|
};
|
|
121
173
|
return XFormComponent;
|
|
122
174
|
}(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
|
+
}
|