﻿/*
function getItemsTabPesquisa(){

    // pluggable renders
    function renderTopic(value, cell, rec, rowIndex, colIndex, ds){
        var str = String.format('{0}', value);
        if(cell.id!=undefined){
            var tipo = "WMS";
            if(ds.baseParams && ds.baseParams.tipoPesq && (ds.baseParams.tipoPesq == "P")){ // significa que é 1 tema
                tipo = "WFS";
            }else{
                if(rec.json.xmin==rec.json.xmax && rec.json.ymin==rec.json.ymax){
                    tipo = "WFS";
                }
            }
            // OpenLayers.i18n("Zoom to Element")
            str = String.format('<P CLASS="zoomToFeature" TITLE="{0}" ONCLICK="zoomToFeature(\'{1}\',\'{2}\',\'{3}\',\'{4}\',\'{5}\',\'{6}\',\'{7}\',\'{8}\',\'{9}\',\'{10}\')" ><LEFT><IMAGE ALIGN="LEFT" VALIGN="MIDDLE" SRC="images/mapa/ZoomToFeature.gif"><B>&nbsp;{11}</B><LEFT></P>',
                    value ,rec.json.xmin,rec.json.ymin,rec.json.xmax,rec.json.ymax,rec.json.datum,rec.json.filterTable,rec.json.filterColumn,rec.json.filterValue,rec.json.tipoid,tipo, value);
        }                        
        return str;
    }
    
    function renderLast(value, p, r){
        return String.format('{0}', value);
    }
    
    function toggleDetails(btn, pressed){
        var view = grid.getView();
        view.showPreview = pressed;
        view.refresh();
    }
    
    // PESQUISA EQUIPAMENTOS E EMPRESAS
    var pesquisaP = Ext.data.Record.create([
            {name:"rank", mapping:"rank"},
            {name:"id", mapping:"objectid"},
            {name:"tipoid", mapping:"tipoid"},
            {name:"nome", mapping:"designacao"},
            {name:"tema", mapping:"tema"},
            {name:"filterTable", mapping:"filterTable"},
            {name:"filterColumn", mapping:"filterColumn"},
            {name:"filterValue", mapping:"filterValue"},
            {name:"xmin", mapping:"xmin"},
            {name:"ymin", mapping:"ymin"},
            {name:"xmax", mapping:"xmax"},
            {name:"ymax", mapping:"ymax"},
            {name:"datum", mapping:"datum"}
        ]);


    var pesquisaReaderP = new Ext.data.JsonReader({
                    totalProperty: "totalRegistos",
                    root: "listaPesquisa",
				    id: 'id'
			    }, pesquisaP);

    var pesquisaDSP = new Ext.data.GroupingStore({
        proxy: new Ext.data.HttpProxy({
	        method: 'POST',
	        scope: this,
	        //jsonData: "{'query': '','sort':'','dir':''}", 
	        jsonData: "{}", 
	        url: 'GeocidMadeira.asmx/getResultadosPesquisa'
	    }),
	    baseParams: {'tipoPesq': 'E', 'appID': app.appID , 'queryAll': app.queryAll},
	    reader: pesquisaReaderP,
	    remoteSort: true,
        sortInfo:{field: 'designacao', direction: "ASC"},
        groupField:'tema'
    });
    pesquisaDSP.setDefaultSort('designacao', 'desc');
    
    var searchBoxP = new Ext.app.SearchField({
                store: pesquisaDSP,
                width:177,
                paramName: 'query'
            });

                    
    pesquisaDSP.on( 'beforeload', function() {
        removeLayerHighlight(); 
        var params = this.store.baseParams
        var jsonData = "{";
        for (var k in params) {
            jsonData += "'"+k+"':'"+params[k]+"',"
        }
        if(jsonData.length>1){
            jsonData = jsonData.substring(0,jsonData.length-1);
        }    
        jsonData += "}";
        this.store.proxy.conn.jsonData = jsonData;
    }, searchBoxP);
    
    
    // the column model has information about grid columns
    // dataIndex maps the column to the specific data field in
    // the data store
    var cmP = new Ext.grid.ColumnModel([{
           id: 'nome', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
           header: "Nome",
           dataIndex: 'nome',
           width: 100,
           hidden: false,
           renderer: renderTopic
        },{
           id: 'tema',
           header: "Tema",
           dataIndex: 'tema',
           width: 40,
           align: 'center',
           hidden: true,
           renderer: renderLast
    }]);

    // by default columns are sortable
    cmP.defaultSortable = true;
    
    var pesquisaEquipamentosEmpresasTab = new Ext.grid.GridPanel({
        title: OpenLayers.i18n("Equipments"),
        collapsed: true,
        frame:true,
        fitToFrame: true,
        store: pesquisaDSP,
        cm: cmP,
        trackMouseOver:true,
        sm: new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn}),
        loadMask: true,
        autoExpandColumn: 'nome',
        viewConfig: {
            forceFit:true,
            enableRowBody:true
        },
        view: new Ext.grid.GroupingView({
            forceFit:true,
            enableRowBody: false,
            enableGroupingMenu: true,
            startCollapsed: true,
            groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
        }),
        tbar: [
            OpenLayers.i18n("Search: ")
            , ' '
            ,searchBoxP 
        ],
        bbar: new Ext.PagingToolbar({
            pageSize: 10,
            store: pesquisaDSP,
            displayInfo: false
        })        
    });
        
    // PESQUISA LUGARES
    var pesquisaL = Ext.data.Record.create([
            {name:"rank", mapping:"rank"},
            {name:"id", mapping:"objectid"},
            {name:"tipoid", mapping:"tipoid"},
            {name:"nome", mapping:"designacao"},
            {name:"freguesia", mapping:"freguesia"},
            {name:"concelho", mapping:"concelho"},
            {name:"filterTable", mapping:"filterTable"},
            {name:"filterColumn", mapping:"filterColumn"},
            {name:"filterValue", mapping:"filterValue"},
            {name:"xmin", mapping:"xmin"},
            {name:"ymin", mapping:"ymin"},
            {name:"xmax", mapping:"xmax"},
            {name:"ymax", mapping:"ymax"},
            {name:"datum", mapping:"datum"}
        ]);


    var pesquisaReaderL = new Ext.data.JsonReader({
                    totalProperty: "totalRegistos",
                    root: "listaPesquisa",
				    id: 'id'
			    }, pesquisaL);

    var pesquisaDSL = new Ext.data.GroupingStore({
        proxy: new Ext.data.HttpProxy({
	        method: 'POST',
	        scope: this,
	        //jsonData: "{'query': 'la','sort':'','dir':''}", 
	        jsonData: "{}", 
	        url: 'GeocidMadeira.asmx/getResultadosPesquisa'
	    }),
	    baseParams: {'tipoPesq': 'L','appID': app.appID , 'queryAll': app.queryAll},
	    reader: pesquisaReaderL,
	    remoteSort: true,
        sortInfo:{field: 'designacao', direction: "ASC"},
        groupField:'freguesia'
    });
    pesquisaDSL.setDefaultSort('designacao', 'desc');
    
    var searchBoxL = new Ext.app.SearchField({
                store: pesquisaDSL,
                width:177,
                paramName: 'query'
            });

                    
    pesquisaDSL.on( 'beforeload', function() {
        removeLayerHighlight(); 
        var params = this.store.baseParams
        var jsonData = "{";
        for (var k in params) {
            jsonData += "'"+k+"':'"+params[k]+"',"
        }
        if(jsonData.length>1){
            jsonData = jsonData.substring(0,jsonData.length-1);
        }    
        jsonData += "}";
        this.store.proxy.conn.jsonData = jsonData;
    }, searchBoxL);
    
    var cmL = new Ext.grid.ColumnModel([{
           id: 'nome',
           header: "Nome",
           dataIndex: 'nome',
           width: 100,
           hidden: false,
           sortable: true,
           renderer: renderTopic
        },{
           id: 'freguesia',
           header: "Freguesia",
           dataIndex: 'freguesia',
           width: 100,
           align: 'center',
           sortable: true,
           hidden: false
        }]);
    
    cmL.defaultSortable = true;

    var pesquisaLugaresTab = new Ext.grid.GridPanel({
        title: OpenLayers.i18n("Places"),
        collapsed: true,
        frame:true,
        fitToFrame: true,
        store: pesquisaDSL,
        cm: cmL,
        trackMouseOver:true,
        sm: new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn}),
        loadMask: true,
        autoExpandColumn: 'nome',
        viewConfig: {
            forceFit:true,
            enableRowBody:false
            //showPreview:true
        },
        view: new Ext.grid.GroupingView({
            forceFit:true,
            enableRowBody: false,
            enableGroupingMenu: true,
            startCollapsed: true,
            groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
        }),
        tbar: [
            OpenLayers.i18n("Search: ")
            , ' '
            ,searchBoxL 
        ],
        bbar: new Ext.PagingToolbar({
            pageSize: 10,
            store: pesquisaDSL,
            displayInfo: false
        })        
    });
    
    // PESQUISA RUAS
    var pesquisaR = Ext.data.Record.create([
            {name:"rank", mapping:"rank"},
            {name:"id", mapping:"objectid"},
            {name:"tipoid", mapping:"tipoid"},
            {name:"nome", mapping:"designacao"},
            {name:"freguesia", mapping:"freguesia"},
            {name:"filterTable", mapping:"filterTable"},
            {name:"filterColumn", mapping:"filterColumn"},
            {name:"filterValue", mapping:"filterValue"},
            {name:"xmin", mapping:"xmin"},
            {name:"ymin", mapping:"ymin"},
            {name:"xmax", mapping:"xmax"},
            {name:"ymax", mapping:"ymax"},
            {name:"datum", mapping:"datum"}
        ]);


    var pesquisaReaderR = new Ext.data.JsonReader({
                    totalProperty: "totalRegistos",
                    root: "listaPesquisa",
				    id: 'id'
			    }, pesquisaR);

    var pesquisaDSR = new Ext.data.GroupingStore({
        proxy: new Ext.data.HttpProxy({
	        method: 'POST',
	        scope: this,
	        //jsonData: "{'query': '','sort':'','dir':''}", 
	        jsonData: "{}", 
	        url: 'GeocidMadeira.asmx/getResultadosPesquisa'
	    }),
	    baseParams: {'tipoPesq': 'R','appID': app.appID , 'queryAll': app.queryAll},
	    reader: pesquisaReaderR,
	    remoteSort: true,
        sortInfo:{field: 'designacao', direction: "DESC"},
        groupField:'freguesia'
    });
    pesquisaDSR.setDefaultSort('designacao', 'DESC');
    
    var searchBoxR = new Ext.app.SearchField({
                store: pesquisaDSR,
                width:177,
                paramName: 'query'
            });

                    
    pesquisaDSR.on( 'beforeload', function() {
        removeLayerHighlight(); 
        var params = this.store.baseParams
        var jsonData = "{";
        for (var k in params) {
            jsonData += "'"+k+"':'"+params[k]+"',"
        }
        if(jsonData.length>1){
            jsonData = jsonData.substring(0,jsonData.length-1);
        }    
        jsonData += "}";
        this.store.proxy.conn.jsonData = jsonData;
    }, searchBoxR);
    
    var cmR = new Ext.grid.ColumnModel([{
           id: 'nome', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
           header: "Nome",
           dataIndex: 'nome',
           width: 100,
           hidden: false,
           renderer: renderTopic
        },{
           id: 'freguesia',
           header: "Freguesia",
           dataIndex: 'freguesia',
           width: 70,
           hidden: false,
           align: 'center',
           renderer: renderLast
    }]);
    
    cmR.defaultSortable = true;

    var tb = new Ext.Toolbar({
         columns: 3
        ,colspan: true
        ,items : [
            OpenLayers.i18n("Search: ")
            , ' '
            ,searchBoxR 
            ,'* ex: Avenida Marginal, 20'
        ]
    });

    var pesquisaRuasTab = new Ext.grid.GridPanel({
        title: OpenLayers.i18n("Addresses"),
        collapsed: true,
        frame:true,
        fitToFrame: true,
        store: pesquisaDSR,
        cm: cmR,
        trackMouseOver:true,
        sm: new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn}),
        loadMask: true,
        autoExpandColumn: 'nome',
        viewConfig: {
            forceFit:true,
            enableRowBody:true,
            showPreview:true
        },
        view: new Ext.grid.GroupingView({
            forceFit:true,
            startCollapsed: true
        }),
        tbar: tb,
        bbar: new Ext.PagingToolbar({
            pageSize: 10,
            store: pesquisaDSR,
            displayInfo: false
        })        
    });
        
    return [pesquisaEquipamentosEmpresasTab, pesquisaLugaresTab, pesquisaRuasTab];
}
*/

function getItemsTabPesquisa(){
    return [getTabPesquisaLugares(), getTabPesquisaRuasMoradas(), getTabPesquisaEquipamentosEmpresas()];
}
