/*
 * LINGUIST.LLMAP.QueryResponse
 * Written by Benjamin J. Cool, Joshua M. Thompson <ben,josh @linguistlist.org>
 *
 * This object class displays the response from an ArcIMS Identify Query.
 */

var QRTest;
LINGUIST.LLMAP.Identify = Ext.extend(Ext.Window, {
	
	//tabIDs: [],
	
    constructor: function(config) {
    
		this.intro = {
				title: 'Help',
				html: 'Welcome to the identify tool. <br /> as you select areas of the map to identify, your results will appear in the tabs here.'
			};
		/*this.reader = new Ext.data.ArrayReader({}, [
		   {name: 'url'},
		   {name: 'serviceName'},
		   {name: 'layername'},
		   {name: 'layerid'}
		]);*/
		
		this.layerPanel = new Ext.TabPanel({
			region: 'center',
			items: [this.intro],
			enableTabScroll: true,
			autoScroll: true
		})
	
		/*this.grid = new Ext.grid.GridPanel({
			store: new Ext.data.GroupingStore({
				reader: this.reader,
				data: [
					['/services/6376/wms?','Service1','test',5]
				],
				sortInfo:{field: 'layername', direction: "ASC"},
				groupField:'serviceName'
			}),
			
			region: 'west',
			width: 150,
			
			columns: [
				{id:'serviceName',header: "Service", hidden: true,  sortable: true, dataIndex: 'serviceName'},
				{header: "", sortable: true, dataIndex: 'layername'}
			],
			
			view: new Ext.grid.GroupingView({
				forceFit:true,
				groupTextTpl: '{text}'
			}),
			
			frame:false,
			collapsible: false,
			animCollapse: false,
			iconCls: 'icon-grid'
		});*/
	
        LINGUIST.LLMAP.Identify.superclass.constructor.call(this, {
            title: 'Identify Response',
            width: 500,
            height: 300,
            layout: 'border',
            autoScroll: true,
            closable: false,
            buttons: [
                {
                    text: 'Hide Window',
                    scope: this,
                    handler: function () { this.hide(); }
                },
                {
                    text: 'Clear',
                    scope: this,
                    handler: this.clear
                }
            ],
            keys: {
                key: Ext.EventObject.ESC,
                scope: this,
                fn: function () { this.hide(); }
            },
            items:[
            	//this.grid,
            	this.layerPanel
            ]
        });
      
    },
	update: function(data){
		QRTest = data;
		/*if(this.tabIDs[data.LAYERS] != null){
			this.tabIDs[data.LAYERS]++;
		}
		else{
			this.tabIDs[data.LAYERS] = 1;
		}
*/		
		
		
		this.layerPanel.add({
			title: data.TITLE,
			html: data.html,
			autoScroll: true
		});
		
		this.layerPanel.setActiveTab(this.layerPanel.items.length-1);
		
		this.show();
		//this.reader.readRecords(data.map.layers);
		//this.grid.reconfigure()
	},
	clear: function(){
		this.layerPanel.removeAll(true);
		this.layerPanel.add(this.intro);
		this.layerPanel.setActiveTab(0)
		//this.tabIDs = [];
	}
});
