lib/Ext/data/NodeInterface.js
function(record) {
            if (!record.isNode) {
                // Apply the methods and fields to the prototype
                var mgr = Ext.data.ModelManager,
                    modelName = record.modelName,
                    modelClass = mgr.getModel(modelName),
                    newFields = [],
                    i, newField, len;

                // Start by adding the NodeInterface methods to the Model's prototype
                modelClass.override(this.getPrototypeBody());

                newFields = this.applyFields(modelClass, [
                    {name: 'parentId',   type: 'string',  defaultValue: null},
                    {name: 'index',      type: 'int',     defaultValue: 0},
                    {name: 'depth',      type: 'int',     defaultValue: 0,     persist: false},
                    {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}
                ]);

                len = newFields.length;

                // We set a dirty flag on the fields collection of the model. Any reader that
                // will read in data for this model will update their extractor functions.
                modelClass.getFields().isDirty = true;

                // Set default values
                for (i = 0; i < len; ++i) {
                    newField = newFields[i];
                    if (record.get(newField.getName()) === undefined) {
                        record.data[newField.getName()] = newField.getDefaultValue();
                    }
                }
            }

            if (!record.isDecorated) {
                record.isDecorated = true;

                Ext.applyIf(record, {
                    firstChild: null,
                    lastChild: null,
                    parentNode: null,
                    previousSibling: null,
                    nextSibling: null,
                    childNodes: []
                });

                record.enableBubble([
                    /**
                     * @event append
                     * Fires when a new child node is appended.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The newly appended node.
                     * @param {Number} index The index of the newly appended node.
                     */
                    "append",

                    /**
                     * @event remove
                     * Fires when a child node is removed.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The removed node.
                     */
                    "remove",

                    /**
                     * @event move
                     * Fires when this node is moved to a new location in the tree.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} oldParent The old parent of this node.
                     * @param {Ext.data.NodeInterface} newParent The new parent of this node.
                     * @param {Number} index The index it was moved to.
                     */
                    "move",

                    /**
                     * @event insert
                     * Fires when a new child node is inserted.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The child node inserted.
                     * @param {Ext.data.NodeInterface} refNode The child node the node was inserted before.
                     */
                    "insert",

                    /**
                     * @event beforeappend
                     * Fires before a new child is appended, return `false` to cancel the append.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The child node to be appended.
                     */
                    "beforeappend",

                    /**
                     * @event beforeremove
                     * Fires before a child is removed, return `false` to cancel the remove.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The child node to be removed.
                     */
                    "beforeremove",

                    /**
                     * @event beforemove
                     * Fires before this node is moved to a new location in the tree. Return `false` to cancel the move.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} oldParent The parent of this node.
                     * @param {Ext.data.NodeInterface} newParent The new parent this node is moving to.
                     * @param {Number} index The index it is being moved to.
                     */
                    "beforemove",

                     /**
                      * @event beforeinsert
                      * Fires before a new child is inserted, return false to cancel the insert.
                      * @param {Ext.data.NodeInterface} this This node
                      * @param {Ext.data.NodeInterface} node The child node to be inserted
                      * @param {Ext.data.NodeInterface} refNode The child node the node is being inserted before
                      */
                    "beforeinsert",

                    /**
                     * @event expand
                     * Fires when this node is expanded.
                     * @param {Ext.data.NodeInterface} this The expanding node.
                     */
                    "expand",

                    /**
                     * @event collapse
                     * Fires when this node is collapsed.
                     * @param {Ext.data.NodeInterface} this The collapsing node.
                     */
                    "collapse",

                    /**
                     * @event beforeexpand
                     * Fires before this node is expanded.
                     * @param {Ext.data.NodeInterface} this The expanding node.
                     */
                    "beforeexpand",

                    /**
                     * @event beforecollapse
                     * Fires before this node is collapsed.
                     * @param {Ext.data.NodeInterface} this The collapsing node.
                     */
                    "beforecollapse",

                    /**
                     * @event sort
                     * Fires when this node's childNodes are sorted.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface[]} childNodes The childNodes of this node.
                     */
                    "sort",

                    'load'
                ]);
            }

            return record;
        }
