Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / examples / ux / grid / menu / ListMenu.js
similarity index 71%
rename from examples/ux/gridfilters/menu/ListMenu.js
rename to examples/ux/grid/menu/ListMenu.js
index 95a7808..4fac001 100644 (file)
@@ -1,19 +1,13 @@
-/*!
- * Ext JS Library 3.3.1
- * Copyright(c) 2006-2010 Sencha Inc.
- * licensing@sencha.com
- * http://www.sencha.com/license
- */
-Ext.namespace('Ext.ux.menu');
-
-/** 
- * @class Ext.ux.menu.ListMenu
+/**
+ * @class Ext.ux.grid.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, {
+Ext.define('Ext.ux.grid.menu.ListMenu', {
+    extend: 'Ext.menu.Menu',
+
     /**
      * @cfg {String} labelField
      * Defaults to 'text'.
@@ -47,9 +41,9 @@ Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
              */
             'checkchange'
         );
-      
-        Ext.ux.menu.ListMenu.superclass.constructor.call(this, cfg = cfg || {});
-    
+
+        this.callParent([cfg = cfg || {}]);
+
         if(!cfg.store && cfg.options){
             var options = [];
             for(var i=0, len=cfg.options.length; i<len; i++){
@@ -60,9 +54,9 @@ Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
                     case 'string': options.push([value, value]); break;
                 }
             }
-            
-            this.store = new Ext.data.Store({
-                reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]),
+
+            this.store = Ext.create('Ext.data.ArrayStore', {
+                fields: ['id', this.labelField],
                 data:   options,
                 listeners: {
                     'load': this.onLoad,
@@ -78,9 +72,9 @@ Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
 
     destroy : function () {
         if (this.store) {
-            this.store.destroy();    
+            this.store.destroy();
         }
-        Ext.ux.menu.ListMenu.superclass.destroy.call(this);
+        this.callParent();
     },
 
     /**
@@ -94,44 +88,49 @@ Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
         var lastArgs = null;
         return function(){
             if(arguments.length === 0){
-                Ext.ux.menu.ListMenu.superclass.show.apply(this, lastArgs);
+                this.callParent(lastArgs);
             } else {
                 lastArgs = arguments;
                 if (this.loadOnShow && !this.loaded) {
                     this.store.load();
                 }
-                Ext.ux.menu.ListMenu.superclass.show.apply(this, arguments);
+                this.callParent(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);
+        var me = this,
+            visible = me.isVisible(),
+            gid, item, itemValue, i, len;
+
+        me.hide(false);
+
+        me.removeAll(true);
+
+        gid = me.single ? Ext.id() : null;
+        for (i = 0, len = records.length; i < len; i++) {
+            itemValue = records[i].get('id');
+            item = Ext.create('Ext.menu.CheckItem', {
+                text: records[i].get(me.labelField),
+                group: gid,
+                checked: Ext.Array.contains(me.selected, itemValue),
+                hideOnClick: false,
+                value: itemValue
+            });
+
+            item.on('checkchange', me.checkChange, me);
+
+            me.add(item);
         }
-        
-        this.loaded = true;
-        
+
+        me.loaded = true;
+
         if (visible) {
-            this.show();
-        }      
-        this.fireEvent('load', this, records);
+            me.show();
+        }
+        me.fireEvent('load', me, records);
     },
 
     /**
@@ -141,7 +140,7 @@ Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
     getSelected : function () {
         return this.selected;
     },
-    
+
     /** @private */
     setSelected : function (value) {
         value = this.selected = [].concat(value);
@@ -150,14 +149,14 @@ Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
             this.items.each(function(item){
                 item.setChecked(false, true);
                 for (var i = 0, len = value.length; i < len; i++) {
-                    if (item.itemId == value[i]) {
+                    if (item.value == 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
@@ -167,11 +166,11 @@ Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
         var value = [];
         this.items.each(function(item){
             if (item.checked) {
-                value.push(item.itemId);
+                value.push(item.value);
             }
         },this);
         this.selected = value;
-        
+
         this.fireEvent('checkchange', item, checked);
-    }    
-});
\ No newline at end of file
+    }
+});