ADD Bannissement (sans le slap)
[euphorik.git] / js / euphorik.js
index 99a461f..6ed1963 100755 (executable)
@@ -21,19 +21,27 @@ var conf = {
       "bigsmile" : [/:D/g, /:-D/g],\r
       "clin" : [/;\)/g, /;-\)/g],\r
       "cool" : [/8\)/g, /8-\)/g],\r
-      "eheheh" : [/:P/g, /:-P/g],\r
-      "oh" : [/:o/g, /:O/g],\r
+      "eheheh" : [/:P/g, /:-P/g],
+      "lol" : [/\[-lol\]/g],
+      "spliff" : [/\[-spliff\]/g],\r
+      "oh" : [/:o/g, /:O/g],
+      "heink" : [/\[-heink\]/g],
+      "hum" : [/\[-hum\]/g],
+      "boh" : [/\[-boh\]/g],
+      "sniff" : [/:\(/g, /:-\(/g],
+      "triste" : [/\[-triste\]/g],\r
       "pascontent" : [/>\(/g, />\(/g],\r
-      "sniff" : [/:\(/g, /:-\(/g],\r
-      "argn" : [/\[:argn\]/g],\r
-      "bunny" : [/\[:lapin\]/g],\r
-      "chat" : [/\[:chat\]/g],\r
-      "renne" : [/\[:renne\]/g],\r
-      "lol" : [/\[:lol\]/g],\r
-      "spliff" : [/\[:spliff\]/g],\r
-      "star" : [/\[:star\]/g],\r
-      "triste" : [/\[:triste\]/g],\r
-      "kirby" : [/\[:kirby\]/g]\r
+      "argn" : [/\[-argn\]/g],
+      "redface" : [/\[-redface\]/g],\r
+      "bunny" : [/\[-lapin\]/g],\r
+      "chat" : [/\[-chat\]/g],\r
+      "renne" : [/\[-renne\]/g],\r
+      "star" : [/\[-star\]/g],\r
+      "kirby" : [/\[-kirby\]/g],
+      "slurp" : [/\[-slurp\]/g],
+      "agreed" : [/\[-agreed\]/g],
+      "dodo" : [/\[-dodo\]/g],
+      "bn" : [/\[-bn\]/g]\r
    }\r
 }\r
 
@@ -106,8 +114,7 @@ var messageType = {informatif: 0, question: 1, erreur: 2}
   */
 Util.prototype.jsonVersAction = function(json)
 {
-   // FIXME : ne plus encapsuler json dans de l'xml (problème avec yaws)
-   return {action: "<json>" + JSON.stringify(json) + "</json>" }
+   return {action : JSON.stringify(json) }
 }
 \r
 Util.prototype.md5 = function(chaine)\r
@@ -184,6 +191,29 @@ Util.prototype.replaceSelection = function(input, replaceString) {
    }\r
 }
 
+Util.prototype.rot13 = function(chaine)
+{
+   var ACode = 'A'.charCodeAt(0)
+   var aCode = 'a'.charCodeAt(0)
+   var MCode = 'M'.charCodeAt(0)
+   var mCode = 'm'.charCodeAt(0)
+   var ZCode = 'Z'.charCodeAt(0)
+   var zCode = 'z'.charCodeAt(0)
+
+   var f = function(ch, pos) {
+      if (pos == ch.length)
+         return ""
+      
+      var c = ch.charCodeAt(pos);
+      return String.fromCharCode(
+         c +
+         (c >= ACode && c <= MCode || c >= aCode && c <= mCode ? 13 :
+         (c > MCode && c <= ZCode || c > mCode && c <= zCode ? -13 : 0))
+      ) + f(ch, pos + 1)
+   }
+   return f(chaine, 0)
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 function Pages()
@@ -275,7 +305,8 @@ Formateur.prototype.traiterLiensConv = function(M)
 }
 \r
 /**\r
-  * FIXME : Cette méthode est attrocement lourde ! A optimiser.\r
+  * FIXME : Cette méthode est attrocement lourde ! A optimiser.
+  * moyenne su échantillon : 234ms\r
   */
 Formateur.prototype.traiterSmiles = function(M)
 {  
@@ -393,8 +424,10 @@ Client.prototype.resetDonneesPersonnelles = function()
    this.password = ""\r
    this.email = ""\r
    this.css = jQuery("link#cssPrincipale").attr("href")
+   this.nickFormat = "nick"
    
    this.pagePrincipale = 1
+   this.ekMaster = false
    
    // les conversations, une conversation est un objet possédant les attributs suivants :
    // - racine (entier)
@@ -528,6 +561,7 @@ Client.prototype.getJSONProfile = function()
       "nick" : this.pseudo,
       "email" : this.email,
       "css" : this.css,
+      "nick_format" : this.nickFormat,
       "main_page" : this.pagePrincipale < 1 ? 1 : this.pagePrincipale,
       "conversations" : this.getJSONConversations()
    }
@@ -565,6 +599,7 @@ Client.prototype.authentifie = function()
 
 Client.prototype.setStatut = function(statut)
 {  
+   //alert(statut)
    // conversation en "enum" si en "string"\r
    if (typeof(statut) == "string")\r
    {
@@ -637,10 +672,11 @@ Client.prototype.connexion = function(messageJson)
 }\r
 \r
 Client.prototype.deconnexion = function()\r
-{\r
+{
+   this.flush()
+   this.delCookie()\r
    this.setStatut(statutType.deconnected) // deconnexion\r
    this.resetDonneesPersonnelles()\r
-   this.delCookie ()\r
 }
 
 Client.prototype.chargerDonnees = function(data)
@@ -658,6 +694,7 @@ Client.prototype.chargerDonnees = function(data)
       this.pseudo = data["nick"]\r
       this.email = data["email"]\r
       this.css = data["css"]
+      this.nickFormat = data["nick_format"]
       
       // la page de la conversation principale
       this.pagePrincipale = data["main_page"] == undefined ? 1 : data["main_page"]
@@ -671,6 +708,7 @@ Client.prototype.chargerDonnees = function(data)
       // les conversations
       thisClient.conversations = data["conversations"]
       
+      thisClient.ekMaster = data["ek_master"]
    }
    this.dernierMessageErreur = data["error_message"]
 }
@@ -733,8 +771,51 @@ Client.prototype.majMenu = function()
    }
 }
 
+Client.prototype.ban = function(userId, minutes)
+{
+   var thisClient = this
+
+   // par défaut un ban correspond à 3 jours
+   if (typeof(minutes) == "undefined")
+      minutes = 60 * 24 * 3
+      
+   jQuery.ajax({
+      type: "POST",
+      url: "request",
+      dataType: "json",
+      data: this.util.jsonVersAction(
+         {
+            "action" : "ban",
+            "cookie" : thisClient.cookie,
+            "duration" : minutes,
+            "user_id" : userId
+         }),
+      success: 
+         function(data)
+         {
+            if (data["reply"] == "error")
+               thisClient.util.messageDialogue(data["error_message"])
+         }
+   })
+}
+
+Client.prototype.kick = function(userId)
+{
+   this.ban(userId, 15)
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
+function initialiserListeStyles(client)
+{
+   jQuery("#menuCss").change(
+      function()
+      {
+         client.setCss("css/" + jQuery("option:selected", this).attr("value") + "/euphorik.css")
+      }
+   )
+}
+
 jQuery.noConflict()
             
 // charge dynamiquement le script de debug
@@ -744,12 +825,6 @@ jQuery.noConflict()
 jQuery(document).ready(
    function()
    {  
-      /* FIXME : ce code pose problème sur konqueror, voir : http://www.kde-forum.org/thread.php?threadid=17993
-      var p = new DOMParser();
-      var doc =  p.parseFromString("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<action/>", "text/xml")
-      var s = new XMLSerializer()
-      alert(s.serializeToString(doc)) */
-   
       var util = new Util()
       var client = new Client(util)
       var pages = new Pages()
@@ -758,22 +833,10 @@ jQuery(document).ready(
       // connexion vers le serveur (utilise un cookie qui traine)\r
       client.connexionCookie()
       
-      // les styles css
-      for (var i = 1; i <= 3; i++)
-      {
-         jQuery("#css"+i).click(function(){
-            client.setCss("css/" + jQuery(this).attr("id").charAt(3) + "/euphorik.css")
-         })
-      }
+      initialiserListeStyles(client)
 
       // TODO : pourquoi jQuery(document).unload ne fonctionne pas ?
-      jQuery(window).unload(
-         function()
-         {
-            //alert("ok")
-            client.flush(false)
-         }
-      )
+      jQuery(window).unload(function(){client.flush(false)})
       
       jQuery("#menu .minichat").click(function(){ pages.afficherPage("minichat") })
       jQuery("#menu .profile").click(function(){ pages.afficherPage("profile") })\r
@@ -789,10 +852,12 @@ jQuery(document).ready(
          )
       })
       jQuery("#menu .register").click(function(){ pages.afficherPage("register") })
+      jQuery("#menu .about").click(function(){ pages.afficherPage("about") })
 
       pages.ajouterPage(new PageMinichat(client, formateur, util))
       pages.ajouterPage(new PageProfile(client, formateur, util))
       pages.ajouterPage(new PageRegister(client, formateur, util))
+      pages.ajouterPage(new PageAbout(client, formateur, util))
       pages.afficherPage("minichat")
    }
 )
\ No newline at end of file