X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2FpageMinichat.js;fp=js%2FpageMinichat.js;h=0b9c5b362ee2b83a41dd0230db2408e89b819f6f;hp=0000000000000000000000000000000000000000;hb=e49a1c483f1751f129c0766d1061b3da44b60581;hpb=d6dcd0fd8af56bd4791aa4e621c2e5058033c37a diff --git a/js/pageMinichat.js b/js/pageMinichat.js new file mode 100755 index 0000000..0b9c5b3 --- /dev/null +++ b/js/pageMinichat.js @@ -0,0 +1,294 @@ +// 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 . + +/*jslint laxbreak:true */ + +euphorik.PageMinichat = function(client, formater, util, communication) { + this.nom = "minichat"; + + this.client = client; + this.formater = formater; + this.util = util; + this.communication = communication; + this.commandes = new euphorik.Commandes(this.client, this, this.util, this.formater); + + // permet d'éviter d'envoyer plusieurs messages simultanément en pressant + // rapidement sur "enter" par exemple + this.envoieMessageEnCours = false; +}; + +euphorik.PageMinichat.prototype.contenu = function() { + // le fait que tout soit collé est fait exprès, permet d'éviter d'avoir des espaces supplémentaires entre les spans + var formulaireXHTML = '' + + '
' + + '

' + + ' ' + + ' ' + + ' 0' + + ' ' + + ' ' + + ' ' + + '

' + + '
'; + + var trollXHTML = '
Troll de la semaine :
'; + var conversationXHTML = '
'; + + if (this.client.chatOrder === "reverse") { + return trollXHTML + formulaireXHTML + conversationXHTML; + } else { + return trollXHTML + conversationXHTML + formulaireXHTML; + } +}; + +euphorik.PageMinichat.prototype.classes = function() { + return this.client.chatOrder === "reverse" ? "orderReverse" : "orderChrono"; +}; + +euphorik.PageMinichat.prototype.charger = function() { + thisPage = this; + + $("#posterMessage input.pseudo").val(this.client.pseudo); + + // cet appel ne doit pas être fait avant l'appel à 'charger' + this.conversations = new euphorik.Conversations(this.client, this.formater, this.util, this.communication, this.fragment); + + this.chargerConversationsFragment(); + + this.conversations.rafraichirMessages(true); + + this.util.setCaretToEnd($("form#posterMessage input.message")[0]); + + // les outils de bannissement (uniquement pour les ekMaster) + if (this.client.ekMaster) { + // TODO : augmentation un peu space, à revoir + this.util.outilsBan = $( + '' + + ' ' + + '

