3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.ux.grid.menu.ListMenu
17 * @extends Ext.menu.Menu
18 * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.
19 * Although not listed as configuration options for this class, this class
20 * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.
22 Ext.define('Ext.ux.grid.menu.ListMenu', {
23 extend: 'Ext.menu.Menu',
26 * @cfg {String} labelField
31 * @cfg {String} paramPrefix
32 * Defaults to 'Loading...'.
34 loadingText : 'Loading...',
36 * @cfg {Boolean} loadOnShow
41 * @cfg {Boolean} single
42 * Specify true to group all items in this list into a single-select
43 * radio button group. Defaults to false.
47 constructor : function (cfg) {
52 * Fires when there is a change in checked items from this list
53 * @param {Object} item Ext.menu.CheckItem
54 * @param {Object} checked The checked value that was set
59 this.callParent([cfg = cfg || {}]);
61 if(!cfg.store && cfg.options){
63 for(var i=0, len=cfg.options.length; i<len; i++){
64 var value = cfg.options[i];
65 switch(Ext.type(value)){
66 case 'array': options.push(value); break;
67 case 'object': options.push([value.id, value[this.labelField]]); break;
68 case 'string': options.push([value, value]); break;
72 this.store = Ext.create('Ext.data.ArrayStore', {
73 fields: ['id', this.labelField],
82 this.add({text: this.loadingText, iconCls: 'loading-indicator'});
83 this.store.on('load', this.onLoad, this);
87 destroy : function () {
89 this.store.destroyStore();
95 * Lists will initially show a 'loading' item while the data is retrieved from the store.
96 * In some cases the loaded data will result in a list that goes off the screen to the
97 * right (as placement calculations were done with the loading item). This adapter will
98 * allow show to be called with no arguments to show with the previous arguments and
99 * thus recalculate the width and potentially hang the menu from the left.
104 if(arguments.length === 0){
105 this.callParent(lastArgs);
107 lastArgs = arguments;
108 if (this.loadOnShow && !this.loaded) {
111 this.callParent(arguments);
117 onLoad : function (store, records) {
119 visible = me.isVisible(),
120 gid, item, itemValue, i, len;
126 gid = me.single ? Ext.id() : null;
127 for (i = 0, len = records.length; i < len; i++) {
128 itemValue = records[i].get('id');
129 item = Ext.create('Ext.menu.CheckItem', {
130 text: records[i].get(me.labelField),
132 checked: Ext.Array.contains(me.selected, itemValue),
137 item.on('checkchange', me.checkChange, me);
147 me.fireEvent('load', me, records);
151 * Get the selected items.
152 * @return {Array} selected
154 getSelected : function () {
155 return this.selected;
159 setSelected : function (value) {
160 value = this.selected = [].concat(value);
163 this.items.each(function(item){
164 item.setChecked(false, true);
165 for (var i = 0, len = value.length; i < len; i++) {
166 if (item.value == value[i]) {
167 item.setChecked(true, true);
175 * Handler for the 'checkchange' event from an check item in this menu
176 * @param {Object} item Ext.menu.CheckItem
177 * @param {Object} checked The checked value that was set
179 checkChange : function (item, checked) {
181 this.items.each(function(item){
183 value.push(item.value);
186 this.selected = value;
188 this.fireEvent('checkchange', item, checked);