MOD amélioration du style
[euphorik.git] / js / euphorik.js
index 86982db..b44f042 100755 (executable)
@@ -1,4 +1,20 @@
 // coding: utf-8\r
+// Copyright 2008 Grégory Burri\r
+//\r
+// This file is part of Euphorik.\r
+//\r
+// Euphorik is free software: you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation, either version 3 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// Euphorik is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with Euphorik.  If not, see <http://www.gnu.org/licenses/>.\r
 \r
 /**\r
   * Contient la base javascript pour le site euphorik.ch.\r
@@ -449,6 +465,9 @@ function Client(util)
    this.resetDonneesPersonnelles()
    
    this.setStatut(statutType.deconnected)\r
+   \r
+   // si true alors chaque modification du client est mémorisé sur le serveur\r
+   this.autoflush = $.browser["opera"]\r
 }
 \r
 Client.prototype.resetDonneesPersonnelles = function()\r
@@ -478,7 +497,9 @@ Client.prototype.setCss = function(css)
 
    this.css = css
    $("link#cssPrincipale").attr("href", this.css)
-   this.majMenu()
+   this.majMenu()\r
+   \r
+   if (this.autoflush) this.flush(true)
 }
 
 Client.prototype.pageSuivante = function(numConv)
@@ -531,7 +552,10 @@ Client.prototype.ajouterConversation = function(racine)
       if (this.conversations[i].root == racine)
          return false
          
-   this.conversations.push({root : racine, page : 1})
+   this.conversations.push({root : racine, page : 1})\r
+   \r
+   if (this.autoflush) this.flush(true)\r
+   
    return true
 }
 
@@ -542,7 +566,9 @@ Client.prototype.supprimerConversation = function(num)
    // décalage TODO : supprimer le dernier élément 
    for (var i = num; i < this.conversations.length - 1; i++)
       this.conversations[i] = this.conversations[i+1]
-   this.conversations.pop()
+   this.conversations.pop()\r
+   \r
+   if (this.autoflush) this.flush(true)
 }
 
 Client.prototype.getJSONLogin = function(login, password)
@@ -888,6 +914,9 @@ function PageEvent(page, util)
    
    // l'objet JSONHttpRequest représentant la connexion d'attente
    this.attenteCourante = null
+   
+   // le multhreading du pauvre, merci javascript de m'offrire autant de primitives pour la gestion de la concurrence...
+   this.stop = false
 }
 
 /**
@@ -895,8 +924,12 @@ function PageEvent(page, util)
   */
 PageEvent.prototype.stopAttenteCourante = function()
 {
+   this.stop = true
+         
    if (this.attenteCourante != null)
+   {
       this.attenteCourante.abort()   
+   }
 }
 
 /**
@@ -906,11 +939,13 @@ PageEvent.prototype.stopAttenteCourante = function()
   */
 PageEvent.prototype.waitEvent = function(funSend, funReceive)
 {
-   var thisPageEvent = this
-      
    this.stopAttenteCourante()
+   
+   this.stop = false
+   
+   var thisPageEvent = this
       
-   // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veux dans l'ordre définit dans le protocole)
+   // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veut dans l'ordre définit dans le protocole)
    // TODO : ya pas mieux ?
    var dataToSend = 
    {
@@ -922,6 +957,7 @@ PageEvent.prototype.waitEvent = function(funSend, funReceive)
       dataToSend[v] = poulpe[v]
    
    ;;; dumpObj(dataToSend)
+   
    this.attenteCourante = jQuery.ajax({
       type: "POST",
       url: "request",
@@ -935,15 +971,24 @@ PageEvent.prototype.waitEvent = function(funSend, funReceive)
             funReceive(data)
             
             // rappel de la fonction dans 100 ms
-            setTimeout(function(){ thisPageEvent.waitEvent(funSend, funReceive) }, 100);
+            setTimeout(function(){ thisPageEvent.waitEvent2(funSend, funReceive) }, 100)
          },
       error:
          function(XMLHttpRequest, textStatus, errorThrown)
          {
-            setTimeout(function(){ thisPageEvent.waitEvent(funSend, funReceive) }, 1000);
+            setTimeout(function(){ thisPageEvent.waitEvent2(funSend, funReceive) }, 1000)
          }
    })
+}
 
+/**
+  * Si un stopAttenteCourante survient un peu n'importe quand il faut imédiatement arreter de boucler.
+  */
+PageEvent.prototype.waitEvent2 = function(funSend, funReceive)
+{
+   if (this.stop)
+      return
+   this.waitEvent(funSend, funReceive)
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////