-<!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.NodeInterface'>/**
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>The source code</title>
+ <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
+ <script type="text/javascript" src="../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-data-NodeInterface'>/**
</span> * @class Ext.data.NodeInterface
* This class is meant to be used as a set of methods that are applied to the prototype of a
* Record to decorate it with a Node API. This means that models used in conjunction with a tree
requires: ['Ext.data.Field'],
statics: {
-<span id='Ext-data.NodeInterface-method-decorate'> /**
+<span id='Ext-data-NodeInterface-method-decorate'> /**
</span> * This method allows you to decorate a Record's prototype to implement the NodeInterface.
* This adds a set of methods, new events, new properties and new fields on every Record
* with the same Model as the passed Record.
modelName = record.modelName,
modelClass = mgr.getModel(modelName),
idName = modelClass.prototype.idProperty,
- instances = Ext.Array.filter(mgr.all.getArray(), function(item) {
- return item.modelName == modelName;
- }),
- iln = instances.length,
newFields = [],
- i, instance, jln, j, newField;
+ i, newField, len;
// Start by adding the NodeInterface methods to the Model's prototype
modelClass.override(this.getPrototypeBody());
newFields = this.applyFields(modelClass, [
- {name: idName, type: 'string', defaultValue: null},
- {name: 'parentId', type: 'string', defaultValue: null},
- {name: 'index', type: 'int', defaultValue: null},
- {name: 'depth', type: 'int', defaultValue: 0},
- {name: 'expanded', type: 'bool', defaultValue: false, persist: false},
- {name: 'checked', type: 'auto', defaultValue: null},
- {name: 'leaf', type: 'bool', defaultValue: false, persist: false},
- {name: 'cls', type: 'string', defaultValue: null, persist: false},
- {name: 'iconCls', type: 'string', defaultValue: null, persist: false},
- {name: 'root', type: 'boolean', defaultValue: false, persist: false},
- {name: 'isLast', type: 'boolean', defaultValue: false, persist: false},
- {name: 'isFirst', type: 'boolean', defaultValue: false, persist: false},
- {name: 'allowDrop', type: 'boolean', defaultValue: true, persist: false},
- {name: 'allowDrag', type: 'boolean', defaultValue: true, persist: false},
- {name: 'loaded', type: 'boolean', defaultValue: false, persist: false},
- {name: 'loading', type: 'boolean', defaultValue: false, persist: false},
- {name: 'href', type: 'string', defaultValue: null, persist: false},
- {name: 'hrefTarget',type: 'string', defaultValue: null, persist: false},
- {name: 'qtip', type: 'string', defaultValue: null, persist: false},
- {name: 'qtitle', type: 'string', defaultValue: null, persist: false}
+ {name: idName, type: 'string', defaultValue: null},
+ {name: 'parentId', type: 'string', defaultValue: null},
+ {name: 'index', type: 'int', defaultValue: null},
+ {name: 'depth', type: 'int', defaultValue: 0},
+ {name: 'expanded', type: 'bool', defaultValue: false, persist: false},
+ {name: 'expandable', type: 'bool', defaultValue: true, persist: false},
+ {name: 'checked', type: 'auto', defaultValue: null},
+ {name: 'leaf', type: 'bool', defaultValue: false, persist: false},
+ {name: 'cls', type: 'string', defaultValue: null, persist: false},
+ {name: 'iconCls', type: 'string', defaultValue: null, persist: false},
+ {name: 'root', type: 'boolean', defaultValue: false, persist: false},
+ {name: 'isLast', type: 'boolean', defaultValue: false, persist: false},
+ {name: 'isFirst', type: 'boolean', defaultValue: false, persist: false},
+ {name: 'allowDrop', type: 'boolean', defaultValue: true, persist: false},
+ {name: 'allowDrag', type: 'boolean', defaultValue: true, persist: false},
+ {name: 'loaded', type: 'boolean', defaultValue: false, persist: false},
+ {name: 'loading', type: 'boolean', defaultValue: false, persist: false},
+ {name: 'href', type: 'string', defaultValue: null, persist: false},
+ {name: 'hrefTarget', type: 'string', defaultValue: null, persist: false},
+ {name: 'qtip', type: 'string', defaultValue: null, persist: false},
+ {name: 'qtitle', type: 'string', defaultValue: null, persist: false}
]);
- jln = newFields.length;
- // Set default values to all instances already out there
- for (i = 0; i < iln; i++) {
- instance = instances[i];
- for (j = 0; j < jln; j++) {
- newField = newFields[j];
- if (instance.get(newField.name) === undefined) {
- instance.data[newField.name] = newField.defaultValue;
- }
+ len = newFields.length;
+ // Set default values
+ for (i = 0; i < len; ++i) {
+ newField = newFields[i];
+ if (record.get(newField.name) === undefined) {
+ record.data[newField.name] = newField.defaultValue;
}
}
}
record.commit(true);
record.enableBubble([
-<span id='Ext-data.NodeInterface-event-append'> /**
+<span id='Ext-data-NodeInterface-event-append'> /**
</span> * @event append
* Fires when a new child node is appended
* @param {Node} this This node
*/
"append",
-<span id='Ext-data.NodeInterface-event-remove'> /**
+<span id='Ext-data-NodeInterface-event-remove'> /**
</span> * @event remove
* Fires when a child node is removed
* @param {Node} this This node
*/
"remove",
-<span id='Ext-data.NodeInterface-event-move'> /**
+<span id='Ext-data-NodeInterface-event-move'> /**
</span> * @event move
* Fires when this node is moved to a new location in the tree
* @param {Node} this This node
*/
"move",
-<span id='Ext-data.NodeInterface-event-insert'> /**
+<span id='Ext-data-NodeInterface-event-insert'> /**
</span> * @event insert
* Fires when a new child node is inserted.
* @param {Node} this This node
*/
"insert",
-<span id='Ext-data.NodeInterface-event-beforeappend'> /**
+<span id='Ext-data-NodeInterface-event-beforeappend'> /**
</span> * @event beforeappend
* Fires before a new child is appended, return false to cancel the append.
* @param {Node} this This node
*/
"beforeappend",
-<span id='Ext-data.NodeInterface-event-beforeremove'> /**
+<span id='Ext-data-NodeInterface-event-beforeremove'> /**
</span> * @event beforeremove
* Fires before a child is removed, return false to cancel the remove.
* @param {Node} this This node
*/
"beforeremove",
-<span id='Ext-data.NodeInterface-event-beforemove'> /**
+<span id='Ext-data-NodeInterface-event-beforemove'> /**
</span> * @event beforemove
* Fires before this node is moved to a new location in the tree. Return false to cancel the move.
* @param {Node} this This node
*/
"beforemove",
-<span id='Ext-data.NodeInterface-event-beforeinsert'> /**
+<span id='Ext-data-NodeInterface-event-beforeinsert'> /**
</span> * @event beforeinsert
* Fires before a new child is inserted, return false to cancel the insert.
* @param {Node} this This node
*/
"beforeinsert",
-<span id='Ext-data.NodeInterface-event-expand'> /**
+<span id='Ext-data-NodeInterface-event-expand'> /**
</span> * @event expand
* Fires when this node is expanded.
* @param {Node} this The expanding node
*/
"expand",
-<span id='Ext-data.NodeInterface-event-collapse'> /**
+<span id='Ext-data-NodeInterface-event-collapse'> /**
</span> * @event collapse
* Fires when this node is collapsed.
* @param {Node} this The collapsing node
*/
"collapse",
-<span id='Ext-data.NodeInterface-event-beforeexpand'> /**
+<span id='Ext-data-NodeInterface-event-beforeexpand'> /**
</span> * @event beforeexpand
* Fires before this node is expanded.
* @param {Node} this The expanding node
*/
"beforeexpand",
-<span id='Ext-data.NodeInterface-event-beforecollapse'> /**
+<span id='Ext-data-NodeInterface-event-beforecollapse'> /**
</span> * @event beforecollapse
* Fires before this node is collapsed.
* @param {Node} this The collapsing node
*/
"beforecollapse",
-<span id='Ext-data.NodeInterface-event-beforecollapse'> /**
-</span> * @event beforecollapse
- * Fires before this node is collapsed.
- * @param {Node} this The collapsing node
+<span id='Ext-data-NodeInterface-event-sort'> /**
+</span> * @event sort
+ * Fires when this node's childNodes are sorted.
+ * @param {Node} this This node.
+ * @param {Array} The childNodes of this node.
*/
"sort"
]);
return {
isNode: true,
-<span id='Ext-data.NodeInterface-method-createNode'> /**
+<span id='Ext-data-NodeInterface-method-createNode'> /**
</span> * Ensures that the passed object is an instance of a Record with the NodeInterface applied
* @return {Boolean}
*/
return Ext.data.NodeInterface.decorate(node);
},
-<span id='Ext-data.NodeInterface-method-isLeaf'> /**
+<span id='Ext-data-NodeInterface-method-isLeaf'> /**
</span> * Returns true if this node is a leaf
* @return {Boolean}
*/
return this.get('leaf') === true;
},
-<span id='Ext-data.NodeInterface-method-setFirstChild'> /**
+<span id='Ext-data-NodeInterface-method-setFirstChild'> /**
</span> * Sets the first child of this node
* @private
* @param {Ext.data.NodeInterface} node
this.firstChild = node;
},
-<span id='Ext-data.NodeInterface-method-setLastChild'> /**
+<span id='Ext-data-NodeInterface-method-setLastChild'> /**
</span> * Sets the last child of this node
* @private
* @param {Ext.data.NodeInterface} node
this.lastChild = node;
},
-<span id='Ext-data.NodeInterface-method-updateInfo'> /**
+<span id='Ext-data-NodeInterface-method-updateInfo'> /**
</span> * Updates general data of this node like isFirst, isLast, depth. This
* method is internally called after a node is moved. This shouldn't
* have to be called by the developer unless they are creating custom
}
},
-<span id='Ext-data.NodeInterface-method-isLast'> /**
+<span id='Ext-data-NodeInterface-method-isLast'> /**
</span> * Returns true if this node is the last child of its parent
* @return {Boolean}
*/
return this.get('isLast');
},
-<span id='Ext-data.NodeInterface-method-isFirst'> /**
+<span id='Ext-data-NodeInterface-method-isFirst'> /**
</span> * Returns true if this node is the first child of its parent
* @return {Boolean}
*/
return this.get('isFirst');
},
-<span id='Ext-data.NodeInterface-method-hasChildNodes'> /**
+<span id='Ext-data-NodeInterface-method-hasChildNodes'> /**
</span> * Returns true if this node has one or more child nodes, else false.
* @return {Boolean}
*/
return !this.isLeaf() && this.childNodes.length > 0;
},
-<span id='Ext-data.NodeInterface-method-isExpandable'> /**
+<span id='Ext-data-NodeInterface-method-isExpandable'> /**
</span> * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>
* node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
* @return {Boolean}
*/
isExpandable : function() {
- return this.get('expandable') || this.hasChildNodes();
+ var me = this;
+
+ if (me.get('expandable')) {
+ return !(me.isLeaf() || (me.isLoaded() && !me.hasChildNodes()));
+ }
+ return false;
},
-<span id='Ext-data.NodeInterface-method-appendChild'> /**
+<span id='Ext-data-NodeInterface-method-appendChild'> /**
</span> * <p>Insert node(s) as the last child node of this node.</p>
* <p>If the node was previously a child node of another parent node, it will be removed from that node first.</p>
* @param {Node/Array} node The node or Array of nodes to append
}
},
-<span id='Ext-data.NodeInterface-method-getBubbleTarget'> /**
+<span id='Ext-data-NodeInterface-method-getBubbleTarget'> /**
</span> * Returns the bubble target for this node
* @private
* @return {Object} The bubble target
return this.parentNode;
},
-<span id='Ext-data.NodeInterface-method-removeChild'> /**
+<span id='Ext-data-NodeInterface-method-removeChild'> /**
</span> * Removes a child node from this node.
* @param {Node} node The node to remove
* @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
}
// remove it from childNodes collection
- me.childNodes.splice(index, 1);
+ Ext.Array.erase(me.childNodes, index, 1);
// update child refs
if (me.firstChild == node) {
return node;
},
-<span id='Ext-data.NodeInterface-method-copy'> /**
+<span id='Ext-data-NodeInterface-method-copy'> /**
</span> * Creates a copy (clone) of this Node.
* @param {String} id (optional) A new id, defaults to this Node's id. See <code>{@link #id}</code>.
* @param {Boolean} deep (optional) <p>If passed as <code>true</code>, all child Nodes are recursively copied into the new Node.</p>
return result;
},
-<span id='Ext-data.NodeInterface-method-clear'> /**
+<span id='Ext-data-NodeInterface-method-clear'> /**
</span> * Clear the node.
* @private
* @param {Boolean} destroy True to destroy the node.
}
},
-<span id='Ext-data.NodeInterface-method-destroy'> /**
+<span id='Ext-data-NodeInterface-method-destroy'> /**
</span> * Destroys the node.
*/
destroy : function(silent) {
* 2) When destroy on the tree is called
* 3) For destroying child nodes on a node
*/
- var me = this;
+ var me = this,
+ options = me.destroyOptions;
if (silent === true) {
me.clear(true);
n.destroy(true);
});
me.childNodes = null;
+ delete me.destroyOptions;
+ me.callOverridden([options]);
} else {
+ me.destroyOptions = silent;
+ // overridden method will be called, since remove will end up calling destroy(true);
me.remove(true);
}
-
- me.callOverridden();
},
-<span id='Ext-data.NodeInterface-method-insertBefore'> /**
+<span id='Ext-data-NodeInterface-method-insertBefore'> /**
</span> * Inserts the first node before the second node in this nodes childNodes collection.
* @param {Node} node The node to insert
* @param {Node} refNode The node to insert before (if null the node is appended)
me.setFirstChild(node);
}
- me.childNodes.splice(refIndex, 0, node);
+ Ext.Array.splice(me.childNodes, refIndex, 0, node);
node.parentNode = me;
node.nextSibling = refNode;
return node;
},
-<span id='Ext-data.NodeInterface-method-insertChild'> /**
+<span id='Ext-data-NodeInterface-method-insertChild'> /**
</span> * Insert a node into this node
* @param {Number} index The zero-based index to insert the node at
* @param {Ext.data.Model} node The node to insert
}
},
-<span id='Ext-data.NodeInterface-method-remove'> /**
+<span id='Ext-data-NodeInterface-method-remove'> /**
</span> * Removes this node from its parent
* @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
* @return {Node} this
return this;
},
-<span id='Ext-data.NodeInterface-method-removeAll'> /**
+<span id='Ext-data-NodeInterface-method-removeAll'> /**
</span> * Removes all child nodes from this node.
* @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
* @return {Node} this
return this;
},
-<span id='Ext-data.NodeInterface-method-getChildAt'> /**
+<span id='Ext-data-NodeInterface-method-getChildAt'> /**
</span> * Returns the child node at the specified index.
* @param {Number} index
* @return {Node}
return this.childNodes[index];
},
-<span id='Ext-data.NodeInterface-method-replaceChild'> /**
+<span id='Ext-data-NodeInterface-method-replaceChild'> /**
</span> * Replaces one child node in this node with another.
* @param {Node} newChild The replacement node
* @param {Node} oldChild The node to replace
return oldChild;
},
-<span id='Ext-data.NodeInterface-method-indexOf'> /**
+<span id='Ext-data-NodeInterface-method-indexOf'> /**
</span> * Returns the index of a child node
* @param {Node} node
* @return {Number} The index of the node or -1 if it was not found
return Ext.Array.indexOf(this.childNodes, child);
},
-<span id='Ext-data.NodeInterface-method-getDepth'> /**
+<span id='Ext-data-NodeInterface-method-getDepth'> /**
</span> * Returns depth of this node (the root node has a depth of 0)
* @return {Number}
*/
return this.get('depth');
},
-<span id='Ext-data.NodeInterface-method-bubble'> /**
+<span id='Ext-data-NodeInterface-method-bubble'> /**
</span> * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function
* will be the args provided or the current node. If the function returns false at any point,
* the bubble is stopped.
},
//</deprecated>
-<span id='Ext-data.NodeInterface-method-cascadeBy'> /**
+<span id='Ext-data-NodeInterface-method-cascadeBy'> /**
</span> * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function
* will be the args provided or the current node. If the function returns false at any point,
* the cascade is stopped on that branch.
}
},
-<span id='Ext-data.NodeInterface-method-eachChild'> /**
+<span id='Ext-data-NodeInterface-method-eachChild'> /**
</span> * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function
* will be the args provided or the current node. If the function returns false at any point,
* the iteration stops.
}
},
-<span id='Ext-data.NodeInterface-method-findChild'> /**
+<span id='Ext-data-NodeInterface-method-findChild'> /**
</span> * Finds the first child that has the attribute with the specified value.
* @param {String} attribute The attribute name
* @param {Mixed} value The value to search for
}, null, deep);
},
-<span id='Ext-data.NodeInterface-method-findChildBy'> /**
+<span id='Ext-data-NodeInterface-method-findChildBy'> /**
</span> * Finds the first child by a custom function. The child matches if the function passed returns <code>true</code>.
* @param {Function} fn A function which must return <code>true</code> if the passed Node is the required Node.
* @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Node being tested.
return null;
},
-<span id='Ext-data.NodeInterface-method-contains'> /**
+<span id='Ext-data-NodeInterface-method-contains'> /**
</span> * Returns true if this node is an ancestor (at any point) of the passed node.
* @param {Node} node
* @return {Boolean}
return node.isAncestor(this);
},
-<span id='Ext-data.NodeInterface-method-isAncestor'> /**
+<span id='Ext-data-NodeInterface-method-isAncestor'> /**
</span> * Returns true if the passed node is an ancestor (at any point) of this node.
* @param {Node} node
* @return {Boolean}
return false;
},
-<span id='Ext-data.NodeInterface-method-sort'> /**
+<span id='Ext-data-NodeInterface-method-sort'> /**
</span> * Sorts this nodes children using the supplied sort function.
* @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.
* @param {Boolean} recursive Whether or not to apply this sort recursively
}
},
-<span id='Ext-data.NodeInterface-method-isExpanded'> /**
+<span id='Ext-data-NodeInterface-method-isExpanded'> /**
</span> * Returns true if this node is expaned
* @return {Boolean}
*/
return this.get('expanded');
},
-<span id='Ext-data.NodeInterface-method-isLoaded'> /**
+<span id='Ext-data-NodeInterface-method-isLoaded'> /**
</span> * Returns true if this node is loaded
* @return {Boolean}
*/
return this.get('loaded');
},
-<span id='Ext-data.NodeInterface-method-isLoading'> /**
+<span id='Ext-data-NodeInterface-method-isLoading'> /**
</span> * Returns true if this node is loading
* @return {Boolean}
*/
return this.get('loading');
},
-<span id='Ext-data.NodeInterface-method-isRoot'> /**
+<span id='Ext-data-NodeInterface-method-isRoot'> /**
</span> * Returns true if this node is the root node
* @return {Boolean}
*/
return !this.parentNode;
},
-<span id='Ext-data.NodeInterface-method-isVisible'> /**
+<span id='Ext-data-NodeInterface-method-isVisible'> /**
</span> * Returns true if this node is visible
* @return {Boolean}
*/
return true;
},
-<span id='Ext-data.NodeInterface-method-expand'> /**
+<span id='Ext-data-NodeInterface-method-expand'> /**
</span> * Expand this node.
* @param {Function} recursive (Optional) True to recursively expand all the children
* @param {Function} callback (Optional) The function to execute once the expand completes
// whether we have to asynchronously load the children from the server
// first. Thats why we pass a callback function to the event that the
// store can call once it has loaded and parsed all the children.
- me.fireEvent('beforeexpand', me, function(records) {
+ me.fireEvent('beforeexpand', me, function() {
me.set('expanded', true);
me.fireEvent('expand', me, me.childNodes, false);
}
},
-<span id='Ext-data.NodeInterface-method-expandChildren'> /**
+<span id='Ext-data-NodeInterface-method-expandChildren'> /**
</span> * Expand all the children of this node.
* @param {Function} recursive (Optional) True to recursively expand all the children
* @param {Function} callback (Optional) The function to execute once all the children are expanded
nodes[i].expand(recursive, function () {
expanding--;
if (callback && !expanding) {
- Ext.callback(callback, scope || me, me.childNodes);
+ Ext.callback(callback, scope || me, [me.childNodes]);
}
});
}
}
if (!expanding && callback) {
- Ext.callback(callback, scope || me, me.childNodes);
- }
+ Ext.callback(callback, scope || me, [me.childNodes]); }
},
-<span id='Ext-data.NodeInterface-method-collapse'> /**
+<span id='Ext-data-NodeInterface-method-collapse'> /**
</span> * Collapse this node.
* @param {Function} recursive (Optional) True to recursively collapse all the children
* @param {Function} callback (Optional) The function to execute once the collapse completes
if (!me.isLeaf()) {
// Now we check if this record is already collapsing or collapsed
if (!me.collapsing && me.isExpanded()) {
- me.fireEvent('beforecollapse', me, function(records) {
+ me.fireEvent('beforecollapse', me, function() {
me.set('expanded', false);
me.fireEvent('collapse', me, me.childNodes, false);
}
// If it's not then we fire the callback right away
else {
- Ext.callback(callback, scope || me, me.childNodes);
+ Ext.callback(callback, scope || me, [me.childNodes]);
}
},
-<span id='Ext-data.NodeInterface-method-collapseChildren'> /**
+<span id='Ext-data-NodeInterface-method-collapseChildren'> /**
</span> * Collapse all the children of this node.
* @param {Function} recursive (Optional) True to recursively collapse all the children
* @param {Function} callback (Optional) The function to execute once all the children are collapsed
nodes[i].collapse(recursive, function () {
collapsing--;
if (callback && !collapsing) {
- Ext.callback(callback, scope || me, me.childNodes);
+ Ext.callback(callback, scope || me, [me.childNodes]);
}
});
}
}
if (!collapsing && callback) {
- Ext.callback(callback, scope || me, me.childNodes);
+ Ext.callback(callback, scope || me, [me.childNodes]);
}
}
};
}
}
-});</pre></pre></body></html>
\ No newline at end of file
+});</pre>
+</body>
+</html>