X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2FpageMinichat%2FpageMinichat.js;h=e952281dfad3bf5b286f8c12426507e9579c258d;hp=d289a99353739abfb6a8e7b115f45d02e5497a10;hb=15f8b5143c6b9dcfe86eda84c22c31826a7f3d1c;hpb=972919ab7f5651cd721eb6eec75f7150fdeaf347 diff --git a/js/pageMinichat/pageMinichat.js b/js/pageMinichat/pageMinichat.js index d289a99..e952281 100755 --- a/js/pageMinichat/pageMinichat.js +++ b/js/pageMinichat/pageMinichat.js @@ -18,12 +18,13 @@ /*jslint laxbreak:true */ -euphorik.PageMinichat = function(client, formateur, util) { +euphorik.PageMinichat = function(client, formateur, util, communication) { this.nom = "minichat"; this.client = client; this.formateur = formateur; this.util = util; + this.communication = communication; this.commandes = new euphorik.Commandes(this.client); // permet d'éviter d'envoyer plusieurs messages simultanément en pressant @@ -226,22 +227,6 @@ euphorik.PageMinichat.prototype.decharger = function() { this.fragment.delVal("conv") }; - -euphorik.PageMinichat.prototype.getJSONMessage = function(pseudo, message) { - var repondA = []; - objectEach(this.conversations.messagesRepond, function(id) { - repondA.push(parseInt(id, 10)); - }); - - return { - "header" : { "action" : "put_message", "version" : euphorik.conf.versionProtocole }, - "cookie" : this.client.cookie, - "nick" : pseudo, - "content" : message, - "answer_to" : repondA - }; -}; - euphorik.PageMinichat.prototype.envoyerMessage = function(pseudo, message) { var thisPageMinichat = this; @@ -275,38 +260,52 @@ euphorik.PageMinichat.prototype.envoyerMessage = function(pseudo, message) { } this.envoieMessageEnCours = true; - jQuery.ajax({ - url : "request", - type: "POST", - data : this.util.jsonVersAction(this.getJSONMessage(pseudo, message)), - dataType : "json", - beforeSend : function(xmlHttpRequest) { - // TODO : ça marche ça ?? - xmlHttpRequest.setRequestHeader("X-Requested-With", ""); - }, - success : function(data, textStatus) { - if(data.reply === "ok") { - // TODO : revoir cette partie - // met à jour la classe des messages auquel repond celui ci (c'est un peu de la triche) TODO : ya mieux ? - objectEach(thisPageMinichat.conversations.messagesRepond, function(messId) { - thisPageMinichat.conversations.conversations.each(function(i, conv) { - var mess = conv.messagesParId[messId]; - if (mess) { - mess.clientARepondu = true; - $("#conversations #" + mess.getId(conv.getId())).addClass("repondu") - } - }); + this.communication.requete( + "put_message", + this.getJSONMessage(pseudo, message), + function() { + // TODO : revoir cette partie + // met à jour la classe des messages auquel repond celui ci (c'est un peu de la triche) TODO : ya mieux ? + objectEach(thisPageMinichat.conversations.messagesRepond, function(messId) { + thisPageMinichat.conversations.conversations.each(function(i, conv) { + var mess = conv.messagesParId[messId]; + if (mess) { + mess.clientARepondu = true; + $("#conversations #" + mess.getId(conv.getId())).addClass("repondu") + } }); - - $("form#posterMessage input.message").val(""); - thisPageMinichat.conversations.enleverMessagesRepond(); - } else if (data.reply === "error") { - thisPageMinichat.util.messageDialogue(data.error_message); - } + }); + $("form#posterMessage input.message").val(""); + thisPageMinichat.conversations.enleverMessagesRepond(); thisPageMinichat.envoieMessageEnCours = false; }, - error : function() { + function(data) { + thisPageMinichat.util.messageDialogue(data.error_message); thisPageMinichat.envoieMessageEnCours = false; + }, + true, + { + beforeSend : function(xmlHttpRequest) { + // TODO : ça marche ça ?? + xmlHttpRequest.setRequestHeader("X-Requested-With", ""); + }, + 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 + }; };