1/* 2 * Ext JS Library 2.2 3 * Copyright(c) 2006-2008, Ext JS, LLC. 4 * [email protected] 5 * 6 * http://extjs.com/license 7 */ 8 9Ext.grid.filter.ListFilter = Ext.extend(Ext.grid.filter.Filter, { 10 labelField: 'text', 11 loadingText: 'Lendo Dados...', 12 loadOnShow: true, 13 value: [], 14 loaded: false, 15 phpMode: false, 16 17 init: function(){ 18 this.menu.add('<span class="loading-indicator">' + this.loadingText + '</span>'); 19 20 if(this.store && this.loadOnShow) { 21 this.menu.on('show', this.onMenuLoad, this); 22 } else if(this.options) { 23 var options = []; 24 for(var i=0, len=this.options.length; i<len; i++) { 25 var value = this.options[i]; 26 switch(Ext.type(value)) { 27 case 'array': 28 options.push(value); 29 break; 30 case 'object': 31 options.push([value.id, value[this.labelField]]); 32 break; 33 case 'string': 34 options.push([value, value]); 35 break; 36 } 37 } 38 39 this.store = new Ext.data.Store({ 40 reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]) 41 }); 42 this.options = options; 43 this.menu.on('show', this.onMenuLoad, this); 44 } 45 46 this.store.on('load', this.onLoad, this); 47 this.bindShowAdapter(); 48 }, 49 50 /** 51 * Lists will initially show a 'loading' item while the data is retrieved from the store. In some cases the 52 * loaded data will result in a list that goes off the screen to the right (as placement calculations were done 53 * with the loading item). This adaptor will allow show to be called with no arguments to show with the previous 54 * arguments and thusly recalculate the width and potentially hang the menu from the left. 55 * 56 */ 57 bindShowAdapter: function() { 58 var oShow = this.menu.show; 59 var lastArgs = null; 60 this.menu.show = function() { 61 if(arguments.length == 0) { 62 oShow.apply(this, lastArgs); 63 } else { 64 lastArgs = arguments; 65 oShow.apply(this, arguments); 66 } 67 }; 68 }, 69 70 onMenuLoad: function() { 71 if(!this.loaded) { 72 if(this.options) { 73 this.store.loadData(this.options); 74 } else { 75 this.store.load(); 76 } 77 } 78 }, 79 80 onLoad: function(store, records) { 81 var visible = this.menu.isVisible(); 82 this.menu.hide(false); 83 84 this.menu.removeAll(); 85 86 var gid = this.single ? Ext.id() : null; 87 for(var i=0, len=records.length; i<len; i++) { 88 var item = new Ext.menu.CheckItem({ 89 text: records[i].get(this.labelField), 90 group: gid, 91 checked: this.value.indexOf(records[i].id) > -1, 92 hideOnClick: false 93 }); 94 95 item.itemId = records[i].id; 96 item.on('checkchange', this.checkChange, this); 97 98 this.menu.add(item); 99 } 100 101 this.setActive(this.isActivatable()); 102 this.loaded = true; 103 104 if(visible) { 105 this.menu.show(); //Adaptor will re-invoke with previous arguments 106 } 107 }, 108 109 checkChange: function(item, checked) { 110 var value = []; 111 this.menu.items.each(function(item) { 112 if(item.checked) { 113 value.push(item.itemId); 114 } 115 },this); 116 this.value = value; 117 118 this.setActive(this.isActivatable()); 119 this.fireEvent("update", this); 120 }, 121 122 isActivatable: function() { 123 return this.value.length > 0; 124 }, 125 126 setValue: function(value) { 127 var value = this.value = [].concat(value); 128 129 if(this.loaded) { 130 this.menu.items.each(function(item) { 131 item.setChecked(false, true); 132 for(var i=0, len=value.length; i<len; i++) { 133 if(item.itemId == value[i]) { 134 item.setChecked(true, true); 135 } 136 } 137 }, this); 138 } 139 140 this.fireEvent("update", this); 141 }, 142 143 getValue: function() { 144 return this.value; 145 }, 146 147 serialize: function() { 148 var args = {active:this.active, type: 'list', value: this.phpMode ? this.value.join(',') : this.value}; 149 this.fireEvent('serialize', args, this); 150 return args; 151 }, 152 153 validateRecord: function(record) { 154 return this.getValue().indexOf(record.get(this.dataIndex)) > -1; 155 } 156});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.