X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..6746dc89c47ed01b165cc1152533605f97eb8e8d:/docs/source/NodeInterface.html diff --git a/docs/source/NodeInterface.html b/docs/source/NodeInterface.html index 55f38f77..80c37841 100644 --- a/docs/source/NodeInterface.html +++ b/docs/source/NodeInterface.html @@ -1,4 +1,21 @@ -Sencha Documentation Project
/**
+
+
+
+  
+  The source code
+  
+  
+  
+  
+
+
+  
/**
  * @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
@@ -9,7 +26,7 @@ Ext.define('Ext.data.NodeInterface', {
     requires: ['Ext.data.Field'],
     
     statics: {
-        /**
+        /**
          * 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.
@@ -24,47 +41,41 @@ Ext.define('Ext.data.NodeInterface', {
                     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;
                     }
                 }
             }
@@ -81,7 +92,7 @@ Ext.define('Ext.data.NodeInterface', {
             record.commit(true);
             
             record.enableBubble([
-                /**
+                /**
                  * @event append
                  * Fires when a new child node is appended
                  * @param {Node} this This node
@@ -90,7 +101,7 @@ Ext.define('Ext.data.NodeInterface', {
                  */
                 "append",
 
-                /**
+                /**
                  * @event remove
                  * Fires when a child node is removed
                  * @param {Node} this This node
@@ -98,7 +109,7 @@ Ext.define('Ext.data.NodeInterface', {
                  */
                 "remove",
 
-                /**
+                /**
                  * @event move
                  * Fires when this node is moved to a new location in the tree
                  * @param {Node} this This node
@@ -108,7 +119,7 @@ Ext.define('Ext.data.NodeInterface', {
                  */
                 "move",
 
-                /**
+                /**
                  * @event insert
                  * Fires when a new child node is inserted.
                  * @param {Node} this This node
@@ -117,7 +128,7 @@ Ext.define('Ext.data.NodeInterface', {
                  */
                 "insert",
 
-                /**
+                /**
                  * @event beforeappend
                  * Fires before a new child is appended, return false to cancel the append.
                  * @param {Node} this This node
@@ -125,7 +136,7 @@ Ext.define('Ext.data.NodeInterface', {
                  */
                 "beforeappend",
 
-                /**
+                /**
                  * @event beforeremove
                  * Fires before a child is removed, return false to cancel the remove.
                  * @param {Node} this This node
@@ -133,7 +144,7 @@ Ext.define('Ext.data.NodeInterface', {
                  */
                 "beforeremove",
 
-                /**
+                /**
                  * @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
@@ -143,7 +154,7 @@ Ext.define('Ext.data.NodeInterface', {
                  */
                 "beforemove",
 
-                 /**
+                 /**
                   * @event beforeinsert
                   * Fires before a new child is inserted, return false to cancel the insert.
                   * @param {Node} this This node
@@ -152,38 +163,39 @@ Ext.define('Ext.data.NodeInterface', {
                   */
                 "beforeinsert",
                 
-                /**
+                /**
                  * @event expand
                  * Fires when this node is expanded.
                  * @param {Node} this The expanding node
                  */
                 "expand",
                 
-                /**
+                /**
                  * @event collapse
                  * Fires when this node is collapsed.
                  * @param {Node} this The collapsing node
                  */
                 "collapse",
                 
-                /**
+                /**
                  * @event beforeexpand
                  * Fires before this node is expanded.
                  * @param {Node} this The expanding node
                  */
                 "beforeexpand",
                 
-                /**
+                /**
                  * @event beforecollapse
                  * Fires before this node is collapsed.
                  * @param {Node} this The collapsing node
                  */
                 "beforecollapse",
                 
-                /**
-                 * @event beforecollapse
-                 * Fires before this node is collapsed.
-                 * @param {Node} this The collapsing node
+                /**
+                 * @event sort
+                 * Fires when this node's childNodes are sorted.
+                 * @param {Node} this This node.
+                 * @param {Array} The childNodes of this node.
                  */
                 "sort"
             ]);
