MOD avancement dans le module 'communication'
authorGreg Burri <greg.burri@gmail.com>
Fri, 8 Aug 2008 15:47:18 +0000 (15:47 +0000)
committerGreg Burri <greg.burri@gmail.com>
Fri, 8 Aug 2008 15:47:18 +0000 (15:47 +0000)
index.yaws
js/client.js
js/communication.js [new file with mode: 0644]
js/euphorik.js
js/protocole.js [deleted file]
js/util.js

index 5bc67bd..9f318dc 100755 (executable)
@@ -42,7 +42,8 @@
 
    <script type="text/javascript" src="js/betterjs.js" prod="delete"></script>
    <script type="text/javascript" src="js/comet.js" prod="delete"></script>
 
    <script type="text/javascript" src="js/betterjs.js" prod="delete"></script>
    <script type="text/javascript" src="js/comet.js" prod="delete"></script>
-   <script type="text/javascript" src="js/fragment.js" prod="delete"></script>
+   <script type="text/javascript" src="js/fragment.js" prod="delete"></script>\r
+   <script type="text/javascript" src="js/communication.js" prod="delete"></script>
 
    <script type="text/javascript" src="js/euphorik.js"></script>
 
 
    <script type="text/javascript" src="js/euphorik.js"></script>
 
index 11466a9..93e5dae 100644 (file)
@@ -21,8 +21,9 @@
 /**\r
   * Représente l'utilisateur du site.\r
   */\r
 /**\r
   * Représente l'utilisateur du site.\r
   */\r
-euphorik.Client = function(util) {\r
+euphorik.Client = function(util, communication) {\r
    this.util = util;\r
    this.util = util;\r
+   this.communication = communication\r
    \r
    this.cookie = null;\r
    this.regexCookie = /^cookie=([^;]*)/;\r
    \r
    this.cookie = null;\r
    this.regexCookie = /^cookie=([^;]*)/;\r
@@ -314,25 +315,20 @@ euphorik.Client.prototype.enregistrement = function(login, password) {
 /**\r
   * Connexion. Réalisée de manière synchrone.\r
   */\r
 /**\r
   * Connexion. Réalisée de manière synchrone.\r
   */\r
-euphorik.Client.prototype.connexion = function(messageJson) {\r
+euphorik.Client.prototype.connexion = function(action, messageJson) {\r
    var thisClient = this;\r
    var thisClient = this;\r
-   jQuery.ajax({\r
-      async: false,\r
-      type: "POST",\r
-      url: "request",\r
-      dataType: "json",\r
-      data: this.util.jsonVersAction(messageJson),\r
-      success:\r
-         function(data){\r
-            if (data.reply === "error") {\r
-               thisClient.util.messageDialogue(data.error_message);\r
-               // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification\r
-               thisClient.delCookie();\r
-            } else {\r
-               thisClient.chargerDonnees(data);\r
-            }\r
-         }\r
-   });\r
+   \r
+   this.communication.requete(\r
+      action,\r
+      messageJson,\r
+      function(data) {\r
+         thisClient.chargerDonnees(data);\r
+      },\r
+      function() {\r
+         thisClient.util.messageDialogue(data.error_message);\r
+         thisClient.delCookie(); // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification\r
+      }\r
+   );\r
    return this.authentifie();\r
 };\r
 \r
    return this.authentifie();\r
 };\r
 \r
diff --git a/js/communication.js b/js/communication.js
new file mode 100644 (file)
index 0000000..db9beb8
--- /dev/null
@@ -0,0 +1,62 @@
+// 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
+// regroupe la partie communication client -> sevreur de euphorik.\r
+\r
+/**\r
+  * @param funError un fonction executé lors d'un réponse 'error' de la part du serveur, peut être redéfinit pour une requête.\r
+  */\r
+euphorik.Communication = function(util, funError) {\r
+}\r
+\r
+euphorik.Communication.prototype.getBase = function(action) {\r
+   this.base = {\r
+      "header" : { "action" : action, "version" : euphorik.conf.versionProtocole }\r
+   };\r
+}\r
+\r
+euphorik.Communication.prototype.requete = function(action, json, funOk, funError, asynchrone) {\r
+   if (asynchrone === undefined) {\r
+      asynchrone = true; // asynchrone par défaut\r
+   }\r
+\r
+   var mess = this.getbase(action);\r
+   objectEach(json, function(nom, val) {\r
+      mess[nom] = val;\r
+   });\r
+   \r
+   jQuery.ajax({\r
+      async: asynchrone,\r
+      type: "POST",\r
+      url: "request",\r
+      dataType: "json",\r
+      data: { action : JSON.stringify(mess) }\r
+      success:\r
+         function(data) {\r
+            if (data.reply === "error") {\r
+               if (funError) {\r
+                  funError(data);\r
+               } else if (this.funError) {\r
+                  this.funError(data);\r
+               }               \r
+            } else if (funOk) {\r
+               funOk(data)\r
+            }\r
+         }\r
+   });\r
+}\r
index 777a036..4a9261a 100755 (executable)
@@ -26,8 +26,9 @@ $(document).ready(
    function() { 
       var fragment = new Fragment();
       var formateur = new euphorik.Formateur();
    function() { 
       var fragment = new Fragment();
       var formateur = new euphorik.Formateur();
-      var util = new euphorik.Util(formateur); 
-      var client = new euphorik.Client(util);
+      var util = new euphorik.Util(formateur); \r
+      var communication = new Communication();
+      var client = new euphorik.Client(util, communication);
       var pages = new euphorik.Pages(fragment);
       
       // connexion vers le serveur (utilise un cookie qui traine)
       var pages = new euphorik.Pages(fragment);
       
       // connexion vers le serveur (utilise un cookie qui traine)
diff --git a/js/protocole.js b/js/protocole.js
deleted file mode 100644 (file)
index 5d1b201..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// 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
-// regroupe la partie communication \r
-// En chantier !!\r
-\r
-euphorik.Protocole = function(util) {\r
-}\r
-\r
-euphorik.Protocole.prototype.getBase = function() {\r
-   this.base = {\r
-      "header" : { "action" : "", "version" : euphorik.conf.versionProtocole }\r
-   };\r
-}\r
-\r
-euphorik.Protocole.prototype.registerAnonyme = function(profile) {\r
-   this.register(undefined, undefined, profile);\r
-}\r
-\r
-euphorik.Protocole.prototype.register = function(login, password, profile) {\r
-   var base = this.getBase();\r
-   if (login && password) {\r
-     base.login = login;\r
-     base.password = password;\r
-   }\r
-   base.profile = profile;\r
-}\r
-\r
-euphorik.Protocole.prototype.requete = function(action, funOk, funError) {\r
-   \r
-}\r
index c9c8bb3..2c66959 100644 (file)
@@ -180,6 +180,7 @@ euphorik.Util.prototype.infoBulle = function(message, element, position) {
 \r
 /**\r
   * Utilisé pour l'envoie de données avec la méthode ajax de jQuery.\r
 \r
 /**\r
   * Utilisé pour l'envoie de données avec la méthode ajax de jQuery.\r
+  * Obsolète : à virer\r
   */\r
 euphorik.Util.prototype.jsonVersAction = function(json) {\r
    return { action : JSON.stringify(json) };\r
   */\r
 euphorik.Util.prototype.jsonVersAction = function(json) {\r
    return { action : JSON.stringify(json) };\r