1 /** 2 * @fileOverview 3 * Copyright (c) 2013 Regione Autonoma della Sardegna 4 * Published under the GPL license.<br> 5 * See <a href="https://sardegnageoportale.it/webgis/license.txt">https://sardegnageoportale.it/webgis/license.txt</a> 6 * for the full text of the license. 7 * @version 0.1 8 */ 9 10 /** 11 * @namespace framework.plugins 12 */ 13 Ext.namespace("framework.widgets"), 14 15 /** 16 * Panel search engine container. 17 * This implementation manage different search engine. 18 * By default, place a comboBox to switch different search engine components located inside the panel. 19 * @name_ PanelSearch 20 * @class Panel search engine container. 21 * @constructor 22 * @extends <a target="_blank" href="http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.panel.Panel">Ext.Panel</a> 23 */ 24 framework.widgets.PanelSearch = Ext.extend(Ext.Panel, 25 /** 26 * @lends framework.widgets.PanelSearch.prototype 27 */ 28 { 29 /** 30 * index of active search engine component 31 * @public 32 * @type number 33 */ 34 activeElem:2, 35 36 /** 37 * Create a panel with one search component active, a comboBox as a switcher 38 * search engine and a botton to perform the search on the active componet. 39 * @private 40 */ 41 initComponent: function() { 42 43 var searchList = []; 44 for(i=0;i<this.items.length;i++){ 45 if(i>0){ 46 this.items[i].hidden = true; 47 } 48 searchList.push([i,this.items[i],this.items[i].nome]); 49 } 50 var firstElem = searchList[0][2]; 51 var store = new Ext.data.ArrayStore({ 52 fields: [ 53 'id', 54 'nameBox', 55 'displayText' 56 ], 57 data: searchList, 58 value:firstElem 59 }); 60 61 this.combo = new Ext.form.ComboBox(Ext.apply({ 62 store: store, 63 id: 'idComboBoxPanelSearch', 64 mode: 'local', 65 typeAhead: false, 66 editable:false, 67 forceSelection:true, 68 triggerAction: 'all', 69 emptyText:'Select a state...', 70 value: firstElem, 71 valueField: 'nameBox', 72 displayField: 'displayText', 73 width: 130, 74 cls:'panelsearch', 75 listeners: { 76 select: function(combo, record, index) { 77 var idx = index+2; 78 if(this.activeElem !== idx){ 79 this.items.items[this.activeElem].setVisible(false); 80 this.items.items[idx].setVisible(true); 81 if (this.items.items[idx].store !== undefined) { 82 this.items.items[idx].store.clearData(); 83 } 84 this.activeElem = idx; 85 86 if(this.items.items[idx].layer) 87 this.items.items[idx].layer.destroyFeatures(); 88 89 if (window.popupAddr) 90 window.popupAddr.destroy(); 91 92 } 93 }, 94 scope: this 95 } 96 }, this.outputConfig)); 97 98 // send search request to the active search engine component 99 this.button = new Ext.Button({ 100 text:'', 101 id: 'buttonSearch', 102 father:this, 103 iconCls: 'gxp-icon-buttonSearch', 104 width:70, 105 height:36, 106 padding: '0 0 0 0', 107 defaultType: 'splitbutton', 108 /*style:{ 109 float: 'right', 110 height: '36px' 111 },*/ 112 cls: "buttonSearch", 113 listeners: { 114 click: function(){ 115 // var searchText = this.father.items.items[this.father.activeElem].getValue(); 116 var searchText = this.father.items.items[this.father.activeElem].textSearch; 117 if(!searchText) 118 searchText = this.father.items.items[this.father.activeElem].getValue(); 119 // this.father.items.items[this.father.activeElem].store.load(); 120 this.father.items.items[this.father.activeElem].focus(); 121 this.father.items.items[this.father.activeElem].setValue(searchText); 122 this.father.items.items[this.father.activeElem].doQuery(searchText,true); 123 } 124 } 125 126 }); 127 var items = []; 128 items.push(this.combo); 129 items.push(this.button); 130 for(i=0;i<this.items.length;i++){ 131 items.push(this.items[i]); 132 } 133 this.items = items; 134 135 var objReturn = framework.widgets.PanelSearch.superclass.initComponent.apply(this, arguments); 136 return objReturn; 137 }, 138 139 selectItem: function(index) { 140 var idx = index+2; 141 if(this.activeElem !== idx){ 142 this.items.items[this.activeElem].setVisible(false); 143 this.items.items[idx].setVisible(true); 144 if (this.items.items[idx].store !== undefined) { 145 this.items.items[idx].store.clearData(); 146 } 147 this.activeElem = idx; 148 149 //if(this.items.items[idx].layer) 150 // this.items.items[idx].layer.destroyFeatures(); 151 /*if (window.popupAddr) 152 window.popupAddr.destroy(); */ 153 this.combo.setValue(this.combo.initialConfig.store.data.items[index].data.displayText); 154 } 155 156 } 157 }); 158 159 /** api: xtype = framework_panelsearch */ 160 Ext.reg("framework_panelsearch", framework.widgets.PanelSearch); 161