@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
package/FindParam.d.ts
ADDED
package/FindParam.js
ADDED
package/gulpfile.js
CHANGED
|
@@ -17,12 +17,15 @@ function generateApi(cb) {
|
|
|
17
17
|
"./lib/components/XAutoComplete",
|
|
18
18
|
"./lib/components/XAutoCompleteBase",
|
|
19
19
|
"./lib/components/XButton",
|
|
20
|
+
"./lib/components/XButtonIconNarrow",
|
|
21
|
+
"./lib/components/XButtonIconSmall",
|
|
20
22
|
"./lib/components/XBrowse",
|
|
21
23
|
"./lib/components/XChangePasswordForm",
|
|
22
24
|
"./lib/components/XCheckbox",
|
|
23
25
|
"./lib/components/XDropdown",
|
|
24
26
|
"./lib/components/XEnvVars",
|
|
25
27
|
"./lib/components/XErrors",
|
|
28
|
+
"./lib/components/XFieldChangeEvent",
|
|
26
29
|
"./lib/components/XFormBase",
|
|
27
30
|
"./lib/components/XFormBaseT",
|
|
28
31
|
"./lib/components/XFormDataTable2",
|
|
@@ -43,6 +46,7 @@ function generateApi(cb) {
|
|
|
43
46
|
"./lib/components/XUtilsConversions",
|
|
44
47
|
"./lib/components/XUtilsMetadata",
|
|
45
48
|
|
|
49
|
+
"./lib/serverApi/FindParam",
|
|
46
50
|
"./lib/serverApi/XUtilsCommon",
|
|
47
51
|
|
|
48
52
|
"./lib/administration/XUserBrowse",
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { DataTableFilterMetaData } from "primereact/datatable";
|
|
2
|
+
import { XCustomFilter } from "../serverApi/FindParam";
|
|
3
|
+
export interface XFieldFilter {
|
|
4
|
+
field: string;
|
|
5
|
+
constraint: DataTableFilterMetaData;
|
|
6
|
+
}
|
|
1
7
|
export interface SearchTableParams {
|
|
2
8
|
onChoose: (chosenRow: any) => void;
|
|
3
|
-
|
|
4
|
-
|
|
9
|
+
displayFieldFilter?: XFieldFilter;
|
|
10
|
+
customFilter?: XCustomFilter;
|
|
5
11
|
}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { XFormComponent, XFormComponentProps } from "./XFormComponent";
|
|
2
|
+
import { XFilterProp, XFormComponent, XFormComponentProps } from "./XFormComponent";
|
|
3
3
|
import { XAssoc } from "../serverApi/XEntityMetadata";
|
|
4
4
|
import { OperationType } from "./XUtils";
|
|
5
5
|
import { XError } from "./XErrors";
|
|
6
|
-
|
|
6
|
+
import { XObject } from "./XObject";
|
|
7
|
+
export interface XAutoCompleteProps extends XFormComponentProps<XObject> {
|
|
7
8
|
assocField: string;
|
|
8
|
-
displayField: string;
|
|
9
|
+
displayField: string | ((suggestion: any) => string);
|
|
9
10
|
searchTable?: any;
|
|
10
11
|
assocForm?: any;
|
|
12
|
+
filter?: XFilterProp;
|
|
11
13
|
size?: number;
|
|
12
14
|
inputStyle?: React.CSSProperties;
|
|
13
15
|
}
|
|
14
|
-
export declare class XAutoComplete extends XFormComponent<XAutoCompleteProps> {
|
|
16
|
+
export declare class XAutoComplete extends XFormComponent<XObject, XAutoCompleteProps> {
|
|
15
17
|
protected xAssoc: XAssoc;
|
|
16
18
|
protected errorInBase: string | undefined;
|
|
17
19
|
state: {
|
|
18
20
|
suggestions: any[];
|
|
19
21
|
};
|
|
20
22
|
constructor(props: XAutoCompleteProps);
|
|
23
|
+
getDisplayFieldOrId(): string;
|
|
21
24
|
componentDidMount(): void;
|
|
22
25
|
readAndSetSuggestions(): Promise<void>;
|
|
23
26
|
getField(): string;
|
|
@@ -71,10 +71,22 @@ var XAutoComplete = /** @class */ (function (_super) {
|
|
|
71
71
|
};
|
|
72
72
|
_this.onChangeAutoCompleteBase = _this.onChangeAutoCompleteBase.bind(_this);
|
|
73
73
|
_this.onErrorChangeAutoCompleteBase = _this.onErrorChangeAutoCompleteBase.bind(_this);
|
|
74
|
-
props.form.addField(props.assocField + '.' +
|
|
74
|
+
props.form.addField(props.assocField + '.' + _this.getDisplayFieldOrId());
|
|
75
75
|
return _this;
|
|
76
76
|
}
|
|
77
|
+
XAutoComplete.prototype.getDisplayFieldOrId = function () {
|
|
78
|
+
// toto je hack - ak ratame displayField cez funkciu, tak nam potom chyba (hociaky) atribut asociovaneho objektu
|
|
79
|
+
// podobne ako na XFormDataTable2, podsunieme id-ckovy atribut
|
|
80
|
+
if (typeof this.props.displayField === 'string') {
|
|
81
|
+
return this.props.displayField; // vsetko ok
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// v displayField mame funkciu, zistime id-ckovy atribut
|
|
85
|
+
return XUtilsMetadata_1.XUtilsMetadata.getXEntity(this.xAssoc.entityName).idField;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
77
88
|
XAutoComplete.prototype.componentDidMount = function () {
|
|
89
|
+
console.log("volany XAutoComplete.componentDidMount()");
|
|
78
90
|
this.readAndSetSuggestions();
|
|
79
91
|
};
|
|
80
92
|
XAutoComplete.prototype.readAndSetSuggestions = function () {
|
|
@@ -82,9 +94,13 @@ var XAutoComplete = /** @class */ (function (_super) {
|
|
|
82
94
|
var suggestions;
|
|
83
95
|
return __generator(this, function (_a) {
|
|
84
96
|
switch (_a.label) {
|
|
85
|
-
case 0: return [4 /*yield*/, XUtils_1.XUtils.
|
|
97
|
+
case 0: return [4 /*yield*/, XUtils_1.XUtils.fetchRows(this.xAssoc.entityName, this.getFilterBase(this.props.filter), typeof this.props.displayField === 'string' ? this.props.displayField : undefined)];
|
|
86
98
|
case 1:
|
|
87
99
|
suggestions = _a.sent();
|
|
100
|
+
// ak mame funkciu, zosortujeme tu
|
|
101
|
+
if (typeof this.props.displayField === 'function') {
|
|
102
|
+
suggestions = XUtils_1.XUtils.arraySort(suggestions, this.props.displayField);
|
|
103
|
+
}
|
|
88
104
|
this.setState({ suggestions: suggestions });
|
|
89
105
|
return [2 /*return*/];
|
|
90
106
|
}
|
|
@@ -102,7 +118,7 @@ var XAutoComplete = /** @class */ (function (_super) {
|
|
|
102
118
|
return assocObject;
|
|
103
119
|
};
|
|
104
120
|
XAutoComplete.prototype.onChangeAutoCompleteBase = function (object, objectChange) {
|
|
105
|
-
this.onValueChangeBase(object);
|
|
121
|
+
this.onValueChangeBase(object, this.props.onChange, objectChange);
|
|
106
122
|
if (objectChange !== XUtils_1.OperationType.None) {
|
|
107
123
|
// zmenil sa zaznam dobrovolnika v DB
|
|
108
124
|
// zatial len refreshneme z DB
|
|
@@ -124,12 +140,11 @@ var XAutoComplete = /** @class */ (function (_super) {
|
|
|
124
140
|
return _super.prototype.validate.call(this);
|
|
125
141
|
};
|
|
126
142
|
XAutoComplete.prototype.render = function () {
|
|
127
|
-
var _a;
|
|
128
143
|
var xEntityAssoc = XUtilsMetadata_1.XUtilsMetadata.getXEntity(this.xAssoc.entityName);
|
|
129
|
-
|
|
144
|
+
//const xDisplayField = XUtilsMetadata.getXFieldByPath(xEntityAssoc, this.props.displayField);
|
|
130
145
|
// TODO - readOnly
|
|
131
146
|
// TODO - size
|
|
132
|
-
|
|
147
|
+
//const size = this.props.size ?? xDisplayField.length;
|
|
133
148
|
// div className="col" nam zabezpeci aby XAutoCompleteBase nezaberal celu dlzku grid-u (ma nastaveny width=100% vdaka "formgroup-inline")
|
|
134
149
|
return (react_1.default.createElement("div", { className: "field grid" },
|
|
135
150
|
react_1.default.createElement("label", { htmlFor: this.props.assocField, className: "col-fixed", style: this.getLabelStyle() }, this.getLabel()),
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { Component } from "react";
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
import { AutoCompleteChangeEvent } from "primereact/autocomplete";
|
|
2
3
|
import { OperationType } from "./XUtils";
|
|
3
4
|
export interface XAutoCompleteBaseProps {
|
|
4
5
|
value: any;
|
|
5
6
|
suggestions: any[];
|
|
6
7
|
onChange: (object: any, objectChange: OperationType) => void;
|
|
7
|
-
field: string;
|
|
8
|
+
field: string | ((suggestion: any) => string);
|
|
8
9
|
valueForm?: any;
|
|
9
10
|
idField?: string;
|
|
10
11
|
maxLength?: number;
|
|
12
|
+
readOnly?: boolean;
|
|
11
13
|
error?: string;
|
|
12
14
|
onErrorChange: (error: string | undefined) => void;
|
|
13
15
|
setFocusOnCreate?: boolean;
|
|
@@ -25,17 +27,19 @@ export declare class XAutoCompleteBase extends Component<XAutoCompleteBaseProps>
|
|
|
25
27
|
formDialogInitObjectForInsert: any | undefined;
|
|
26
28
|
constructor(props: XAutoCompleteBaseProps);
|
|
27
29
|
componentDidMount(): void;
|
|
30
|
+
getDisplayValue(suggestion: any): string;
|
|
28
31
|
completeMethod(event: {
|
|
29
32
|
query: string;
|
|
30
33
|
}): void;
|
|
31
|
-
onChange(e:
|
|
34
|
+
onChange(e: AutoCompleteChangeEvent): void;
|
|
32
35
|
onSelect(e: any): void;
|
|
33
|
-
onBlur(e:
|
|
36
|
+
onBlur(e: React.FocusEvent<HTMLInputElement>): void;
|
|
34
37
|
createErrorMessage(): string;
|
|
35
38
|
setFocusToInput(): void;
|
|
36
39
|
setObjectValue(object: any, objectChange: OperationType): void;
|
|
37
40
|
formDialogOnSaveOrCancel(object: any | null, objectChange: OperationType): void;
|
|
38
41
|
formDialogOnHide(): void;
|
|
39
42
|
computeInputValue(): any;
|
|
43
|
+
itemTemplate(suggestion: any, index: number): React.ReactNode;
|
|
40
44
|
render(): JSX.Element;
|
|
41
45
|
}
|
|
@@ -80,6 +80,7 @@ var autocomplete_1 = require("primereact/autocomplete");
|
|
|
80
80
|
var splitbutton_1 = require("primereact/splitbutton");
|
|
81
81
|
var dialog_1 = require("primereact/dialog");
|
|
82
82
|
var XUtils_1 = require("./XUtils");
|
|
83
|
+
var button_1 = require("primereact/button");
|
|
83
84
|
var XAutoCompleteBase = /** @class */ (function (_super) {
|
|
84
85
|
__extends(XAutoCompleteBase, _super);
|
|
85
86
|
function XAutoCompleteBase(props) {
|
|
@@ -98,6 +99,7 @@ var XAutoCompleteBase = /** @class */ (function (_super) {
|
|
|
98
99
|
_this.onBlur = _this.onBlur.bind(_this);
|
|
99
100
|
_this.formDialogOnSaveOrCancel = _this.formDialogOnSaveOrCancel.bind(_this);
|
|
100
101
|
_this.formDialogOnHide = _this.formDialogOnHide.bind(_this);
|
|
102
|
+
_this.itemTemplate = _this.itemTemplate.bind(_this);
|
|
101
103
|
return _this;
|
|
102
104
|
}
|
|
103
105
|
XAutoCompleteBase.prototype.componentDidMount = function () {
|
|
@@ -105,6 +107,17 @@ var XAutoCompleteBase = /** @class */ (function (_super) {
|
|
|
105
107
|
this.setFocusToInput();
|
|
106
108
|
}
|
|
107
109
|
};
|
|
110
|
+
XAutoCompleteBase.prototype.getDisplayValue = function (suggestion) {
|
|
111
|
+
var displayValue;
|
|
112
|
+
if (typeof this.props.field === 'string') {
|
|
113
|
+
displayValue = suggestion[this.props.field];
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// this.props.field is function returning string
|
|
117
|
+
displayValue = this.props.field(suggestion);
|
|
118
|
+
}
|
|
119
|
+
return displayValue;
|
|
120
|
+
};
|
|
108
121
|
XAutoCompleteBase.prototype.completeMethod = function (event) {
|
|
109
122
|
var _this = this;
|
|
110
123
|
var filteredSuggestions;
|
|
@@ -114,7 +127,7 @@ var XAutoCompleteBase = /** @class */ (function (_super) {
|
|
|
114
127
|
else {
|
|
115
128
|
var queryNormalized_1 = XUtils_1.XUtils.normalizeString(event.query);
|
|
116
129
|
filteredSuggestions = this.props.suggestions.filter(function (suggestion) {
|
|
117
|
-
var fieldValue =
|
|
130
|
+
var fieldValue = _this.getDisplayValue(suggestion);
|
|
118
131
|
// bolo:
|
|
119
132
|
//return XUtils.normalizeString(fieldValue).startsWith(queryNormalized);
|
|
120
133
|
return XUtils_1.XUtils.normalizeString(fieldValue).indexOf(queryNormalized_1) !== -1;
|
|
@@ -164,6 +177,9 @@ var XAutoCompleteBase = /** @class */ (function (_super) {
|
|
|
164
177
|
//console.log('onBlur - setujem timeout');
|
|
165
178
|
//setTimeout(() => {this.onBlurInvalidInput();}, 100);
|
|
166
179
|
// najnovsi sposob
|
|
180
|
+
// TODO - problem - ak zapisem nejake znaky a vyselektujem nejaky zaznam tak vznikne cerveny preblik (az nasledny onSelect zrusi state.notValid = true)
|
|
181
|
+
// zial neviem odlisit event sposobeny selektnutim zaznamu a event sposobeny kliknutim niekam vedla
|
|
182
|
+
//console.log(e);
|
|
167
183
|
this.setState({ notValid: true }); // ocervenime input
|
|
168
184
|
this.props.onErrorChange(this.createErrorMessage()); // ohlasime nevalidnost parentovi
|
|
169
185
|
}
|
|
@@ -231,18 +247,30 @@ var XAutoCompleteBase = /** @class */ (function (_super) {
|
|
|
231
247
|
if (!this.state.inputChanged) {
|
|
232
248
|
// poznamka: ak object === null tak treba do inputu zapisovat prazdny retazec, ak by sme pouzili null, neprejavila by sa zmena v modeli na null
|
|
233
249
|
var object = this.props.value;
|
|
234
|
-
|
|
250
|
+
if (typeof this.props.field === 'string') {
|
|
251
|
+
inputValue = (object !== null) ? object : ""; // TODO - je "" ok?
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
inputValue = (object !== null) ? this.props.field(object) : "";
|
|
255
|
+
}
|
|
235
256
|
}
|
|
236
257
|
else {
|
|
237
258
|
inputValue = this.state.inputValueState;
|
|
238
259
|
}
|
|
239
260
|
return inputValue;
|
|
240
261
|
};
|
|
262
|
+
XAutoCompleteBase.prototype.itemTemplate = function (suggestion, index) {
|
|
263
|
+
// @ts-ignore
|
|
264
|
+
return this.props.field(suggestion);
|
|
265
|
+
};
|
|
241
266
|
XAutoCompleteBase.prototype.render = function () {
|
|
242
267
|
var _this = this;
|
|
243
|
-
|
|
244
|
-
var
|
|
268
|
+
var _a;
|
|
269
|
+
var readOnly = (_a = this.props.readOnly) !== null && _a !== void 0 ? _a : false;
|
|
270
|
+
var dropdownButton;
|
|
245
271
|
if (this.props.valueForm) {
|
|
272
|
+
// mame CRUD operacie, potrebujeme SplitButton
|
|
273
|
+
var splitButtonItems = [];
|
|
246
274
|
splitButtonItems.push({
|
|
247
275
|
icon: 'pi pi-plus',
|
|
248
276
|
command: function (e) {
|
|
@@ -250,7 +278,7 @@ var XAutoCompleteBase = /** @class */ (function (_super) {
|
|
|
250
278
|
_this.formDialogObjectId = undefined;
|
|
251
279
|
_this.formDialogInitObjectForInsert = {};
|
|
252
280
|
// ak mame nevalidnu hodnotu, tak ju predplnime (snaha o user friendly)
|
|
253
|
-
if (_this.state.inputChanged) {
|
|
281
|
+
if (_this.state.inputChanged && typeof _this.props.field === 'string') {
|
|
254
282
|
_this.formDialogInitObjectForInsert[_this.props.field] = _this.state.inputValueState;
|
|
255
283
|
}
|
|
256
284
|
_this.setState({ formDialogOpened: true });
|
|
@@ -279,28 +307,41 @@ var XAutoCompleteBase = /** @class */ (function (_super) {
|
|
|
279
307
|
}
|
|
280
308
|
}
|
|
281
309
|
});
|
|
310
|
+
// remove nebudeme podporovat, je technicky problematicky - nemozme vymazat zaznam z DB koli FK constraintu
|
|
311
|
+
// {
|
|
312
|
+
// icon: 'pi pi-times',
|
|
313
|
+
// command: (e: any) => {
|
|
314
|
+
// console.log('remove');
|
|
315
|
+
// }
|
|
316
|
+
// },
|
|
317
|
+
splitButtonItems.push({
|
|
318
|
+
icon: 'pi pi-chevron-down',
|
|
319
|
+
command: function (e) {
|
|
320
|
+
// zobrazi cely suggestions list, zide sa ak chceme vidiet vsetky moznosti
|
|
321
|
+
// neprakticke ak mame vela poloziek v suggestions list
|
|
322
|
+
// krasne zobrazi cely objekt!
|
|
323
|
+
// this.autoCompleteRef.current je element <AutoComplete .../>, ktory vytvarame v render metode
|
|
324
|
+
//console.log(this.autoCompleteRef.current);
|
|
325
|
+
// otvori dropdown (search je metoda popisana v API, volanie sme skopcili zo zdrojakov primereact)
|
|
326
|
+
_this.autoCompleteRef.current.search(e, '', 'dropdown');
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
dropdownButton = react_1.default.createElement(splitbutton_1.SplitButton, { model: splitButtonItems, className: 'x-splitbutton-only-dropdown' + XUtils_1.XUtils.mobileCssSuffix(), menuClassName: 'x-splitbutton-only-dropdown-menu' + XUtils_1.XUtils.mobileCssSuffix(), disabled: readOnly });
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
// mame len 1 operaciu - dame jednoduchy button
|
|
333
|
+
dropdownButton = react_1.default.createElement(button_1.Button, { icon: "pi pi-chevron-down", onClick: function (e) { return _this.autoCompleteRef.current.search(e, '', 'dropdown'); }, className: 'x-dropdownbutton' + XUtils_1.XUtils.mobileCssSuffix(), disabled: readOnly });
|
|
282
334
|
}
|
|
283
|
-
// remove nebudeme podporovat, je technicky problematicky - nemozme vymazat zaznam z DB koli FK constraintu
|
|
284
|
-
// {
|
|
285
|
-
// icon: 'pi pi-times',
|
|
286
|
-
// command: (e: any) => {
|
|
287
|
-
// console.log('remove');
|
|
288
|
-
// }
|
|
289
|
-
// },
|
|
290
|
-
splitButtonItems.push({
|
|
291
|
-
icon: 'pi pi-chevron-down',
|
|
292
|
-
command: function (e) {
|
|
293
|
-
// zobrazi cely suggestions list, zide sa ak chceme vidiet vsetky moznosti
|
|
294
|
-
// neprakticke ak mame vela poloziek v suggestions list
|
|
295
|
-
// krasne zobrazi cely objekt!
|
|
296
|
-
// this.autoCompleteRef.current je element <AutoComplete .../>, ktory vytvarame v render metode
|
|
297
|
-
//console.log(this.autoCompleteRef.current);
|
|
298
|
-
// otvori dropdown (search je metoda popisana v API, volanie sme skopcili zo zdrojakov primereact)
|
|
299
|
-
_this.autoCompleteRef.current.search(e, '', 'dropdown');
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
335
|
// vypocitame inputValue
|
|
303
336
|
var inputValue = this.computeInputValue();
|
|
337
|
+
// poznamka: asi by sa dalo pouzivat vzdy len itemTemplate (nepouzivat field)
|
|
338
|
+
var fieldOrItemTemplate;
|
|
339
|
+
if (typeof this.props.field === 'string') {
|
|
340
|
+
fieldOrItemTemplate = { field: this.props.field };
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
fieldOrItemTemplate = { itemTemplate: this.itemTemplate };
|
|
344
|
+
}
|
|
304
345
|
var error;
|
|
305
346
|
if (this.state.notValid) {
|
|
306
347
|
// ak je v nevalidnom stave, tak ma tato chybova hlaska prednost pred ostatnymi (ak nahodou su)
|
|
@@ -313,9 +354,9 @@ var XAutoCompleteBase = /** @class */ (function (_super) {
|
|
|
313
354
|
// <DobrovolnikForm id={this.formDialogObjectId} object={this.formDialogInitObjectForInsert} onSaveOrCancel={this.formDialogOnSaveOrCancel}/>
|
|
314
355
|
// formgroup-inline lepi SplitButton na autocomplete a zarovna jeho vysku
|
|
315
356
|
return (react_1.default.createElement("div", { className: "x-auto-complete-base" },
|
|
316
|
-
react_1.default.createElement(autocomplete_1.AutoComplete, __assign({ value: inputValue, suggestions: this.state.filteredSuggestions, completeMethod: this.completeMethod,
|
|
317
|
-
|
|
318
|
-
this.props.valueForm != undefined ?
|
|
357
|
+
react_1.default.createElement(autocomplete_1.AutoComplete, __assign({ value: inputValue, suggestions: this.state.filteredSuggestions, completeMethod: this.completeMethod }, fieldOrItemTemplate, { onChange: this.onChange, onSelect: this.onSelect, onBlur: this.onBlur, maxLength: this.props.maxLength, ref: this.autoCompleteRef, readOnly: readOnly, disabled: readOnly }, XUtils_1.XUtils.createErrorProps(error))),
|
|
358
|
+
dropdownButton,
|
|
359
|
+
this.props.valueForm != undefined && !readOnly ?
|
|
319
360
|
react_1.default.createElement(dialog_1.Dialog, { visible: this.state.formDialogOpened, onHide: this.formDialogOnHide, header: this.formDialogObjectId ? 'Modification' : 'New record' }, react_1.default.cloneElement(this.props.valueForm, {
|
|
320
361
|
id: this.formDialogObjectId, object: this.formDialogInitObjectForInsert, onSaveOrCancel: this.formDialogOnSaveOrCancel
|
|
321
362
|
}, this.props.valueForm.children))
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { XFormComponentDT, XFormComponentDTProps } from "./XFormComponentDT";
|
|
3
|
+
import { XAssoc } from "../serverApi/XEntityMetadata";
|
|
4
|
+
import { OperationType } from "./XUtils";
|
|
5
|
+
import { XError } from "./XErrors";
|
|
6
|
+
import { XTableFieldFilterProp } from "./XFormDataTable2";
|
|
7
|
+
export interface XAutoCompleteDTProps extends XFormComponentDTProps {
|
|
8
|
+
assocField: string;
|
|
9
|
+
displayField: string | ((suggestion: any) => string);
|
|
10
|
+
searchTable?: any;
|
|
11
|
+
assocForm?: any;
|
|
12
|
+
filter?: XTableFieldFilterProp;
|
|
13
|
+
}
|
|
14
|
+
export declare class XAutoCompleteDT extends XFormComponentDT<XAutoCompleteDTProps> {
|
|
15
|
+
protected xAssoc: XAssoc;
|
|
16
|
+
protected errorInBase: string | undefined;
|
|
17
|
+
state: {
|
|
18
|
+
suggestions: any[];
|
|
19
|
+
};
|
|
20
|
+
constructor(props: XAutoCompleteDTProps);
|
|
21
|
+
componentDidMount(): void;
|
|
22
|
+
readAndSetSuggestions(): Promise<void>;
|
|
23
|
+
getField(): string;
|
|
24
|
+
isNotNull(): boolean;
|
|
25
|
+
getValue(): any | null;
|
|
26
|
+
onChangeAutoCompleteBase(object: any, objectChange: OperationType): void;
|
|
27
|
+
onErrorChangeAutoCompleteBase(error: string | undefined): void;
|
|
28
|
+
validate(): {
|
|
29
|
+
field: string;
|
|
30
|
+
xError: XError;
|
|
31
|
+
} | undefined;
|
|
32
|
+
render(): JSX.Element;
|
|
33
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.XAutoCompleteDT = void 0;
|
|
58
|
+
var XUtilsMetadata_1 = require("./XUtilsMetadata");
|
|
59
|
+
var react_1 = __importDefault(require("react"));
|
|
60
|
+
var XFormComponentDT_1 = require("./XFormComponentDT");
|
|
61
|
+
var XUtils_1 = require("./XUtils");
|
|
62
|
+
var XAutoCompleteBase_1 = require("./XAutoCompleteBase");
|
|
63
|
+
var XAutoCompleteDT = /** @class */ (function (_super) {
|
|
64
|
+
__extends(XAutoCompleteDT, _super);
|
|
65
|
+
function XAutoCompleteDT(props) {
|
|
66
|
+
var _this = _super.call(this, props) || this;
|
|
67
|
+
_this.xAssoc = XUtilsMetadata_1.XUtilsMetadata.getXAssocToOne(XUtilsMetadata_1.XUtilsMetadata.getXEntity(props.entity), props.assocField);
|
|
68
|
+
_this.errorInBase = undefined;
|
|
69
|
+
_this.state = {
|
|
70
|
+
suggestions: []
|
|
71
|
+
};
|
|
72
|
+
_this.onChangeAutoCompleteBase = _this.onChangeAutoCompleteBase.bind(_this);
|
|
73
|
+
_this.onErrorChangeAutoCompleteBase = _this.onErrorChangeAutoCompleteBase.bind(_this);
|
|
74
|
+
return _this;
|
|
75
|
+
}
|
|
76
|
+
XAutoCompleteDT.prototype.componentDidMount = function () {
|
|
77
|
+
this.readAndSetSuggestions();
|
|
78
|
+
};
|
|
79
|
+
XAutoCompleteDT.prototype.readAndSetSuggestions = function () {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var suggestions;
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
84
|
+
case 0: return [4 /*yield*/, XUtils_1.XUtils.fetchRows(this.xAssoc.entityName, this.getFilterBase(this.props.filter), typeof this.props.displayField === 'string' ? this.props.displayField : undefined)];
|
|
85
|
+
case 1:
|
|
86
|
+
suggestions = _a.sent();
|
|
87
|
+
// ak mame funkciu, zosortujeme tu
|
|
88
|
+
if (typeof this.props.displayField === 'function') {
|
|
89
|
+
suggestions = XUtils_1.XUtils.arraySort(suggestions, this.props.displayField);
|
|
90
|
+
}
|
|
91
|
+
this.setState({ suggestions: suggestions });
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
XAutoCompleteDT.prototype.getField = function () {
|
|
98
|
+
return this.props.assocField;
|
|
99
|
+
};
|
|
100
|
+
XAutoCompleteDT.prototype.isNotNull = function () {
|
|
101
|
+
return !this.xAssoc.isNullable;
|
|
102
|
+
};
|
|
103
|
+
XAutoCompleteDT.prototype.getValue = function () {
|
|
104
|
+
var assocObject = this.getValueFromRowData();
|
|
105
|
+
return assocObject;
|
|
106
|
+
};
|
|
107
|
+
XAutoCompleteDT.prototype.onChangeAutoCompleteBase = function (object, objectChange) {
|
|
108
|
+
this.onValueChangeBase(object, this.props.onChange, objectChange);
|
|
109
|
+
if (objectChange !== XUtils_1.OperationType.None) {
|
|
110
|
+
// zmenil sa zaznam dobrovolnika v DB
|
|
111
|
+
// zatial len refreshneme z DB
|
|
112
|
+
// ak by bol reqest pomaly, mozme pri inserte (nove id) / update (existujuce id) upravit zoznam a usetrime tym request do DB
|
|
113
|
+
// ak bol delete (dobrovolnik === null), treba urobit refresh do DB (alebo si poslat id-cko zmazaneho zaznamu)
|
|
114
|
+
this.readAndSetSuggestions();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
XAutoCompleteDT.prototype.onErrorChangeAutoCompleteBase = function (error) {
|
|
118
|
+
this.errorInBase = error; // odlozime si error
|
|
119
|
+
};
|
|
120
|
+
// overrides method in XFormComponent
|
|
121
|
+
XAutoCompleteDT.prototype.validate = function () {
|
|
122
|
+
if (this.errorInBase) {
|
|
123
|
+
// error message dame na onChange, mohli by sme aj na onSet (predtym onBlur), je to jedno viac-menej
|
|
124
|
+
// TODO - fieldLabel
|
|
125
|
+
return { field: this.getField(), xError: { onChange: this.errorInBase, fieldLabel: undefined } };
|
|
126
|
+
}
|
|
127
|
+
// zavolame povodnu metodu
|
|
128
|
+
return _super.prototype.validate.call(this);
|
|
129
|
+
};
|
|
130
|
+
XAutoCompleteDT.prototype.render = function () {
|
|
131
|
+
var xEntityAssoc = XUtilsMetadata_1.XUtilsMetadata.getXEntity(this.xAssoc.entityName);
|
|
132
|
+
//const xDisplayField = XUtilsMetadata.getXFieldByPath(xEntityAssoc, this.props.displayField);
|
|
133
|
+
// TODO - size
|
|
134
|
+
//const size = this.props.size ?? xDisplayField.length;
|
|
135
|
+
// div className="col" nam zabezpeci aby XAutoCompleteBase nezaberal celu dlzku grid-u (ma nastaveny width=100% vdaka "formgroup-inline")
|
|
136
|
+
return (react_1.default.createElement(XAutoCompleteBase_1.XAutoCompleteBase, { value: this.getValue(), suggestions: this.state.suggestions, onChange: this.onChangeAutoCompleteBase, field: this.props.displayField, valueForm: this.props.assocForm, idField: xEntityAssoc.idField, readOnly: this.isReadOnly(), error: this.getError(), onErrorChange: this.onErrorChangeAutoCompleteBase }));
|
|
137
|
+
};
|
|
138
|
+
return XAutoCompleteDT;
|
|
139
|
+
}(XFormComponentDT_1.XFormComponentDT));
|
|
140
|
+
exports.XAutoCompleteDT = XAutoCompleteDT;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { ButtonProps } from "primereact/button";
|
|
3
|
+
import { IconType } from "primereact/utils";
|
|
2
4
|
export declare const XButton: (props: {
|
|
3
5
|
label?: string | undefined;
|
|
4
|
-
icon?:
|
|
6
|
+
icon?: IconType<ButtonProps>;
|
|
5
7
|
onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
6
8
|
disabled?: boolean | undefined;
|
|
7
9
|
}) => JSX.Element;
|
|
@@ -7,7 +7,7 @@ exports.XButton = void 0;
|
|
|
7
7
|
var react_1 = __importDefault(require("react"));
|
|
8
8
|
var button_1 = require("primereact/button");
|
|
9
9
|
var XButton = function (props) {
|
|
10
|
-
// zatial iba pridany class x-button, aby sme vedeli nastavit margin "m-1" (
|
|
10
|
+
// zatial iba pridany class x-button, aby sme vedeli nastavit margin "m-1" (0.25rem)
|
|
11
11
|
return (react_1.default.createElement(button_1.Button, { label: props.label, icon: props.icon, onClick: props.onClick, disabled: props.disabled, className: "m-1" }));
|
|
12
12
|
};
|
|
13
13
|
exports.XButton = XButton;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ButtonProps } from "primereact/button";
|
|
3
|
+
import { IconType } from "primereact/utils";
|
|
4
|
+
export declare const XButtonIconNarrow: (props: {
|
|
5
|
+
icon: IconType<ButtonProps>;
|
|
6
|
+
onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
7
|
+
disabled?: boolean | undefined;
|
|
8
|
+
tooltip?: any;
|
|
9
|
+
addMargin?: boolean | undefined;
|
|
10
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.XButtonIconNarrow = void 0;
|
|
7
|
+
var react_1 = __importDefault(require("react"));
|
|
8
|
+
var button_1 = require("primereact/button");
|
|
9
|
+
var XUtils_1 = require("./XUtils");
|
|
10
|
+
// button s ikonkou, zuzeny na 1.5rem (21px), na mobile nezuzeny, defaultne s marginom "m-1" (0.25rem) (ako XButton), margin sa da vypnut (pouzivane pre editovatelnu tabulku)
|
|
11
|
+
// zmyslom narrow buttonu je setrit miesto
|
|
12
|
+
var XButtonIconNarrow = function (props) {
|
|
13
|
+
var className = '';
|
|
14
|
+
if (!XUtils_1.XUtils.isMobile()) {
|
|
15
|
+
className += 'x-button-icon-narrow';
|
|
16
|
+
}
|
|
17
|
+
if (props.addMargin === undefined || props.addMargin === true) {
|
|
18
|
+
if (className !== '') {
|
|
19
|
+
className += ' ';
|
|
20
|
+
}
|
|
21
|
+
className += 'm-1';
|
|
22
|
+
}
|
|
23
|
+
return (react_1.default.createElement(button_1.Button, { icon: props.icon, onClick: props.onClick, disabled: props.disabled, className: className !== '' ? className : undefined, tooltip: props.tooltip }));
|
|
24
|
+
};
|
|
25
|
+
exports.XButtonIconNarrow = XButtonIconNarrow;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { ButtonProps } from "primereact/button";
|
|
3
|
+
import { IconType } from "primereact/utils";
|
|
2
4
|
export declare const XButtonIconSmall: (props: {
|
|
3
|
-
icon:
|
|
5
|
+
icon: IconType<ButtonProps>;
|
|
4
6
|
onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
5
7
|
disabled?: boolean | undefined;
|
|
6
8
|
tooltip?: any;
|