@@ -216,7 +228,7 @@ Ext.define('Ext.data.NodeInterface', {
             return {
                 isNode: true,
 
-                /**
+                /**
                  * Ensures that the passed object is an instance of a Record with the NodeInterface applied
                  * @return {Boolean}
                  */
@@ -228,7 +240,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return Ext.data.NodeInterface.decorate(node);
                 },
                 
-                /**
+                /**
                  * Returns true if this node is a leaf
                  * @return {Boolean}
                  */
@@ -236,7 +248,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return this.get('leaf') === true;
                 },
 
-                /**
+                /**
                  * Sets the first child of this node
                  * @private
                  * @param {Ext.data.NodeInterface} node
@@ -245,7 +257,7 @@ Ext.define('Ext.data.NodeInterface', {
                     this.firstChild = node;
                 },
 
-                /**
+                /**
                  * Sets the last child of this node
                  * @private
                  * @param {Ext.data.NodeInterface} node
@@ -254,7 +266,7 @@ Ext.define('Ext.data.NodeInterface', {
                     this.lastChild = node;
                 },
 
-                /**
+                /**
                  * 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
@@ -296,7 +308,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }
                 },
 
-                /**
+                /**
                  * Returns true if this node is the last child of its parent
                  * @return {Boolean}
                  */
@@ -304,7 +316,7 @@ Ext.define('Ext.data.NodeInterface', {
                    return this.get('isLast');
                 },
 
-                /**
+                /**
                  * Returns true if this node is the first child of its parent
                  * @return {Boolean}
                  */
@@ -312,7 +324,7 @@ Ext.define('Ext.data.NodeInterface', {
                    return this.get('isFirst');
                 },
 
-                /**
+                /**
                  * Returns true if this node has one or more child nodes, else false.
                  * @return {Boolean}
                  */
@@ -320,16 +332,21 @@ Ext.define('Ext.data.NodeInterface', {
                     return !this.isLeaf() && this.childNodes.length > 0;
                 },
 
-                /**
+                /**
                  * 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;
                 },
 
-                /**
+                /**
                  * <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
@@ -409,7 +426,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }
                 },
                 
-                /**
+                /**
                  * Returns the bubble target for this node
                  * @private
                  * @return {Object} The bubble target
@@ -418,7 +435,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return this.parentNode;
                 },
 
-                /**
+                /**
                  * 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>.
@@ -433,7 +450,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }
 
                     // remove it from childNodes collection
-                    me.childNodes.splice(index, 1);
+                    Ext.Array.erase(me.childNodes, index, 1);
 
                     // update child refs
                     if (me.firstChild == node) {
@@ -472,7 +489,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return node;
                 },
 
-                /**
+                /**
                  * 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>
@@ -494,7 +511,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return result;
                 },
 
-                /**
+                /**
                  * Clear the node.
                  * @private
                  * @param {Boolean} destroy True to destroy the node.
@@ -509,7 +526,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }
                 },
 
-                /**
+                /**
                  * Destroys the node.
                  */
                 destroy : function(silent) {
@@ -519,7 +536,8 @@ Ext.define('Ext.data.NodeInterface', {
                      * 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);
@@ -527,14 +545,16 @@ Ext.define('Ext.data.NodeInterface', {
                             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();
                 },
 
-                /**
+                /**
                  * 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)
@@ -580,7 +600,7 @@ Ext.define('Ext.data.NodeInterface', {
                         me.setFirstChild(node);
                     }
 
-                    me.childNodes.splice(refIndex, 0, node);
+                    Ext.Array.splice(me.childNodes, refIndex, 0, node);
                     node.parentNode = me;
                     
                     node.nextSibling = refNode;
@@ -616,7 +636,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return node;
                 },
                 
-                /**
+                /**
                  * 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
@@ -632,7 +652,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }
                 },
 
-                /**
+                /**
                  * 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
@@ -646,7 +666,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return this;
                 },
 
-                /**
+                /**
                  * 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
@@ -661,7 +681,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return this;
                 },
 
-                /**
+                /**
                  * Returns the child node at the specified index.
                  * @param {Number} index
                  * @return {Node}
@@ -670,7 +690,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return this.childNodes[index];
                 },
 
-                /**
+                /**
                  * Replaces one child node in this node with another.
                  * @param {Node} newChild The replacement node
                  * @param {Node} oldChild The node to replace
@@ -684,7 +704,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return oldChild;
                 },
 
-                /**
+                /**
                  * Returns the index of a child node
                  * @param {Node} node
                  * @return {Number} The index of the node or -1 if it was not found
@@ -693,7 +713,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return Ext.Array.indexOf(this.childNodes, child);
                 },
 
-                /**
+                /**
                  * Returns depth of this node (the root node has a depth of 0)
                  * @return {Number}
                  */
@@ -701,7 +721,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return this.get('depth');
                 },
 
-                /**
+                /**
                  * 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.
@@ -728,7 +748,7 @@ Ext.define('Ext.data.NodeInterface', {
                 },
                 //</deprecated>
 
-                /**
+                /**
                  * 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.
@@ -748,7 +768,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }
                 },
 
-                /**
+                /**
                  * 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.
@@ -768,7 +788,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }
                 },
 
-                /**
+                /**
                  * 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
@@ -781,7 +801,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }, null, deep);
                 },
 
-                /**
+                /**
                  * 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.
@@ -809,7 +829,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return null;
                 },
 
-                /**
+                /**
                  * Returns true if this node is an ancestor (at any point) of the passed node.
                  * @param {Node} node
                  * @return {Boolean}
@@ -818,7 +838,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return node.isAncestor(this);
                 },
 
-                /**
+                /**
                  * Returns true if the passed node is an ancestor (at any point) of this node.
                  * @param {Node} node
                  * @return {Boolean}
@@ -834,7 +854,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return false;
                 },
 
-                /**
+                /**
                  * 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
@@ -871,7 +891,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }
                 },
                         
-                /**
+                /**
                  * Returns true if this node is expaned
                  * @return {Boolean}
                  */        
@@ -879,7 +899,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return this.get('expanded');
                 },
                 
-                /**
+                /**
                  * Returns true if this node is loaded
                  * @return {Boolean}
                  */ 
@@ -887,7 +907,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return this.get('loaded');
                 },
 
-                /**
+                /**
                  * Returns true if this node is loading
                  * @return {Boolean}
                  */ 
@@ -895,7 +915,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return this.get('loading');
                 },
                                 
-                /**
+                /**
                  * Returns true if this node is the root node
                  * @return {Boolean}
                  */ 
@@ -903,7 +923,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return !this.parentNode;
                 },
                 
-                /**
+                /**
                  * Returns true if this node is visible
                  * @return {Boolean}
                  */ 
@@ -918,7 +938,7 @@ Ext.define('Ext.data.NodeInterface', {
                     return true;
                 },
                 
-                /**
+                /**
                  * 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
@@ -938,7 +958,7 @@ Ext.define('Ext.data.NodeInterface', {
                             // 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);
                                 
@@ -969,7 +989,7 @@ Ext.define('Ext.data.NodeInterface', {
                     }
                 },
                 
-                /**
+                /**
                  * 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
@@ -990,18 +1010,17 @@ Ext.define('Ext.data.NodeInterface', {
                             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]);                    }
                 },
 
-                /**
+                /**
                  * 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
@@ -1014,7 +1033,7 @@ Ext.define('Ext.data.NodeInterface', {
                     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);
                                 
@@ -1034,11 +1053,11 @@ Ext.define('Ext.data.NodeInterface', {
                     }
                     // 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]); 
                     }
                 },
                 
-                /**
+                /**
                  * 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
@@ -1059,17 +1078,19 @@ Ext.define('Ext.data.NodeInterface', {
                             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]);
                     }
                 }
             };
         }
     }
-});
\ No newline at end of file +});
+ +