DataViewModel.html
5.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-selection-DataViewModel'>/**
</span> * @private
*/
Ext.define('Ext.selection.DataViewModel', {
extend: 'Ext.selection.Model',
requires: ['Ext.util.KeyNav'],
deselectOnContainerClick: true,
<span id='Ext-selection-DataViewModel-cfg-enableKeyNav'> /**
</span> * @cfg {Boolean} enableKeyNav
*
* Turns on/off keyboard navigation within the DataView.
*/
enableKeyNav: true,
constructor: function(cfg){
this.addEvents(
<span id='Ext-selection-DataViewModel-event-beforedeselect'> /**
</span> * @event beforedeselect
* Fired before a record is deselected. If any listener returns false, the
* deselection is cancelled.
* @param {Ext.selection.DataViewModel} this
* @param {Ext.data.Model} record The deselected record
*/
'beforedeselect',
<span id='Ext-selection-DataViewModel-event-beforeselect'> /**
</span> * @event beforeselect
* Fired before a record is selected. If any listener returns false, the
* selection is cancelled.
* @param {Ext.selection.DataViewModel} this
* @param {Ext.data.Model} record The selected record
*/
'beforeselect',
<span id='Ext-selection-DataViewModel-event-deselect'> /**
</span> * @event deselect
* Fired after a record is deselected
* @param {Ext.selection.DataViewModel} this
* @param {Ext.data.Model} record The deselected record
*/
'deselect',
<span id='Ext-selection-DataViewModel-event-select'> /**
</span> * @event select
* Fired after a record is selected
* @param {Ext.selection.DataViewModel} this
* @param {Ext.data.Model} record The selected record
*/
'select'
);
this.callParent(arguments);
},
bindComponent: function(view) {
var me = this,
eventListeners = {
refresh: me.refresh,
scope: me
};
me.view = view;
me.bindStore(view.getStore());
eventListeners[view.triggerEvent] = me.onItemClick;
eventListeners[view.triggerCtEvent] = me.onContainerClick;
view.on(eventListeners);
if (me.enableKeyNav) {
me.initKeyNav(view);
}
},
onItemClick: function(view, record, item, index, e) {
this.selectWithEvent(record, e);
},
onContainerClick: function() {
if (this.deselectOnContainerClick) {
this.deselectAll();
}
},
initKeyNav: function(view) {
var me = this;
if (!view.rendered) {
view.on({
render: Ext.Function.bind(me.initKeyNav, me, [view]),
single: true
});
return;
}
view.el.set({
tabIndex: -1
});
me.keyNav = new Ext.util.KeyNav({
target: view.el,
ignoreInputFields: true,
down: Ext.pass(me.onNavKey, [1], me),
right: Ext.pass(me.onNavKey, [1], me),
left: Ext.pass(me.onNavKey, [-1], me),
up: Ext.pass(me.onNavKey, [-1], me),
scope: me
});
},
onNavKey: function(step) {
step = step || 1;
var me = this,
view = me.view,
selected = me.getSelection()[0],
numRecords = me.view.store.getCount(),
idx;
if (selected) {
idx = view.indexOf(view.getNode(selected)) + step;
} else {
idx = 0;
}
if (idx < 0) {
idx = numRecords - 1;
} else if (idx >= numRecords) {
idx = 0;
}
me.select(idx);
},
// Allow the DataView to update the ui
onSelectChange: function(record, isSelected, suppressEvent, commitFn) {
var me = this,
view = me.view,
eventName = isSelected ? 'select' : 'deselect';
if ((suppressEvent || me.fireEvent('before' + eventName, me, record)) !== false &&
commitFn() !== false) {
if (view) {
if (isSelected) {
view.onItemSelect(record);
} else {
view.onItemDeselect(record);
}
}
if (!suppressEvent) {
me.fireEvent(eventName, me, record);
}
}
},
destroy: function(){
Ext.destroy(this.keyNav);
this.callParent();
}
});
</pre>
</body>
</html>