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