/*
 * Bloomberg.com Symbology
 * 
 * @author amalamud
 */

Symbology.SearchPanel = Ext.extend(Ext.Panel, {
	layout : 'accordion',
	layoutConfig : {
		autoWidth : false
	},

	initComponent : function() {
		Ext.apply(this, {
			items : [{
				id : 'newSearch',
				title : 'Custom Search',
				xtype : 'newSearchForm',
				helpFn : this.showHelp
			}, {
				id : 'predefSearches',
				title : 'Predefined Searches',
				xtype : 'predefSearchTree',
				helpFn : this.showHelp
			}, {
				id : 'exeSearches',
				title : 'Predefined Files',
				xtype : 'fileGrid',
				helpFn : this.showHelp
			}]
		});

		Symbology.SearchPanel.superclass.initComponent.apply(this, arguments);

		this.addEvents('search');

	}, // initComponent

	onRender : function() {
		Symbology.SearchPanel.superclass.onRender.apply(this, arguments);

		var newSearch = Ext.getCmp('newSearch');
		this.relayEvents(newSearch, ['search']);

		var predefSearch = Ext.getCmp('predefSearches');
		this.relayEvents(predefSearch, ['search']);
	}, // onRender

	showHelp : function(winId, winTitle, pageUrl) {
		var win = Ext.WindowMgr.get(winId);
		if (win != null) {
			Ext.WindowMgr.bringToFront(win);
			return;
		}

		win = new Ext.Window({
			id : winId,
			title : winTitle,
			height : 500,
			width : 600,
			closable : true,
			plain : true,
			layout : 'fit',
			items : {
				xtype : 'panel',
				autoScroll : true,
				bodyStyle : 'padding:10px;',
				autoLoad : pageUrl
			}
		});
		win.show();

	} // showHelp

});

Ext.reg('searchPanel', Symbology.SearchPanel);