function(record) {
            if (!record.isNode) {
                // Apply the methods and fields to the prototype
                var mgr = Ext.data.ModelManager,
                    modelName = record.modelName,
                    modelClass = mgr.getModel(modelName),
                    newFields = [],
                    i, newField, len;

                // Start by adding the NodeInterface methods to the Model's prototype
                modelClass.override(this.getPrototypeBody());

                newFields = this.applyFields(modelClass, [
                    {name: 'parentId',   type: 'string',  defaultValue: null},
                    {name: 'index',      type: 'int',     defaultValue: 0},
                    {name: 'depth',      type: 'int',     defaultValue: 0,     persist: false},
                    {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}
                ]);

                len = newFields.length;

                // We set a dirty flag on the fields collection of the model. Any reader that
                // will read in data for this model will update their extractor functions.
                modelClass.getFields().isDirty = true;

                // Set default values
                for (i = 0; i < len; ++i) {
                    newField = newFields[i];
                    if (record.get(newField.getName()) === undefined) {
                        record.data[newField.getName()] = newField.getDefaultValue();
                    }
                }
            }

            if (!record.isDecorated) {
                record.isDecorated = true;

                Ext.applyIf(record, {
                    firstChild: null,
                    lastChild: null,
                    parentNode: null,
                    previousSibling: null,
                    nextSibling: null,
                    childNodes: []
                });

                record.enableBubble([
                    /**
                     * @event append
                     * Fires when a new child node is appended.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The newly appended node.
                     * @param {Number} index The index of the newly appended node.
                     */
                    "append",

                    /**
                     * @event remove
                     * Fires when a child node is removed.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The removed node.
                     */
                    "remove",

                    /**
                     * @event move
                     * Fires when this node is moved to a new location in the tree.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} oldParent The old parent of this node.
                     * @param {Ext.data.NodeInterface} newParent The new parent of this node.
                     * @param {Number} index The index it was moved to.
                     */
                    "move",

                    /**
                     * @event insert
                     * Fires when a new child node is inserted.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The child node inserted.
                     * @param {Ext.data.NodeInterface} refNode The child node the node was inserted before.
                     */
                    "insert",

                    /**
                     * @event beforeappend
                     * Fires before a new child is appended, return `false` to cancel the append.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The child node to be appended.
                     */
                    "beforeappend",

                    /**
                     * @event beforeremove
                     * Fires before a child is removed, return `false` to cancel the remove.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} node The child node to be removed.
                     */
                    "beforeremove",

                    /**
                     * @event beforemove
                     * Fires before this node is moved to a new location in the tree. Return `false` to cancel the move.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface} oldParent The parent of this node.
                     * @param {Ext.data.NodeInterface} newParent The new parent this node is moving to.
                     * @param {Number} index The index it is being moved to.
                     */
                    "beforemove",

                     /**
                      * @event beforeinsert
                      * Fires before a new child is inserted, return false to cancel the insert.
                      * @param {Ext.data.NodeInterface} this This node
                      * @param {Ext.data.NodeInterface} node The child node to be inserted
                      * @param {Ext.data.NodeInterface} refNode The child node the node is being inserted before
                      */
                    "beforeinsert",

                    /**
                     * @event expand
                     * Fires when this node is expanded.
                     * @param {Ext.data.NodeInterface} this The expanding node.
                     */
                    "expand",

                    /**
                     * @event collapse
                     * Fires when this node is collapsed.
                     * @param {Ext.data.NodeInterface} this The collapsing node.
                     */
                    "collapse",

                    /**
                     * @event beforeexpand
                     * Fires before this node is expanded.
                     * @param {Ext.data.NodeInterface} this The expanding node.
                     */
                    "beforeexpand",

                    /**
                     * @event beforecollapse
                     * Fires before this node is collapsed.
                     * @param {Ext.data.NodeInterface} this The collapsing node.
                     */
                    "beforecollapse",

                    /**
                     * @event sort
                     * Fires when this node's childNodes are sorted.
                     * @param {Ext.data.NodeInterface} this This node.
                     * @param {Ext.data.NodeInterface[]} childNodes The childNodes of this node.
                     */
                    "sort",

                    'load'
                ]);
            }

            return record;
        }
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.
@param {Ext.data.Model} record The Record you want to decorate the prototype of.
@static