Participantes = function(config) {
  Ext.apply(this, config);	
  this.config = config
  
  this.Botonera  = new Ext.Toolbar(config.menu.id); 	
  this.Botonera.addButton({id:'Nuevo-Participante-btn', text: 'Agregar ', className: 'Nuevo-Participante', 
  							handler: this.agregarNuevoParticipante.createDelegate(this)});
  this.Botonera.addSeparator();							
  this.Botonera.addButton({id:'Quitar-Participante-btn', text: 'Quitar', className: 'Quitar-Participante', 
  							handler: this.quitarParticipante.createDelegate(this)});
 };

Participantes.prototype = {
	init : function(AST_ID, rolId){

		this.astId 			= AST_ID;
		
	/*	function renderTipo(v){
			var valor = '';
			if (v != ''){
				valor = v;
				if (v.indexOf('|') > 0){
					arr = v.split('|');
					valor = arr[1];
					id	  = arr[0];
				}
				// obtiene filas modificadas
				var eds = this.ds.getModifiedRecords();   
				if (eds.length > 0){
					callback = { 
						failure: function(o){
								new mensaje('Error.',o.responseText,{modal:true, width:380, height:400, shadow:true, closable:true}).show(this.id);
								}
					   };
					url = 'modulos/participantes/actualizarRol.asp?PA_ID=' + eds[0].data.Id + '&ROL_ID=' + id
					YAHOO.util.Connect.asyncRequest('GET', url, callback);
				}
				this.ds.commitChanges(); // cambia el estado de las celdas editadas
			}
			return valor;
    	}; */
    
		var fm = Ext.form, Ed = Ext.grid.GridEditor;

		this.cm = new Ext.grid.ColumnModel([{
			   header: "Id",
			   dataIndex: 'Id',
			   width: 30,
			   editor: null
			},{
			   header: "Nombre",
			   dataIndex: 'Nombre',
			   width: 350,
			   editor: null
			},{
			   header: "Empresa",
			   dataIndex: 'Empresa',
			   width: 180,
			   editor: null
			},{
			   header: "Celular",
			   dataIndex: 'Celular',
			   width: 95,
			   editor: null
			}/*,{
			   header: "Rol",
			   dataIndex: 'Rol',
			   width: 130,
			   renderer: renderTipo.createDelegate(this),
			   editor: new Ed(new Ext.form.ComboBox({
				   typeAhead    : true,
				   triggerAction: 'all',
				   transform    : rolId,
				   lazyRender   : true
			  }))
			}*/]);
		
		
		
		// by default columns are sortable
		this.cm.defaultSortable = true;
	
		var Plant = Ext.data.Record.create([
			   {name: 'Id', type: 'string'},
			   {name: 'Nombre', type: 'string'},
			   {name: 'Empresa', type: 'string'},
			   {name: 'Celular', type: 'string'}/*,
			   {name: 'Rol', type: 'string'}*/
		  ]);
	
		this.ds = new Ext.data.Store({
			proxy		: new Ext.data.HttpProxy({url: 'modulos/participantes/listar.asp'}),
			baseParams  : {AST_ID: this.astId},
			reader: new Ext.data.XmlReader({
				   record: 'Participante'
			   }, Plant)
		});
		
		this.grid = new Ext.grid.EditorGrid(this.config.grid.id, {
			ds: this.ds,
			cm: this.cm,
			//selModel: new Ext.grid.RowSelectionModel(),
			enableColLock:false
		});
		
	
		this.grid.render();

		this.ds.load();
	},
	
	agregarNuevoParticipante: function(o){
	  // propiedades del grid de la lista de valores
	   	dialogConfig = {
				  grid		: {
								proxy	   : { name   : "HttpProxy",
											   url 	  : "modulos/usuarios/listar.asp",
											   params : { start: 0, limit: 20}	
							 				 },
								baseParams : {fun   : 1},
								reader	   : {name  : "XmlReader",
											  meta  : {record 	: "Usuario", totalRecords	: "Contador", id : "USU_LOGIN_RED"},
											  recordType  : [{name : "USU_LOGIN_RED"  , mapping : "USU_LOGIN_RED"},
															 {name : "USU_NOMBRES" , mapping : "USU_NOMBRES"},
															 {name : "USU_APELLIDO_PATERNO" , mapping : "USU_APELLIDO_PATERNO"},
															 {name : "USU_EMPRESA", mapping : "USU_EMPRESA"}
															  ]																				  													 
											  },
								 remoteSort	: true,
								 defaultSort: {field: "USU_LOGIN_RED", direction: "desc"},																	 
								 columnModel: {
												model: [{id : "USU_LOGIN_RED"	,header : "Login"	,dataIndex : "USU_LOGIN_RED"	,width:   5	,sortable : false},
														{id : "USU_NOMBRES"  	,header : "Nombre"	,dataIndex : "USU_NOMBRES" 	,width: 100	,sortable : false},
														{id : "USU_APELLIDO_PATERNO"  ,header : "Apellido Paterno"	,dataIndex : "USU_APELLIDO_PATERNO" 	,width: 120	,sortable : false},
														{id : "USU_EMPRESA" ,header : "Empresa"	,dataIndex : "USU_EMPRESA"	,width: 140	,sortable : false}																	
														],
												defaultSortable : false		 
											},
								descripcion : ''
							},
					ventana   : {
								titulo	  : 'Lista de Participantes.',
								subTitulo : 'Participantes'
							    },
					dialog    : {
									 autoTabs	: true,
									 width		: 405,
									 height		: 510,
									 shadow		: true,
									 closable	: true,
									 collapsible: false,
									 modal		: true,
									 minWidth	: 150,
									 minHeight	: 80						 
							    },
					filtro	  : {
										etiquetaInput : 'Apellido',
										etiquetaBoton : 'Buscar'
								},
					fncAceptar: this.agregarParticipante.createDelegate(this)
				};
			this.ListaUsuarios = new listaValores(dialogConfig);
			this.ListaUsuarios.toFront();
			this.ListaUsuarios.show('Nuevo-Participante-btn');
		},
	quitarParticipante: function(){
		// var row = this.grid.getSelections();
		
		if (this.grid.selModel.hasSelection()){
			var row = this.grid.selModel.selection.record
			callback = {
					failure: function(o){
								 new mensaje('Error.',
											 o.responseText,
											{ modal:true,
											  width:600,
											  height:800,
											  shadow:true,
											  closable:true }
											 ).show('Nuevo-Participante-btn');
					}
			}

			url = 'modulos/participantes/eliminar.asp?PA_ID=' + row.data.Id
			YAHOO.util.Connect.asyncRequest('GET', url, callback);
		}
		
		this.ds.load();//this.gridConfig.proxy
	},
	agregarParticipante: function(o){
		var w = this
		var row = this.ListaUsuarios.Grid.grid.getSelections();

		if (row){
			callback = {
					failure: function(o){
								 new mensaje('Error.',
											 o.responseText,
											{ modal:true,
											  width:600,
											  height:800,
											  shadow:true,
											  closable:true }
											 ).show('Nuevo-Participante-btn');
					}
			}
			
			url = 'modulos/participantes/insertar.asp?loginUsuario=' + row[0].data.USU_LOGIN_RED + '&AST_ID=' + this.astId
			YAHOO.util.Connect.asyncRequest('GET', url, callback );
			
		}
		
		this.ds.load();//this.gridConfig.proxy
		this.ListaUsuarios.hide();

	}
	
 };

