]>
git.proxmox.com Git - extjs.git/blob - extjs/packages/core/src/data/NodeStore.js
5 Ext
.define('Ext.data.NodeStore', {
6 extend
: 'Ext.data.Store',
10 'Ext.data.NodeInterface'
14 * @property {Boolean} isNodeStore
15 * `true` in this class to identify an object as an instantiated NodeStore, or subclass thereof.
21 * @cfg {Ext.data.Model} node The Record you want to bind this Store to. Note that
22 * this record will be decorated with the {@link Ext.data.NodeInterface} if this is not the
29 * @cfg {Boolean} recursive Set this to `true` if you want this NodeStore to represent
30 * all the descendants of the node in its flat data collection. This is useful for
31 * rendering a tree structure to a DataView and is being used internally by
32 * the TreeView. Any records that are moved, removed, inserted or appended to the
33 * node at any depth below the node this store is bound to will be automatically
34 * updated in this Store's internal flat data structure.
40 * @cfg {Boolean} rootVisible `false` to not include the root node in this Stores collection.
46 * @cfg {Boolean} folderSort
47 * Set to `true` to automatically prepend a leaf sorter.
52 implicitModel
: 'Ext.data.TreeModel',
54 // NodeStores are never buffered or paged. They are loaded from the TreeStore to reflect all visible
56 // BufferedRenderer always asks for the *total* count, so this must return the count.
57 getTotalCount: function() {
58 return this.getCount();
61 updateFolderSort: function(folderSort
) {
62 var data
= this.getData();
64 data
.setTrackGroups(false);
67 groupFn
: this.folderSortFn
70 data
.setGrouper(null);
74 folderSortFn: function(node
) {
75 return node
.data
.leaf
? 1 : 0;
78 afterReject : function(record
) {
80 // Must pass the 5th param (modifiedFieldNames) as null, otherwise the
81 // event firing machinery appends the listeners "options" object to the arg list
82 // which may get used as the modified fields array by a handler.
83 // This array is used for selective grid cell updating by Grid View.
84 // Null will be treated as though all cells need updating.
85 if (me
.contains(record
)) {
86 me
.onUpdate(record
, Ext
.data
.Model
.REJECT
, null);
87 me
.fireEvent('update', me
, record
, Ext
.data
.Model
.REJECT
, null);
91 afterCommit : function(record
, modifiedFieldNames
) {
93 if (!modifiedFieldNames
) {
94 modifiedFieldNames
= null;
96 if (me
.contains(record
)) {
97 me
.onUpdate(record
, Ext
.data
.Model
.COMMIT
, modifiedFieldNames
);
98 me
.fireEvent('update', me
, record
, Ext
.data
.Model
.COMMIT
, modifiedFieldNames
);
102 onNodeAppend: function(parent
, node
) {
103 if (parent
=== this.getNode()) {
104 this.add([node
].concat(this.retrieveChildNodes(node
)));
108 onNodeInsert: function(parent
, node
, refNode
) {
112 if (parent
=== me
.getNode()) {
113 idx
= me
.indexOf(refNode
) || 0;
114 me
.insert(0, [node
].concat(me
.retrieveChildNodes(node
)));
118 onNodeRemove: function(parent
, node
) {
119 if (parent
=== this.getNode()) {
120 this.remove([node
].concat(this.retrieveChildNodes(node
)));
124 onNodeExpand: function(parent
, records
) {
125 if (parent
=== this.getNode()) {
126 this.loadRecords(records
);
130 applyNode: function(node
) {
133 node
= new (this.getModel())(node
);
136 Ext
.data
.NodeInterface
.decorate(node
);
142 updateNode: function(node
, oldNode
) {
146 if (oldNode
&& !oldNode
.destroyed
) {
148 append
: 'onNodeAppend',
149 insert
: 'onNodeInsert',
150 remove
: 'onNodeRemove',
159 append
: 'onNodeAppend',
160 insert
: 'onNodeInsert',
161 remove
: 'onNodeRemove'
167 if (node
.childNodes
.length
) {
168 data
= data
.concat(me
.retrieveChildNodes(node
));
170 if (me
.getRootVisible()) {
172 } else if (node
.isLoaded() || node
.isLoading()) {
173 node
.set('expanded', true);
176 me
.getData().clear();
177 me
.fireEvent('clear', me
);
180 if (me
.isInitializing
) {
181 me
.inlineData
= data
;
187 if (data
.length
=== 0) {
188 me
.loaded
= node
.loaded
= true;
191 me
.fireEvent('refresh', me
, me
.data
);
196 * @param {Object} node
199 isVisible: function(node
) {
200 var parent
= node
.parentNode
;
202 if (!this.getRecursive() && parent
!== this.getNode()) {
207 if (!parent
.isExpanded()) {
211 //we need to check this because for a nodestore the node is not likely to be the root
212 //so we stop going up the chain when we hit the original node as we don't care about any
213 //ancestors above the configured node
214 if (parent
=== this.getNode()) {
218 parent
= parent
.parentNode
;
225 * Private method used to deeply retrieve the children of a record without recursion.
227 * @param {Ext.data.NodeInterface} root
228 * @return {Ext.data.NodeInterface[]}
230 retrieveChildNodes: function(root
) {
231 var node
= this.getNode(),
232 recursive
= this.getRecursive(),
236 if (!root
.childNodes
.length
|| (!recursive
&& root
!== node
)) {
241 return root
.childNodes
;
247 if (child
=== root
) {
250 child
= child
.nextSibling
|| child
.parentNode
;
253 if (child
!== root
) {
256 if (child
.firstChild
) {
258 child
= child
.firstChild
;
260 child
= child
.nextSibling
|| child
.parentNode
;