 // vim: sw=4:ts=4:nu:nospell:fdc=4
 /*global Ext, EQP */
 /**
 * Componente de �rea de administra��o de grupos
 *
 * @author Ot�vio Augusto
 * @copyright (c) 2009, by Ot�vio Augusto
 * @company Net On - Solu��es Tecnol�gicas
 * @date 7 de Setembro 2009
 *
 */

//Define o namespace
Ext.ns('App.Admin');

App.Admin.Setor = Ext.extend(App.Module,{
	
	title: 'Gerenciamento de Setores',	
	id: 'admin-setor',	
	bodyBorder: false,
	layout: 'fit',
	iconCls: 'app-setor-16',
	moduleAction: 'setor_action/',
	
	/**
	 * Inicializa o componente
	 */
	initComponent: function(){		
		//Chama o initComponent da super classe
		App.Admin.Setor.superclass.initComponent.apply(this, arguments);
	},//end of initComponent
		
	/**
	 * Cria o DataGrid de visualiza��o de Grupos
	 */
	createGrid : function(){
				
		/* Desativado em 02/02/10 por Otávio
		this.store = new Ext.data.JsonStore({
	    	proxy: new Ext.data.HttpProxy({ 
	    		url: App.sysURL + this.moduleAction + 'findAll/',
	    		method: 'POST'
	    	}),
		    root: 'results',
		    idProperty: 'id',  
		    totalProperty: 'total',
		    fields: ['nome','acesso','id']
		});*/

                this.store = App.stores.Setor;
                
		var grid = {
			xtype: 'editorgrid',
			store: this.store,
			id: this.id + '-grid',
			tbar: this.actionBar,
			 bbar: {
		        xtype: 'paging',
		        store: this.store,       // grid and PagingToolbar using same store
		        displayInfo: true,
		        pageSize: App.pageSize,
		        prependButtons: true
		    },			
			columns:[
				{id: 'nome',header:'Setor',dataIndex:'nome',width:100}
			],
			view : new Ext.grid.GridView({
				forceFit: true
			})
		};
		
		//Retorna o DataGrid criado
		return grid;
	},	
	
	/**
	 * Cria a janela e o formul�rio de edi��o de registro
	 */
	createForm : function(){
		this.window = new Ext.Window({
			title: 'Setor',
			iconCls: 'app-setor-16',
			layout: 'fit',
			width: 300,
			autoHeight: true,
			closeAction: 'hide',
			defaultButton: 0,
			items:[
				this.form = new Ext.form.FormPanel({
					baseCls: 'x-plain',
					labelAlign:'top',
                                        autoHeight: true,
					bodyStyle: 'padding:8px',
					items:[
						{
							xtype: 'hidden',
							name: 'id'
						},
						{
							xtype: 'textfield',
							fieldLabel: 'Nome do grupo',
							allowBlank: false,
							name: 'nome',
							anchor: '98%'
						}
					]
				})
			],
			buttons:[
				{
					text:'<b>Salvar</b>',
					id: this.id + '-save-btn',
					scope: this
				},
				{
					text: 'Cancelar',
					scope: this,
					handler: this.cancel
				}
			]
		});
	}
});

//Registra o novo componente
Ext.reg('admin-setor',App.Admin.Setor);
