@michalrakus/x-react-web-lib 1.11.0 → 1.11.1

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.
@@ -4,12 +4,14 @@ import { XAssoc } from "../serverApi/XEntityMetadata";
4
4
  import { OperationType } from "./XUtils";
5
5
  import { XError } from "./XErrors";
6
6
  import { XObject } from "./XObject";
7
+ import { DataTableSortMeta } from "primereact/datatable";
7
8
  export interface XAutoCompleteProps extends XFormComponentProps<XObject> {
8
9
  assocField: string;
9
10
  displayField: string;
10
11
  searchBrowse?: JSX.Element;
11
12
  assocForm?: JSX.Element;
12
13
  filter?: XFilterProp;
14
+ sortField?: string | DataTableSortMeta[];
13
15
  suggestions?: any[];
14
16
  size?: number;
15
17
  inputStyle?: React.CSSProperties;
@@ -79,17 +79,18 @@ var XAutoComplete = /** @class */ (function (_super) {
79
79
  this.readAndSetSuggestions();
80
80
  };
81
81
  XAutoComplete.prototype.readAndSetSuggestions = function () {
82
+ var _a;
82
83
  return __awaiter(this, void 0, void 0, function () {
83
84
  var suggestions;
84
- return __generator(this, function (_a) {
85
- switch (_a.label) {
85
+ return __generator(this, function (_b) {
86
+ switch (_b.label) {
86
87
  case 0:
87
88
  if (!(this.props.suggestions === undefined)) return [3 /*break*/, 2];
88
- return [4 /*yield*/, XUtils_1.XUtils.fetchRows(this.xAssoc.entityName, this.getFilterBase(this.props.filter), this.props.displayField)];
89
+ return [4 /*yield*/, XUtils_1.XUtils.fetchRows(this.xAssoc.entityName, this.getFilterBase(this.props.filter), (_a = this.props.sortField) !== null && _a !== void 0 ? _a : this.props.displayField)];
89
90
  case 1:
90
- suggestions = _a.sent();
91
+ suggestions = _b.sent();
91
92
  this.setState({ suggestions: suggestions });
92
- _a.label = 2;
93
+ _b.label = 2;
93
94
  case 2: return [2 /*return*/];
94
95
  }
95
96
  });
@@ -377,7 +377,7 @@ var XAutoCompleteBase = /** @class */ (function (_super) {
377
377
  react_1.default.createElement(autocomplete_1.AutoComplete, __assign({ value: inputValue, suggestions: this.state.filteredSuggestions, completeMethod: this.completeMethod, field: this.props.field, 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))),
378
378
  dropdownButton,
379
379
  this.props.valueForm != undefined && !readOnly ?
380
- 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, {
380
+ react_1.default.createElement(dialog_1.Dialog, { visible: this.state.formDialogOpened, onHide: this.formDialogOnHide, header: this.formDialogObjectId ? 'Modification' : 'New row' }, react_1.default.cloneElement(this.props.valueForm, {
381
381
  id: this.formDialogObjectId, initValues: this.formDialogInitValuesForInsert, onSaveOrCancel: this.formDialogOnSaveOrCancel
382
382
  } /*, this.props.valueForm.children*/))
383
383
  : undefined,
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { XFormBase } from "./XFormBase";
3
3
  import { XField } from "../serverApi/XEntityMetadata";
4
+ import { XTableFieldReadOnlyProp } from "./XFormDataTable2";
4
5
  export declare const XCheckboxDT: (props: {
5
6
  form: XFormBase;
6
7
  xField: XField;
7
8
  field: string;
8
9
  rowData: any;
9
- readOnly?: boolean | undefined;
10
+ readOnly?: XTableFieldReadOnlyProp | undefined;
10
11
  }) => JSX.Element;
@@ -7,16 +7,8 @@ exports.XCheckboxDT = void 0;
7
7
  var react_1 = __importDefault(require("react"));
8
8
  var tristatecheckbox_1 = require("primereact/tristatecheckbox");
9
9
  var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
10
+ var XUtils_1 = require("./XUtils");
10
11
  var XCheckboxDT = function (props) {
11
- // ak mame path, field je vzdy readOnly
12
- var readOnly;
13
- var posDot = props.field.indexOf(".");
14
- if (posDot !== -1) {
15
- readOnly = true;
16
- }
17
- else {
18
- readOnly = props.readOnly !== undefined ? props.readOnly : false;
19
- }
20
12
  var onValueChange = function (field, rowData, newValue) {
21
13
  // pri klikani na TriStateCheckbox prichadza v newValue cyklicky: true -> false -> null
22
14
  // ak mame not null atribut, tak pri null hodnote skocime rovno na true
@@ -41,6 +33,7 @@ var XCheckboxDT = function (props) {
41
33
  // konvertovat null hodnotu na "" (vo funkcii stringAsUI) je dolezite aby sa prejavila zmena na null v modeli (a tiez aby korektne pridal novy riadok)
42
34
  fieldValue = rowDataValue;
43
35
  }
36
+ var readOnly = XUtils_1.XUtils.isReadOnlyTableField(props.field, props.readOnly, props.form.state.object, props.rowData);
44
37
  return (react_1.default.createElement(tristatecheckbox_1.TriStateCheckbox, { id: props.field, value: fieldValue, onChange: function (e) { return onValueChange(props.field, props.rowData, e.value); }, disabled: readOnly }));
45
38
  };
46
39
  exports.XCheckboxDT = XCheckboxDT;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { XFormBase } from "./XFormBase";
3
- import { XDropdownOptionsMap } from "./XFormDataTable2";
3
+ import { XDropdownOptionsMap, XTableFieldReadOnlyProp } from "./XFormDataTable2";
4
4
  import { XCustomFilter } from "../serverApi/FindParam";
5
5
  export declare const XDropdownDT: (props: {
6
6
  form: XFormBase;
@@ -12,5 +12,5 @@ export declare const XDropdownDT: (props: {
12
12
  dropdownOptionsMap: XDropdownOptionsMap;
13
13
  onDropdownOptionsMapChange: (dropdownOptionsMap: XDropdownOptionsMap) => void;
14
14
  rowData: any;
15
- readOnly?: boolean | undefined;
15
+ readOnly?: XTableFieldReadOnlyProp | undefined;
16
16
  }) => JSX.Element;
@@ -103,7 +103,6 @@ var XDropdownDT = function (props) {
103
103
  }
104
104
  });
105
105
  }); };
106
- var readOnly = props.readOnly !== undefined ? props.readOnly : false;
107
106
  var onValueChange = function (assocField, rowData, newValue) {
108
107
  // zmenime hodnotu v modeli (odtial sa hodnota cita)
109
108
  var newValueOrNull;
@@ -118,7 +117,6 @@ var XDropdownDT = function (props) {
118
117
  // kedze "rowData" je sucastou "props.form.state.object", tak nam staci zavolat setState({object: object}), aby sa zmena prejavila
119
118
  props.form.onObjectDataChange();
120
119
  };
121
- // TODO - readOnly implementovat
122
120
  // Dropdown setuje do atributu object.assocField asociovany objekt zo zoznamu objektov ktore ziskame podla asociacie
123
121
  var assocObject = null;
124
122
  if (props.rowData !== null) {
@@ -129,7 +127,8 @@ var XDropdownDT = function (props) {
129
127
  }
130
128
  }
131
129
  var options = props.dropdownOptionsMap[props.assocField] !== undefined ? props.dropdownOptionsMap[props.assocField] : []; // mozno mozme do options prasknut rovno undefined...
130
+ var readOnly = XUtils_1.XUtils.isReadOnlyTableField(undefined, props.readOnly, props.form.state.object, props.rowData);
132
131
  // appendTo={document.body} appenduje overlay panel na element body - eliminuje problem s overflow (pozri poznamku v XDropdownDTFilter)
133
- return (react_1.default.createElement(dropdown_1.Dropdown, { appendTo: document.body, id: props.assocField, optionLabel: props.displayField, value: assocObject, options: options, dataKey: idField, onChange: function (e) { return onValueChange(props.assocField, props.rowData, e.target.value); } }));
132
+ return (react_1.default.createElement(dropdown_1.Dropdown, { appendTo: document.body, id: props.assocField, optionLabel: props.displayField, value: assocObject, options: options, dataKey: idField, onChange: function (e) { return onValueChange(props.assocField, props.rowData, e.target.value); }, readOnly: readOnly, disabled: readOnly }));
134
133
  };
135
134
  exports.XDropdownDT = XDropdownDT;
@@ -1,8 +1,8 @@
1
1
  import { Component } from "react";
2
2
  import { XObject } from "./XObject";
3
3
  import { OperationType } from "./XUtils";
4
- import { FieldOnChange, XFormComponent } from "./XFormComponent";
5
- import { TableFieldOnChange, XFormDataTable2, XRowTechData } from "./XFormDataTable2";
4
+ import { XFieldOnChange, XFormComponent } from "./XFormComponent";
5
+ import { XTableFieldOnChange, XFormDataTable2, XRowTechData } from "./XFormDataTable2";
6
6
  import { XErrorMap, XErrors } from "./XErrors";
7
7
  export type XOnSaveOrCancelProp = (object: XObject | null, objectChange: OperationType) => void;
8
8
  export interface XFormProps {
@@ -35,12 +35,12 @@ export declare abstract class XFormBase extends Component<XFormProps> {
35
35
  getXObject(): XObject;
36
36
  getObject(): any;
37
37
  isAddRow(): any;
38
- onFieldChange(field: string, value: any, error?: string | undefined, onChange?: FieldOnChange, assocObjectChange?: OperationType): void;
39
- onTableFieldChange(rowData: any, field: string, value: any, error?: string | undefined, onChange?: TableFieldOnChange, assocObjectChange?: OperationType): void;
38
+ onFieldChange(field: string, value: any, error?: string | undefined, onChange?: XFieldOnChange, assocObjectChange?: OperationType): void;
39
+ onTableFieldChange(rowData: any, field: string, value: any, error?: string | undefined, onChange?: XTableFieldOnChange, assocObjectChange?: OperationType): void;
40
40
  /**
41
41
  * @deprecated - mal by sa pouzivat onTableFieldChange
42
42
  */
43
- onObjectDataChange(row?: any, onChange?: TableFieldOnChange): void;
43
+ onObjectDataChange(row?: any, onChange?: XTableFieldOnChange): void;
44
44
  setStateXForm(): void;
45
45
  onTableAddRow(assocField: string, newRow: any, dataKey?: string, selectedRow?: {}): void;
46
46
  static getNextRowId(rowList: any[], dataKey: string): number;
@@ -4,7 +4,7 @@ import { XError } from "./XErrors";
4
4
  import { OperationType } from "./XUtils";
5
5
  import { XFieldChangeEvent } from "./XFieldChangeEvent";
6
6
  import { XCustomFilter } from "../serverApi/FindParam";
7
- export type FieldOnChange = (e: XFieldChangeEvent<any>) => void;
7
+ export type XFieldOnChange = (e: XFieldChangeEvent<any>) => void;
8
8
  export type XReadOnlyProp = boolean | ((object: any) => boolean);
9
9
  export type XFilterProp = XCustomFilter | ((object: any) => XCustomFilter | undefined);
10
10
  export interface XFormComponentProps<T> {
@@ -13,13 +13,13 @@ export interface XFormComponentProps<T> {
13
13
  readOnly?: XReadOnlyProp;
14
14
  labelStyle?: React.CSSProperties;
15
15
  inline?: boolean;
16
- onChange?: FieldOnChange;
16
+ onChange?: XFieldOnChange;
17
17
  }
18
18
  export declare abstract class XFormComponent<T, P extends XFormComponentProps<T>> extends Component<P> {
19
19
  protected constructor(props: P);
20
20
  abstract getField(): string;
21
21
  getValueFromObject(): any;
22
- onValueChangeBase(value: any, onChange?: FieldOnChange, assocObjectChange?: OperationType): void;
22
+ onValueChangeBase(value: any, onChange?: XFieldOnChange, assocObjectChange?: OperationType): void;
23
23
  abstract isNotNull(): boolean;
24
24
  isReadOnly(): boolean;
25
25
  getLabel(): string;
@@ -3,19 +3,19 @@ import { Component } from "react";
3
3
  import { OperationType } from "./XUtils";
4
4
  import { XError } from "./XErrors";
5
5
  import { XCustomFilter } from "../serverApi/FindParam";
6
- import { XTableFieldFilterProp, TableFieldOnChange } from "./XFormDataTable2";
6
+ import { XTableFieldFilterProp, XTableFieldOnChange, XTableFieldReadOnlyProp } from "./XFormDataTable2";
7
7
  export interface XFormComponentDTProps {
8
8
  form: XFormBase;
9
9
  entity: string;
10
10
  rowData: any;
11
- readOnly?: boolean;
12
- onChange?: TableFieldOnChange;
11
+ readOnly?: XTableFieldReadOnlyProp;
12
+ onChange?: XTableFieldOnChange;
13
13
  }
14
14
  export declare abstract class XFormComponentDT<P extends XFormComponentDTProps> extends Component<P> {
15
15
  protected constructor(props: P);
16
16
  abstract getField(): string;
17
17
  getValueFromRowData(): any;
18
- onValueChangeBase(value: any, onChange?: TableFieldOnChange, assocObjectChange?: OperationType): void;
18
+ onValueChangeBase(value: any, onChange?: XTableFieldOnChange, assocObjectChange?: OperationType): void;
19
19
  abstract isNotNull(): boolean;
20
20
  isReadOnly(): boolean;
21
21
  validate(): {
@@ -60,17 +60,16 @@ var XFormComponentDT = /** @class */ (function (_super) {
60
60
  else if (typeof this.props.readOnly === 'boolean') {
61
61
  readOnly = this.props.readOnly;
62
62
  }
63
- // else if (typeof this.props.readOnly === 'function') {
64
- // // TODO - tazko povedat ci niekedy bude object === null (asi ano vid metodu getFilterBase)
65
- // TODO - use also this.props.rowData
66
- // const object: XObject = this.props.form.state.object;
67
- // if (object) {
68
- // readOnly = this.props.readOnly(this.props.form.getXObject());
69
- // }
70
- // else {
71
- // readOnly = true;
72
- // }
73
- // }
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(), this.props.rowData);
68
+ }
69
+ else {
70
+ readOnly = true;
71
+ }
72
+ }
74
73
  else {
75
74
  // readOnly is undefined
76
75
  readOnly = false;
@@ -67,6 +67,7 @@ export declare class XFormDataTable2 extends Component<XFormDataTableProps> {
67
67
  constructor(props: XFormDataTableProps);
68
68
  getPathForColumn(columnProps: XFormColumnProps): string;
69
69
  static getHeader(columnProps: XFormColumnProps, xEntity: XEntity, field: string, xField: XField): string;
70
+ static isReadOnlyHeader(path: string | undefined, readOnly: XTableFieldReadOnlyProp | undefined): boolean;
70
71
  getEntity(): string;
71
72
  createInitFilters(): DataTableFilterMeta;
72
73
  getFilterMatchMode(xField: XField): FilterMatchMode;
@@ -85,16 +86,17 @@ export declare class XFormDataTable2 extends Component<XFormDataTableProps> {
85
86
  isReadOnly(): boolean;
86
87
  render(): JSX.Element;
87
88
  }
88
- export type TableFieldOnChange = (e: XTableFieldChangeEvent<any, any>) => void;
89
+ export type XTableFieldOnChange = (e: XTableFieldChangeEvent<any, any>) => void;
90
+ export type XTableFieldReadOnlyProp = boolean | ((object: any, tableRow: any) => boolean);
89
91
  export type XTableFieldFilterProp = XCustomFilter | ((object: any, rowData: any) => XCustomFilter | undefined);
90
92
  export interface XFormColumnProps {
91
93
  type: "inputSimple" | "dropdown" | "autoComplete" | "searchButton";
92
94
  header?: any;
93
- readOnly?: boolean;
95
+ readOnly?: XTableFieldReadOnlyProp;
94
96
  dropdownInFilter?: boolean;
95
97
  showFilterMenu?: boolean;
96
98
  width?: string;
97
- onChange?: TableFieldOnChange;
99
+ onChange?: XTableFieldOnChange;
98
100
  }
99
101
  export interface XFormInputSimpleColumnProps extends XFormColumnProps {
100
102
  field: string;
@@ -79,6 +79,7 @@ var tristatecheckbox_1 = require("primereact/tristatecheckbox");
79
79
  var api_1 = require("primereact/api");
80
80
  var XAutoCompleteDT_1 = require("./XAutoCompleteDT");
81
81
  var XButtonIconNarrow_1 = require("./XButtonIconNarrow");
82
+ var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
82
83
  var XLocale_1 = require("./XLocale");
83
84
  var XInputIntervalDT_1 = require("./XInputIntervalDT");
84
85
  var XFormDataTable2 = /** @class */ (function (_super) {
@@ -151,7 +152,7 @@ var XFormDataTable2 = /** @class */ (function (_super) {
151
152
  }
152
153
  };
153
154
  XFormDataTable2.getHeader = function (columnProps, xEntity, field, xField) {
154
- var _a, _b, _c, _d;
155
+ var _a;
155
156
  // poznamky - parametre field a xField by sme mohli vyratavat na zaklade columnProps ale kedze ich uz mame, setrime performance a neduplikujeme vypocet
156
157
  // nie je to tu uplne idealne nakodene, ale je to pomerne prehladne
157
158
  var isNullable = true;
@@ -159,35 +160,58 @@ var XFormDataTable2 = /** @class */ (function (_super) {
159
160
  if (columnProps.type === "inputSimple") {
160
161
  var columnPropsInputSimple = columnProps;
161
162
  isNullable = xField.isNullable;
162
- readOnly = XUtils_1.XUtils.isReadOnly(columnPropsInputSimple.field, columnProps.readOnly);
163
+ readOnly = XFormDataTable2.isReadOnlyHeader(columnPropsInputSimple.field, columnProps.readOnly);
163
164
  }
164
165
  else if (columnProps.type === "dropdown") {
165
166
  var columnPropsDropdown = columnProps;
166
167
  var xAssoc = XUtilsMetadata_1.XUtilsMetadata.getXAssocToOne(xEntity, columnPropsDropdown.assocField);
167
168
  isNullable = xAssoc.isNullable;
168
- readOnly = (_a = columnProps.readOnly) !== null && _a !== void 0 ? _a : false;
169
+ readOnly = XFormDataTable2.isReadOnlyHeader(undefined, columnProps.readOnly);
169
170
  }
170
171
  else if (columnProps.type === "autoComplete") {
171
172
  var columnPropsAutoComplete = columnProps;
172
173
  var xAssoc = XUtilsMetadata_1.XUtilsMetadata.getXAssocToOne(xEntity, columnPropsAutoComplete.assocField);
173
174
  isNullable = xAssoc.isNullable;
174
- readOnly = (_b = columnProps.readOnly) !== null && _b !== void 0 ? _b : false;
175
+ readOnly = XFormDataTable2.isReadOnlyHeader(undefined, columnProps.readOnly);
175
176
  }
176
177
  else if (columnProps.type === "searchButton") {
177
178
  var columnPropsSearchButton = columnProps;
178
179
  var xAssoc = XUtilsMetadata_1.XUtilsMetadata.getXAssocToOne(xEntity, columnPropsSearchButton.assocField);
179
180
  isNullable = xAssoc.isNullable;
180
- readOnly = (_c = columnProps.readOnly) !== null && _c !== void 0 ? _c : false;
181
+ readOnly = XFormDataTable2.isReadOnlyHeader(undefined, columnProps.readOnly);
181
182
  }
182
183
  else {
183
184
  throw "Unknown prop type = " + columnProps.type;
184
185
  }
185
- var header = (_d = columnProps.header) !== null && _d !== void 0 ? _d : field;
186
+ var header = (_a = columnProps.header) !== null && _a !== void 0 ? _a : field;
186
187
  if (!isNullable && !readOnly) {
187
188
  header = XUtils_1.XUtils.markNotNull(header);
188
189
  }
189
190
  return header;
190
191
  };
192
+ // helper
193
+ XFormDataTable2.isReadOnlyHeader = function (path, readOnly) {
194
+ var isReadOnly;
195
+ if (path && !XUtilsCommon_1.XUtilsCommon.isSingleField(path)) {
196
+ // if the length of field is 2 or more, then readOnly
197
+ isReadOnly = true;
198
+ }
199
+ // formReadOnlyBase is called on the level XFormDataTable2
200
+ // else if (this.props.form.formReadOnlyBase("xxx")) {
201
+ // isReadOnly = true;
202
+ // }
203
+ else if (typeof readOnly === 'boolean') {
204
+ isReadOnly = readOnly;
205
+ }
206
+ else if (typeof readOnly === 'function') {
207
+ isReadOnly = false;
208
+ }
209
+ else {
210
+ // readOnly is undefined
211
+ isReadOnly = false;
212
+ }
213
+ return isReadOnly;
214
+ };
191
215
  XFormDataTable2.prototype.getEntity = function () {
192
216
  if (this.entity === undefined) {
193
217
  throw "Unexpected error: this.entity is undefined";
@@ -324,12 +348,11 @@ var XFormDataTable2 = /** @class */ (function (_super) {
324
348
  */
325
349
  // body={(rowData: any) => bodyTemplate(childColumn.props.field, rowData)}
326
350
  XFormDataTable2.prototype.bodyTemplate = function (columnProps, tableReadOnly, rowData, xEntity) {
327
- var _a, _b;
328
351
  var body;
352
+ // tableReadOnly has higher prio then property readOnly
353
+ var readOnly = tableReadOnly ? true : columnProps.readOnly;
329
354
  if (columnProps.type === "inputSimple") {
330
355
  var columnPropsInputSimple = columnProps;
331
- // tableReadOnly has higher prio then property readOnly
332
- var readOnly = tableReadOnly || ((_a = columnPropsInputSimple.readOnly) !== null && _a !== void 0 ? _a : false);
333
356
  var xField = XUtilsMetadata_1.XUtilsMetadata.getXFieldByPath(xEntity, columnPropsInputSimple.field);
334
357
  if (xField.type === "decimal" || xField.type === "number") {
335
358
  body = react_1.default.createElement(XInputDecimalDT_1.XInputDecimalDT, { form: this.props.form, entity: this.getEntity(), field: columnPropsInputSimple.field, rowData: rowData, readOnly: readOnly, onChange: columnPropsInputSimple.onChange });
@@ -350,12 +373,10 @@ var XFormDataTable2 = /** @class */ (function (_super) {
350
373
  }
351
374
  else if (columnProps.type === "dropdown") {
352
375
  var columnPropsDropdown = columnProps;
353
- body = react_1.default.createElement(XDropdownDT_1.XDropdownDT, { form: this.props.form, entity: this.getEntity(), assocField: columnPropsDropdown.assocField, displayField: columnPropsDropdown.displayField, sortField: columnPropsDropdown.sortField, filter: columnPropsDropdown.filter, dropdownOptionsMap: this.state.dropdownOptionsMap, onDropdownOptionsMapChange: this.onDropdownOptionsMapChange, rowData: rowData });
376
+ body = react_1.default.createElement(XDropdownDT_1.XDropdownDT, { form: this.props.form, entity: this.getEntity(), assocField: columnPropsDropdown.assocField, displayField: columnPropsDropdown.displayField, sortField: columnPropsDropdown.sortField, filter: columnPropsDropdown.filter, dropdownOptionsMap: this.state.dropdownOptionsMap, onDropdownOptionsMapChange: this.onDropdownOptionsMapChange, rowData: rowData, readOnly: readOnly });
354
377
  }
355
378
  else if (columnProps.type === "autoComplete") {
356
379
  var columnPropsAutoComplete = columnProps;
357
- // tableReadOnly has higher prio then property readOnly
358
- var readOnly = tableReadOnly || ((_b = columnPropsAutoComplete.readOnly) !== null && _b !== void 0 ? _b : false);
359
380
  body = react_1.default.createElement(XAutoCompleteDT_1.XAutoCompleteDT, { form: this.props.form, entity: this.getEntity(), assocField: columnPropsAutoComplete.assocField, displayField: columnPropsAutoComplete.displayField, searchBrowse: columnPropsAutoComplete.searchBrowse, assocForm: columnPropsAutoComplete.assocForm, filter: columnPropsAutoComplete.filter, suggestions: columnPropsAutoComplete.suggestions, rowData: rowData, readOnly: readOnly });
360
381
  }
361
382
  else if (columnProps.type === "searchButton") {
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { XFormBase } from "./XFormBase";
3
3
  import { XField } from "../serverApi/XEntityMetadata";
4
+ import { XTableFieldReadOnlyProp } from "./XFormDataTable2";
4
5
  export declare const XInputDateDT: (props: {
5
6
  form: XFormBase;
6
7
  xField: XField;
7
8
  field: string;
8
9
  rowData: any;
9
- readOnly?: boolean | undefined;
10
+ readOnly?: XTableFieldReadOnlyProp | undefined;
10
11
  }) => JSX.Element;
@@ -8,18 +8,10 @@ var XUtilsConversions_1 = require("./XUtilsConversions");
8
8
  var calendar_1 = require("primereact/calendar");
9
9
  var react_1 = __importDefault(require("react"));
10
10
  var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
11
+ var XUtils_1 = require("./XUtils");
11
12
  var XInputDateDT = function (props) {
12
13
  var showTime = (props.xField.type === 'datetime');
13
14
  var cssClassName = showTime ? 'x-input-datetime' : 'x-input-date';
14
- // ak mame path, field je vzdy readOnly
15
- var readOnly;
16
- var posDot = props.field.indexOf(".");
17
- if (posDot !== -1) {
18
- readOnly = true;
19
- }
20
- else {
21
- readOnly = props.readOnly !== undefined ? props.readOnly : false;
22
- }
23
15
  var onValueChange = function (field, rowData, newValue) {
24
16
  // z Calendar prichadza e.value - typ Date alebo null
25
17
  // zmenime hodnotu v modeli (odtial sa hodnota cita)
@@ -47,6 +39,7 @@ var XInputDateDT = function (props) {
47
39
  }
48
40
  // fieldValue zostalo undefined (konvertujeme null -> undefined) - Calendar pozaduje undefined, nechce null
49
41
  }
42
+ var readOnly = XUtils_1.XUtils.isReadOnlyTableField(props.field, props.readOnly, props.form.state.object, props.rowData);
50
43
  // TODO - nefunguje dobre pridavanie noveho riadku - su tam stare neupdatnute hodnoty - este to asi neopravili https://github.com/primefaces/primereact/issues/1277
51
44
  // test mame na TestovaciForm
52
45
  // appendTo={document.body} appenduje overlay panel na element body - eliminuje problem s overflow (pozri poznamku v XDropdownDTFilter)
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { XFormBase } from "./XFormBase";
3
+ import { XTableFieldReadOnlyProp } from "./XFormDataTable2";
3
4
  export declare const XInputTextDT: (props: {
4
5
  form: XFormBase;
5
6
  entity: string;
6
7
  field: string;
7
8
  rowData: any;
8
- readOnly?: boolean | undefined;
9
+ readOnly?: XTableFieldReadOnlyProp | undefined;
9
10
  }) => JSX.Element;
@@ -9,17 +9,9 @@ var inputtext_1 = require("primereact/inputtext");
9
9
  var XUtilsConversions_1 = require("./XUtilsConversions");
10
10
  var XUtilsMetadata_1 = require("./XUtilsMetadata");
11
11
  var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
12
+ var XUtils_1 = require("./XUtils");
12
13
  var XInputTextDT = function (props) {
13
14
  var xField = XUtilsMetadata_1.XUtilsMetadata.getXFieldByPathStr(props.entity, props.field);
14
- // ak mame path, field je vzdy readOnly
15
- var readOnly;
16
- var posDot = props.field.indexOf(".");
17
- if (posDot !== -1) {
18
- readOnly = true;
19
- }
20
- else {
21
- readOnly = props.readOnly !== undefined ? props.readOnly : false;
22
- }
23
15
  var onValueChange = function (field, rowData, newValue) {
24
16
  // zmenime hodnotu v modeli (odtial sa hodnota cita)
25
17
  rowData[field] = (0, XUtilsConversions_1.stringFromUI)(newValue);
@@ -37,6 +29,7 @@ var XInputTextDT = function (props) {
37
29
  // konvertovat null hodnotu na "" (vo funkcii stringAsUI) je dolezite aby sa prejavila zmena na null v modeli (a tiez aby korektne pridal novy riadok)
38
30
  fieldValue = (0, XUtilsConversions_1.stringAsUI)(rowDataValue);
39
31
  }
32
+ var readOnly = XUtils_1.XUtils.isReadOnlyTableField(props.field, props.readOnly, props.form.state.object, props.rowData);
40
33
  return (react_1.default.createElement(inputtext_1.InputText, { id: props.field, value: fieldValue, onChange: function (e) { return onValueChange(props.field, props.rowData, e.target.value); }, readOnly: readOnly, maxLength: xField.length, className: "x-input-to-resize" }));
41
34
  };
42
35
  exports.XInputTextDT = XInputTextDT;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { XFormBase } from "./XFormBase";
3
+ import { XTableFieldReadOnlyProp } from "./XFormDataTable2";
3
4
  export declare const XSearchButtonDT: (props: {
4
5
  form: XFormBase;
5
6
  entity: string;
@@ -8,5 +9,5 @@ export declare const XSearchButtonDT: (props: {
8
9
  searchBrowse: JSX.Element;
9
10
  assocForm?: JSX.Element | undefined;
10
11
  rowData: any;
11
- readOnly?: boolean | undefined;
12
+ readOnly?: XTableFieldReadOnlyProp | undefined;
12
13
  }) => JSX.Element;
@@ -102,7 +102,6 @@ var XSearchButtonDT = function (props) {
102
102
  }
103
103
  return inputValue;
104
104
  };
105
- var readOnly = props.readOnly !== undefined ? props.readOnly : false;
106
105
  var onInputValueChange = function (e) {
107
106
  setInputChanged(true);
108
107
  setInputValueState(e.target.value);
@@ -177,6 +176,7 @@ var XSearchButtonDT = function (props) {
177
176
  };
178
177
  // vypocitame inputValue
179
178
  var inputValue = computeInputValue();
179
+ var readOnly = XUtils_1.XUtils.isReadOnlyTableField(undefined, props.readOnly, props.form.state.object, props.rowData);
180
180
  return (react_1.default.createElement("div", null,
181
181
  react_1.default.createElement("div", { className: "x-search-button-base" },
182
182
  react_1.default.createElement(inputtext_1.InputText, { id: props.assocField, value: inputValue, onChange: onInputValueChange, onBlur: onInputBlur, readOnly: readOnly, ref: inputTextRef }),
@@ -4,6 +4,9 @@ import React from "react";
4
4
  import { XEnvVar } from "./XEnvVars";
5
5
  import { XError, XErrorMap } from "./XErrors";
6
6
  import { XCustomFilter, XCustomFilterItem } from "../serverApi/FindParam";
7
+ import { DataTableSortMeta } from "primereact/datatable";
8
+ import { XObject } from "./XObject";
9
+ import { XTableFieldReadOnlyProp } from "./XFormDataTable2";
7
10
  export declare enum OperationType {
8
11
  None = 0,
9
12
  Insert = 1,
@@ -44,7 +47,7 @@ export declare class XUtils {
44
47
  static registerAppForm(elem: any, entity: string, formId?: string): void;
45
48
  static getAppForm(entity: string, formId?: string): any;
46
49
  static fetchMany(path: string, value: any, usePublicToken?: boolean | XToken): Promise<any[]>;
47
- static fetchRows(entity: string, customFilter?: XCustomFilter | undefined, sortField?: string, fields?: string[]): Promise<any[]>;
50
+ static fetchRows(entity: string, customFilter?: XCustomFilter | undefined, sortField?: string | DataTableSortMeta[] | undefined, fields?: string[]): Promise<any[]>;
48
51
  static fetchOne(path: string, value: any, usePublicToken?: boolean | XToken): Promise<any>;
49
52
  static fetchString(path: string, value: any): Promise<string>;
50
53
  static fetch(path: string, value: any, usePublicToken?: boolean | XToken): Promise<any>;
@@ -86,6 +89,7 @@ export declare class XUtils {
86
89
  */
87
90
  static arrayIntersect<T>(array1: T[], array2: T[], idField: string): T[];
88
91
  static isReadOnly(path: string, readOnlyInit?: boolean): boolean;
92
+ static isReadOnlyTableField(path: string | undefined, readOnly: XTableFieldReadOnlyProp | undefined, object: XObject | null, tableRow: any): boolean;
89
93
  static markNotNull(label: string): string;
90
94
  static showErrorMessage(message: string, e: unknown): void;
91
95
  static createErrorProps(error: string | undefined): {};
@@ -99,4 +103,5 @@ export declare class XUtils {
99
103
  static normalizeString(value: string): string;
100
104
  static createCustomFilterItems(customFilter: XCustomFilter | undefined): XCustomFilterItem[] | undefined;
101
105
  static filterAnd(...filters: (XCustomFilter | undefined)[]): XCustomFilterItem[] | undefined;
106
+ static isTableRowInserted(tableRow: any): boolean;
102
107
  }
@@ -265,11 +265,20 @@ var XUtils = /** @class */ (function () {
265
265
  // pomocna metodka pouzivajuca lazyDataTable service
266
266
  XUtils.fetchRows = function (entity, customFilter, sortField, fields) {
267
267
  return __awaiter(this, void 0, void 0, function () {
268
- var findParam, rowList;
268
+ var multiSortMeta, findParam, rowList;
269
269
  return __generator(this, function (_a) {
270
270
  switch (_a.label) {
271
271
  case 0:
272
- findParam = { resultType: FindParam_1.ResultType.AllRows, entity: entity, customFilterItems: XUtils.createCustomFilterItems(customFilter), multiSortMeta: sortField ? [{ field: sortField, order: 1 }] : undefined, fields: fields };
272
+ multiSortMeta = undefined;
273
+ if (sortField) {
274
+ if (Array.isArray(sortField)) {
275
+ multiSortMeta = sortField;
276
+ }
277
+ else {
278
+ multiSortMeta = [{ field: sortField, order: 1 }];
279
+ }
280
+ }
281
+ findParam = { resultType: FindParam_1.ResultType.AllRows, entity: entity, customFilterItems: XUtils.createCustomFilterItems(customFilter), multiSortMeta: multiSortMeta, fields: fields };
273
282
  return [4 /*yield*/, XUtils.fetchOne('lazyDataTableFindRows', findParam)];
274
283
  case 1:
275
284
  rowList = (_a.sent()).rowList;
@@ -546,6 +555,35 @@ var XUtils = /** @class */ (function () {
546
555
  }
547
556
  return readOnly;
548
557
  };
558
+ // docasna funkcia, kym sa vsade nebude pouzivat XFormComponentDT a jej isReadOnly()
559
+ XUtils.isReadOnlyTableField = function (path, readOnly, object, tableRow) {
560
+ var isReadOnly;
561
+ if (path && !XUtilsCommon_1.XUtilsCommon.isSingleField(path)) {
562
+ // if the length of field is 2 or more, then readOnly
563
+ isReadOnly = true;
564
+ }
565
+ // formReadOnlyBase is called on the level XFormDataTable2
566
+ // else if (this.props.form.formReadOnlyBase("xxx")) {
567
+ // isReadOnly = true;
568
+ // }
569
+ else if (typeof readOnly === 'boolean') {
570
+ isReadOnly = readOnly;
571
+ }
572
+ else if (typeof readOnly === 'function') {
573
+ // TODO - tazko povedat ci niekedy bude object === null (asi ano vid metodu getFilterBase)
574
+ if (object) {
575
+ isReadOnly = readOnly(object, tableRow);
576
+ }
577
+ else {
578
+ isReadOnly = true;
579
+ }
580
+ }
581
+ else {
582
+ // readOnly is undefined
583
+ isReadOnly = false;
584
+ }
585
+ return isReadOnly;
586
+ };
549
587
  XUtils.markNotNull = function (label) {
550
588
  return label + ' *';
551
589
  };
@@ -685,6 +723,11 @@ var XUtils = /** @class */ (function () {
685
723
  }
686
724
  return customFilterItemsResult;
687
725
  };
726
+ // pomocna metodka
727
+ XUtils.isTableRowInserted = function (tableRow) {
728
+ var _a;
729
+ return (_a = tableRow.__x_generatedRowId) !== null && _a !== void 0 ? _a : false; // specialny priznak, ze sme vygenerovali id-cko
730
+ };
688
731
  XUtils.dropdownEmptyOptionValue = " ";
689
732
  XUtils.xBackendUrl = undefined;
690
733
  // nacachovany XToken - na rozlicnych miestach potrebujeme vediet uzivatela
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.11.0",
3
+ "version": "1.11.1",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",