ADD troll sur la page principale
[euphorik.git] / js / pageMinichat.js
index ed0321c..1f6a118 100755 (executable)
@@ -15,6 +15,7 @@ function PageMinichat(client, formateur, util)
 PageMinichat.prototype.contenu = function()
 {
    return '\
+<div id="trollCourant">Troll de la semaine : <span class="troll"></span></div>\
 <form method="post" action="">\
    <p>\
       <input class="captcha" name="captcha" type="text" size="8" maxlength="8"></input>\
@@ -671,6 +672,8 @@ function Messages(client, formateur, util)
    this.conversations = new Array() // les conversations, la première représente la conversation principale
    this.nouvelleConversation(0)
    
+   this.trollIdCourant = 0
+   
    this.pageEvent = new PageEvent("chat", this.util)
 }
 
@@ -682,10 +685,11 @@ Messages.prototype.getJSONrafraichirMessages = function()
    var mess =  {
       "message_count" : conf.nbMessageAffiche,
       "main_page" : this.client.pagePrincipale,
-      "conversations" : this.getJSONConversations()
+      "conversations" : this.getJSONConversations(),
+      "troll_id" : this.trollIdCourant
    }
    
-   if (this.client.cookie != null) mess["cookie"] = this.client.cookie;
+   if (this.client.cookie != null) mess["cookie"] = this.client.cookie
    mess["last_message_id"] = this.conversations[0].idDernierMessageAffiche
    
    return mess
@@ -894,21 +898,32 @@ Messages.prototype.rafraichirMessages = function(vider)
       function() { return thisMessages.getJSONrafraichirMessages() },
       function(data)
       {
-            if (vider)
-            {
-               thisMessages.viderMessages()
-               vider = false
-            }
-            
-            // ajoute les messages reçus à leur conversation respective
-            for (var numConv = 0; numConv < data["conversations"].length; numConv++)
-            {
-               if (! thisMessages.ajouterMessages(data["conversations"][numConv], numConv))
+         if (vider)
+         {
+            thisMessages.viderMessages()
+            vider = false
+         }
+               
+         // en fonction du message
+         switch(data["reply"])
+         {
+            case "new_troll" :
+               thisMessages.trollIdCourant = data["troll_id"]
+               $("#trollCourant .troll").html(thisMessages.formateur.traitementComplet(data["content"]))
+               break
+               
+            case "new_messages" :                        
+               // ajoute les messages reçus à leur conversation respective
+               for (var numConv = 0; numConv < data["conversations"].length; numConv++)
                {
-                  thisMessages.util.messageDialogue("La conversation {" + thisMessages.client.conversations[numConv -1].root.toString(36) + "} n'existe pas")
-                  thisMessages.client.supprimerConversation(numConv - 1) 
+                  if (! thisMessages.ajouterMessages(data["conversations"][numConv], numConv))
+                  {
+                     thisMessages.util.messageDialogue("La conversation {" + thisMessages.client.conversations[numConv -1].root.toString(36) + "} n'existe pas")
+                     thisMessages.client.supprimerConversation(numConv - 1) 
+                  }
                }
-            }
+               break
+         }
       }
    )
 }