3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">Ext.namespace('Ext.ux.menu');
\r
10 <div id="cls-Ext.ux.menu.ListMenu"></div>/**
\r
11 * @class Ext.ux.menu.ListMenu
\r
12 * @extends Ext.menu.Menu
\r
13 * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.
\r
14 * Although not listed as configuration options for this class, this class
\r
15 * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.
\r
17 Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
\r
18 <div id="cfg-Ext.ux.menu.ListMenu-labelField"></div>/**
\r
19 * @cfg {String} labelField
\r
20 * Defaults to 'text'.
\r
22 labelField : 'text',
\r
23 <div id="cfg-Ext.ux.menu.ListMenu-paramPrefix"></div>/**
\r
24 * @cfg {String} paramPrefix
\r
25 * Defaults to 'Loading...'.
\r
27 loadingText : 'Loading...',
\r
28 <div id="cfg-Ext.ux.menu.ListMenu-loadOnShow"></div>/**
\r
29 * @cfg {Boolean} loadOnShow
\r
33 <div id="cfg-Ext.ux.menu.ListMenu-single"></div>/**
\r
34 * @cfg {Boolean} single
\r
35 * Specify true to group all items in this list into a single-select
\r
36 * radio button group. Defaults to false.
\r
40 constructor : function (cfg) {
\r
43 <div id="event-Ext.ux.menu.ListMenu-checkchange"></div>/**
\r
44 * @event checkchange
\r
45 * Fires when there is a change in checked items from this list
\r
46 * @param {Object} item Ext.menu.CheckItem
\r
47 * @param {Object} checked The checked value that was set
\r
52 Ext.ux.menu.ListMenu.superclass.constructor.call(this, cfg = cfg || {});
\r
54 if(!cfg.store && cfg.options){
\r
56 for(var i=0, len=cfg.options.length; i<len; i++){
\r
57 var value = cfg.options[i];
\r
58 switch(Ext.type(value)){
\r
59 case 'array': options.push(value); break;
\r
60 case 'object': options.push([value.id, value[this.labelField]]); break;
\r
61 case 'string': options.push([value, value]); break;
\r
65 this.store = new Ext.data.Store({
\r
66 reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]),
\r
69 'load': this.onLoad,
\r
75 this.add({text: this.loadingText, iconCls: 'loading-indicator'});
\r
76 this.store.on('load', this.onLoad, this);
\r
80 destroy : function () {
\r
82 this.store.destroy();
\r
84 Ext.ux.menu.ListMenu.superclass.destroy.call(this);
\r
87 <div id="method-Ext.ux.menu.ListMenu-show"></div>/**
\r
88 * Lists will initially show a 'loading' item while the data is retrieved from the store.
\r
89 * In some cases the loaded data will result in a list that goes off the screen to the
\r
90 * right (as placement calculations were done with the loading item). This adapter will
\r
91 * allow show to be called with no arguments to show with the previous arguments and
\r
92 * thus recalculate the width and potentially hang the menu from the left.
\r
94 show : function () {
\r
95 var lastArgs = null;
\r
97 if(arguments.length === 0){
\r
98 Ext.ux.menu.ListMenu.superclass.show.apply(this, lastArgs);
\r
100 lastArgs = arguments;
\r
101 if (this.loadOnShow && !this.loaded) {
\r
104 Ext.ux.menu.ListMenu.superclass.show.apply(this, arguments);
\r
110 onLoad : function (store, records) {
\r
111 var visible = this.isVisible();
\r
114 this.removeAll(true);
\r
116 var gid = this.single ? Ext.id() : null;
\r
117 for(var i=0, len=records.length; i<len; i++){
\r
118 var item = new Ext.menu.CheckItem({
\r
119 text: records[i].get(this.labelField),
\r
121 checked: this.selected.indexOf(records[i].id) > -1,
\r
122 hideOnClick: false});
\r
124 item.itemId = records[i].id;
\r
125 item.on('checkchange', this.checkChange, this);
\r
130 this.loaded = true;
\r
135 this.fireEvent('load', this, records);
\r
138 <div id="method-Ext.ux.menu.ListMenu-getSelected"></div>/**
\r
139 * Get the selected items.
\r
140 * @return {Array} selected
\r
142 getSelected : function () {
\r
143 return this.selected;
\r
147 setSelected : function (value) {
\r
148 value = this.selected = [].concat(value);
\r
151 this.items.each(function(item){
\r
152 item.setChecked(false, true);
\r
153 for (var i = 0, len = value.length; i < len; i++) {
\r
154 if (item.itemId == value[i]) {
\r
155 item.setChecked(true, true);
\r
162 <div id="method-Ext.ux.menu.ListMenu-checkChange"></div>/**
\r
163 * Handler for the 'checkchange' event from an check item in this menu
\r
164 * @param {Object} item Ext.menu.CheckItem
\r
165 * @param {Object} checked The checked value that was set
\r
167 checkChange : function (item, checked) {
\r
169 this.items.each(function(item){
\r
170 if (item.checked) {
\r
171 value.push(item.itemId);
\r
174 this.selected = value;
\r
176 this.fireEvent('checkchange', item, checked);
\r