X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2FpageMinichat.js;h=da53627f888ef508f9cecacb511bd56d681e9357;hp=03024bcb00bfc5be0b5f21c5c00c7cd8da313024;hb=650c44a784cabc8a1f2bd1daa7e5e61ccf74ca6f;hpb=77a18f781417d222d52b50221e9051194bd3195f diff --git a/js/pageMinichat.js b/js/pageMinichat.js index 03024bc..da53627 100755 --- a/js/pageMinichat.js +++ b/js/pageMinichat.js @@ -1,19 +1,19 @@ -// coding: utf-8 -// Copyright 2008 Grégory Burri -// -// This file is part of Euphorik. -// -// Euphorik is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Euphorik is distributed in the hope that it will be useful, -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License +// coding: utf-8 +// Copyright 2008 Grégory Burri +// +// This file is part of Euphorik. +// +// Euphorik is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Euphorik is distributed in the hope that it will be useful, +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License // along with Euphorik. If not, see . function PageMinichat(client, formateur, util) @@ -24,6 +24,10 @@ function PageMinichat(client, formateur, util) this.formateur = formateur this.util = util + // permet d'éviter d'envoyer plusieurs messages simultanément en pressant + // rapidement sur "enter" par exemple + this.envoieMessageEnCours = false + this.regexMessageTagMatch = /\{.*?\}>/g this.regexMessageTagReplace = /^(.*?\{.*?\}>)*/ } @@ -54,7 +58,7 @@ PageMinichat.prototype.charger = function() this.messages = new Messages(this.client, this.formateur, this.util) this.messages.rafraichirMessages(true) - + this.util.setCaretToEnd($("form input.message")[0]) // les outils de bannissement (uniquement pour les ekMaster) @@ -173,9 +177,9 @@ PageMinichat.prototype.getJSONMessage = function(pseudo, message, repondA) } PageMinichat.prototype.envoyerMessage = function(pseudo, message) -{ +{ var thisPageMinichat = this - + // (un pseudo vide est autorisé) pseudo = this.formateur.filtrerInputPseudo(pseudo) @@ -187,53 +191,75 @@ PageMinichat.prototype.envoyerMessage = function(pseudo, message) for(var i = 0; i < tags.length; i++) repondA.push(parseInt(/\{(.*?)\}>/.exec(tags[i])[1], 36)) message = message.replace(this.regexMessageTagReplace, "") - } - - message = message.trim() - if (message == "") + } + + message = message.trim() + if (message == "") { - this.util.messageDialogue("Le message est vide") - return - } - - if (!this.client.authentifie()) - if (!this.client.enregistrement()) - { - this.util.messageDialogue("login impossible") - return + this.util.messageDialogue("Le message est vide") + return + } + + if (!this.client.authentifie()) + if (!this.client.enregistrement()) + { + this.util.messageDialogue("login impossible") + return } - this.client.pseudo = pseudo - - ;; dumpObj(this.getJSONMessage(pseudo, message, repondA)) - jQuery.ajax( - { - url : "request", - type: "POST", - data : this.util.jsonVersAction(this.getJSONMessage(pseudo, message, repondA)), + this.client.pseudo = pseudo + + // évite le double post + if (this.envoieMessageEnCours) + { + this.util.messageDialogue("Message en cours d'envoie...") + return + } + this.envoieMessageEnCours = true + + ;; dumpObj(this.getJSONMessage(pseudo, message, repondA)) + jQuery.ajax( + { + url : "request", + type: "POST", + data : this.util.jsonVersAction(this.getJSONMessage(pseudo, message, repondA)), dataType : "json", beforeSend : function(xmlHttpRequest) { + // TODO : ça marche ça ?? xmlHttpRequest.setRequestHeader("X-Requested-With", "") - }, - success : function(data, textStatus) + }, + success : function(data, textStatus) { ;; dumpObj(data) if(data["reply"] == "ok") - { + { $("form input.message").val("") // met à jour la classe des messages auquel repond celui ci (c'est un peu de la triche) TODO : ya mieux ? for (var i = 0; i < repondA.length; i++) + { + for (var j = 0; j < thisPageMinichat.messages.conversations.length; j++) + { + var mess = thisPageMinichat.messages.conversations[j].messagesParId[repondA[i]] + if (mess != undefined) + mess.clientARepondu = true + } $("#conversations div#mess" + repondA[i].toString(36)).addClass("repondu") + } } else if (data["reply"] == "error") { thisPageMinichat.util.messageDialogue(data["error_message"]) - } - } - } + } + thisPageMinichat.envoieMessageEnCours = false + }, + error : function() + { + thisPageMinichat.envoieMessageEnCours = false + } + } ) } @@ -561,7 +587,7 @@ Conversation.prototype.flush = function(funClickOuvrirConv) var DOM = $(XHTML) DOM.each( function() - { + { $(".lienConv", this).click( function(event) { @@ -570,6 +596,49 @@ Conversation.prototype.flush = function(funClickOuvrirConv) funClickOuvrirConv(parseInt(racine.substring(1, racine.length - 1), 36)) return false } + ) + + thisConversation.util.infoBulle("Extraction de la conversation", $(".extraire", this)) + + // l'id du message + var idMess36 = $(this).attr("id").substr(4) + var idMess = parseInt(idMess36, 36) + + $(this).click( + function(event) + { + if ($(event.target).is("a") || $(event.target).parents("#outilsBan").length > 0) return + + // extraction d'une conversation + if ($(event.target).is(".extraire")) + { + funClickOuvrirConv(idMess) + return + } + + var valCourant = $("input.message").val() + if (valCourant == undefined) valCourant = "" + var tag = $(".pseudo span.ident", this).text() + "{" + idMess36 + "}" + ">" + if (valCourant.indexOf(tag, 0) == -1) + $("input.message").val(tag + " " + valCourant) + thisConversation.util.setCaretToEnd($("form input.message")[0]) + } + ) + + // mise en évidence de la conversation + $(".entete", this).hover( + function() + { + thisConversation.decolorerEntetes() + thisConversation.afficherConversation(idMess) + }, + // quand on sort de l'entête du message la mise en évidence est enlevée + function() + { + thisConversation.enleverMiseEnEvidence() + thisConversation.decolorerEntetes() + thisConversation.colorerEntetes() + } ) if (thisConversation.client.viewTimes) @@ -619,50 +688,7 @@ Conversation.prototype.flush = function(funClickOuvrirConv) { $("#outilsBan", this).hide() } - ) - - thisConversation.util.infoBulle("Extraction de la conversation", $(".extraire", this)) - - // l'id du message - var idMess36 = $(this).attr("id").substr(4) - var idMess = parseInt(idMess36, 36) - - $(this).click( - function(event) - { - if ($(event.target).is("a") || $(event.target).parents("#outilsBan").length > 0) return - - // extraction d'une conversation - if ($(event.target).is(".extraire")) - { - funClickOuvrirConv(idMess) - return - } - - var valCourant = $("input.message").val() - if (valCourant == undefined) valCourant = "" - var tag = $(".pseudo span.ident", this).text() + "{" + idMess36 + "}" + ">" - if (valCourant.indexOf(tag, 0) == -1) - $("input.message").val(tag + " " + valCourant) - thisConversation.util.setCaretToEnd($("form input.message")[0]) - } - ) - - // mise en évidence de la conversation - $(".entete", this).hover( - function() - { - thisConversation.decolorerEntetes() - thisConversation.afficherConversation(idMess) - }, - // quand on sort de l'entête du message la mise en évidence est enlevée - function() - { - thisConversation.enleverMiseEnEvidence() - thisConversation.decolorerEntetes() - thisConversation.colorerEntetes() - } - ) + ) } ) DOM.prependTo("#conversations #" + this.getId()) @@ -817,7 +843,7 @@ Messages.prototype.ajouterMessage = function(element, numConversation) element["nick"], element["login"], element["content"] - ) + ) message.appartientAuClient = element["owner"] message.clientARepondu = element["answered"] @@ -904,10 +930,10 @@ Messages.prototype.supprimerConversation = function(num) * Ajuste la largeur des conversations en fonction de leur nombre. modifie l'attribut CSS 'width'. */ Messages.prototype.ajusterLargeurConversations = function() -{ - var largeurPourcent = (100 / this.conversations.length) - // le "- 0.01" evite que IE se chie dessus lamentablement et affiche les conversations les unes au dessus des autres - if($.browser["msie"]) +{ + var largeurPourcent = (100 / this.conversations.length) + // le "- 0.01" evite que IE se chie dessus lamentablement et affiche les conversations les unes au dessus des autres + if($.browser["msie"]) largeurPourcent -= 0.05 $("#conversations .conversation").css("width", largeurPourcent + "%") }