-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathbaseEditorClass.ts
More file actions
102 lines (89 loc) · 3.26 KB
/
Copy pathbaseEditorClass.ts
File metadata and controls
102 lines (89 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { BindingEventService } from '@slickgrid-universal/binding';
import { SlickEventData, type SlickGrid } from '../core/index.js';
import type { Column, ColumnEditor, CompositeEditorOption, EditorArguments, EditorValidator, GridOption } from './../interfaces/index.js';
/*
* An example of a 'detached' editor.
* KeyDown events are also handled to provide handling for Tab, Shift-Tab, Esc and Ctrl-Enter.
*/
export class BaseEditorClass {
protected _bindEventService: BindingEventService;
/** is the Editor disabled? */
disabled = false;
/** SlickGrid Grid object */
protected grid: SlickGrid;
/** Grid options */
protected gridOptions: GridOption;
constructor(protected readonly args: EditorArguments) {
this.grid = args.grid;
this.gridOptions = (this.grid.getOptions() || {}) as GridOption;
this._bindEventService = new BindingEventService();
}
/** Get Column Definition object */
get columnDef(): Column {
return this.args.column;
}
/** Get Column Editor object */
get columnEditor(): ColumnEditor {
return this.columnDef?.editor || ({} as ColumnEditor);
}
/** Getter for the item data context object */
get dataContext(): any {
return this.args.item;
}
get hasAutoCommitEdit(): boolean {
return this.gridOptions.autoCommitEdit ?? false;
}
/** Get the Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return this.columnEditor?.validator ?? this.columnDef?.validator;
}
// --
// protected functions
// ------------------
/** when it's a Composite Editor, we'll check if the Editor is editable (by checking onBeforeEditCell) and if not Editable we'll disable the Editor */
protected checkInputUsabilityState(): boolean {
const activeCell = this.grid.getActiveCell();
const isCellEditable = this.grid.onBeforeEditCell
.notify({
...activeCell,
item: this.dataContext,
column: this.args.column,
grid: this.grid,
target: 'composite',
compositeEditorOptions: this.args.compositeEditorOptions,
})
.getReturnValue();
return isCellEditable;
}
protected handleChangeOnCompositeEditor(
event: Event | null,
compositeEditorOptions: CompositeEditorOption,
triggeredBy: 'user' | 'system' = 'user',
isCalledByClearValue = false
): void {
const activeCell = this.grid.getActiveCell();
const column = this.args.column;
const columnId = this.columnDef?.id ?? '';
const item = this.dataContext;
const grid = this.grid;
const isExcludeDisabledFieldFormValues = this.gridOptions?.compositeEditorOptions?.excludeDisabledFieldFormValues ?? false;
if (
isCalledByClearValue ||
(this.disabled && isExcludeDisabledFieldFormValues && compositeEditorOptions.formValues.hasOwnProperty(columnId))
) {
delete compositeEditorOptions.formValues[columnId]; // when the input is disabled we won't include it in the form result object
}
grid.onCompositeEditorChange.notify(
{
...activeCell,
item,
grid,
column,
formValues: compositeEditorOptions.formValues,
editors: compositeEditorOptions.editors,
triggeredBy,
},
new SlickEventData(event)
);
}
}