neo.mjs 4.1.0 → 4.2.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/buildScripts/addConfig.mjs +398 -0
- package/buildScripts/createApp.mjs +3 -3
- package/buildScripts/createClass.mjs +7 -7
- package/examples/grid/covid/GridContainer.mjs +113 -0
- package/examples/grid/covid/GridContainerController.mjs +62 -0
- package/examples/grid/covid/MainContainer.mjs +36 -0
- package/examples/grid/covid/Model.mjs +65 -0
- package/examples/grid/covid/Store.mjs +35 -0
- package/examples/grid/covid/Util.mjs +165 -0
- package/examples/grid/covid/app.mjs +6 -0
- package/examples/grid/covid/index.html +11 -0
- package/examples/grid/covid/neo-config.json +8 -0
- package/package.json +5 -4
- package/resources/scss/src/examples/grid/covid/GridContainer.scss +21 -0
- package/resources/scss/src/grid/Container.scss +6 -34
- package/resources/scss/src/grid/View.scss +73 -1
- package/resources/scss/src/grid/header/Button.scss +67 -7
- package/resources/scss/src/grid/header/Toolbar.scss +6 -2
- package/resources/scss/src/table/View.scss +2 -2
- package/resources/scss/theme-dark/grid/Container.scss +17 -0
- package/resources/scss/theme-dark/grid/View.scss +29 -0
- package/resources/scss/theme-dark/grid/_all.scss +3 -0
- package/resources/scss/theme-dark/grid/header/Button.scss +15 -0
- package/resources/scss/theme-dark/grid/header/Toolbar.scss +0 -0
- package/resources/scss/theme-dark/grid/header/_all.scss +2 -0
- package/resources/scss/theme-light/grid/Container.scss +17 -0
- package/resources/scss/theme-light/grid/View.scss +29 -0
- package/resources/scss/theme-light/grid/_all.scss +3 -0
- package/resources/scss/theme-light/grid/header/Button.scss +15 -0
- package/resources/scss/theme-light/grid/header/Toolbar.scss +0 -0
- package/resources/scss/theme-light/grid/header/_all.scss +2 -0
- package/src/grid/Container.mjs +252 -83
- package/src/grid/View.mjs +206 -11
- package/src/grid/header/Button.mjs +127 -2
- package/src/grid/header/Toolbar.mjs +42 -54
- package/src/selection/grid/CellColumnModel.mjs +122 -0
- package/src/selection/grid/CellColumnRowModel.mjs +122 -0
- package/src/selection/grid/CellModel.mjs +184 -0
- package/src/selection/grid/CellRowModel.mjs +164 -0
- package/src/selection/grid/ColumnModel.mjs +185 -0
- package/src/selection/grid/RowModel.mjs +188 -0
- package/src/selection/table/RowModel.mjs +26 -32
- package/src/table/Container.mjs +9 -13
- package/src/table/header/Toolbar.mjs +1 -1
@@ -0,0 +1,122 @@
|
|
1
|
+
import CellRowModel from './CellRowModel.mjs';
|
2
|
+
import ColumnModel from './ColumnModel.mjs';
|
3
|
+
import VDomUtil from '../../util/VDom.mjs';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @class Neo.selection.grid.CellColumnRowModel
|
7
|
+
* @extends Neo.selection.grid.CellRowModel
|
8
|
+
*/
|
9
|
+
class CellColumnRowModel extends CellRowModel {
|
10
|
+
static getConfig() {return {
|
11
|
+
/**
|
12
|
+
* @member {String} className='Neo.selection.grid.CellColumnRowModel'
|
13
|
+
* @protected
|
14
|
+
*/
|
15
|
+
className: 'Neo.selection.grid.CellColumnRowModel',
|
16
|
+
/**
|
17
|
+
* @member {String} ntype='selection-grid-cellcolumnrowmodel'
|
18
|
+
* @protected
|
19
|
+
*/
|
20
|
+
ntype: 'selection-grid-cellcolumnrowmodel',
|
21
|
+
/**
|
22
|
+
* @member {String} cls='neo-selection-cellcolumnrowmodel'
|
23
|
+
* @protected
|
24
|
+
*/
|
25
|
+
cls: 'neo-selection-cellcolumnrowmodel',
|
26
|
+
/**
|
27
|
+
* @member {String} selectedColumnCellCls='selected-column-cell'
|
28
|
+
* @protected
|
29
|
+
*/
|
30
|
+
selectedColumnCellCls: 'selected-column-cell',
|
31
|
+
/**
|
32
|
+
* @member {Array|null} selectedColumnCellIds=null
|
33
|
+
* @protected
|
34
|
+
*/
|
35
|
+
selectedColumnCellIds: null
|
36
|
+
}}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @param {Object} config
|
40
|
+
*/
|
41
|
+
construct(config) {
|
42
|
+
super.construct(config);
|
43
|
+
|
44
|
+
this.selectedColumnCellIds = [];
|
45
|
+
}
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @param {Boolean} [silent] true to prevent a vdom update
|
49
|
+
*/
|
50
|
+
deselectAllCells(silent) {
|
51
|
+
let me = this,
|
52
|
+
cellIds = [...me.selectedColumnCellIds],
|
53
|
+
view = me.view,
|
54
|
+
vdom = view.vdom;
|
55
|
+
|
56
|
+
cellIds.forEach(cellId => {
|
57
|
+
me.deselect(cellId, true, me.selectedColumnCellIds, me.selectedColumnCellCls);
|
58
|
+
});
|
59
|
+
|
60
|
+
if (!silent) {
|
61
|
+
view.vdom = vdom;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* @param {Object} data
|
67
|
+
*/
|
68
|
+
onCellClick(data) {
|
69
|
+
let me = this,
|
70
|
+
id = ColumnModel.getCellId(data.path),
|
71
|
+
columnNodeIds, index, tbodyNode;
|
72
|
+
|
73
|
+
if (id) {
|
74
|
+
index = ColumnModel.getColumnIndex(id, me.view.items[0].items);
|
75
|
+
tbodyNode = VDomUtil.findVdomChild(me.view.vdom, {tag: 'tbody'}).vdom;
|
76
|
+
columnNodeIds = VDomUtil.getColumnNodesIds(tbodyNode, index);
|
77
|
+
|
78
|
+
me.deselectAllCells(true);
|
79
|
+
me.select(columnNodeIds, me.selectedColumnCellIds, me.selectedColumnCellCls);
|
80
|
+
}
|
81
|
+
|
82
|
+
super.onCellClick(data);
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* @param {Object} data
|
87
|
+
* @param {Number} step
|
88
|
+
*/
|
89
|
+
onNavKeyColumn(data, step) {
|
90
|
+
let me = this,
|
91
|
+
idArray = ColumnModel.getCellId(data.path).split('__'),
|
92
|
+
currentColumn = idArray[2],
|
93
|
+
view = me.view,
|
94
|
+
dataFields = view.columns.map(c => c.dataField),
|
95
|
+
newIndex = (dataFields.indexOf(currentColumn) + step) % dataFields.length,
|
96
|
+
columnNodeIds, tbodyNode;
|
97
|
+
|
98
|
+
while (newIndex < 0) {
|
99
|
+
newIndex += dataFields.length;
|
100
|
+
}
|
101
|
+
|
102
|
+
tbodyNode = VDomUtil.findVdomChild(me.view.vdom, {tag: 'tbody'}).vdom;
|
103
|
+
columnNodeIds = VDomUtil.getColumnNodesIds(tbodyNode, newIndex);
|
104
|
+
|
105
|
+
me.deselectAllCells(true);
|
106
|
+
me.select(columnNodeIds, me.selectedColumnCellIds, me.selectedColumnCellCls);
|
107
|
+
|
108
|
+
super.onNavKeyColumn(data, step);
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
*
|
113
|
+
*/
|
114
|
+
unregister() {
|
115
|
+
this.deselectAllCells();
|
116
|
+
super.unregister();
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
Neo.applyClassConfig(CellColumnRowModel);
|
121
|
+
|
122
|
+
export default CellColumnRowModel;
|
@@ -0,0 +1,184 @@
|
|
1
|
+
import Model from '../Model.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @class Neo.selection.grid.CellModel
|
5
|
+
* @extends Neo.selection.Model
|
6
|
+
*/
|
7
|
+
class CellModel extends Model {
|
8
|
+
static getConfig() {return {
|
9
|
+
/**
|
10
|
+
* @member {String} className='Neo.selection.grid.CellModel'
|
11
|
+
* @protected
|
12
|
+
*/
|
13
|
+
className: 'Neo.selection.grid.CellModel',
|
14
|
+
/**
|
15
|
+
* @member {String} ntype='selection-grid-cellmodel'
|
16
|
+
* @protected
|
17
|
+
*/
|
18
|
+
ntype: 'selection-grid-cellmodel',
|
19
|
+
/**
|
20
|
+
* @member {String} cls='selection-cellmodel'
|
21
|
+
* @protected
|
22
|
+
*/
|
23
|
+
cls: 'neo-selection-cellmodel'
|
24
|
+
}}
|
25
|
+
|
26
|
+
/**
|
27
|
+
*
|
28
|
+
*/
|
29
|
+
addDomListener() {
|
30
|
+
let me = this,
|
31
|
+
view = me.view,
|
32
|
+
domListeners = view.domListeners;
|
33
|
+
|
34
|
+
domListeners.push({
|
35
|
+
click : me.onCellClick,
|
36
|
+
delegate: '.neo-grid-cell',
|
37
|
+
scope : me
|
38
|
+
});
|
39
|
+
|
40
|
+
view.domListeners = domListeners;
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* @param {Object} data
|
45
|
+
*/
|
46
|
+
onCellClick(data) {
|
47
|
+
let me = this,
|
48
|
+
id = null,
|
49
|
+
path = data.path,
|
50
|
+
i = 0,
|
51
|
+
len = path.length;
|
52
|
+
|
53
|
+
for (; i < len; i++) {
|
54
|
+
if (path[i].tagName === 'td') {
|
55
|
+
id = path[i].id;
|
56
|
+
break;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
if (id) {
|
61
|
+
me.toggleSelection(id);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* @param {Object} data
|
67
|
+
*/
|
68
|
+
onKeyDownDown(data) {
|
69
|
+
this.onNavKeyRow(data, 1);
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* @param {Object} data
|
74
|
+
*/
|
75
|
+
onKeyDownLeft(data) {
|
76
|
+
this.onNavKeyColumn(data, -1);
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* @param {Object} data
|
81
|
+
*/
|
82
|
+
onKeyDownRight(data) {
|
83
|
+
this.onNavKeyColumn(data, 1);
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* @param {Object} data
|
88
|
+
*/
|
89
|
+
onKeyDownUp(data) {
|
90
|
+
this.onNavKeyRow(data, -1);
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* @param {Object} data
|
95
|
+
* @param {Number} step
|
96
|
+
*/
|
97
|
+
onNavKeyColumn(data, step) {
|
98
|
+
let me = this,
|
99
|
+
view = me.view,
|
100
|
+
idArray = data.path[0].id.split('__'),
|
101
|
+
currentColumn = idArray[2],
|
102
|
+
dataFields = view.columns.map(c => c.dataField),
|
103
|
+
newIndex = (dataFields.indexOf(currentColumn) + step) % dataFields.length,
|
104
|
+
id;
|
105
|
+
|
106
|
+
while (newIndex < 0) {
|
107
|
+
newIndex += dataFields.length;
|
108
|
+
}
|
109
|
+
|
110
|
+
idArray[2] = dataFields[newIndex];
|
111
|
+
id = idArray.join('__');
|
112
|
+
|
113
|
+
me.select(id);
|
114
|
+
view.focus(id);
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* @param {Object} data
|
119
|
+
* @param {Number} step
|
120
|
+
*/
|
121
|
+
onNavKeyRow(data, step) {
|
122
|
+
let me = this,
|
123
|
+
view = me.view,
|
124
|
+
store = view.store,
|
125
|
+
idArray = data.path[0].id.split('__'),
|
126
|
+
recordId = idArray[1],
|
127
|
+
newIndex = (store.indexOf(recordId) + step) % store.getCount(),
|
128
|
+
id;
|
129
|
+
|
130
|
+
while (newIndex < 0) {
|
131
|
+
newIndex += store.getCount();
|
132
|
+
}
|
133
|
+
|
134
|
+
idArray[1] = store.getKeyAt(newIndex);
|
135
|
+
id = idArray.join('__');
|
136
|
+
|
137
|
+
me.select(id);
|
138
|
+
view.focus(id);
|
139
|
+
}
|
140
|
+
|
141
|
+
/**
|
142
|
+
* @param {Neo.component.Base} component
|
143
|
+
*/
|
144
|
+
register(component) {
|
145
|
+
super.register(component);
|
146
|
+
|
147
|
+
let me = this,
|
148
|
+
id = me.id,
|
149
|
+
view = me.view;
|
150
|
+
|
151
|
+
if (view.keys) {
|
152
|
+
view.keys._keys.push(
|
153
|
+
{fn: 'onKeyDownDown' ,key: 'Down' ,scope: id},
|
154
|
+
{fn: 'onKeyDownLeft' ,key: 'Left' ,scope: id},
|
155
|
+
{fn: 'onKeyDownRight' ,key: 'Right' ,scope: id},
|
156
|
+
{fn: 'onKeyDownUp' ,key: 'Up' ,scope: id}
|
157
|
+
);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
*
|
163
|
+
*/
|
164
|
+
unregister() {
|
165
|
+
let me = this,
|
166
|
+
id = me.id,
|
167
|
+
view = me.view;
|
168
|
+
|
169
|
+
if (view.keys) {
|
170
|
+
view.keys.removeKeys([
|
171
|
+
{fn: 'onKeyDownDown' ,key: 'Down' ,scope: id},
|
172
|
+
{fn: 'onKeyDownLeft' ,key: 'Left' ,scope: id},
|
173
|
+
{fn: 'onKeyDownRight' ,key: 'Right' ,scope: id},
|
174
|
+
{fn: 'onKeyDownUp' ,key: 'Up' ,scope: id}
|
175
|
+
]);
|
176
|
+
}
|
177
|
+
|
178
|
+
super.unregister();
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
Neo.applyClassConfig(CellModel);
|
183
|
+
|
184
|
+
export default CellModel;
|
@@ -0,0 +1,164 @@
|
|
1
|
+
import CellModel from './CellModel.mjs';
|
2
|
+
import NeoArray from '../../util/Array.mjs';
|
3
|
+
import RowModel from './RowModel.mjs';
|
4
|
+
import VDomUtil from '../../util/VDom.mjs';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @class Neo.selection.grid.CellRowModel
|
8
|
+
* @extends Neo.selection.grid.CellModel
|
9
|
+
*/
|
10
|
+
class CellRowModel extends CellModel {
|
11
|
+
static getConfig() {return {
|
12
|
+
/**
|
13
|
+
* @member {String} className='Neo.selection.grid.CellRowModel'
|
14
|
+
* @protected
|
15
|
+
*/
|
16
|
+
className: 'Neo.selection.grid.CellRowModel',
|
17
|
+
/**
|
18
|
+
* @member {String} ntype='selection-grid-cellrowmodel'
|
19
|
+
* @protected
|
20
|
+
*/
|
21
|
+
ntype: 'selection-grid-cellrowmodel',
|
22
|
+
/**
|
23
|
+
* @member {String} cls='neo-selection-cellrowmodel'
|
24
|
+
* @protected
|
25
|
+
*/
|
26
|
+
cls: 'neo-selection-cellrowmodel',
|
27
|
+
/**
|
28
|
+
* @member {Array|null} selectedRowIds=null
|
29
|
+
* @protected
|
30
|
+
*/
|
31
|
+
selectedRowIds: null
|
32
|
+
}}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @param {Object} config
|
36
|
+
*/
|
37
|
+
construct(config) {
|
38
|
+
super.construct(config);
|
39
|
+
|
40
|
+
this.selectedRowIds = [];
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* @param {Boolean} [silent] true to prevent a vdom update
|
45
|
+
*/
|
46
|
+
deselectAllRows(silent) {
|
47
|
+
let me = this,
|
48
|
+
rowIds = [...me.selectedRowIds],
|
49
|
+
view = me.view,
|
50
|
+
vdom = view.vdom;
|
51
|
+
|
52
|
+
rowIds.forEach(rowId => {
|
53
|
+
me.deselectRow(rowId, true);
|
54
|
+
});
|
55
|
+
|
56
|
+
if (!silent) {
|
57
|
+
view.vdom = vdom;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* @param {String} rowId
|
63
|
+
* @param {Boolean} [silent] true to prevent a vdom update
|
64
|
+
*/
|
65
|
+
deselectRow(rowId, silent) {
|
66
|
+
let me = this,
|
67
|
+
view = me.view,
|
68
|
+
vdom = view.vdom,
|
69
|
+
node = view.getVdomChild(rowId),
|
70
|
+
cls;
|
71
|
+
|
72
|
+
if (node) {
|
73
|
+
cls = node.cls || [];
|
74
|
+
NeoArray.remove(cls, me.selectedCls);
|
75
|
+
node.cls = cls;
|
76
|
+
}
|
77
|
+
|
78
|
+
NeoArray.remove(me.selectedRowIds, rowId);
|
79
|
+
|
80
|
+
if (!silent) {
|
81
|
+
view.vdom = vdom;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* @param {Object} data
|
87
|
+
*/
|
88
|
+
onCellClick(data) {
|
89
|
+
let me = this,
|
90
|
+
node = RowModel.getRowNode(data.path), // we could add a separate export for this method
|
91
|
+
id = node?.id;
|
92
|
+
|
93
|
+
if (id) {
|
94
|
+
me.deselectAllRows(true);
|
95
|
+
me.selectRow(id);
|
96
|
+
}
|
97
|
+
|
98
|
+
super.onCellClick(data);
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* @param {Object} data
|
103
|
+
* @param {Number} step
|
104
|
+
*/
|
105
|
+
onNavKeyRow(data, step) {
|
106
|
+
super.onNavKeyRow(data, step);
|
107
|
+
|
108
|
+
let me = this,
|
109
|
+
node = RowModel.getRowNode(data.path),
|
110
|
+
view = me.view,
|
111
|
+
store = view.store,
|
112
|
+
vdomNode = VDomUtil.findVdomChild(view.vdom, node.id),
|
113
|
+
newIndex = (vdomNode.index + step) % store.getCount(),
|
114
|
+
parentNode = vdomNode.parentNode,
|
115
|
+
id;
|
116
|
+
|
117
|
+
while (newIndex < 0) {
|
118
|
+
newIndex += store.getCount();
|
119
|
+
}
|
120
|
+
|
121
|
+
id = parentNode.cn[newIndex].id;
|
122
|
+
|
123
|
+
if (id) {
|
124
|
+
me.deselectAllRows(true);
|
125
|
+
me.selectRow(id);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
/**
|
130
|
+
* @param {String} id
|
131
|
+
* @param {Boolean} [silent]
|
132
|
+
*/
|
133
|
+
selectRow(id, silent) {
|
134
|
+
let me = this,
|
135
|
+
view = me.view,
|
136
|
+
vdom = view.vdom,
|
137
|
+
vdomNode = id && view.getVdomChild(id),
|
138
|
+
cls;
|
139
|
+
|
140
|
+
if (vdomNode) {
|
141
|
+
cls = vdomNode.cls || [];
|
142
|
+
NeoArray.add(cls, me.selectedCls);
|
143
|
+
vdomNode.cls = cls;
|
144
|
+
|
145
|
+
me.selectedRowIds.push(id);
|
146
|
+
}
|
147
|
+
|
148
|
+
if (!silent) {
|
149
|
+
view.vdom = vdom;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
*
|
155
|
+
*/
|
156
|
+
unregister() {
|
157
|
+
this.deselectAllRows();
|
158
|
+
super.unregister();
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
Neo.applyClassConfig(CellRowModel);
|
163
|
+
|
164
|
+
export default CellRowModel;
|
@@ -0,0 +1,185 @@
|
|
1
|
+
import Model from '../Model.mjs';
|
2
|
+
import VDomUtil from '../../util/VDom.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @class Neo.selection.grid.ColumnModel
|
6
|
+
* @extends Neo.selection.Model
|
7
|
+
*/
|
8
|
+
class ColumnModel extends Model {
|
9
|
+
static getConfig() {return {
|
10
|
+
/**
|
11
|
+
* @member {String} className='Neo.selection.grid.ColumnModel'
|
12
|
+
* @protected
|
13
|
+
*/
|
14
|
+
className: 'Neo.selection.grid.ColumnModel',
|
15
|
+
/**
|
16
|
+
* @member {String} ntype='selection-grid-columnmodel'
|
17
|
+
* @protected
|
18
|
+
*/
|
19
|
+
ntype: 'selection-grid-columnmodel',
|
20
|
+
/**
|
21
|
+
* @member {String} cls='selection-columnmodel'
|
22
|
+
* @protected
|
23
|
+
*/
|
24
|
+
cls: 'neo-selection-columnmodel'
|
25
|
+
}}
|
26
|
+
|
27
|
+
/**
|
28
|
+
*
|
29
|
+
*/
|
30
|
+
addDomListener() {
|
31
|
+
let me = this,
|
32
|
+
view = me.view,
|
33
|
+
domListeners = view.domListeners;
|
34
|
+
|
35
|
+
domListeners.push({
|
36
|
+
click : me.onCellClick,
|
37
|
+
delegate: '.neo-grid-cell',
|
38
|
+
scope : me
|
39
|
+
});
|
40
|
+
|
41
|
+
view.domListeners = domListeners;
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @param {Object} eventPath
|
46
|
+
* @returns {String|null} cellId
|
47
|
+
*/
|
48
|
+
static getCellId(eventPath) {
|
49
|
+
let id = null,
|
50
|
+
i = 0,
|
51
|
+
len = eventPath.length;
|
52
|
+
|
53
|
+
for (; i < len; i++) {
|
54
|
+
if (eventPath[i].tagName === 'td') {
|
55
|
+
id = eventPath[i].id;
|
56
|
+
break;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
return id;
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* todo: move to table.Container or view
|
65
|
+
* @param {String} cellId
|
66
|
+
* @param {Array} columns
|
67
|
+
* @returns {Number} index
|
68
|
+
*/
|
69
|
+
static getColumnIndex(cellId, columns) {
|
70
|
+
let idArray = cellId.split('__'),
|
71
|
+
currentColumn = idArray[2],
|
72
|
+
dataFields = columns.map(c => c.dataField);
|
73
|
+
|
74
|
+
return dataFields.indexOf(currentColumn);
|
75
|
+
}
|
76
|
+
|
77
|
+
/**
|
78
|
+
* @param {Object} data
|
79
|
+
*/
|
80
|
+
onCellClick(data) {
|
81
|
+
let me = this,
|
82
|
+
id = ColumnModel.getCellId(data.path),
|
83
|
+
columnNodeIds, index, tbodyNode;
|
84
|
+
|
85
|
+
if (id) {
|
86
|
+
index = ColumnModel.getColumnIndex(id, me.view.items[0].items);
|
87
|
+
tbodyNode = VDomUtil.findVdomChild(me.view.vdom, {tag: 'tbody'}).vdom;
|
88
|
+
columnNodeIds = VDomUtil.getColumnNodesIds(tbodyNode, index);
|
89
|
+
|
90
|
+
me.select(columnNodeIds);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* @param {Object} data
|
96
|
+
*/
|
97
|
+
onKeyDownLeft(data) {
|
98
|
+
this.onNavKeyColumn(data, -1);
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* @param {Object} data
|
103
|
+
*/
|
104
|
+
onKeyDownRight(data) {
|
105
|
+
this.onNavKeyColumn(data, 1);
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @param {Object} data
|
110
|
+
* @param {Number} step
|
111
|
+
*/
|
112
|
+
onNavKeyColumn(data, step) {
|
113
|
+
let me = this,
|
114
|
+
idArray = ColumnModel.getCellId(data.path).split('__'),
|
115
|
+
currentColumn = idArray[2],
|
116
|
+
view = me.view,
|
117
|
+
dataFields = view.columns.map(c => c.dataField),
|
118
|
+
newIndex = (dataFields.indexOf(currentColumn) + step) % dataFields.length,
|
119
|
+
columnNodeIds, id, tbodyNode;
|
120
|
+
|
121
|
+
while (newIndex < 0) {
|
122
|
+
newIndex += dataFields.length;
|
123
|
+
}
|
124
|
+
|
125
|
+
idArray[2] = dataFields[newIndex];
|
126
|
+
id = idArray.join('__');
|
127
|
+
|
128
|
+
tbodyNode = VDomUtil.findVdomChild(me.view.vdom, {tag: 'tbody'}).vdom;
|
129
|
+
columnNodeIds = VDomUtil.getColumnNodesIds(tbodyNode, newIndex);
|
130
|
+
|
131
|
+
me.select(columnNodeIds);
|
132
|
+
view.focus(id); // we have to focus one cell to ensure the keynav keeps working
|
133
|
+
}
|
134
|
+
|
135
|
+
/**
|
136
|
+
* @param {Neo.component.Base} component
|
137
|
+
*/
|
138
|
+
register(component) {
|
139
|
+
super.register(component);
|
140
|
+
|
141
|
+
let me = this,
|
142
|
+
id = me.id,
|
143
|
+
view = me.view;
|
144
|
+
|
145
|
+
if (view.keys) {
|
146
|
+
view.keys._keys.push({
|
147
|
+
fn : 'onKeyDownLeft',
|
148
|
+
key : 'Left',
|
149
|
+
scope: id
|
150
|
+
}, {
|
151
|
+
fn : 'onKeyDownRight',
|
152
|
+
key : 'Right',
|
153
|
+
scope: id
|
154
|
+
});
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
/**
|
160
|
+
*
|
161
|
+
*/
|
162
|
+
unregister() {
|
163
|
+
let me = this,
|
164
|
+
id = me.id,
|
165
|
+
view = me.view;
|
166
|
+
|
167
|
+
if (view.keys) {
|
168
|
+
view.keys.removeKeys([{
|
169
|
+
fn : 'onKeyDownLeft',
|
170
|
+
key : 'Left',
|
171
|
+
scope: id
|
172
|
+
}, {
|
173
|
+
fn : 'onKeyDownRight',
|
174
|
+
key : 'Right',
|
175
|
+
scope: id
|
176
|
+
}]);
|
177
|
+
}
|
178
|
+
|
179
|
+
super.unregister();
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
Neo.applyClassConfig(ColumnModel);
|
184
|
+
|
185
|
+
export default ColumnModel;
|