1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
<html>
<head>
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
</head>
<body onload="prettyPrint();">
<pre class="prettyprint lang-js">Ext.namespace('Ext.ux.menu');
<div id="cls-Ext.ux.menu.ListMenu"></div>/**
* @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, {
<div id="cfg-Ext.ux.menu.ListMenu-labelField"></div>/**
* @cfg {String} labelField
* Defaults to 'text'.
*/
labelField : 'text',
<div id="cfg-Ext.ux.menu.ListMenu-paramPrefix"></div>/**
* @cfg {String} paramPrefix
* Defaults to 'Loading...'.
*/
loadingText : 'Loading...',
<div id="cfg-Ext.ux.menu.ListMenu-loadOnShow"></div>/**
* @cfg {Boolean} loadOnShow
* Defaults to true.
*/
loadOnShow : true,
<div id="cfg-Ext.ux.menu.ListMenu-single"></div>/**
* @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(
<div id="event-Ext.ux.menu.ListMenu-checkchange"></div>/**
* @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);
},
<div id="method-Ext.ux.menu.ListMenu-show"></div>/**
* 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);
},
<div id="method-Ext.ux.menu.ListMenu-getSelected"></div>/**
* 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);
}
},
<div id="method-Ext.ux.menu.ListMenu-checkChange"></div>/**
* 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);
}
});</pre>
</body>
</html>
|