
/////////////////////////////////////////////////////////////////////////////////
//         TournamentView Widget Renderer
////////////////////////////////

// Add widget to library:
library["JTOURNAMENTVIEW"]=widgetInfo("JTOURNAMENTVIEW","new jTournamentView", "Vista torneo") 


function jTournamentView_Render(config)
{
	
	this.obj = "jTournamentView_RenderObject" + (jTournamentView_Render.count++)
	eval(this.obj + "=this")
	
	
	this.div=this.obj + "DIV"


	this.config=config
	
	

}


jTournamentView_Render.prototype.render=jTournamentView_RenderRender
jTournamentView_Render.prototype.destroy=jTournamentView_RenderDestroy
jTournamentView_Render.prototype.dataCallback=jTournamentView_RenderDataCallback


function jTournamentView_RenderRender()
{
	
	
	
	cfg=this.config

	createLayer(this.div,null,0,0,100,100,"Cargando ...",null)
	
	this.lyr=new DynLayer(this.div)

	
	this.lyr.css.cssText=cfg["STYLE"]
	this.lyr.show();
	
	
	triviaOps.execute.scoresPerTournament(null,cfg["IDTournament"],cfg["CHANNEL_NAME"],cfg["TOP"],new Function('ret',this.obj+'.dataCallback(ret)')    )
	
	
	return true;	

}

function jTournamentView_RenderDestroy()
{
	this.config=null
	delete this.config
}

function jTournamentView_RenderDataCallback(ret)
{
	var st="";
	
	if(!ret.return_value)
		{
		st=  "La vista torneo no ha sido configurada apropiadamente y no puede mostrarse. Utiliza el editor "
		st+= "para seleccionar el torneo que debe visualizarse aquí."
		}
	else
		{

			var rc= new jRecordset()
	
			rc.load(ret.return_value)
	
			var n

			
			st+='<TABLE class="scoretable" width=100% height=100%>'
	
			st+='<th>Pos:</th>'
			st+='<th>Nick:</th>'
			st+='<th>Puntos:</th>'
	
			n=0
			while (!rc.eof())
			{
				n++
					st+="<tr>";
					st+='<td>' + n + 'º</td>'
					st+='<td>' + rc.fieldValue("NickName") + '</td>'
					st+='<td>' + rc.fieldValue("TotalScore") + '</td>'
					st+="</tr>"
					
					rc.moveNext();
	
			}


			st+="</table>"
		}

	
	this.lyr.write(st)


}

jTournamentView_Render.count=0
