+++ /dev/null
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-Ext.grid.filter.ListFilter = Ext.extend(Ext.grid.filter.Filter, {\r
- labelField: 'text',\r
- loadingText: 'Loading...',\r
- loadOnShow: true,\r
- value: [],\r
- loaded: false,\r
- phpMode: false,\r
- \r
- init: function(){\r
- this.menu.add('<span class="loading-indicator">' + this.loadingText + '</span>');\r
- \r
- if(this.store && this.loadOnShow) {\r
- this.menu.on('show', this.onMenuLoad, this);\r
- } else if(this.options) {\r
- var options = [];\r
- for(var i=0, len=this.options.length; i<len; i++) {\r
- var value = this.options[i];\r
- switch(Ext.type(value)) {\r
- case 'array': \r
- options.push(value);\r
- break;\r
- case 'object':\r
- options.push([value.id, value[this.labelField]]);\r
- break;\r
- case 'string':\r
- options.push([value, value]);\r
- break;\r
- }\r
- }\r
- \r
- this.store = new Ext.data.Store({\r
- reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField])\r
- });\r
- this.options = options;\r
- this.menu.on('show', this.onMenuLoad, this);\r
- }\r
- \r
- this.store.on('load', this.onLoad, this);\r
- this.bindShowAdapter();\r
- },\r
- \r
- /**\r
- * Lists will initially show a 'loading' item while the data is retrieved from the store. In some cases the\r
- * loaded data will result in a list that goes off the screen to the right (as placement calculations were done\r
- * with the loading item). This adaptor will allow show to be called with no arguments to show with the previous\r
- * arguments and thusly recalculate the width and potentially hang the menu from the left.\r
- * \r
- */\r
- bindShowAdapter: function() {\r
- var oShow = this.menu.show;\r
- var lastArgs = null;\r
- this.menu.show = function() {\r
- if(arguments.length == 0) {\r
- oShow.apply(this, lastArgs);\r
- } else {\r
- lastArgs = arguments;\r
- oShow.apply(this, arguments);\r
- }\r
- };\r
- },\r
- \r
- onMenuLoad: function() {\r
- if(!this.loaded) {\r
- if(this.options) {\r
- this.store.loadData(this.options);\r
- } else {\r
- this.store.load();\r
- }\r
- }\r
- },\r
- \r
- onLoad: function(store, records) {\r
- var visible = this.menu.isVisible();\r
- this.menu.hide(false);\r
- \r
- this.menu.removeAll();\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.value.indexOf(records[i].id) > -1,\r
- hideOnClick: false\r
- });\r
- \r
- item.itemId = records[i].id;\r
- item.on('checkchange', this.checkChange, this);\r
- \r
- this.menu.add(item);\r
- }\r
- \r
- this.setActive(this.isActivatable());\r
- this.loaded = true;\r
- \r
- if(visible) {\r
- this.menu.show(); //Adaptor will re-invoke with previous arguments\r
- }\r
- },\r
- \r
- checkChange: function(item, checked) {\r
- var value = [];\r
- this.menu.items.each(function(item) {\r
- if(item.checked) {\r
- value.push(item.itemId);\r
- }\r
- },this);\r
- this.value = value;\r
- \r
- this.setActive(this.isActivatable());\r
- this.fireEvent("update", this);\r
- },\r
- \r
- isActivatable: function() {\r
- return this.value.length > 0;\r
- },\r
- \r
- setValue: function(value) {\r
- var value = this.value = [].concat(value);\r
-\r
- if(this.loaded) {\r
- this.menu.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
- this.fireEvent("update", this);\r
- },\r
- \r
- getValue: function() {\r
- return this.value;\r
- },\r
- \r
- serialize: function() {\r
- var args = {type: 'list', value: this.phpMode ? this.value.join(',') : this.value};\r
- this.fireEvent('serialize', args, this);\r
- return args;\r
- },\r
- \r
- validateRecord: function(record) {\r
- return this.getValue().indexOf(record.get(this.dataIndex)) > -1;\r
- }\r
-});
\ No newline at end of file