' + + ' Ban de 3 jours' + + ' Ban de 15 min' + + ' Avertissement' + + '
' + ); + + this.util.infoBulle("Slap", $("#slap", this.util.outilsBan)); + this.util.infoBulle("Kick (" + euphorik.conf.tempsKick + "min)", $("#kick", this.util.outilsBan)); + this.util.infoBulle("Ban (" + euphorik.conf.tempsBan / 24 / 60 + " jours)", $("#ban", this.util.outilsBan)); + this.util.infoBulle("La raison", $("input", this.util.outilsBan)); + } + + // la barre d'outils liée à chaque message + this.util.outilsMessage = $('
').prependTo("#page.minichat"); + this.util.infoBulle("Ouvrir la conversation liée au troll de la semaine", $("#trollCourant .troll")); + this.util.infoBulle("Cliquer sur les messages pour les enlevers de la liste", + $("form#posterMessage #repondA").hover( + function() { + thisPage.util.afficherBoite( + $(".messages", this), + $(this), + euphorik.Util.positionTypeX.centre, + thisPage.client.chatOrder === "reverse" ? euphorik.Util.positionTypeY.bas : euphorik.Util.positionTypeY.haut + ); + }, + function() { $(".messages", this).hide(); } + ).click( + function(e) { + if ($(e.target).is(".nb")) { + thisPage.conversations.enleverMessagesRepond(); + } + } + ), + euphorik.Util.positionBulleType.droite + ); + + // + $("body").append('
'); + // affichage des smiles + $("#smiles").append(this.formater.getSmilesHTML()).children().each( + function(i) { + var opacityBase = $(this).css("opacity"); + $(this).click( + function() { + thisPage.util.replaceSelection($("form#posterMessage input.message")[0], thisPage.formater.smiles[$(this).attr("class")][0].source.replace(/\\/g, "")); + } + ).hover( + function() { $(this).animate({opacity: 1}, 200); }, + function() { $(this).animate({opacity: opacityBase}, 200); } + ); + } + ); + $("form#posterMessage button.smiles").hover( + // affichage de la boite présentant les smiles + function(e){ thisPage.util.afficherBoite($("#smiles"), $(e.target), euphorik.Util.positionTypeX.centre, euphorik.Util.positionTypeY.basRecouvrement); }, + function(){} + ); + $("#smiles").hover( + function(){}, + function() { + $("#smiles").hide(); + } + ); + //
+ + // événements + var nouveauMessage = + function() { + // captcha anti bot + if ($("form#posterMessage input.captcha").val() !== "") { + return; + } + + var message = $("form#posterMessage input.message").val(); + + // traitement des commandes.. + var retCommandes = thisPage.commandes.exec(message); + switch (retCommandes[0]) { + case euphorik.Commandes.statut.pas_une_commande : + thisPage.envoyerMessage(message); + break; + case euphorik.Commandes.statut.erreur_commande : + thisPage.util.messageDialog(retCommandes[1], euphorik.Util.messageType.erreur); + break; + case euphorik.Commandes.statut.ok : + $("form#posterMessage input.message").val(""); + break; + } + + $("form#posterMessage input.message").focus(); + }; + + $("form#posterMessage").keypress( + function(e) { + if (e.which === 13) { // return + nouveauMessage(); + } + } + ); + + $("form#posterMessage button.return").click(nouveauMessage); + + // interdiction de submiter le formulaire + $("form#posterMessage").submit(function(){ return false; }); + + $("input.pseudo").click( + function() { + var input = $("input.pseudo")[0]; + if (input.value === euphorik.conf.pseudoDefaut) { + input.value = ""; + } + } + ); +}; + +euphorik.PageMinichat.prototype.chargerConversationsFragment = function() { + var thisPageMinichat = this; + + // attention : "conv" doit être un tableau d'entier + try { + var conv = this.fragment.getVal("conv"); + if (conv) { + conv.each(function(i, racine) { + thisPageMinichat.client.ajouterConversation(racine) + }); + } + } catch(e) { + ;; console.log(e) + } +}; + +euphorik.PageMinichat.prototype.decharger = function() { + this.conversations.comet.stopAttenteCourante(); + + $("body #smiles").remove(); + + this.fragment.delVal("conv"); +}; + +/** + * Envoie un nouve message donné, le pseudo utilisé est celui se trouvant + * dans la zone de saisie (form#posterMessage input.pseudo). + */ +euphorik.PageMinichat.prototype.envoyerMessage = function(message) { + var thisPageMinichat = this; + var pseudo = $("form#posterMessage input.pseudo").val(); + + // (un pseudo vide est autorisé) + pseudo = this.formater.filtrerInputPseudo(pseudo); + + if (pseudo === euphorik.conf.pseudoDefaut) { + this.util.messageDialog("Le pseudo ne peut pas être " + euphorik.conf.pseudoDefaut); + return; + } + + message = message.trim(); + if (!message) { + this.util.messageDialog("Le message est vide"); + return; + } + + this.client.pseudo = pseudo; + + if (!this.client.authentifie()) { + if (!this.client.enregistrement()) { + this.util.messageDialog("login impossible"); + return; + } + } + + // évite le double post + if (this.envoieMessageEnCours) { + this.util.messageDialog("Message en cours d'envoie..."); + return; + } + this.envoieMessageEnCours = true; + + this.communication.requete( + "put_message", + this.getJSONMessage(pseudo, message), + function() { + $("form#posterMessage input.message").val(""); + thisPageMinichat.conversations.enleverMessagesRepond(); + thisPageMinichat.envoieMessageEnCours = false; + }, + function(data) { + thisPageMinichat.util.messageDialog(data.error_message); + thisPageMinichat.envoieMessageEnCours = false; + }, + true, + { + error : function() { + thisPageMinichat.envoieMessageEnCours = false; + } + } + ); +}; + +euphorik.PageMinichat.prototype.getJSONMessage = function(pseudo, message) { + var repondA = []; + objectEach(this.conversations.messagesRepond, function(id) { + repondA.push(parseInt(id, 10)); + }); + + return { + "cookie" : this.client.cookie, + "nick" : pseudo, + "content" : message, + "answer_to" : repondA + }; +};