2 // Copyright 2008 Grégory Burri
4 // This file is part of Euphorik.
6 // Euphorik is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // Euphorik is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
19 // Regroupe la partie communication JSON client -> serveur de euphorik.
20 // Voir : http://dev.euphorik.ch/wiki/euk/Protocole
23 * @param funError un fonction executé lors d'un réponse 'error' de la part du serveur, peut être redéfinit pour une requête.
25 euphorik
.Communication = function(funError
) {
26 this.funError
= funError
;
29 euphorik
.Communication
.prototype.requete = function(action
, json
, funOk
, funError
, asynchrone
, paramsSupp
) {
30 var thisCommunication
= this;
31 if (asynchrone
=== undefined) {
32 asynchrone
= true; // asynchrone par défaut
35 var mess
= this.getBase(action
);
36 objectEach(json
, function(nom
, val
) {
45 data: { action : JSON
.stringify(mess
) },
48 if (data
.reply
=== "error") {
51 } else if (thisCommunication
.funError
) {
52 thisCommunication
.funError(data
);
61 objectEach(paramsSupp
, function(nom
, val
) {
62 paramsAjax
[nom
] = val
;
66 jQuery
.ajax(paramsAjax
);
69 euphorik
.Communication
.prototype.getBase = function(action
) {
71 "header" : { "action" : action
, "version" : euphorik
.conf
.versionProtocole
}