<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>
/**\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.communication = communication\r
\r
this.cookie = null;\r
this.regexCookie = /^cookie=([^;]*)/;\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
- 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
--- /dev/null
+// 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
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)
+++ /dev/null
-// 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
\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