Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / examples / ux / gridfilters / menu / ListMenu.js
index 4687d25..a6fe81a 100644 (file)
 /*!
- * Ext JS Library 3.1.1
- * Copyright(c) 2006-2010 Ext JS, LLC
+ * Ext JS Library 3.2.0
+ * Copyright(c) 2006-2010 Ext JS, Inc.
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
-Ext.namespace('Ext.ux.menu');\r
-\r
-/** \r
- * @class Ext.ux.menu.ListMenu\r
- * @extends Ext.menu.Menu\r
- * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.\r
- * Although not listed as configuration options for this class, this class\r
- * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.\r
- */\r
-Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {\r
-    /**\r
-     * @cfg {String} labelField\r
-     * Defaults to 'text'.\r
-     */\r
-    labelField :  'text',\r
-    /**\r
-     * @cfg {String} paramPrefix\r
-     * Defaults to 'Loading...'.\r
-     */\r
-    loadingText : 'Loading...',\r
-    /**\r
-     * @cfg {Boolean} loadOnShow\r
-     * Defaults to true.\r
-     */\r
-    loadOnShow : true,\r
-    /**\r
-     * @cfg {Boolean} single\r
-     * Specify true to group all items in this list into a single-select\r
-     * radio button group. Defaults to false.\r
-     */\r
-    single : false,\r
-\r
-    constructor : function (cfg) {\r
-        this.selected = [];\r
-        this.addEvents(\r
-            /**\r
-             * @event checkchange\r
-             * Fires when there is a change in checked items from this list\r
-             * @param {Object} item Ext.menu.CheckItem\r
-             * @param {Object} checked The checked value that was set\r
-             */\r
-            'checkchange'\r
-        );\r
-      \r
-        Ext.ux.menu.ListMenu.superclass.constructor.call(this, cfg = cfg || {});\r
-    \r
-        if(!cfg.store && cfg.options){\r
-            var options = [];\r
-            for(var i=0, len=cfg.options.length; i<len; i++){\r
-                var value = cfg.options[i];\r
-                switch(Ext.type(value)){\r
-                    case 'array':  options.push(value); break;\r
-                    case 'object': options.push([value.id, value[this.labelField]]); break;\r
-                    case 'string': options.push([value, value]); break;\r
-                }\r
-            }\r
-            \r
-            this.store = new Ext.data.Store({\r
-                reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]),\r
-                data:   options,\r
-                listeners: {\r
-                    'load': this.onLoad,\r
-                    scope:  this\r
-                }\r
-            });\r
-            this.loaded = true;\r
-        } else {\r
-            this.add({text: this.loadingText, iconCls: 'loading-indicator'});\r
-            this.store.on('load', this.onLoad, this);\r
-        }\r
-    },\r
-\r
-    destroy : function () {\r
-        if (this.store) {\r
-            this.store.destroy();    \r
-        }\r
-        Ext.ux.menu.ListMenu.superclass.destroy.call(this);\r
-    },\r
-\r
-    /**\r
-     * Lists will initially show a 'loading' item while the data is retrieved from the store.\r
-     * In some cases the loaded data will result in a list that goes off the screen to the\r
-     * right (as placement calculations were done with the loading item). This adapter will\r
-     * allow show to be called with no arguments to show with the previous arguments and\r
-     * thus recalculate the width and potentially hang the menu from the left.\r
-     */\r
-    show : function () {\r
-        var lastArgs = null;\r
-        return function(){\r
-            if(arguments.length === 0){\r
-                Ext.ux.menu.ListMenu.superclass.show.apply(this, lastArgs);\r
-            } else {\r
-                lastArgs = arguments;\r
-                if (this.loadOnShow && !this.loaded) {\r
-                    this.store.load();\r
-                }\r
-                Ext.ux.menu.ListMenu.superclass.show.apply(this, arguments);\r
-            }\r
-        };\r
-    }(),\r
-    \r
-    /** @private */\r
-    onLoad : function (store, records) {\r
-        var visible = this.isVisible();\r
-        this.hide(false);\r
-        \r
-        this.removeAll(true);\r
-        \r
-        var gid = this.single ? Ext.id() : null;\r
-        for(var i=0, len=records.length; i<len; i++){\r
-            var item = new Ext.menu.CheckItem({\r
-                text:    records[i].get(this.labelField), \r
-                group:   gid,\r
-                checked: this.selected.indexOf(records[i].id) > -1,\r
-                hideOnClick: false});\r
-            \r
-            item.itemId = records[i].id;\r
-            item.on('checkchange', this.checkChange, this);\r
-                        \r
-            this.add(item);\r
-        }\r
-        \r
-        this.loaded = true;\r
-        \r
-        if (visible) {\r
-            this.show();\r
-        }      \r
-        this.fireEvent('load', this, records);\r
-    },\r
-\r
-    /**\r
-     * Get the selected items.\r
-     * @return {Array} selected\r
-     */\r
-    getSelected : function () {\r
-        return this.selected;\r
-    },\r
-    \r
-    /** @private */\r
-    setSelected : function (value) {\r
-        value = this.selected = [].concat(value);\r
-\r
-        if (this.loaded) {\r
-            this.items.each(function(item){\r
-                item.setChecked(false, true);\r
-                for (var i = 0, len = value.length; i < len; i++) {\r
-                    if (item.itemId == value[i]) {\r
-                        item.setChecked(true, true);\r
-                    }\r
-                }\r
-            }, this);\r
-        }\r
-    },\r
-    \r
-    /**\r
-     * Handler for the 'checkchange' event from an check item in this menu\r
-     * @param {Object} item Ext.menu.CheckItem\r
-     * @param {Object} checked The checked value that was set\r
-     */\r
-    checkChange : function (item, checked) {\r
-        var value = [];\r
-        this.items.each(function(item){\r
-            if (item.checked) {\r
-                value.push(item.itemId);\r
-            }\r
-        },this);\r
-        this.selected = value;\r
-        \r
-        this.fireEvent('checkchange', item, checked);\r
-    }    \r
+Ext.namespace('Ext.ux.menu');
+
+/** 
+ * @class Ext.ux.menu.ListMenu
+ * @extends Ext.menu.Menu
+ * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.
+ * Although not listed as configuration options for this class, this class
+ * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.
+ */
+Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
+    /**
+     * @cfg {String} labelField
+     * Defaults to 'text'.
+     */
+    labelField :  'text',
+    /**
+     * @cfg {String} paramPrefix
+     * Defaults to 'Loading...'.
+     */
+    loadingText : 'Loading...',
+    /**
+     * @cfg {Boolean} loadOnShow
+     * Defaults to true.
+     */
+    loadOnShow : true,
+    /**
+     * @cfg {Boolean} single
+     * Specify true to group all items in this list into a single-select
+     * radio button group. Defaults to false.
+     */
+    single : false,
+
+    constructor : function (cfg) {
+        this.selected = [];
+        this.addEvents(
+            /**
+             * @event checkchange
+             * Fires when there is a change in checked items from this list
+             * @param {Object} item Ext.menu.CheckItem
+             * @param {Object} checked The checked value that was set
+             */
+            'checkchange'
+        );
+      
+        Ext.ux.menu.ListMenu.superclass.constructor.call(this, cfg = cfg || {});
+    
+        if(!cfg.store && cfg.options){
+            var options = [];
+            for(var i=0, len=cfg.options.length; i<len; i++){
+                var value = cfg.options[i];
+                switch(Ext.type(value)){
+                    case 'array':  options.push(value); break;
+                    case 'object': options.push([value.id, value[this.labelField]]); break;
+                    case 'string': options.push([value, value]); break;
+                }
+            }
+            
+            this.store = new Ext.data.Store({
+                reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]),
+                data:   options,
+                listeners: {
+                    'load': this.onLoad,
+                    scope:  this
+                }
+            });
+            this.loaded = true;
+        } else {
+            this.add({text: this.loadingText, iconCls: 'loading-indicator'});
+            this.store.on('load', this.onLoad, this);
+        }
+    },
+
+    destroy : function () {
+        if (this.store) {
+            this.store.destroy();    
+        }
+        Ext.ux.menu.ListMenu.superclass.destroy.call(this);
+    },
+
+    /**
+     * Lists will initially show a 'loading' item while the data is retrieved from the store.
+     * In some cases the loaded data will result in a list that goes off the screen to the
+     * right (as placement calculations were done with the loading item). This adapter will
+     * allow show to be called with no arguments to show with the previous arguments and
+     * thus recalculate the width and potentially hang the menu from the left.
+     */
+    show : function () {
+        var lastArgs = null;
+        return function(){
+            if(arguments.length === 0){
+                Ext.ux.menu.ListMenu.superclass.show.apply(this, lastArgs);
+            } else {
+                lastArgs = arguments;
+                if (this.loadOnShow && !this.loaded) {
+                    this.store.load();
+                }
+                Ext.ux.menu.ListMenu.superclass.show.apply(this, arguments);
+            }
+        };
+    }(),
+    
+    /** @private */
+    onLoad : function (store, records) {
+        var visible = this.isVisible();
+        this.hide(false);
+        
+        this.removeAll(true);
+        
+        var gid = this.single ? Ext.id() : null;
+        for(var i=0, len=records.length; i<len; i++){
+            var item = new Ext.menu.CheckItem({
+                text:    records[i].get(this.labelField), 
+                group:   gid,
+                checked: this.selected.indexOf(records[i].id) > -1,
+                hideOnClick: false});
+            
+            item.itemId = records[i].id;
+            item.on('checkchange', this.checkChange, this);
+                        
+            this.add(item);
+        }
+        
+        this.loaded = true;
+        
+        if (visible) {
+            this.show();
+        }      
+        this.fireEvent('load', this, records);
+    },
+
+    /**
+     * Get the selected items.
+     * @return {Array} selected
+     */
+    getSelected : function () {
+        return this.selected;
+    },
+    
+    /** @private */
+    setSelected : function (value) {
+        value = this.selected = [].concat(value);
+
+        if (this.loaded) {
+            this.items.each(function(item){
+                item.setChecked(false, true);
+                for (var i = 0, len = value.length; i < len; i++) {
+                    if (item.itemId == value[i]) {
+                        item.setChecked(true, true);
+                    }
+                }
+            }, this);
+        }
+    },
+    
+    /**
+     * Handler for the 'checkchange' event from an check item in this menu
+     * @param {Object} item Ext.menu.CheckItem
+     * @param {Object} checked The checked value that was set
+     */
+    checkChange : function (item, checked) {
+        var value = [];
+        this.items.each(function(item){
+            if (item.checked) {
+                value.push(item.itemId);
+            }
+        },this);
+        this.selected = value;
+        
+        this.fireEvent('checkchange', item, checked);
+    }    
 });
\ No newline at end of file