4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-data-NodeStore'>/**
19 </span> * @class Ext.data.NodeStore
20 * @extends Ext.data.AbstractStore
24 Ext.define('Ext.data.NodeStore', {
25 extend: 'Ext.data.Store',
27 requires: ['Ext.data.NodeInterface'],
29 <span id='Ext-data-NodeStore-cfg-node'> /**
30 </span> * @cfg {Ext.data.Model} node
31 * The Record you want to bind this Store to. Note that
32 * this record will be decorated with the Ext.data.NodeInterface if this is not the
37 <span id='Ext-data-NodeStore-cfg-recursive'> /**
38 </span> * @cfg {Boolean} recursive
39 * Set this to true if you want this NodeStore to represent
40 * all the descendents of the node in its flat data collection. This is useful for
41 * rendering a tree structure to a DataView and is being used internally by
42 * the TreeView. Any records that are moved, removed, inserted or appended to the
43 * node at any depth below the node this store is bound to will be automatically
44 * updated in this Store's internal flat data structure.
48 <span id='Ext-data-NodeStore-cfg-rootVisible'> /**
49 </span> * @cfg {Boolean} rootVisible
50 * False to not include the root node in this Stores collection.
54 constructor: function(config) {
58 config = config || {};
59 Ext.apply(me, config);
62 if (Ext.isDefined(me.proxy)) {
63 Ext.Error.raise("A NodeStore cannot be bound to a proxy. Instead bind it to a record " +
64 "decorated with the NodeInterface by setting the node config.");
68 config.proxy = {type: 'proxy'};
69 me.callParent([config]);
71 me.addEvents('expand', 'collapse', 'beforeexpand', 'beforecollapse');
80 setNode: function(node) {
83 if (me.node && me.node != node) {
84 // We want to unbind our listeners on the old node
86 expand: me.onNodeExpand,
87 collapse: me.onNodeCollapse,
88 append: me.onNodeAppend,
89 insert: me.onNodeInsert,
90 remove: me.onNodeRemove,
98 Ext.data.NodeInterface.decorate(node);
100 if (me.rootVisible) {
104 expand: me.onNodeExpand,
105 collapse: me.onNodeCollapse,
106 append: me.onNodeAppend,
107 insert: me.onNodeInsert,
108 remove: me.onNodeRemove,
113 if (node.isExpanded() && node.isLoaded()) {
114 me.onNodeExpand(node, node.childNodes, true);
119 onNodeSort: function(node, childNodes) {
122 if ((me.indexOf(node) !== -1 || (node === me.node && !me.rootVisible) && node.isExpanded())) {
123 me.onNodeCollapse(node, childNodes, true);
124 me.onNodeExpand(node, childNodes, true);
128 onNodeExpand: function(parent, records, suppressEvent) {
130 insertIndex = me.indexOf(parent) + 1,
131 ln = records ? records.length : 0,
134 if (!me.recursive && parent !== me.node) {
138 if (!me.isVisible(parent)) {
142 if (!suppressEvent && me.fireEvent('beforeexpand', parent, records, insertIndex) === false) {
147 me.insert(insertIndex, records);
148 for (i = 0; i < ln; i++) {
150 if (record.isExpanded()) {
151 if (record.isLoaded()) {
153 me.onNodeExpand(record, record.childNodes, true);
156 record.set('expanded', false);
163 if (!suppressEvent) {
164 me.fireEvent('expand', parent, records);
168 onNodeCollapse: function(parent, records, suppressEvent) {
171 collapseIndex = me.indexOf(parent) + 1,
174 if (!me.recursive && parent !== me.node) {
178 if (!suppressEvent && me.fireEvent('beforecollapse', parent, records, collapseIndex) === false) {
182 for (i = 0; i < ln; i++) {
185 if (record.isExpanded()) {
186 me.onNodeCollapse(record, record.childNodes, true);
190 if (!suppressEvent) {
191 me.fireEvent('collapse', parent, records, collapseIndex);
195 onNodeAppend: function(parent, node, index) {
199 if (me.isVisible(node)) {
203 sibling = node.previousSibling;
204 while (sibling.isExpanded() && sibling.lastChild) {
205 sibling = sibling.lastChild;
209 me.insert(me.indexOf(refNode) + 1, node);
210 if (!node.isLeaf() && node.isExpanded()) {
211 if (node.isLoaded()) {
213 me.onNodeExpand(node, node.childNodes, true);
216 node.set('expanded', false);
223 onNodeInsert: function(parent, node, refNode) {
225 index = this.indexOf(refNode);
227 if (index != -1 && me.isVisible(node)) {
228 me.insert(index, node);
229 if (!node.isLeaf() && node.isExpanded()) {
230 if (node.isLoaded()) {
232 me.onNodeExpand(node, node.childNodes, true);
235 node.set('expanded', false);
242 onNodeRemove: function(parent, node, index) {
244 if (me.indexOf(node) != -1) {
245 if (!node.isLeaf() && node.isExpanded()) {
246 me.onNodeCollapse(node, node.childNodes, true);
252 isVisible: function(node) {
253 var parent = node.parentNode;
255 if (parent === this.node && !this.rootVisible && parent.isExpanded()) {
259 if (this.indexOf(parent) === -1 || !parent.isExpanded()) {
263 parent = parent.parentNode;