/** * @author Gabriele */ function Commento() { this.script_page = "/ajax/commento.php"; this.checkFormCommenti = function() { nome = document.getElementById("nome"); commento = document.getElementById("commento"); //if (nome.value.length <= 2) //{ // alert("Devi inserire almeno 3 caratteri."); // nome.style.borderColor = "red"; // nome.focus(); // return false; //} if (commento.value.length <= 2) { alert("Devi inserire almeno 3 caratteri."); commento.style.borderColor = "red"; commento.focus(); return false; } nome.style.borderColor = ""; commento.style.borderColor = ""; return true; } this.sendComment = function() { if (this.checkFormCommenti()) { this.setLoadingSrc("/immagini/vote_loader.gif"); this.setLoadingTarget(document.getElementById("php_response")); this.setTarget(this.gestisciRisposta); this.params["operazione"] = "commenta"; this.params["idc"] = document.getElementById("idc").value; this.params["rating"] = document.getElementById("rating").value; this.params["tipo_modulo"] = document.getElementById("tipo_modulo").value; this.params["nome"] = document.getElementById("nome").value; this.params["commento"] = document.getElementById("commento").value; this.makeRequest(this.script_page); alert("Grazie. Il tuo commento dovrà essere moderato prima di poter essere visualizzato."); } } this.listaCommenti = function(idc, pag) { this.setLoadingSrc("/immagini/vote_loader.gif"); this.setLoadingTarget(document.getElementById("php_response")); this.setTarget(document.getElementById("php_response")); this.params["operazione"] = "lista_commenti"; this.params["tipo_modulo"] = document.getElementById("tipo_modulo").value; this.params["idc"] = parseInt(idc); this.params["pag"] = (pag == null || pag == undefined) ? 1 : parseInt(pag); this.makeRequest(this.script_page); } this.gestisciRisposta = function(response) { response = new String(response); response = response.split(":"); response[0] = response[0].replace(/\n/g, ''); response[0] = response[0].replace(/\r/g, ''); console.log(response); if (response[0] == 'OK'){ document.getElementById('form_commento').reset(); document.getElementById('rating_star').value = 0; jQuery("ul.rating_widget li").css('background-position', '0px 0px'); }else if (response[0] == 'FLOOD'){ alert('Devi aspettare un minuto per inserire il prossimo commento.'); }else{ alert('Errore nell\'inserimento del commento!'); } eval("comm.listaCommenti(" + response[1] + ", 1);"); } } Commento.prototype = new AjaxModule(); Commento.prototype.constructor = Commento;