1 /**
  2 * Template para urna con estrellas
  3 * Autor: Alejandro Vera <[email protected]>
  4 * @constructor
  5 */
  6 var NTGVotaThemeStars2 = function(){
  7 
  8 	/**
  9 	* Identificador (nombre corto) del tema
 10 	*/
 11 	this.id = "stars2";
 12 
 13 	/**
 14 	* Funcion para obtener HTML de Urna
 15 	* @param {String} code Codigo de votacion
 16 	* @param {String} id identificador del elemento que se vota
 17 	* @return {String} Codigo HTML de la urna de votacion
 18 	*/
 19 	this.getUrn = function(code,id) {
 20 		var config = NTGVota.getVotation(code,id).config;
 21 		var strHTML = '<div class="votacion"><span id="ntgvota_'+code+'_'+id+'_msg" style="float:left;" class="text-votacion">'+NTGVota.Messages.GREETING+'</span>';
 22 		strHTML += '<span class="votos-estrellas"><ul id="ntgvota_items_'+code+'_'+id+'" class="ntgvota-items">';
 23 		for (var i = 0 ; i < 5 ; i++) {
 24 			strHTML += '<li><a href="javascript:void(null)" onclick="javascript:NTGVota.getVotation(\''+code+'\',\''+id+'\').vota('+config.values[i].value+');" title="'+config.values[i].title+'" class="'+NTGVotaThemeStars2.classes[i]+'">'+config.values[i].value+'</a></li>';
 25 		}
 26 		strHTML += '</ul></span><span class="text-votacion-borde" style="float:left;">Resultado</span><span class="resultados-estrellas">';
 27 		strHTML += '<ul class="ntgvota-result"><li id="voto_'+code+'_'+id+'" class="current-vote" style="width: 0%;"></li></ul></span><span id="voto_'+code+'_'+id+'_count" class="text-votacion" style="float:left;"></span></div>';
 28 		return strHTML;
 29 	}
 30 
 31 	/**
 32 	* Funcion para mostrar resultado de
 33 	* votacion actual
 34 	* @param {Array} data Arreglo con elementos de RespuestaDeVotacion
 35 	*/
 36 	this.showCurrent = function(code,id) {
 37 		var vot = NTGVota.getVotation(code,id);
 38 		if (vot) {
 39 			document.getElementById('voto_'+code+'_'+id).style.width = parseInt(vot.current.p * 20) + '%';
 40 			document.getElementById('voto_'+code+'_'+id+'_count').innerHTML = vot.current.count + ' votos';
 41 			if (vot.current.voted) {
 42 				document.getElementById('ntgvota_items_'+code+'_'+id).innerHTML = '<li class="'+NTGVotaThemeStars2.classes["" + (vot.current.voted-1) + ""]+'_voted">'+vot.current.voted+'</li>';
 43 			}
 44 		}
 45 	}
 46 
 47 	/**
 48 	* Funcion para mostrar mensaje
 49 	* @param {String} code Codigo de votacion
 50 	* @param {String} id identificador del elemento que se vota
 51 	* @param {String} msg Mensaje a desplegar
 52 	* @param {Number} autohide Milisegundos en los que se va a ocultar el mensaje. 0 deshabilita el ocultamiento. 3 segundos por defecto
 53 	*/
 54 	this.writeMsg = function(code,id,msg,autohide) {
 55 		//if (typeof(autohide) == 'undefined') {autohide = 3000;}
 56 		var msgbox = document.getElementById('ntgvota_'+code+'_'+id+'_msg');
 57 		msgbox.innerHTML = msg;
 58 		if (autohide) {
 59 			var clearfunc = function () { msgbox.innerHTML = ""; }
 60 			setTimeout(clearfunc,autohide);
 61 		}
 62 	}
 63 
 64 	/**
 65 	* Funcion para mostrar estado de espera
 66 	* @param {String} code Codigo de votacion
 67 	* @param {String} id identificador del elemento que se vota
 68 	*/
 69 	this.showWait = function(code,id) {
 70 		this.writeMsg(code,id,'<img src="'+NTGVota.Path+'/themes/stars2/loading.gif" border="0" align="absmiddle">',0);
 71 	}
 72 
 73 };
 74 
 75 /**
 76 * Arreglo de clases css para valores
 77 */
 78 NTGVotaThemeStars2.classes = ['one-vote','two-vote','three-vote','four-vote','five-vote'];
 79 
 80 // Preload loading image
 81 var plimg = new Image();
 82 plimg.src = NTGVota.Path+'/themes/stars2/loading.gif';
 83 
 84 // Registro de tema
 85 NTGVota.registerTheme(new NTGVotaThemeStars2());
 86 
 87