﻿/*
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";
            }
            // 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 LUGARES
    var pesquisaL = Ext.data.Record.create([
            {name:"id", mapping:"objectid"},
            {name:"nome", mapping:"nome"},
            {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: 'nome', direction: "ASC"},
        groupField:'freguesia'
    });
    pesquisaDSL.setDefaultSort('nome', 'desc');
    
    var searchBoxL = new Ext.app.SearchField({
                store: pesquisaDSL,
                width:177,
                paramName: 'query'
            });

                    
    pesquisaDSL.on( 'beforeload', function() {
        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("Lugares"),
        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 FREGUESIAS
    var pesquisaF = Ext.data.Record.create([
            {name:"id", mapping:"objectid"},
            {name:"nome", mapping:"nome"},
            {name:"concelho", mapping:"concelho"},
            {name:"distrito", mapping:"distrito"},
            {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 pesquisaReaderF = new Ext.data.JsonReader({
                    totalProperty: "totalRegistos",
                    root: "listaPesquisa",
				    id: 'id'
			    }, pesquisaF);

    var pesquisaDSF = new Ext.data.GroupingStore({
        proxy: new Ext.data.HttpProxy({
	        method: 'POST',
	        scope: this,
	        //jsonData: "{'query': '','sort':'','dir':''}", 
	        jsonData: "{}", 
	        url: 'GeocidMadeira.asmx/getResultadosPesquisa'
	    }),
	    baseParams: {'tipoPesq': 'F','appID': app.appID , 'queryAll': app.queryAll},
	    reader: pesquisaReaderF,
	    remoteSort: true,
        sortInfo:{field: 'nome', direction: "ASC"},
        groupField:'concelho'
    });
    pesquisaDSF.setDefaultSort('nome', 'desc');
    
    var searchBoxF = new Ext.app.SearchField({
                store: pesquisaDSF,
                width:177,
                paramName: 'query'
            });

                    
    pesquisaDSF.on( 'beforeload', function() {
        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;
    }, searchBoxF);
    
    var cmF = new Ext.grid.ColumnModel([{
           id: 'nome',
           header: "Nome",
           dataIndex: 'nome',
           width: 100,
           hidden: false,
           sortable: true,
           renderer: renderTopic
        },{
           id: 'concelho',
           header: "Concelho",
           dataIndex: 'concelho',
           width: 100,
           align: 'center',
           sortable: true,
           hidden: false
        }]);
    
    cmL.defaultSortable = true;

    var pesquisaFreguesiasTab = new Ext.grid.GridPanel({
        title: OpenLayers.i18n("Freguesias"),
        collapsed: true,
        frame:true,
        fitToFrame: true,
        store: pesquisaDSF,
        cm: cmF,
        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: ")
            , ' '
            ,searchBoxF
        ],
        bbar: new Ext.PagingToolbar({
            pageSize: 10,
            store: pesquisaDSF,
            displayInfo: false
        })        
    });
        
    return [pesquisaLugaresTab, pesquisaFreguesiasTab];
}
*/

function getItemsTabPesquisa(){
    return [getTabPesquisaLugares()];
}
