X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=js%2Fcommunication.js;fp=js%2Fcommunication.js;h=db9beb887fd7d09b4079293376c00ca0ea02d775;hb=972919ab7f5651cd721eb6eec75f7150fdeaf347;hp=0000000000000000000000000000000000000000;hpb=9be780a2fbd68bf4c71431d94e8e8c07666468fb;p=euphorik.git 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) + } + } + }); +}