From: Greg Burri Date: Fri, 8 Aug 2008 15:47:18 +0000 (+0000) Subject: MOD avancement dans le module 'communication' X-Git-Tag: 1.1.0~12 X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=972919ab7f5651cd721eb6eec75f7150fdeaf347;p=euphorik.git MOD avancement dans le module 'communication' --- diff --git a/index.yaws b/index.yaws index 5bc67bd..9f318dc 100755 --- a/index.yaws +++ b/index.yaws @@ -42,7 +42,8 @@ - + + diff --git a/js/client.js b/js/client.js index 11466a9..93e5dae 100644 --- a/js/client.js +++ b/js/client.js @@ -21,8 +21,9 @@ /** * Représente l'utilisateur du site. */ -euphorik.Client = function(util) { +euphorik.Client = function(util, communication) { this.util = util; + this.communication = communication this.cookie = null; this.regexCookie = /^cookie=([^;]*)/; @@ -314,25 +315,20 @@ euphorik.Client.prototype.enregistrement = function(login, password) { /** * Connexion. Réalisée de manière synchrone. */ -euphorik.Client.prototype.connexion = function(messageJson) { +euphorik.Client.prototype.connexion = function(action, messageJson) { var thisClient = this; - jQuery.ajax({ - async: false, - type: "POST", - url: "request", - dataType: "json", - data: this.util.jsonVersAction(messageJson), - success: - function(data){ - if (data.reply === "error") { - thisClient.util.messageDialogue(data.error_message); - // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification - thisClient.delCookie(); - } else { - thisClient.chargerDonnees(data); - } - } - }); + + this.communication.requete( + action, + messageJson, + function(data) { + thisClient.chargerDonnees(data); + }, + function() { + thisClient.util.messageDialogue(data.error_message); + thisClient.delCookie(); // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification + } + ); return this.authentifie(); }; diff --git a/js/communication.js b/js/communication.js new file mode 100644 index 0000000..db9beb8 --- /dev/null +++ b/js/communication.js @@ -0,0 +1,62 @@ +// coding: utf-8 +// Copyright 2008 Grégory Burri +// +// This file is part of Euphorik. +// +// Euphorik is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Euphorik is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Euphorik. If not, see . + +// regroupe la partie communication client -> sevreur de euphorik. + +/** + * @param funError un fonction executé lors d'un réponse 'error' de la part du serveur, peut être redéfinit pour une requête. + */ +euphorik.Communication = function(util, funError) { +} + +euphorik.Communication.prototype.getBase = function(action) { + this.base = { + "header" : { "action" : action, "version" : euphorik.conf.versionProtocole } + }; +} + +euphorik.Communication.prototype.requete = function(action, json, funOk, funError, asynchrone) { + if (asynchrone === undefined) { + asynchrone = true; // asynchrone par défaut + } + + var mess = this.getbase(action); + objectEach(json, function(nom, val) { + mess[nom] = val; + }); + + jQuery.ajax({ + async: asynchrone, + type: "POST", + url: "request", + dataType: "json", + data: { action : JSON.stringify(mess) } + success: + function(data) { + if (data.reply === "error") { + if (funError) { + funError(data); + } else if (this.funError) { + this.funError(data); + } + } else if (funOk) { + funOk(data) + } + } + }); +} diff --git a/js/euphorik.js b/js/euphorik.js index 777a036..4a9261a 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -26,8 +26,9 @@ $(document).ready( 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); + 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) diff --git a/js/protocole.js b/js/protocole.js deleted file mode 100644 index 5d1b201..0000000 --- a/js/protocole.js +++ /dev/null @@ -1,46 +0,0 @@ -// coding: utf-8 -// Copyright 2008 Grégory Burri -// -// This file is part of Euphorik. -// -// Euphorik is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Euphorik is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Euphorik. If not, see . - -// regroupe la partie communication -// En chantier !! - -euphorik.Protocole = function(util) { -} - -euphorik.Protocole.prototype.getBase = function() { - this.base = { - "header" : { "action" : "", "version" : euphorik.conf.versionProtocole } - }; -} - -euphorik.Protocole.prototype.registerAnonyme = function(profile) { - this.register(undefined, undefined, profile); -} - -euphorik.Protocole.prototype.register = function(login, password, profile) { - var base = this.getBase(); - if (login && password) { - base.login = login; - base.password = password; - } - base.profile = profile; -} - -euphorik.Protocole.prototype.requete = function(action, funOk, funError) { - -} diff --git a/js/util.js b/js/util.js index c9c8bb3..2c66959 100644 --- a/js/util.js +++ b/js/util.js @@ -180,6 +180,7 @@ euphorik.Util.prototype.infoBulle = function(message, element, position) { /** * Utilisé pour l'envoie de données avec la méthode ajax de jQuery. + * Obsolète : à virer */ euphorik.Util.prototype.jsonVersAction = function(json) { return { action : JSON.stringify(json) };