FIX légère optimisation du rafraichissement des messages
[euphorik.git] / js / euphorik.js
index d040dc3..5a15c00 100755 (executable)
@@ -13,7 +13,7 @@
   * Normalement 'const' à la place de 'var' mais non supporté par IE7.
   */\r
 var conf = {\r
-   nbMessageAffiche : 10, // (par page)
+   nbMessageAffiche : 40, // (par page)
    pseudoDefaut : "<nick>",\r
    tempsAffichageMessageDialogue : 4000, // en ms\r
    smiles : {   \r
@@ -384,7 +384,7 @@ Formateur.prototype.traiterPourFenetreLightBox = function(M, urlCourante)
    thisFormateur = this
    var traitementUrl = function(url)
    {
-      return "[" + thisFormateur.getShort(url)[0] + (urlCourante == url ? ": image courante" : "") + "]"
+      return "[" + thisFormateur.getShort(url)[0] + (urlCourante == url ? "*" : "") + "]"
    }
    \r
    return this.remplacerBalisesHTML(M).replace(this.regexUrl, traitementUrl)
@@ -413,10 +413,7 @@ function Client(util)
    // données personnels\r
    this.resetDonneesPersonnelles()
    
-   this.setStatut(statutType.deconnected)
-   
-   // le dernier message d'erreur recut du serveur (par exemple une connexion foireuse : "login impossible")
-   this.dernierMessageErreur = ""\r
+   this.setStatut(statutType.deconnected)\r
 }
 \r
 Client.prototype.resetDonneesPersonnelles = function()\r
@@ -428,6 +425,7 @@ Client.prototype.resetDonneesPersonnelles = function()
    this.email = ""\r
    this.css = $("link#cssPrincipale").attr("href")
    this.nickFormat = "nick"
+   this.cookie = undefined
    
    this.pagePrincipale = 1
    this.ekMaster = false
@@ -611,7 +609,7 @@ Client.prototype.setStatut = function(statut)
          (statut == "auth_not_registered" ? statutType.auth_not_registered : statutType.deconnected)\r
    }   \r
    \r
-   if (statut == this.statut) return   \r
+   if (statut == this.statut) return\r
    \r
    this.statut = statut   \r
    this.majMenu()
@@ -642,8 +640,11 @@ Client.prototype.enregistrement = function(login, password)
       this.login = login
       this.password = password
       if(this.flush())
+      {
          this.setStatut(statutType.auth_registered)
-      return true
+         return true
+      }
+      return false
    }
    else\r
    {
@@ -666,7 +667,10 @@ Client.prototype.connexion = function(messageJson)
             function(data)
             {
                ;;; dumpObj(data)
-               thisClient.chargerDonnees(data)
+               if (data["reply"] == "error")
+                  thisClient.util.messageDialogue(data["error_message"])
+               else
+                  thisClient.chargerDonnees(data)
             }
       }
    )
@@ -675,10 +679,10 @@ Client.prototype.connexion = function(messageJson)
 \r
 Client.prototype.deconnexion = function()\r
 {
-   this.flush()
-   this.delCookie()\r
-   this.setStatut(statutType.deconnected) // deconnexion\r
+   this.flush(true)
+   this.delCookie()
    this.resetDonneesPersonnelles()\r
+   this.setStatut(statutType.deconnected) // deconnexion\r
 }
 
 Client.prototype.chargerDonnees = function(data)
@@ -707,7 +711,6 @@ Client.prototype.chargerDonnees = function(data)
       // les conversations
       this.conversations = data["conversations"]
    }
-   this.dernierMessageErreur = data["error_message"]
 }
 
 /**
@@ -718,12 +721,14 @@ Client.prototype.chargerDonnees = function(data)
 Client.prototype.flush = function(async)
 {
    if (async == undefined)
-      async = true
+      async = false
       
    if (!this.authentifie())
       return false
 
-   thisClient = this
+   var thisClient = this
+   var ok = true
+   
    ;;; dumpObj(this.getJSONProfile())
    jQuery.ajax(
       {
@@ -735,12 +740,17 @@ Client.prototype.flush = function(async)
          success:
             function(data)
             {
-               //thisClient.util.log(thisClient.util.serializer.serializeToString(data))   
+               ;;; dumpObj(data)
+               if (data["reply"] == "error")
+               {
+                  thisClient.util.messageDialogue(data["error_message"])
+                  ok = false
+               }
             }
       }
    )
-   // TODO : retourner false si un problème est survenu lors de l'update du profile
-   return true
+   
+   return ok
 }
 
 Client.prototype.majMenu = function()
@@ -930,7 +940,7 @@ $(document).ready(
       initialiserListeStyles(client)
 
       // TODO : pourquoi $(document).unload ne fonctionne pas ?
-      $(window).unload(function(){client.flush(false)})
+      $(window).unload(function(){client.flush()})
       
       $("#menu .minichat").click(function(){ pages.afficherPage("minichat") })
       $("#menu .admin").click(function(){ pages.afficherPage("admin") })