X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=js%2Feuphorik.js;h=d040dc3d5fcaceb368d0c5a4961123803c078b4f;hb=3ea00589df90388456e8587b1bebdeab0f7e99fa;hp=b36fbbbe2d85108cbcad7866d67d8ff8c753214e;hpb=81b3e94e62dd60087d71efc42004f8222d9e1e7a;p=euphorik.git diff --git a/js/euphorik.js b/js/euphorik.js index b36fbbb..d040dc3 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -74,6 +74,8 @@ function Util() }) } +var messageType = {informatif: 0, question: 1, erreur: 2} + /** * Affiche une boite de dialogue avec un message à l'intérieur. * @param message le message (string) @@ -105,9 +107,7 @@ Util.prototype.messageDialogue = function(message, type, boutons) $("#info").slideDown(200) this.timeoutMessageDialogue = setTimeout(fermer, conf.tempsAffichageMessageDialogue) -} - -var messageType = {informatif: 0, question: 1, erreur: 2} +} /** * Utilisé pour l'envoie de donnée avec la méthode ajax de jQuery. @@ -282,6 +282,11 @@ Formateur.prototype.getSmilesHTML = function() return XHTML } +/** + * Formatage complet d'un texte. + * @M le message + * @pseudo facultatif, permet de contruire le label des images sous la forme : " : " + */ Formateur.prototype.traitementComplet = function(M, pseudo) { return this.traiterLiensConv(this.traiterSmiles(this.traiterURL(this.remplacerBalisesHTML(M), pseudo))) @@ -327,9 +332,6 @@ Formateur.prototype.remplacerBalisesHTML = function(M) Formateur.prototype.traiterURL = function(M, pseudo) { thisFormateur = this - - if (pseudo == undefined) - pseudo = "" var traitementUrl = function(url) { @@ -337,7 +339,7 @@ Formateur.prototype.traiterURL = function(M, pseudo) if (!thisFormateur.regexTestProtocoleExiste.test(url)) url = "http://" + url var extension = thisFormateur.getShort(url) - return "[" + extension[0] + "]" + return "[" + extension[0] + "]" } return M.replace(this.regexUrl, traitementUrl) } @@ -350,8 +352,8 @@ Formateur.prototype.getShort = function(url) { var estUneImage = false var versionShort = null - var rechercheImg = this.regexImg.exec(url) - //alert(url) + var rechercheImg = this.regexImg.exec(url) + if (rechercheImg != null) { versionShort = rechercheImg[1].toLowerCase() @@ -418,7 +420,8 @@ function Client(util) } Client.prototype.resetDonneesPersonnelles = function() -{ +{ + this.id = 0 this.pseudo = conf.pseudoDefaut this.login = "" this.password = "" @@ -437,7 +440,7 @@ Client.prototype.resetDonneesPersonnelles = function() Client.prototype.setCss = function(css) { - if (this.css == css) + if (this.css == css || css == "") return this.css = css @@ -599,7 +602,6 @@ Client.prototype.authentifie = function() Client.prototype.setStatut = function(statut) { - //alert(statut) // conversation en "enum" si en "string" if (typeof(statut) == "string") { @@ -681,34 +683,29 @@ Client.prototype.deconnexion = function() Client.prototype.chargerDonnees = function(data) { - var thisClient = this - + // la modification du statut qui suit met à jour le menu, le menu dépend (page admin) + // de l'état ekMaster + this.ekMaster = data["ek_master"] != undefined ? data["ek_master"] : false + this.setStatut(data["status"]) if (this.authentifie()) { this.cookie = data["cookie"] this.setCookie() - + + this.id = data["id"] this.login = data["login"] this.pseudo = data["nick"] this.email = data["email"] - this.css = data["css"] + this.setCss(data["css"]) this.nickFormat = data["nick_format"] // la page de la conversation principale this.pagePrincipale = data["main_page"] == undefined ? 1 : data["main_page"] - // met à jour la css - if (this.css != "") - { - $("link#cssPrincipale").attr("href", this.css) - this.majMenu() - } // les conversations - thisClient.conversations = data["conversations"] - - thisClient.ekMaster = data["ek_master"] + this.conversations = data["conversations"] } this.dernierMessageErreur = data["error_message"] } @@ -751,7 +748,7 @@ Client.prototype.majMenu = function() // TODO : à virer : ne plus changer de style de display ... spa beau .. ou trouver une autre méthode var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client - $("#menu .admin").css("display", this.ekMaster ? "none" : "inline") + $("#menu .admin").css("display", this.ekMaster ? "inline" : "none") // met à jour le menu if (this.statut == statutType.auth_registered) @@ -774,7 +771,6 @@ Client.prototype.majMenu = function() } } - Client.prototype.slap = function(userId, raison) { var thisClient = this @@ -799,7 +795,6 @@ Client.prototype.slap = function(userId, raison) }) } - Client.prototype.ban = function(userId, raison, minutes) { var thisClient = this @@ -836,6 +831,77 @@ Client.prototype.kick = function(userId, raison) /////////////////////////////////////////////////////////////////////////////////////////////////// +/** + * classe permettant de gérer les événements (push serveur). + * @page la page + */ +function PageEvent(page, util) +{ + this.page = page + this.util = util + + // l'objet JSONHttpRequest représentant la connexion d'attente + this.attenteCourante = null +} + +/** + * Arrête l'attente courante s'il y en a une. + */ +PageEvent.prototype.stopAttenteCourante = function() +{ + if (this.attenteCourante != null) + this.attenteCourante.abort() +} + +/** + * Attend un événement lié à la page. + * @funSend une fonction renvoyant les données json à envoyer + * @funReceive une fonction qui accepte un paramètre correspondant au données reçues + */ +PageEvent.prototype.waitEvent = function(funSend, funReceive) +{ + var thisPageEvent = this + + this.stopAttenteCourante() + + // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veux dans l'ordre définit dans le protocole) + // TODO : ya pas mieux ? + var dataToSend = + { + "action" : "wait_event", + "page" : this.page + } + var poulpe = funSend() + for (v in poulpe) + dataToSend[v] = poulpe[v] + + ;;; dumpObj(dataToSend) + this.attenteCourante = jQuery.ajax({ + type: "POST", + url: "request", + dataType: "json", + data: this.util.jsonVersAction(dataToSend), + success: + function(data) + { + ;;; dumpObj(data) + + funReceive(data) + + // rappel de la fonction dans 100 ms + setTimeout(function(){ thisPageEvent.waitEvent(funSend, funReceive) }, 100); + }, + error: + function(XMLHttpRequest, textStatus, errorThrown) + { + setTimeout(function(){ thisPageEvent.rafraichirMessages(funSend, funReceive) }, 1000); + } + }) + +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + function initialiserListeStyles(client) { $("#menuCss").change(