Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / pkgs / data-list-views-debug.js
diff --git a/pkgs/data-list-views-debug.js b/pkgs/data-list-views-debug.js
new file mode 100644 (file)
index 0000000..ec0ac8e
--- /dev/null
@@ -0,0 +1,1278 @@
+/*!
+ * Ext JS Library 3.0.0
+ * Copyright(c) 2006-2009 Ext JS, LLC
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+/**
+ * @class Ext.DataView
+ * @extends Ext.BoxComponent
+ * A mechanism for displaying data using custom layout templates and formatting. DataView uses an {@link Ext.XTemplate}
+ * as its internal templating mechanism, and is bound to an {@link Ext.data.Store}
+ * so that as the data in the store changes the view is automatically updated to reflect the changes.  The view also
+ * provides built-in behavior for many common events that can occur for its contained items including click, doubleclick,
+ * mouseover, mouseout, etc. as well as a built-in selection model. <b>In order to use these features, an {@link #itemSelector}
+ * config must be provided for the DataView to determine what nodes it will be working with.</b>
+ *
+ * <p>The example below binds a DataView to a {@link Ext.data.Store} and renders it into an {@link Ext.Panel}.</p>
+ * <pre><code>
+var store = new Ext.data.JsonStore({
+    url: 'get-images.php',
+    root: 'images',
+    fields: [
+        'name', 'url',
+        {name:'size', type: 'float'},
+        {name:'lastmod', type:'date', dateFormat:'timestamp'}
+    ]
+});
+store.load();
+
+var tpl = new Ext.XTemplate(
+    '&lt;tpl for="."&gt;',
+        '&lt;div class="thumb-wrap" id="{name}"&gt;',
+        '&lt;div class="thumb"&gt;&lt;img src="{url}" title="{name}"&gt;&lt;/div&gt;',
+        '&lt;span class="x-editable"&gt;{shortName}&lt;/span&gt;&lt;/div&gt;',
+    '&lt;/tpl&gt;',
+    '&lt;div class="x-clear"&gt;&lt;/div&gt;'
+);
+
+var panel = new Ext.Panel({
+    id:'images-view',
+    frame:true,
+    width:535,
+    autoHeight:true,
+    collapsible:true,
+    layout:'fit',
+    title:'Simple DataView',
+
+    items: new Ext.DataView({
+        store: store,
+        tpl: tpl,
+        autoHeight:true,
+        multiSelect: true,
+        overClass:'x-view-over',
+        itemSelector:'div.thumb-wrap',
+        emptyText: 'No images to display'
+    })
+});
+panel.render(document.body);
+</code></pre>
+ * @constructor
+ * Create a new DataView
+ * @param {Object} config The config object
+ * @xtype dataview
+ */
+Ext.DataView = Ext.extend(Ext.BoxComponent, {
+    /**
+     * @cfg {String/Array} tpl
+     * The HTML fragment or an array of fragments that will make up the template used by this DataView.  This should
+     * be specified in the same format expected by the constructor of {@link Ext.XTemplate}.
+     */
+    /**
+     * @cfg {Ext.data.Store} store
+     * The {@link Ext.data.Store} to bind this DataView to.
+     */
+    /**
+     * @cfg {String} itemSelector
+     * <b>This is a required setting</b>. A simple CSS selector (e.g. <tt>div.some-class</tt> or 
+     * <tt>span:first-child</tt>) that will be used to determine what nodes this DataView will be
+     * working with.
+     */
+    /**
+     * @cfg {Boolean} multiSelect
+     * True to allow selection of more than one item at a time, false to allow selection of only a single item
+     * at a time or no selection at all, depending on the value of {@link #singleSelect} (defaults to false).
+     */
+    /**
+     * @cfg {Boolean} singleSelect
+     * True to allow selection of exactly one item at a time, false to allow no selection at all (defaults to false).
+     * Note that if {@link #multiSelect} = true, this value will be ignored.
+     */
+    /**
+     * @cfg {Boolean} simpleSelect
+     * True to enable multiselection by clicking on multiple items without requiring the user to hold Shift or Ctrl,
+     * false to force the user to hold Ctrl or Shift to select more than on item (defaults to false).
+     */
+    /**
+     * @cfg {String} overClass
+     * A CSS class to apply to each item in the view on mouseover (defaults to undefined).
+     */
+    /**
+     * @cfg {String} loadingText
+     * A string to display during data load operations (defaults to undefined).  If specified, this text will be
+     * displayed in a loading div and the view's contents will be cleared while loading, otherwise the view's
+     * contents will continue to display normally until the new data is loaded and the contents are replaced.
+     */
+    /**
+     * @cfg {String} selectedClass
+     * A CSS class to apply to each selected item in the view (defaults to 'x-view-selected').
+     */
+    selectedClass : "x-view-selected",
+    /**
+     * @cfg {String} emptyText
+     * The text to display in the view when there is no data to display (defaults to '').
+     */
+    emptyText : "",
+
+    /**
+     * @cfg {Boolean} deferEmptyText True to defer emptyText being applied until the store's first load
+     */
+    deferEmptyText: true,
+    /**
+     * @cfg {Boolean} trackOver True to enable mouseenter and mouseleave events
+     */
+    trackOver: false,
+
+    //private
+    last: false,
+
+    // private
+    initComponent : function(){
+        Ext.DataView.superclass.initComponent.call(this);
+        if(Ext.isString(this.tpl) || Ext.isArray(this.tpl)){
+            this.tpl = new Ext.XTemplate(this.tpl);
+        }
+
+        this.addEvents(
+            /**
+             * @event beforeclick
+             * Fires before a click is processed. Returns false to cancel the default action.
+             * @param {Ext.DataView} this
+             * @param {Number} index The index of the target node
+             * @param {HTMLElement} node The target node
+             * @param {Ext.EventObject} e The raw event object
+             */
+            "beforeclick",
+            /**
+             * @event click
+             * Fires when a template node is clicked.
+             * @param {Ext.DataView} this
+             * @param {Number} index The index of the target node
+             * @param {HTMLElement} node The target node
+             * @param {Ext.EventObject} e The raw event object
+             */
+            "click",
+            /**
+             * @event mouseenter
+             * Fires when the mouse enters a template node. trackOver:true or an overCls must be set to enable this event.
+             * @param {Ext.DataView} this
+             * @param {Number} index The index of the target node
+             * @param {HTMLElement} node The target node
+             * @param {Ext.EventObject} e The raw event object
+             */
+            "mouseenter",
+            /**
+             * @event mouseleave
+             * Fires when the mouse leaves a template node. trackOver:true or an overCls must be set to enable this event.
+             * @param {Ext.DataView} this
+             * @param {Number} index The index of the target node
+             * @param {HTMLElement} node The target node
+             * @param {Ext.EventObject} e The raw event object
+             */
+            "mouseleave",
+            /**
+             * @event containerclick
+             * Fires when a click occurs and it is not on a template node.
+             * @param {Ext.DataView} this
+             * @param {Ext.EventObject} e The raw event object
+             */
+            "containerclick",
+            /**
+             * @event dblclick
+             * Fires when a template node is double clicked.
+             * @param {Ext.DataView} this
+             * @param {Number} index The index of the target node
+             * @param {HTMLElement} node The target node
+             * @param {Ext.EventObject} e The raw event object
+             */
+            "dblclick",
+            /**
+             * @event contextmenu
+             * Fires when a template node is right clicked.
+             * @param {Ext.DataView} this
+             * @param {Number} index The index of the target node
+             * @param {HTMLElement} node The target node
+             * @param {Ext.EventObject} e The raw event object
+             */
+            "contextmenu",
+            /**
+             * @event containercontextmenu
+             * Fires when a right click occurs that is not on a template node.
+             * @param {Ext.DataView} this
+             * @param {Ext.EventObject} e The raw event object
+             */
+            "containercontextmenu",
+            /**
+             * @event selectionchange
+             * Fires when the selected nodes change.
+             * @param {Ext.DataView} this
+             * @param {Array} selections Array of the selected nodes
+             */
+            "selectionchange",
+
+            /**
+             * @event beforeselect
+             * Fires before a selection is made. If any handlers return false, the selection is cancelled.
+             * @param {Ext.DataView} this
+             * @param {HTMLElement} node The node to be selected
+             * @param {Array} selections Array of currently selected nodes
+             */
+            "beforeselect"
+        );
+
+        this.store = Ext.StoreMgr.lookup(this.store);
+        this.all = new Ext.CompositeElementLite();
+        this.selected = new Ext.CompositeElementLite();
+    },
+
+    // private
+    afterRender : function(){
+        Ext.DataView.superclass.afterRender.call(this);
+
+               this.mon(this.getTemplateTarget(), {
+            "click": this.onClick,
+            "dblclick": this.onDblClick,
+            "contextmenu": this.onContextMenu,
+            scope:this
+        });
+
+        if(this.overClass || this.trackOver){
+            this.mon(this.getTemplateTarget(), {
+                "mouseover": this.onMouseOver,
+                "mouseout": this.onMouseOut,
+                scope:this
+            });
+        }
+
+        if(this.store){
+            this.bindStore(this.store, true);
+        }
+    },
+
+    /**
+     * Refreshes the view by reloading the data from the store and re-rendering the template.
+     */
+    refresh : function(){
+        this.clearSelections(false, true);
+        var el = this.getTemplateTarget();
+        el.update("");
+        var records = this.store.getRange();
+        if(records.length < 1){
+            if(!this.deferEmptyText || this.hasSkippedEmptyText){
+                el.update(this.emptyText);
+            }
+            this.all.clear();
+        }else{
+            this.tpl.overwrite(el, this.collectData(records, 0));
+            this.all.fill(Ext.query(this.itemSelector, el.dom));
+            this.updateIndexes(0);
+        }
+        this.hasSkippedEmptyText = true;
+    },
+
+    getTemplateTarget: function(){
+        return this.el;
+    },
+
+    /**
+     * Function which can be overridden to provide custom formatting for each Record that is used by this
+     * DataView's {@link #tpl template} to render each node.
+     * @param {Array/Object} data The raw data object that was used to create the Record.
+     * @param {Number} recordIndex the index number of the Record being prepared for rendering.
+     * @param {Record} record The Record being prepared for rendering.
+     * @return {Array/Object} The formatted data in a format expected by the internal {@link #tpl template}'s overwrite() method.
+     * (either an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}))
+     */
+    prepareData : function(data){
+        return data;
+    },
+
+    /**
+     * <p>Function which can be overridden which returns the data object passed to this
+     * DataView's {@link #tpl template} to render the whole DataView.</p>
+     * <p>This is usually an Array of data objects, each element of which is processed by an
+     * {@link Ext.XTemplate XTemplate} which uses <tt>'&lt;tpl for="."&gt;'</tt> to iterate over its supplied
+     * data object as an Array. However, <i>named</i> properties may be placed into the data object to
+     * provide non-repeating data such as headings, totals etc.</p>
+     * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.
+     * @param {Number} startIndex the index number of the Record being prepared for rendering.
+     * @return {Array} An Array of data objects to be processed by a repeating XTemplate. May also
+     * contain <i>named</i> properties.
+     */
+    collectData : function(records, startIndex){
+        var r = [];
+        for(var i = 0, len = records.length; i < len; i++){
+            r[r.length] = this.prepareData(records[i].data, startIndex+i, records[i]);
+        }
+        return r;
+    },
+
+    // private
+    bufferRender : function(records){
+        var div = document.createElement('div');
+        this.tpl.overwrite(div, this.collectData(records));
+        return Ext.query(this.itemSelector, div);
+    },
+
+    // private
+    onUpdate : function(ds, record){
+        var index = this.store.indexOf(record);
+        var sel = this.isSelected(index);
+        var original = this.all.elements[index];
+        var node = this.bufferRender([record], index)[0];
+
+        this.all.replaceElement(index, node, true);
+        if(sel){
+            this.selected.replaceElement(original, node);
+            this.all.item(index).addClass(this.selectedClass);
+        }
+        this.updateIndexes(index, index);
+    },
+
+    // private
+    onAdd : function(ds, records, index){
+        if(this.all.getCount() === 0){
+            this.refresh();
+            return;
+        }
+        var nodes = this.bufferRender(records, index), n, a = this.all.elements;
+        if(index < this.all.getCount()){
+            n = this.all.item(index).insertSibling(nodes, 'before', true);
+            a.splice.apply(a, [index, 0].concat(nodes));
+        }else{
+            n = this.all.last().insertSibling(nodes, 'after', true);
+            a.push.apply(a, nodes);
+        }
+        this.updateIndexes(index);
+    },
+
+    // private
+    onRemove : function(ds, record, index){
+        this.deselect(index);
+        this.all.removeElement(index, true);
+        this.updateIndexes(index);
+        if (this.store.getCount() === 0){
+            this.refresh();
+        }
+    },
+
+    /**
+     * Refreshes an individual node's data from the store.
+     * @param {Number} index The item's data index in the store
+     */
+    refreshNode : function(index){
+        this.onUpdate(this.store, this.store.getAt(index));
+    },
+
+    // private
+    updateIndexes : function(startIndex, endIndex){
+        var ns = this.all.elements;
+        startIndex = startIndex || 0;
+        endIndex = endIndex || ((endIndex === 0) ? 0 : (ns.length - 1));
+        for(var i = startIndex; i <= endIndex; i++){
+            ns[i].viewIndex = i;
+        }
+    },
+    
+    /**
+     * Returns the store associated with this DataView.
+     * @return {Ext.data.Store} The store
+     */
+    getStore : function(){
+        return this.store;
+    },
+
+    /**
+     * Changes the data store bound to this view and refreshes it.
+     * @param {Store} store The store to bind to this view
+     */
+    bindStore : function(store, initial){
+        if(!initial && this.store){
+            this.store.un("beforeload", this.onBeforeLoad, this);
+            this.store.un("datachanged", this.refresh, this);
+            this.store.un("add", this.onAdd, this);
+            this.store.un("remove", this.onRemove, this);
+            this.store.un("update", this.onUpdate, this);
+            this.store.un("clear", this.refresh, this);
+            if(store !== this.store && this.store.autoDestroy){
+                this.store.destroy();
+            }
+        }
+        if(store){
+            store = Ext.StoreMgr.lookup(store);
+            store.on({
+                scope: this,
+                beforeload: this.onBeforeLoad,
+                datachanged: this.refresh,
+                add: this.onAdd,
+                remove: this.onRemove,
+                update: this.onUpdate,
+                clear: this.refresh
+            });
+        }
+        this.store = store;
+        if(store){
+            this.refresh();
+        }
+    },
+
+    /**
+     * Returns the template node the passed child belongs to, or null if it doesn't belong to one.
+     * @param {HTMLElement} node
+     * @return {HTMLElement} The template node
+     */
+    findItemFromChild : function(node){
+        return Ext.fly(node).findParent(this.itemSelector, this.getTemplateTarget());
+    },
+
+    // private
+    onClick : function(e){
+        var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
+        if(item){
+            var index = this.indexOf(item);
+            if(this.onItemClick(item, index, e) !== false){
+                this.fireEvent("click", this, index, item, e);
+            }
+        }else{
+            if(this.fireEvent("containerclick", this, e) !== false){
+                this.onContainerClick(e);
+            }
+        }
+    },
+
+    onContainerClick : function(e){
+        this.clearSelections();
+    },
+
+    // private
+    onContextMenu : function(e){
+        var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
+        if(item){
+            this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
+        }else{
+            this.fireEvent("containercontextmenu", this, e);
+        }
+    },
+
+    // private
+    onDblClick : function(e){
+        var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
+        if(item){
+            this.fireEvent("dblclick", this, this.indexOf(item), item, e);
+        }
+    },
+
+    // private
+    onMouseOver : function(e){
+        var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
+        if(item && item !== this.lastItem){
+            this.lastItem = item;
+            Ext.fly(item).addClass(this.overClass);
+            this.fireEvent("mouseenter", this, this.indexOf(item), item, e);
+        }
+    },
+
+    // private
+    onMouseOut : function(e){
+        if(this.lastItem){
+            if(!e.within(this.lastItem, true, true)){
+                Ext.fly(this.lastItem).removeClass(this.overClass);
+                this.fireEvent("mouseleave", this, this.indexOf(this.lastItem), this.lastItem, e);
+                delete this.lastItem;
+            }
+        }
+    },
+
+    // private
+    onItemClick : function(item, index, e){
+        if(this.fireEvent("beforeclick", this, index, item, e) === false){
+            return false;
+        }
+        if(this.multiSelect){
+            this.doMultiSelection(item, index, e);
+            e.preventDefault();
+        }else if(this.singleSelect){
+            this.doSingleSelection(item, index, e);
+            e.preventDefault();
+        }
+        return true;
+    },
+
+    // private
+    doSingleSelection : function(item, index, e){
+        if(e.ctrlKey && this.isSelected(index)){
+            this.deselect(index);
+        }else{
+            this.select(index, false);
+        }
+    },
+
+    // private
+    doMultiSelection : function(item, index, e){
+        if(e.shiftKey && this.last !== false){
+            var last = this.last;
+            this.selectRange(last, index, e.ctrlKey);
+            this.last = last; // reset the last
+        }else{
+            if((e.ctrlKey||this.simpleSelect) && this.isSelected(index)){
+                this.deselect(index);
+            }else{
+                this.select(index, e.ctrlKey || e.shiftKey || this.simpleSelect);
+            }
+        }
+    },
+
+    /**
+     * Gets the number of selected nodes.
+     * @return {Number} The node count
+     */
+    getSelectionCount : function(){
+        return this.selected.getCount();
+    },
+
+    /**
+     * Gets the currently selected nodes.
+     * @return {Array} An array of HTMLElements
+     */
+    getSelectedNodes : function(){
+        return this.selected.elements;
+    },
+
+    /**
+     * Gets the indexes of the selected nodes.
+     * @return {Array} An array of numeric indexes
+     */
+    getSelectedIndexes : function(){
+        var indexes = [], s = this.selected.elements;
+        for(var i = 0, len = s.length; i < len; i++){
+            indexes.push(s[i].viewIndex);
+        }
+        return indexes;
+    },
+
+    /**
+     * Gets an array of the selected records
+     * @return {Array} An array of {@link Ext.data.Record} objects
+     */
+    getSelectedRecords : function(){
+        var r = [], s = this.selected.elements;
+        for(var i = 0, len = s.length; i < len; i++){
+            r[r.length] = this.store.getAt(s[i].viewIndex);
+        }
+        return r;
+    },
+
+    /**
+     * Gets an array of the records from an array of nodes
+     * @param {Array} nodes The nodes to evaluate
+     * @return {Array} records The {@link Ext.data.Record} objects
+     */
+    getRecords : function(nodes){
+        var r = [], s = nodes;
+        for(var i = 0, len = s.length; i < len; i++){
+            r[r.length] = this.store.getAt(s[i].viewIndex);
+        }
+        return r;
+    },
+
+    /**
+     * Gets a record from a node
+     * @param {HTMLElement} node The node to evaluate
+     * @return {Record} record The {@link Ext.data.Record} object
+     */
+    getRecord : function(node){
+        return this.store.getAt(node.viewIndex);
+    },
+
+    /**
+     * Clears all selections.
+     * @param {Boolean} suppressEvent (optional) True to skip firing of the selectionchange event
+     */
+    clearSelections : function(suppressEvent, skipUpdate){
+        if((this.multiSelect || this.singleSelect) && this.selected.getCount() > 0){
+            if(!skipUpdate){
+                this.selected.removeClass(this.selectedClass);
+            }
+            this.selected.clear();
+            this.last = false;
+            if(!suppressEvent){
+                this.fireEvent("selectionchange", this, this.selected.elements);
+            }
+        }
+    },
+
+    /**
+     * Returns true if the passed node is selected, else false.
+     * @param {HTMLElement/Number} node The node or node index to check
+     * @return {Boolean} True if selected, else false
+     */
+    isSelected : function(node){
+        return this.selected.contains(this.getNode(node));
+    },
+
+    /**
+     * Deselects a node.
+     * @param {HTMLElement/Number} node The node to deselect
+     */
+    deselect : function(node){
+        if(this.isSelected(node)){
+            node = this.getNode(node);
+            this.selected.removeElement(node);
+            if(this.last == node.viewIndex){
+                this.last = false;
+            }
+            Ext.fly(node).removeClass(this.selectedClass);
+            this.fireEvent("selectionchange", this, this.selected.elements);
+        }
+    },
+
+    /**
+     * Selects a set of nodes.
+     * @param {Array/HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node,
+     * id of a template node or an array of any of those to select
+     * @param {Boolean} keepExisting (optional) true to keep existing selections
+     * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
+     */
+    select : function(nodeInfo, keepExisting, suppressEvent){
+        if(Ext.isArray(nodeInfo)){
+            if(!keepExisting){
+                this.clearSelections(true);
+            }
+            for(var i = 0, len = nodeInfo.length; i < len; i++){
+                this.select(nodeInfo[i], true, true);
+            }
+            if(!suppressEvent){
+                this.fireEvent("selectionchange", this, this.selected.elements);
+            }
+        } else{
+            var node = this.getNode(nodeInfo);
+            if(!keepExisting){
+                this.clearSelections(true);
+            }
+            if(node && !this.isSelected(node)){
+                if(this.fireEvent("beforeselect", this, node, this.selected.elements) !== false){
+                    Ext.fly(node).addClass(this.selectedClass);
+                    this.selected.add(node);
+                    this.last = node.viewIndex;
+                    if(!suppressEvent){
+                        this.fireEvent("selectionchange", this, this.selected.elements);
+                    }
+                }
+            }
+        }
+    },
+
+    /**
+     * Selects a range of nodes. All nodes between start and end are selected.
+     * @param {Number} start The index of the first node in the range
+     * @param {Number} end The index of the last node in the range
+     * @param {Boolean} keepExisting (optional) True to retain existing selections
+     */
+    selectRange : function(start, end, keepExisting){
+        if(!keepExisting){
+            this.clearSelections(true);
+        }
+        this.select(this.getNodes(start, end), true);
+    },
+
+    /**
+     * Gets a template node.
+     * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
+     * @return {HTMLElement} The node or null if it wasn't found
+     */
+    getNode : function(nodeInfo){
+        if(Ext.isString(nodeInfo)){
+            return document.getElementById(nodeInfo);
+        }else if(Ext.isNumber(nodeInfo)){
+            return this.all.elements[nodeInfo];
+        }
+        return nodeInfo;
+    },
+
+    /**
+     * Gets a range nodes.
+     * @param {Number} start (optional) The index of the first node in the range
+     * @param {Number} end (optional) The index of the last node in the range
+     * @return {Array} An array of nodes
+     */
+    getNodes : function(start, end){
+        var ns = this.all.elements;
+        start = start || 0;
+        end = !Ext.isDefined(end) ? Math.max(ns.length - 1, 0) : end;
+        var nodes = [], i;
+        if(start <= end){
+            for(i = start; i <= end && ns[i]; i++){
+                nodes.push(ns[i]);
+            }
+        } else{
+            for(i = start; i >= end && ns[i]; i--){
+                nodes.push(ns[i]);
+            }
+        }
+        return nodes;
+    },
+
+    /**
+     * Finds the index of the passed node.
+     * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
+     * @return {Number} The index of the node or -1
+     */
+    indexOf : function(node){
+        node = this.getNode(node);
+        if(Ext.isNumber(node.viewIndex)){
+            return node.viewIndex;
+        }
+        return this.all.indexOf(node);
+    },
+
+    // private
+    onBeforeLoad : function(){
+        if(this.loadingText){
+            this.clearSelections(false, true);
+            this.getTemplateTarget().update('<div class="loading-indicator">'+this.loadingText+'</div>');
+            this.all.clear();
+        }
+    },
+
+    onDestroy : function(){
+        Ext.DataView.superclass.onDestroy.call(this);
+        this.bindStore(null);
+    }
+});
+
+/**
+ * Changes the data store bound to this view and refreshes it. (deprecated in favor of bindStore)
+ * @param {Store} store The store to bind to this view
+ */
+Ext.DataView.prototype.setStore = Ext.DataView.prototype.bindStore;
+
+Ext.reg('dataview', Ext.DataView);/**\r
+ * @class Ext.ListView\r
+ * @extends Ext.DataView\r
+ * <p>Ext.ListView is a fast and light-weight implentation of a\r
+ * {@link Ext.grid.GridPanel Grid} like view with the following characteristics:</p>\r
+ * <div class="mdetail-params"><ul>\r
+ * <li>resizable columns</li>\r
+ * <li>selectable</li>\r
+ * <li>column widths are initially proportioned by percentage based on the container\r
+ * width and number of columns</li>\r
+ * <li>uses templates to render the data in any required format</li>\r
+ * <li>no horizontal scrolling</li>\r
+ * <li>no editing</li>\r
+ * </ul></div>\r
+ * <p>Example usage:</p>\r
+ * <pre><code>\r
+// consume JSON of this form:\r
+{\r
+   "images":[\r
+      {\r
+         "name":"dance_fever.jpg",\r
+         "size":2067,\r
+         "lastmod":1236974993000,\r
+         "url":"images\/thumbs\/dance_fever.jpg"\r
+      },\r
+      {\r
+         "name":"zack_sink.jpg",\r
+         "size":2303,\r
+         "lastmod":1236974993000,\r
+         "url":"images\/thumbs\/zack_sink.jpg"\r
+      }\r
+   ]\r
+} \r
+var store = new Ext.data.JsonStore({\r
+    url: 'get-images.php',\r
+    root: 'images',\r
+    fields: [\r
+        'name', 'url',\r
+        {name:'size', type: 'float'},\r
+        {name:'lastmod', type:'date', dateFormat:'timestamp'}\r
+    ]\r
+});\r
+store.load();\r
+\r
+var listView = new Ext.ListView({\r
+    store: store,\r
+    multiSelect: true,\r
+    emptyText: 'No images to display',\r
+    reserveScrollOffset: true,\r
+    columns: [{\r
+        header: 'File',\r
+        width: .5,\r
+        dataIndex: 'name'\r
+    },{\r
+        header: 'Last Modified',\r
+        width: .35, \r
+        dataIndex: 'lastmod',\r
+        tpl: '{lastmod:date("m-d h:i a")}'\r
+    },{\r
+        header: 'Size',\r
+        dataIndex: 'size',\r
+        tpl: '{size:fileSize}', // format using Ext.util.Format.fileSize()\r
+        align: 'right'\r
+    }]\r
+});\r
+\r
+// put it in a Panel so it looks pretty\r
+var panel = new Ext.Panel({\r
+    id:'images-view',\r
+    width:425,\r
+    height:250,\r
+    collapsible:true,\r
+    layout:'fit',\r
+    title:'Simple ListView <i>(0 items selected)</i>',\r
+    items: listView\r
+});\r
+panel.render(document.body);\r
+\r
+// little bit of feedback\r
+listView.on('selectionchange', function(view, nodes){\r
+    var l = nodes.length;\r
+    var s = l != 1 ? 's' : '';\r
+    panel.setTitle('Simple ListView <i>('+l+' item'+s+' selected)</i>');\r
+});\r
+ * </code></pre>\r
+ * @constructor\r
+ * @param {Object} config\r
+ * @xtype listview\r
+ */\r
+Ext.ListView = Ext.extend(Ext.DataView, {\r
+    /**\r
+     * Set this property to <tt>true</tt> to disable the header click handler disabling sort\r
+     * (defaults to <tt>false</tt>).\r
+     * @type Boolean\r
+     * @property disableHeaders\r
+     */\r
+    /**\r
+     * @cfg {Boolean} hideHeaders\r
+     * <tt>true</tt> to hide the {@link #internalTpl header row} (defaults to <tt>false</tt> so\r
+     * the {@link #internalTpl header row} will be shown).\r
+     */\r
+    /**\r
+     * @cfg {String} itemSelector\r
+     * Defaults to <tt>'dl'</tt> to work with the preconfigured <b><tt>{@link Ext.DataView#tpl tpl}</tt></b>.\r
+     * This setting specifies the CSS selector (e.g. <tt>div.some-class</tt> or <tt>span:first-child</tt>)\r
+     * that will be used to determine what nodes the ListView will be working with.   \r
+     */\r
+    itemSelector: 'dl',\r
+    /**\r
+     * @cfg {String} selectedClass The CSS class applied to a selected row (defaults to\r
+     * <tt>'x-list-selected'</tt>). An example overriding the default styling:\r
+    <pre><code>\r
+    .x-list-selected {background-color: yellow;}\r
+    </code></pre>\r
+     * @type String\r
+     */\r
+    selectedClass:'x-list-selected',\r
+    /**\r
+     * @cfg {String} overClass The CSS class applied when over a row (defaults to\r
+     * <tt>'x-list-over'</tt>). An example overriding the default styling:\r
+    <pre><code>\r
+    .x-list-over {background-color: orange;}\r
+    </code></pre>\r
+     * @type String\r
+     */\r
+    overClass:'x-list-over',\r
+    /**\r
+     * @cfg {Boolean} reserveScrollOffset\r
+     * By default will defer accounting for the configured <b><tt>{@link #scrollOffset}</tt></b>\r
+     * for 10 milliseconds.  Specify <tt>true</tt> to account for the configured\r
+     * <b><tt>{@link #scrollOffset}</tt></b> immediately.\r
+     */\r
+    /**\r
+     * @cfg {Number} scrollOffset The amount of space to reserve for the scrollbar (defaults to\r
+     * <tt>19</tt> pixels)\r
+     */\r
+    scrollOffset : 19,\r
+    /**\r
+     * @cfg {Boolean/Object} columnResize\r
+     * Specify <tt>true</tt> or specify a configuration object for {@link Ext.ListView.ColumnResizer}\r
+     * to enable the columns to be resizable (defaults to <tt>true</tt>).\r
+     */\r
+    columnResize: true,\r
+    /**\r
+     * @cfg {Array} columns An array of column configuration objects, for example:\r
+     * <pre><code>\r
+{\r
+    align: 'right',\r
+    dataIndex: 'size',\r
+    header: 'Size',\r
+    tpl: '{size:fileSize}',\r
+    width: .35\r
+}\r
+     * </code></pre> \r
+     * Acceptable properties for each column configuration object are:\r
+     * <div class="mdetail-params"><ul>\r
+     * <li><b><tt>align</tt></b> : String<div class="sub-desc">Set the CSS text-align property\r
+     * of the column. Defaults to <tt>'left'</tt>.</div></li>\r
+     * <li><b><tt>dataIndex</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.\r
+     * {@link Ext.grid.Column#dataIndex dataIndex} for details.</div></li>\r
+     * <li><b><tt>header</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.\r
+     * {@link Ext.grid.Column#header header} for details.</div></li>\r
+     * <li><b><tt>tpl</tt></b> : String<div class="sub-desc">Specify a string to pass as the\r
+     * configuration string for {@link Ext.XTemplate}.  By default an {@link Ext.XTemplate}\r
+     * will be implicitly created using the <tt>dataIndex</tt>.</div></li>\r
+     * <li><b><tt>width</tt></b> : Number<div class="sub-desc">Percentage of the container width\r
+     * this column should be allocated.  Columns that have no width specified will be\r
+     * allocated with an equal percentage to fill 100% of the container width.  To easily take\r
+     * advantage of the full container width, leave the width of at least one column undefined.\r
+     * Note that if you do not want to take up the full width of the container, the width of\r
+     * every column needs to be explicitly defined.</div></li>\r
+     * </ul></div>\r
+     */\r
+    /**\r
+     * @cfg {Boolean/Object} columnSort\r
+     * Specify <tt>true</tt> or specify a configuration object for {@link Ext.ListView.Sorter}\r
+     * to enable the columns to be sortable (defaults to <tt>true</tt>).\r
+     */\r
+    columnSort: true,\r
+    /**\r
+     * @cfg {String/Array} internalTpl\r
+     * The template to be used for the header row.  See {@link #tpl} for more details.\r
+     */\r
+\r
+    initComponent : function(){\r
+        if(this.columnResize){\r
+            this.colResizer = new Ext.ListView.ColumnResizer(this.colResizer);\r
+            this.colResizer.init(this);\r
+        }\r
+        if(this.columnSort){\r
+            this.colSorter = new Ext.ListView.Sorter(this.columnSort);\r
+            this.colSorter.init(this);\r
+        }\r
+        if(!this.internalTpl){\r
+            this.internalTpl = new Ext.XTemplate(\r
+                '<div class="x-list-header"><div class="x-list-header-inner">',\r
+                    '<tpl for="columns">',\r
+                    '<div style="width:{width}%;text-align:{align};"><em unselectable="on" id="',this.id, '-xlhd-{#}">',\r
+                        '{header}',\r
+                    '</em></div>',\r
+                    '</tpl>',\r
+                    '<div class="x-clear"></div>',\r
+                '</div></div>',\r
+                '<div class="x-list-body"><div class="x-list-body-inner">',\r
+                '</div></div>'\r
+            );\r
+        }\r
+        if(!this.tpl){\r
+            this.tpl = new Ext.XTemplate(\r
+                '<tpl for="rows">',\r
+                    '<dl>',\r
+                        '<tpl for="parent.columns">',\r
+                        '<dt style="width:{width}%;text-align:{align};"><em unselectable="on">',\r
+                            '{[values.tpl.apply(parent)]}',\r
+                        '</em></dt>',\r
+                        '</tpl>',\r
+                        '<div class="x-clear"></div>',\r
+                    '</dl>',\r
+                '</tpl>'\r
+            );\r
+        };\r
+        var cs = this.columns, allocatedWidth = 0, colsWithWidth = 0, len = cs.length;\r
+        for(var i = 0; i < len; i++){\r
+            var c = cs[i];\r
+            if(!c.tpl){\r
+                c.tpl = new Ext.XTemplate('{' + c.dataIndex + '}');\r
+            }else if(Ext.isString(c.tpl)){\r
+                c.tpl = new Ext.XTemplate(c.tpl);\r
+            }\r
+            c.align = c.align || 'left';\r
+            if(Ext.isNumber(c.width)){\r
+                c.width *= 100;\r
+                allocatedWidth += c.width;\r
+                colsWithWidth++;\r
+            }\r
+        }\r
+        // auto calculate missing column widths\r
+        if(colsWithWidth < len){\r
+            var remaining = len - colsWithWidth;\r
+            if(allocatedWidth < 100){\r
+                var perCol = ((100-allocatedWidth) / remaining);\r
+                for(var j = 0; j < len; j++){\r
+                    var c = cs[j];\r
+                    if(!Ext.isNumber(c.width)){\r
+                        c.width = perCol;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        Ext.ListView.superclass.initComponent.call(this);\r
+    },\r
+\r
+    onRender : function(){\r
+        Ext.ListView.superclass.onRender.apply(this, arguments);\r
+\r
+        this.internalTpl.overwrite(this.el, {columns: this.columns});\r
+        \r
+        this.innerBody = Ext.get(this.el.dom.childNodes[1].firstChild);\r
+        this.innerHd = Ext.get(this.el.dom.firstChild.firstChild);\r
+\r
+        if(this.hideHeaders){\r
+            this.el.dom.firstChild.style.display = 'none';\r
+        }\r
+    },\r
+\r
+    getTemplateTarget : function(){\r
+        return this.innerBody;\r
+    },\r
+\r
+    /**\r
+     * <p>Function which can be overridden which returns the data object passed to this\r
+     * view's {@link #tpl template} to render the whole ListView. The returned object \r
+     * shall contain the following properties:</p>\r
+     * <div class="mdetail-params"><ul>\r
+     * <li><b>columns</b> : String<div class="sub-desc">See <tt>{@link #columns}</tt></div></li>\r
+     * <li><b>rows</b> : String<div class="sub-desc">See\r
+     * <tt>{@link Ext.DataView}.{@link Ext.DataView#collectData collectData}</div></li>\r
+     * </ul></div>\r
+     * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.\r
+     * @param {Number} startIndex the index number of the Record being prepared for rendering.\r
+     * @return {Object} A data object containing properties to be processed by a repeating\r
+     * XTemplate as described above.\r
+     */\r
+    collectData : function(){\r
+        var rs = Ext.ListView.superclass.collectData.apply(this, arguments);\r
+        return {\r
+            columns: this.columns,\r
+            rows: rs\r
+        }\r
+    },\r
+\r
+    verifyInternalSize : function(){\r
+        if(this.lastSize){\r
+            this.onResize(this.lastSize.width, this.lastSize.height);\r
+        }\r
+    },\r
+\r
+    // private\r
+    onResize : function(w, h){\r
+        var bd = this.innerBody.dom;\r
+        var hd = this.innerHd.dom\r
+        if(!bd){\r
+            return;\r
+        }\r
+        var bdp = bd.parentNode;\r
+        if(Ext.isNumber(w)){\r
+            var sw = w - this.scrollOffset;\r
+            if(this.reserveScrollOffset || ((bdp.offsetWidth - bdp.clientWidth) > 10)){\r
+                bd.style.width = sw + 'px';\r
+                hd.style.width = sw + 'px';\r
+            }else{\r
+                bd.style.width = w + 'px';\r
+                hd.style.width = w + 'px';\r
+                setTimeout(function(){\r
+                    if((bdp.offsetWidth - bdp.clientWidth) > 10){\r
+                        bd.style.width = sw + 'px';\r
+                        hd.style.width = sw + 'px';\r
+                    }\r
+                }, 10);\r
+            }\r
+        }\r
+        if(Ext.isNumber(h == 'number')){\r
+            bdp.style.height = (h - hd.parentNode.offsetHeight) + 'px';\r
+        }\r
+    },\r
+\r
+    updateIndexes : function(){\r
+        Ext.ListView.superclass.updateIndexes.apply(this, arguments);\r
+        this.verifyInternalSize();\r
+    },\r
+\r
+    findHeaderIndex : function(hd){\r
+        hd = hd.dom || hd;\r
+        var pn = hd.parentNode, cs = pn.parentNode.childNodes;\r
+        for(var i = 0, c; c = cs[i]; i++){\r
+            if(c == pn){\r
+                return i;\r
+            }\r
+        }\r
+        return -1;\r
+    },\r
+\r
+    setHdWidths : function(){\r
+        var els = this.innerHd.dom.getElementsByTagName('div');\r
+        for(var i = 0, cs = this.columns, len = cs.length; i < len; i++){\r
+            els[i].style.width = cs[i].width + '%';\r
+        }\r
+    }\r
+});\r
+\r
+Ext.reg('listview', Ext.ListView);/**\r
+ * @class Ext.ListView.ColumnResizer\r
+ * @extends Ext.util.Observable\r
+ * <p>Supporting Class for Ext.ListView.</p>\r
+ * @constructor\r
+ * @param {Object} config\r
+ */\r
+Ext.ListView.ColumnResizer = Ext.extend(Ext.util.Observable, {\r
+    /**\r
+     * @cfg {Number} minPct The minimum percentage to allot for any column (defaults to <tt>.05</tt>)\r
+     */\r
+    minPct: .05,\r
+\r
+    constructor: function(config){\r
+        Ext.apply(this, config);\r
+        Ext.ListView.ColumnResizer.superclass.constructor.call(this);\r
+    },\r
+    init : function(listView){\r
+        this.view = listView;\r
+        listView.on('render', this.initEvents, this);\r
+    },\r
+\r
+    initEvents : function(view){\r
+        view.mon(view.innerHd, 'mousemove', this.handleHdMove, this);\r
+        this.tracker = new Ext.dd.DragTracker({\r
+            onBeforeStart: this.onBeforeStart.createDelegate(this),\r
+            onStart: this.onStart.createDelegate(this),\r
+            onDrag: this.onDrag.createDelegate(this),\r
+            onEnd: this.onEnd.createDelegate(this),\r
+            tolerance: 3,\r
+            autoStart: 300\r
+        });\r
+        this.tracker.initEl(view.innerHd);\r
+        view.on('beforedestroy', this.tracker.destroy, this.tracker);\r
+    },\r
+\r
+    handleHdMove : function(e, t){\r
+        var hw = 5;\r
+        var x = e.getPageX();\r
+        var hd = e.getTarget('em', 3, true);\r
+        if(hd){\r
+            var r = hd.getRegion();\r
+            var ss = hd.dom.style;\r
+            var pn = hd.dom.parentNode;\r
+\r
+            if(x - r.left <= hw && pn != pn.parentNode.firstChild){\r
+                this.activeHd = Ext.get(pn.previousSibling.firstChild);\r
+                               ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';\r
+            } else if(r.right - x <= hw && pn != pn.parentNode.lastChild.previousSibling){\r
+                this.activeHd = hd;\r
+                               ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';\r
+            } else{\r
+                delete this.activeHd;\r
+                ss.cursor = '';\r
+            }\r
+        }\r
+    },\r
+\r
+    onBeforeStart : function(e){\r
+        this.dragHd = this.activeHd;\r
+        return !!this.dragHd;\r
+    },\r
+\r
+    onStart: function(e){\r
+        this.view.disableHeaders = true;\r
+        this.proxy = this.view.el.createChild({cls:'x-list-resizer'});\r
+        this.proxy.setHeight(this.view.el.getHeight());\r
+\r
+        var x = this.tracker.getXY()[0];\r
+        var w = this.view.innerHd.getWidth();\r
+\r
+        this.hdX = this.dragHd.getX();\r
+        this.hdIndex = this.view.findHeaderIndex(this.dragHd);\r
+\r
+        this.proxy.setX(this.hdX);\r
+        this.proxy.setWidth(x-this.hdX);\r
+\r
+        this.minWidth = w*this.minPct;\r
+        this.maxWidth = w - (this.minWidth*(this.view.columns.length-1-this.hdIndex));\r
+    },\r
+\r
+    onDrag: function(e){\r
+        var cursorX = this.tracker.getXY()[0];\r
+        this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));\r
+    },\r
+\r
+    onEnd: function(e){\r
+        var nw = this.proxy.getWidth();\r
+        this.proxy.remove();\r
+\r
+        var index = this.hdIndex;\r
+        var vw = this.view, cs = vw.columns, len = cs.length;\r
+        var w = this.view.innerHd.getWidth(), minPct = this.minPct * 100;\r
+\r
+        var pct = Math.ceil((nw*100) / w);\r
+        var diff = cs[index].width - pct;\r
+        var each = Math.floor(diff / (len-1-index));\r
+        var mod = diff - (each * (len-1-index));\r
+\r
+        for(var i = index+1; i < len; i++){\r
+            var cw = cs[i].width + each;\r
+            var ncw = Math.max(minPct, cw);\r
+            if(cw != ncw){\r
+                mod += cw - ncw;\r
+            }\r
+            cs[i].width = ncw;\r
+        }\r
+        cs[index].width = pct;\r
+        cs[index+1].width += mod;\r
+        delete this.dragHd;\r
+        this.view.setHdWidths();\r
+        this.view.refresh();\r
+        setTimeout(function(){\r
+            vw.disableHeaders = false;\r
+        }, 100);\r
+    }\r
+});/**\r
+ * @class Ext.ListView.Sorter\r
+ * @extends Ext.util.Observable\r
+ * <p>Supporting Class for Ext.ListView.</p>\r
+ * @constructor\r
+ * @param {Object} config\r
+ */\r
+Ext.ListView.Sorter = Ext.extend(Ext.util.Observable, {\r
+    /**\r
+     * @cfg {Array} sortClasses\r
+     * The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)\r
+     */\r
+    sortClasses : ["sort-asc", "sort-desc"],\r
+\r
+    constructor: function(config){\r
+        Ext.apply(this, config);\r
+        Ext.ListView.Sorter.superclass.constructor.call(this);\r
+    },\r
+\r
+    init : function(listView){\r
+        this.view = listView;\r
+        listView.on('render', this.initEvents, this);\r
+    },\r
+\r
+    initEvents : function(view){\r
+        view.mon(view.innerHd, 'click', this.onHdClick, this);\r
+        view.innerHd.setStyle('cursor', 'pointer');\r
+        view.mon(view.store, 'datachanged', this.updateSortState, this);\r
+        this.updateSortState.defer(10, this, [view.store]);\r
+    },\r
+\r
+    updateSortState : function(store){\r
+        var state = store.getSortState();\r
+        if(!state){\r
+            return;\r
+        }\r
+        this.sortState = state;\r
+        var cs = this.view.columns, sortColumn = -1;\r
+        for(var i = 0, len = cs.length; i < len; i++){\r
+            if(cs[i].dataIndex == state.field){\r
+                sortColumn = i;\r
+                break;\r
+            }\r
+        }\r
+        if(sortColumn != -1){\r
+            var sortDir = state.direction;\r
+            this.updateSortIcon(sortColumn, sortDir);\r
+        }\r
+    },\r
+\r
+    updateSortIcon : function(col, dir){\r
+        var sc = this.sortClasses;\r
+        var hds = this.view.innerHd.select('em').removeClass(sc);\r
+        hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);\r
+    },\r
+\r
+    onHdClick : function(e){\r
+        var hd = e.getTarget('em', 3);\r
+        if(hd && !this.view.disableHeaders){\r
+            var index = this.view.findHeaderIndex(hd);\r
+            this.view.store.sort(this.view.columns[index].dataIndex);\r
+        }\r
+    }\r
+});
\ No newline at end of file