@michalrakus/x-react-web-lib 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/README.md +3 -3
  2. package/gulpfile.js +82 -82
  3. package/lib/administration/XBrowseMetaBrowse.d.ts +2 -2
  4. package/lib/administration/XBrowseMetaBrowse.js +21 -21
  5. package/lib/administration/XBrowseMetaForm.d.ts +5 -5
  6. package/lib/administration/XBrowseMetaForm.js +63 -63
  7. package/lib/administration/XUserBrowse.d.ts +2 -2
  8. package/lib/administration/XUserBrowse.js +88 -87
  9. package/lib/administration/XUserForm.d.ts +9 -9
  10. package/lib/administration/XUserForm.js +195 -194
  11. package/lib/components/SearchTableParams.d.ts +11 -11
  12. package/lib/components/SearchTableParams.js +2 -2
  13. package/lib/components/SourceCodeLinkEntity.d.ts +4 -4
  14. package/lib/components/SourceCodeLinkEntity.js +14 -14
  15. package/lib/components/XAutoComplete.d.ts +36 -36
  16. package/lib/components/XAutoComplete.js +155 -155
  17. package/lib/components/XAutoCompleteBase.d.ts +45 -45
  18. package/lib/components/XAutoCompleteBase.js +371 -371
  19. package/lib/components/XAutoCompleteDT.d.ts +33 -33
  20. package/lib/components/XAutoCompleteDT.js +140 -140
  21. package/lib/components/XBrowse.d.ts +33 -33
  22. package/lib/components/XBrowse.js +360 -360
  23. package/lib/components/XButton.d.ts +9 -9
  24. package/lib/components/XButton.js +13 -13
  25. package/lib/components/XButtonIconMedium.d.ts +9 -9
  26. package/lib/components/XButtonIconMedium.js +13 -13
  27. package/lib/components/XButtonIconNarrow.d.ts +10 -10
  28. package/lib/components/XButtonIconNarrow.js +25 -25
  29. package/lib/components/XButtonIconSmall.d.ts +9 -9
  30. package/lib/components/XButtonIconSmall.js +13 -13
  31. package/lib/components/XCalendar.d.ts +8 -8
  32. package/lib/components/XCalendar.js +27 -27
  33. package/lib/components/XChangePasswordForm.d.ts +5 -5
  34. package/lib/components/XChangePasswordForm.js +160 -160
  35. package/lib/components/XCheckbox.d.ts +8 -8
  36. package/lib/components/XCheckbox.js +57 -57
  37. package/lib/components/XCheckboxDT.d.ts +10 -10
  38. package/lib/components/XCheckboxDT.js +46 -46
  39. package/lib/components/XDataTable.d.ts +11 -11
  40. package/lib/components/XDataTable.js +197 -197
  41. package/lib/components/XDropdown.d.ts +18 -18
  42. package/lib/components/XDropdown.js +57 -57
  43. package/lib/components/XDropdownDT.d.ts +13 -13
  44. package/lib/components/XDropdownDT.js +128 -128
  45. package/lib/components/XDropdownDTFilter.d.ts +7 -7
  46. package/lib/components/XDropdownDTFilter.js +121 -121
  47. package/lib/components/XDropdownForEntity.d.ts +25 -25
  48. package/lib/components/XDropdownForEntity.js +149 -149
  49. package/lib/components/XDropdownFormDTFilter.d.ts +7 -7
  50. package/lib/components/XDropdownFormDTFilter.js +121 -121
  51. package/lib/components/XEditColumnDialog.d.ts +13 -13
  52. package/lib/components/XEditColumnDialog.js +112 -112
  53. package/lib/components/XEnvVars.d.ts +15 -12
  54. package/lib/components/XEnvVars.js +23 -20
  55. package/lib/components/XErrors.d.ts +12 -12
  56. package/lib/components/XErrors.js +2 -2
  57. package/lib/components/XExportRowsDialog.d.ts +15 -15
  58. package/lib/components/XExportRowsDialog.js +184 -184
  59. package/lib/components/XFieldChangeEvent.d.ts +11 -11
  60. package/lib/components/XFieldChangeEvent.js +2 -2
  61. package/lib/components/XFieldSelector.d.ts +7 -7
  62. package/lib/components/XFieldSelector.js +113 -113
  63. package/lib/components/XFormBase.d.ts +59 -59
  64. package/lib/components/XFormBase.js +526 -526
  65. package/lib/components/XFormBaseModif.d.ts +5 -5
  66. package/lib/components/XFormBaseModif.js +33 -33
  67. package/lib/components/XFormBaseT.d.ts +4 -4
  68. package/lib/components/XFormBaseT.js +31 -31
  69. package/lib/components/XFormComponent.d.ts +40 -40
  70. package/lib/components/XFormComponent.js +177 -177
  71. package/lib/components/XFormComponentDT.d.ts +30 -30
  72. package/lib/components/XFormComponentDT.js +145 -145
  73. package/lib/components/XFormDataTable2.d.ts +143 -143
  74. package/lib/components/XFormDataTable2.js +686 -686
  75. package/lib/components/XFormFooter.d.ts +6 -6
  76. package/lib/components/XFormFooter.js +19 -19
  77. package/lib/components/XFormNavigator3.d.ts +12 -12
  78. package/lib/components/XFormNavigator3.js +130 -130
  79. package/lib/components/XHolders.d.ts +7 -7
  80. package/lib/components/XHolders.js +15 -15
  81. package/lib/components/XInput.d.ts +13 -13
  82. package/lib/components/XInput.js +38 -38
  83. package/lib/components/XInputDT.d.ts +11 -11
  84. package/lib/components/XInputDT.js +37 -37
  85. package/lib/components/XInputDate.d.ts +13 -13
  86. package/lib/components/XInputDate.js +63 -63
  87. package/lib/components/XInputDateDT.d.ts +10 -10
  88. package/lib/components/XInputDateDT.js +55 -55
  89. package/lib/components/XInputDecimal.d.ts +15 -15
  90. package/lib/components/XInputDecimal.js +78 -78
  91. package/lib/components/XInputDecimalBase.d.ts +12 -12
  92. package/lib/components/XInputDecimalBase.js +18 -18
  93. package/lib/components/XInputDecimalDT.d.ts +11 -11
  94. package/lib/components/XInputDecimalDT.js +74 -74
  95. package/lib/components/XInputFileList.d.ts +36 -36
  96. package/lib/components/XInputFileList.js +251 -251
  97. package/lib/components/XInputText.d.ts +12 -12
  98. package/lib/components/XInputText.js +69 -69
  99. package/lib/components/XInputTextDT.d.ts +9 -9
  100. package/lib/components/XInputTextDT.js +42 -42
  101. package/lib/components/XInputTextarea.d.ts +18 -18
  102. package/lib/components/XInputTextarea.js +85 -85
  103. package/lib/components/XLazyDataTable.d.ts +78 -78
  104. package/lib/components/XLazyDataTable.js +885 -885
  105. package/lib/components/XLocale.d.ts +26 -26
  106. package/lib/components/XLocale.js +59 -59
  107. package/lib/components/XLoginDialog.d.ts +8 -8
  108. package/lib/components/XLoginDialog.js +21 -21
  109. package/lib/components/XLoginForm.d.ts +7 -7
  110. package/lib/components/XLoginForm.js +128 -128
  111. package/lib/components/XObject.d.ts +3 -3
  112. package/lib/components/XObject.js +2 -2
  113. package/lib/components/XResponseError.d.ts +11 -11
  114. package/lib/components/XResponseError.js +32 -32
  115. package/lib/components/XSearchButton.d.ts +26 -26
  116. package/lib/components/XSearchButton.js +225 -225
  117. package/lib/components/XSearchButtonDT.d.ts +12 -12
  118. package/lib/components/XSearchButtonDT.js +188 -188
  119. package/lib/components/XSearchButtonOld.d.ts +13 -13
  120. package/lib/components/XSearchButtonOld.js +212 -212
  121. package/lib/components/XToOneAssocButton.d.ts +8 -8
  122. package/lib/components/XToOneAssocButton.js +30 -30
  123. package/lib/components/XToken.d.ts +6 -6
  124. package/lib/components/XToken.js +2 -2
  125. package/lib/components/XUtils.d.ts +74 -74
  126. package/lib/components/XUtils.js +627 -627
  127. package/lib/components/XUtilsConversions.d.ts +12 -12
  128. package/lib/components/XUtilsConversions.js +125 -125
  129. package/lib/components/XUtilsMetadata.d.ts +39 -39
  130. package/lib/components/XUtilsMetadata.js +452 -452
  131. package/lib/components/locale/x-en.json +26 -26
  132. package/lib/components/useXToken.d.ts +2 -2
  133. package/lib/components/useXToken.js +44 -44
  134. package/lib/serverApi/ExportImportParam.d.ts +51 -51
  135. package/lib/serverApi/ExportImportParam.js +34 -34
  136. package/lib/serverApi/FindParam.d.ts +34 -34
  137. package/lib/serverApi/FindParam.js +30 -30
  138. package/lib/serverApi/FindResult.d.ts +8 -8
  139. package/lib/serverApi/FindResult.js +2 -2
  140. package/lib/serverApi/XBrowseMetadata.d.ts +19 -19
  141. package/lib/serverApi/XBrowseMetadata.js +2 -2
  142. package/lib/serverApi/XEntityMetadata.d.ts +35 -35
  143. package/lib/serverApi/XEntityMetadata.js +2 -2
  144. package/lib/serverApi/XFileJsonField.d.ts +6 -6
  145. package/lib/serverApi/XFileJsonField.js +2 -2
  146. package/lib/serverApi/XUser.d.ts +8 -7
  147. package/lib/serverApi/XUser.js +2 -2
  148. package/lib/serverApi/XUserAuthenticationIfc.d.ts +9 -9
  149. package/lib/serverApi/XUserAuthenticationIfc.js +2 -2
  150. package/lib/serverApi/XUtilsCommon.d.ts +13 -13
  151. package/lib/serverApi/XUtilsCommon.js +110 -110
  152. package/package.json +1 -1
@@ -1,371 +1,371 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
- if (k2 === undefined) k2 = k;
30
- var desc = Object.getOwnPropertyDescriptor(m, k);
31
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
- desc = { enumerable: true, get: function() { return m[k]; } };
33
- }
34
- Object.defineProperty(o, k2, desc);
35
- }) : (function(o, m, k, k2) {
36
- if (k2 === undefined) k2 = k;
37
- o[k2] = m[k];
38
- }));
39
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
- Object.defineProperty(o, "default", { enumerable: true, value: v });
41
- }) : function(o, v) {
42
- o["default"] = v;
43
- });
44
- var __importStar = (this && this.__importStar) || function (mod) {
45
- if (mod && mod.__esModule) return mod;
46
- var result = {};
47
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
- __setModuleDefault(result, mod);
49
- return result;
50
- };
51
- var __read = (this && this.__read) || function (o, n) {
52
- var m = typeof Symbol === "function" && o[Symbol.iterator];
53
- if (!m) return o;
54
- var i = m.call(o), r, ar = [], e;
55
- try {
56
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
57
- }
58
- catch (error) { e = { error: error }; }
59
- finally {
60
- try {
61
- if (r && !r.done && (m = i["return"])) m.call(i);
62
- }
63
- finally { if (e) throw e.error; }
64
- }
65
- return ar;
66
- };
67
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
68
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
69
- if (ar || !(i in from)) {
70
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
71
- ar[i] = from[i];
72
- }
73
- }
74
- return to.concat(ar || Array.prototype.slice.call(from));
75
- };
76
- Object.defineProperty(exports, "__esModule", { value: true });
77
- exports.XAutoCompleteBase = void 0;
78
- var react_1 = __importStar(require("react"));
79
- var autocomplete_1 = require("primereact/autocomplete");
80
- var splitbutton_1 = require("primereact/splitbutton");
81
- var dialog_1 = require("primereact/dialog");
82
- var XUtils_1 = require("./XUtils");
83
- var button_1 = require("primereact/button");
84
- var XAutoCompleteBase = /** @class */ (function (_super) {
85
- __extends(XAutoCompleteBase, _super);
86
- function XAutoCompleteBase(props) {
87
- var _this = _super.call(this, props) || this;
88
- _this.autoCompleteRef = react_1.default.createRef();
89
- _this.state = {
90
- inputChanged: false,
91
- inputValueState: undefined,
92
- notValid: false,
93
- filteredSuggestions: undefined,
94
- formDialogOpened: false
95
- };
96
- _this.completeMethod = _this.completeMethod.bind(_this);
97
- _this.onChange = _this.onChange.bind(_this);
98
- _this.onSelect = _this.onSelect.bind(_this);
99
- _this.onBlur = _this.onBlur.bind(_this);
100
- _this.formDialogOnSaveOrCancel = _this.formDialogOnSaveOrCancel.bind(_this);
101
- _this.formDialogOnHide = _this.formDialogOnHide.bind(_this);
102
- _this.itemTemplate = _this.itemTemplate.bind(_this);
103
- return _this;
104
- }
105
- XAutoCompleteBase.prototype.componentDidMount = function () {
106
- if (this.props.setFocusOnCreate) {
107
- this.setFocusToInput();
108
- }
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
- };
121
- XAutoCompleteBase.prototype.completeMethod = function (event) {
122
- var _this = this;
123
- var filteredSuggestions;
124
- if (!event.query.trim().length) {
125
- filteredSuggestions = __spreadArray([], __read(this.props.suggestions), false);
126
- }
127
- else {
128
- var queryNormalized_1 = XUtils_1.XUtils.normalizeString(event.query);
129
- filteredSuggestions = this.props.suggestions.filter(function (suggestion) {
130
- var fieldValue = _this.getDisplayValue(suggestion);
131
- // specialna null polozka (prazdny objekt) - test dame az za test fieldValue na undefined - koli performance
132
- if (fieldValue === undefined && Object.keys(suggestion).length === 0) {
133
- return false;
134
- }
135
- // bolo:
136
- //return XUtils.normalizeString(fieldValue).startsWith(queryNormalized);
137
- return XUtils_1.XUtils.normalizeString(fieldValue).indexOf(queryNormalized_1) !== -1;
138
- });
139
- }
140
- this.setState({ filteredSuggestions: filteredSuggestions });
141
- };
142
- XAutoCompleteBase.prototype.onChange = function (e) {
143
- if (typeof e.value === 'string') {
144
- this.setState({ inputChanged: true, inputValueState: e.value });
145
- }
146
- };
147
- XAutoCompleteBase.prototype.onSelect = function (e) {
148
- this.setObjectValue(e.value, XUtils_1.OperationType.None);
149
- };
150
- XAutoCompleteBase.prototype.onBlur = function (e) {
151
- // optimalizacia - testujeme len ak inputChanged === true
152
- if (this.state.inputChanged) {
153
- if (e.target.value === '') {
154
- this.setObjectValue(null, XUtils_1.OperationType.None); // prazdny retazec znamena null hodnotu
155
- }
156
- else {
157
- // skusime ci filteredSuggestions nemaju prave jeden element
158
- var filteredSuggestions = this.state.filteredSuggestions;
159
- if (filteredSuggestions && filteredSuggestions.length === 1) {
160
- this.setObjectValue(filteredSuggestions[0], XUtils_1.OperationType.None);
161
- }
162
- else {
163
- // tu by sme mohli skusit vyratat vysledok pre filteredSuggestions este raz, mozno este vypocet filteredSuggestions nedobehol
164
- // mohli by sme: zobrazit vsetky povolene hodnoty (v dialogu/v dropdown liste), zobrazit nejaky alert
165
- //alert("invalid value");
166
- // radi by sme stopli dalsie event-y (napr. stlacenie buttonu, ktore vyvolalo stratu focus-u), ale nezafungovalo nam to
167
- //e.preventDefault();
168
- //e.stopPropagation();
169
- // nefunguje ani toto
170
- //console.log('stop propagation');
171
- //console.log(e);
172
- //e.nativeEvent.stopImmediatePropagation();
173
- //e.preventDefault();
174
- // zobrazime dropdown list aby sme usera upovedomili ze ma vybrat nejaku hodnotu
175
- // toto neni moc prakticke ak mame vela poloziek v dropdown-e - lepsi by bol asi confirm, ci pridat novu polozku do DB
176
- // zrusil som, lebo pri vybere z dropdownu kliknutim sa vola tento onBlur (este pred onSelect), zobrazi sa iny dropdown ako vidi uzivatel a vyberie sa z neho ina polozka ako je ta na ktoru klikol user
177
- //this.autoCompleteRef.current.onDropdownClick();
178
- // vratime focus do inputu
179
- // obycajne setnutie focusu nefunguje, treba v setnut focus v samostatnom evente
180
- // TODO - aj nejaky stop event skusit
181
- //console.log('onBlur - setujem timeout');
182
- //setTimeout(() => {this.onBlurInvalidInput();}, 100);
183
- // najnovsi sposob
184
- // TODO - problem - ak zapisem nejake znaky a vyselektujem nejaky zaznam tak vznikne cerveny preblik (az nasledny onSelect zrusi state.notValid = true)
185
- // zial neviem odlisit event sposobeny selektnutim zaznamu a event sposobeny kliknutim niekam vedla
186
- //console.log(e);
187
- this.setState({ notValid: true }); // ocervenime input
188
- this.props.onErrorChange(this.createErrorMessage()); // ohlasime nevalidnost parentovi
189
- }
190
- }
191
- }
192
- };
193
- XAutoCompleteBase.prototype.createErrorMessage = function () {
194
- return "Value \"".concat(this.state.inputValueState, "\" was not found among valid values.");
195
- };
196
- /*
197
- onBlurInvalidInput() {
198
- // ak uzivatel vyvolal onBlur kliknutim na polozku dropdown list-u, tak sa v priebehu 100 ms (oneskorenie volania onBlurInvalidInput()) zavolal onSelect,
199
- // zmenil sa inputChanged a netreba nic riesit
200
- if (this.state.inputChanged) {
201
- console.log('onBlurInvalidInput - idem otvorit confirm');
202
- if (window.confirm(`Value "${this.state.inputValueState}" was not found among valid values, create new valid value?`)) {
203
- // otvorime dialog na insert
204
- this.formDialogObjectId = undefined;
205
- // TODO - pridat ako novu prop metodu ktora bude vracat bude mat parameter this.state.inputValueState a vrati object
206
- // ak bude tato metoda undefined, tak zostane tato povodna funkcionalita
207
- this.formDialogInitObjectForInsert = {};
208
- this.formDialogInitObjectForInsert[this.props.field] = this.state.inputValueState;
209
- this.setState({formDialogOpened: true});
210
- }
211
- else {
212
- // vratime focus do inputu, je tam nevalidna hodnota
213
- console.log('onBlurInvalidInput - idem vratit focus');
214
- this.setFocusToInput();
215
- }
216
- }
217
- }
218
- */
219
- XAutoCompleteBase.prototype.setFocusToInput = function () {
220
- this.autoCompleteRef.current.focus();
221
- };
222
- XAutoCompleteBase.prototype.setObjectValue = function (object, objectChange) {
223
- this.setState({ inputChanged: false, notValid: false });
224
- this.props.onChange(object, objectChange);
225
- this.props.onErrorChange(undefined); // uz nie sme v nevalidnom stave
226
- };
227
- XAutoCompleteBase.prototype.formDialogOnSaveOrCancel = function (object, objectChange) {
228
- if (object !== null) {
229
- // ak bol save, treba tento novy object pouzit
230
- this.setObjectValue(object, objectChange);
231
- // treba upravit this.state.filteredSuggestions? setli sme novy objekt, panel so suggestions by mal byt zavrety - TODO - overit
232
- }
233
- else {
234
- // bol cancel, vratime focus do inputu ak treba
235
- if (this.state.inputChanged) {
236
- this.setFocusToInput();
237
- }
238
- }
239
- this.setState({ formDialogOpened: false });
240
- };
241
- XAutoCompleteBase.prototype.formDialogOnHide = function () {
242
- this.setState({ formDialogOpened: false });
243
- // ak mame v inpute neplatnu hodnotu, vratime kurzor na input
244
- if (this.state.inputChanged) {
245
- this.setFocusToInput();
246
- }
247
- };
248
- // vracia objekt (ak inputChanged === false) alebo string (ak inputChanged === true)
249
- XAutoCompleteBase.prototype.computeInputValue = function () {
250
- var inputValue = null;
251
- if (!this.state.inputChanged) {
252
- // poznamka: ak object === null tak treba do inputu zapisovat prazdny retazec, ak by sme pouzili null, neprejavila by sa zmena v modeli na null
253
- var object = this.props.value;
254
- if (typeof this.props.field === 'string') {
255
- inputValue = (object !== null) ? object : ""; // TODO - je "" ok?
256
- }
257
- else {
258
- inputValue = (object !== null) ? this.props.field(object) : "";
259
- }
260
- }
261
- else {
262
- inputValue = this.state.inputValueState;
263
- }
264
- return inputValue;
265
- };
266
- XAutoCompleteBase.prototype.itemTemplate = function (suggestion, index) {
267
- // @ts-ignore
268
- return this.props.field(suggestion);
269
- };
270
- XAutoCompleteBase.prototype.render = function () {
271
- var _this = this;
272
- var _a;
273
- var readOnly = (_a = this.props.readOnly) !== null && _a !== void 0 ? _a : false;
274
- var dropdownButton;
275
- if (this.props.valueForm) {
276
- // mame CRUD operacie, potrebujeme SplitButton
277
- var splitButtonItems = [];
278
- splitButtonItems.push({
279
- icon: 'pi pi-plus',
280
- command: function (e) {
281
- // otvorime dialog na insert
282
- _this.formDialogObjectId = undefined;
283
- _this.formDialogInitObjectForInsert = {};
284
- // ak mame nevalidnu hodnotu, tak ju predplnime (snaha o user friendly)
285
- if (_this.state.inputChanged && typeof _this.props.field === 'string') {
286
- _this.formDialogInitObjectForInsert[_this.props.field] = _this.state.inputValueState;
287
- }
288
- _this.setState({ formDialogOpened: true });
289
- }
290
- });
291
- splitButtonItems.push({
292
- icon: 'pi pi-pencil',
293
- command: function (e) {
294
- if (_this.state.inputChanged) {
295
- alert("Value \"".concat(_this.state.inputValueState, "\" was not found among valid values, please enter some valid value."));
296
- _this.setFocusToInput();
297
- }
298
- else {
299
- if (_this.props.value === null) {
300
- alert('Please select some row.');
301
- }
302
- else {
303
- // otvorime dialog na update
304
- if (_this.props.idField === undefined) {
305
- throw "XAutoCompleteBase: property valueForm is defined but property idField is also needed for form editation.";
306
- }
307
- _this.formDialogObjectId = _this.props.value[_this.props.idField];
308
- _this.formDialogInitObjectForInsert = undefined;
309
- _this.setState({ formDialogOpened: true });
310
- }
311
- }
312
- }
313
- });
314
- // remove nebudeme podporovat, je technicky problematicky - nemozme vymazat zaznam z DB koli FK constraintu
315
- // {
316
- // icon: 'pi pi-times',
317
- // command: (e: any) => {
318
- // console.log('remove');
319
- // }
320
- // },
321
- splitButtonItems.push({
322
- icon: 'pi pi-chevron-down',
323
- command: function (e) {
324
- // zobrazi cely suggestions list, zide sa ak chceme vidiet vsetky moznosti
325
- // neprakticke ak mame vela poloziek v suggestions list
326
- // krasne zobrazi cely objekt!
327
- // this.autoCompleteRef.current je element <AutoComplete .../>, ktory vytvarame v render metode
328
- //console.log(this.autoCompleteRef.current);
329
- // otvori dropdown (search je metoda popisana v API, volanie sme skopcili zo zdrojakov primereact)
330
- _this.autoCompleteRef.current.search(e, '', 'dropdown');
331
- }
332
- });
333
- 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 });
334
- }
335
- else {
336
- // mame len 1 operaciu - dame jednoduchy button
337
- 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 });
338
- }
339
- // vypocitame inputValue
340
- var inputValue = this.computeInputValue();
341
- // poznamka: asi by sa dalo pouzivat vzdy len itemTemplate (nepouzivat field)
342
- var fieldOrItemTemplate;
343
- if (typeof this.props.field === 'string') {
344
- fieldOrItemTemplate = { field: this.props.field };
345
- }
346
- else {
347
- fieldOrItemTemplate = { itemTemplate: this.itemTemplate };
348
- }
349
- var error;
350
- if (this.state.notValid) {
351
- // ak je v nevalidnom stave, tak ma tato chybova hlaska prednost pred ostatnymi (ak nahodou su)
352
- error = this.createErrorMessage();
353
- }
354
- else {
355
- error = this.props.error;
356
- }
357
- // Dialog pre konkretny form:
358
- // <DobrovolnikForm id={this.formDialogObjectId} object={this.formDialogInitObjectForInsert} onSaveOrCancel={this.formDialogOnSaveOrCancel}/>
359
- // formgroup-inline lepi SplitButton na autocomplete a zarovna jeho vysku
360
- return (react_1.default.createElement("div", { className: "x-auto-complete-base" },
361
- 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))),
362
- dropdownButton,
363
- this.props.valueForm != undefined && !readOnly ?
364
- 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, {
365
- id: this.formDialogObjectId, object: this.formDialogInitObjectForInsert, onSaveOrCancel: this.formDialogOnSaveOrCancel
366
- }, this.props.valueForm.children))
367
- : undefined));
368
- };
369
- return XAutoCompleteBase;
370
- }(react_1.Component));
371
- exports.XAutoCompleteBase = XAutoCompleteBase;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ var __read = (this && this.__read) || function (o, n) {
52
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
53
+ if (!m) return o;
54
+ var i = m.call(o), r, ar = [], e;
55
+ try {
56
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
57
+ }
58
+ catch (error) { e = { error: error }; }
59
+ finally {
60
+ try {
61
+ if (r && !r.done && (m = i["return"])) m.call(i);
62
+ }
63
+ finally { if (e) throw e.error; }
64
+ }
65
+ return ar;
66
+ };
67
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
68
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
69
+ if (ar || !(i in from)) {
70
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
71
+ ar[i] = from[i];
72
+ }
73
+ }
74
+ return to.concat(ar || Array.prototype.slice.call(from));
75
+ };
76
+ Object.defineProperty(exports, "__esModule", { value: true });
77
+ exports.XAutoCompleteBase = void 0;
78
+ var react_1 = __importStar(require("react"));
79
+ var autocomplete_1 = require("primereact/autocomplete");
80
+ var splitbutton_1 = require("primereact/splitbutton");
81
+ var dialog_1 = require("primereact/dialog");
82
+ var XUtils_1 = require("./XUtils");
83
+ var button_1 = require("primereact/button");
84
+ var XAutoCompleteBase = /** @class */ (function (_super) {
85
+ __extends(XAutoCompleteBase, _super);
86
+ function XAutoCompleteBase(props) {
87
+ var _this = _super.call(this, props) || this;
88
+ _this.autoCompleteRef = react_1.default.createRef();
89
+ _this.state = {
90
+ inputChanged: false,
91
+ inputValueState: undefined,
92
+ notValid: false,
93
+ filteredSuggestions: undefined,
94
+ formDialogOpened: false
95
+ };
96
+ _this.completeMethod = _this.completeMethod.bind(_this);
97
+ _this.onChange = _this.onChange.bind(_this);
98
+ _this.onSelect = _this.onSelect.bind(_this);
99
+ _this.onBlur = _this.onBlur.bind(_this);
100
+ _this.formDialogOnSaveOrCancel = _this.formDialogOnSaveOrCancel.bind(_this);
101
+ _this.formDialogOnHide = _this.formDialogOnHide.bind(_this);
102
+ _this.itemTemplate = _this.itemTemplate.bind(_this);
103
+ return _this;
104
+ }
105
+ XAutoCompleteBase.prototype.componentDidMount = function () {
106
+ if (this.props.setFocusOnCreate) {
107
+ this.setFocusToInput();
108
+ }
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
+ };
121
+ XAutoCompleteBase.prototype.completeMethod = function (event) {
122
+ var _this = this;
123
+ var filteredSuggestions;
124
+ if (!event.query.trim().length) {
125
+ filteredSuggestions = __spreadArray([], __read(this.props.suggestions), false);
126
+ }
127
+ else {
128
+ var queryNormalized_1 = XUtils_1.XUtils.normalizeString(event.query);
129
+ filteredSuggestions = this.props.suggestions.filter(function (suggestion) {
130
+ var fieldValue = _this.getDisplayValue(suggestion);
131
+ // specialna null polozka (prazdny objekt) - test dame az za test fieldValue na undefined - koli performance
132
+ if (fieldValue === undefined && Object.keys(suggestion).length === 0) {
133
+ return false;
134
+ }
135
+ // bolo:
136
+ //return XUtils.normalizeString(fieldValue).startsWith(queryNormalized);
137
+ return XUtils_1.XUtils.normalizeString(fieldValue).indexOf(queryNormalized_1) !== -1;
138
+ });
139
+ }
140
+ this.setState({ filteredSuggestions: filteredSuggestions });
141
+ };
142
+ XAutoCompleteBase.prototype.onChange = function (e) {
143
+ if (typeof e.value === 'string') {
144
+ this.setState({ inputChanged: true, inputValueState: e.value });
145
+ }
146
+ };
147
+ XAutoCompleteBase.prototype.onSelect = function (e) {
148
+ this.setObjectValue(e.value, XUtils_1.OperationType.None);
149
+ };
150
+ XAutoCompleteBase.prototype.onBlur = function (e) {
151
+ // optimalizacia - testujeme len ak inputChanged === true
152
+ if (this.state.inputChanged) {
153
+ if (e.target.value === '') {
154
+ this.setObjectValue(null, XUtils_1.OperationType.None); // prazdny retazec znamena null hodnotu
155
+ }
156
+ else {
157
+ // skusime ci filteredSuggestions nemaju prave jeden element
158
+ var filteredSuggestions = this.state.filteredSuggestions;
159
+ if (filteredSuggestions && filteredSuggestions.length === 1) {
160
+ this.setObjectValue(filteredSuggestions[0], XUtils_1.OperationType.None);
161
+ }
162
+ else {
163
+ // tu by sme mohli skusit vyratat vysledok pre filteredSuggestions este raz, mozno este vypocet filteredSuggestions nedobehol
164
+ // mohli by sme: zobrazit vsetky povolene hodnoty (v dialogu/v dropdown liste), zobrazit nejaky alert
165
+ //alert("invalid value");
166
+ // radi by sme stopli dalsie event-y (napr. stlacenie buttonu, ktore vyvolalo stratu focus-u), ale nezafungovalo nam to
167
+ //e.preventDefault();
168
+ //e.stopPropagation();
169
+ // nefunguje ani toto
170
+ //console.log('stop propagation');
171
+ //console.log(e);
172
+ //e.nativeEvent.stopImmediatePropagation();
173
+ //e.preventDefault();
174
+ // zobrazime dropdown list aby sme usera upovedomili ze ma vybrat nejaku hodnotu
175
+ // toto neni moc prakticke ak mame vela poloziek v dropdown-e - lepsi by bol asi confirm, ci pridat novu polozku do DB
176
+ // zrusil som, lebo pri vybere z dropdownu kliknutim sa vola tento onBlur (este pred onSelect), zobrazi sa iny dropdown ako vidi uzivatel a vyberie sa z neho ina polozka ako je ta na ktoru klikol user
177
+ //this.autoCompleteRef.current.onDropdownClick();
178
+ // vratime focus do inputu
179
+ // obycajne setnutie focusu nefunguje, treba v setnut focus v samostatnom evente
180
+ // TODO - aj nejaky stop event skusit
181
+ //console.log('onBlur - setujem timeout');
182
+ //setTimeout(() => {this.onBlurInvalidInput();}, 100);
183
+ // najnovsi sposob
184
+ // TODO - problem - ak zapisem nejake znaky a vyselektujem nejaky zaznam tak vznikne cerveny preblik (az nasledny onSelect zrusi state.notValid = true)
185
+ // zial neviem odlisit event sposobeny selektnutim zaznamu a event sposobeny kliknutim niekam vedla
186
+ //console.log(e);
187
+ this.setState({ notValid: true }); // ocervenime input
188
+ this.props.onErrorChange(this.createErrorMessage()); // ohlasime nevalidnost parentovi
189
+ }
190
+ }
191
+ }
192
+ };
193
+ XAutoCompleteBase.prototype.createErrorMessage = function () {
194
+ return "Value \"".concat(this.state.inputValueState, "\" was not found among valid values.");
195
+ };
196
+ /*
197
+ onBlurInvalidInput() {
198
+ // ak uzivatel vyvolal onBlur kliknutim na polozku dropdown list-u, tak sa v priebehu 100 ms (oneskorenie volania onBlurInvalidInput()) zavolal onSelect,
199
+ // zmenil sa inputChanged a netreba nic riesit
200
+ if (this.state.inputChanged) {
201
+ console.log('onBlurInvalidInput - idem otvorit confirm');
202
+ if (window.confirm(`Value "${this.state.inputValueState}" was not found among valid values, create new valid value?`)) {
203
+ // otvorime dialog na insert
204
+ this.formDialogObjectId = undefined;
205
+ // TODO - pridat ako novu prop metodu ktora bude vracat bude mat parameter this.state.inputValueState a vrati object
206
+ // ak bude tato metoda undefined, tak zostane tato povodna funkcionalita
207
+ this.formDialogInitObjectForInsert = {};
208
+ this.formDialogInitObjectForInsert[this.props.field] = this.state.inputValueState;
209
+ this.setState({formDialogOpened: true});
210
+ }
211
+ else {
212
+ // vratime focus do inputu, je tam nevalidna hodnota
213
+ console.log('onBlurInvalidInput - idem vratit focus');
214
+ this.setFocusToInput();
215
+ }
216
+ }
217
+ }
218
+ */
219
+ XAutoCompleteBase.prototype.setFocusToInput = function () {
220
+ this.autoCompleteRef.current.focus();
221
+ };
222
+ XAutoCompleteBase.prototype.setObjectValue = function (object, objectChange) {
223
+ this.setState({ inputChanged: false, notValid: false });
224
+ this.props.onChange(object, objectChange);
225
+ this.props.onErrorChange(undefined); // uz nie sme v nevalidnom stave
226
+ };
227
+ XAutoCompleteBase.prototype.formDialogOnSaveOrCancel = function (object, objectChange) {
228
+ if (object !== null) {
229
+ // ak bol save, treba tento novy object pouzit
230
+ this.setObjectValue(object, objectChange);
231
+ // treba upravit this.state.filteredSuggestions? setli sme novy objekt, panel so suggestions by mal byt zavrety - TODO - overit
232
+ }
233
+ else {
234
+ // bol cancel, vratime focus do inputu ak treba
235
+ if (this.state.inputChanged) {
236
+ this.setFocusToInput();
237
+ }
238
+ }
239
+ this.setState({ formDialogOpened: false });
240
+ };
241
+ XAutoCompleteBase.prototype.formDialogOnHide = function () {
242
+ this.setState({ formDialogOpened: false });
243
+ // ak mame v inpute neplatnu hodnotu, vratime kurzor na input
244
+ if (this.state.inputChanged) {
245
+ this.setFocusToInput();
246
+ }
247
+ };
248
+ // vracia objekt (ak inputChanged === false) alebo string (ak inputChanged === true)
249
+ XAutoCompleteBase.prototype.computeInputValue = function () {
250
+ var inputValue = null;
251
+ if (!this.state.inputChanged) {
252
+ // poznamka: ak object === null tak treba do inputu zapisovat prazdny retazec, ak by sme pouzili null, neprejavila by sa zmena v modeli na null
253
+ var object = this.props.value;
254
+ if (typeof this.props.field === 'string') {
255
+ inputValue = (object !== null) ? object : ""; // TODO - je "" ok?
256
+ }
257
+ else {
258
+ inputValue = (object !== null) ? this.props.field(object) : "";
259
+ }
260
+ }
261
+ else {
262
+ inputValue = this.state.inputValueState;
263
+ }
264
+ return inputValue;
265
+ };
266
+ XAutoCompleteBase.prototype.itemTemplate = function (suggestion, index) {
267
+ // @ts-ignore
268
+ return this.props.field(suggestion);
269
+ };
270
+ XAutoCompleteBase.prototype.render = function () {
271
+ var _this = this;
272
+ var _a;
273
+ var readOnly = (_a = this.props.readOnly) !== null && _a !== void 0 ? _a : false;
274
+ var dropdownButton;
275
+ if (this.props.valueForm) {
276
+ // mame CRUD operacie, potrebujeme SplitButton
277
+ var splitButtonItems = [];
278
+ splitButtonItems.push({
279
+ icon: 'pi pi-plus',
280
+ command: function (e) {
281
+ // otvorime dialog na insert
282
+ _this.formDialogObjectId = undefined;
283
+ _this.formDialogInitObjectForInsert = {};
284
+ // ak mame nevalidnu hodnotu, tak ju predplnime (snaha o user friendly)
285
+ if (_this.state.inputChanged && typeof _this.props.field === 'string') {
286
+ _this.formDialogInitObjectForInsert[_this.props.field] = _this.state.inputValueState;
287
+ }
288
+ _this.setState({ formDialogOpened: true });
289
+ }
290
+ });
291
+ splitButtonItems.push({
292
+ icon: 'pi pi-pencil',
293
+ command: function (e) {
294
+ if (_this.state.inputChanged) {
295
+ alert("Value \"".concat(_this.state.inputValueState, "\" was not found among valid values, please enter some valid value."));
296
+ _this.setFocusToInput();
297
+ }
298
+ else {
299
+ if (_this.props.value === null) {
300
+ alert('Please select some row.');
301
+ }
302
+ else {
303
+ // otvorime dialog na update
304
+ if (_this.props.idField === undefined) {
305
+ throw "XAutoCompleteBase: property valueForm is defined but property idField is also needed for form editation.";
306
+ }
307
+ _this.formDialogObjectId = _this.props.value[_this.props.idField];
308
+ _this.formDialogInitObjectForInsert = undefined;
309
+ _this.setState({ formDialogOpened: true });
310
+ }
311
+ }
312
+ }
313
+ });
314
+ // remove nebudeme podporovat, je technicky problematicky - nemozme vymazat zaznam z DB koli FK constraintu
315
+ // {
316
+ // icon: 'pi pi-times',
317
+ // command: (e: any) => {
318
+ // console.log('remove');
319
+ // }
320
+ // },
321
+ splitButtonItems.push({
322
+ icon: 'pi pi-chevron-down',
323
+ command: function (e) {
324
+ // zobrazi cely suggestions list, zide sa ak chceme vidiet vsetky moznosti
325
+ // neprakticke ak mame vela poloziek v suggestions list
326
+ // krasne zobrazi cely objekt!
327
+ // this.autoCompleteRef.current je element <AutoComplete .../>, ktory vytvarame v render metode
328
+ //console.log(this.autoCompleteRef.current);
329
+ // otvori dropdown (search je metoda popisana v API, volanie sme skopcili zo zdrojakov primereact)
330
+ _this.autoCompleteRef.current.search(e, '', 'dropdown');
331
+ }
332
+ });
333
+ 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 });
334
+ }
335
+ else {
336
+ // mame len 1 operaciu - dame jednoduchy button
337
+ 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 });
338
+ }
339
+ // vypocitame inputValue
340
+ var inputValue = this.computeInputValue();
341
+ // poznamka: asi by sa dalo pouzivat vzdy len itemTemplate (nepouzivat field)
342
+ var fieldOrItemTemplate;
343
+ if (typeof this.props.field === 'string') {
344
+ fieldOrItemTemplate = { field: this.props.field };
345
+ }
346
+ else {
347
+ fieldOrItemTemplate = { itemTemplate: this.itemTemplate };
348
+ }
349
+ var error;
350
+ if (this.state.notValid) {
351
+ // ak je v nevalidnom stave, tak ma tato chybova hlaska prednost pred ostatnymi (ak nahodou su)
352
+ error = this.createErrorMessage();
353
+ }
354
+ else {
355
+ error = this.props.error;
356
+ }
357
+ // Dialog pre konkretny form:
358
+ // <DobrovolnikForm id={this.formDialogObjectId} object={this.formDialogInitObjectForInsert} onSaveOrCancel={this.formDialogOnSaveOrCancel}/>
359
+ // formgroup-inline lepi SplitButton na autocomplete a zarovna jeho vysku
360
+ return (react_1.default.createElement("div", { className: "x-auto-complete-base" },
361
+ 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))),
362
+ dropdownButton,
363
+ this.props.valueForm != undefined && !readOnly ?
364
+ 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, {
365
+ id: this.formDialogObjectId, object: this.formDialogInitObjectForInsert, onSaveOrCancel: this.formDialogOnSaveOrCancel
366
+ }, this.props.valueForm.children))
367
+ : undefined));
368
+ };
369
+ return XAutoCompleteBase;
370
+ }(react_1.Component));
371
+ exports.XAutoCompleteBase = XAutoCompleteBase;