X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fcommunication.js;h=417e8337b4b87186f0aacb36a1f34088bf4e8dff;hp=db9beb887fd7d09b4079293376c00ca0ea02d775;hb=351623b2a00432ae5b690476c68b8fb05cc8dd03;hpb=972919ab7f5651cd721eb6eec75f7150fdeaf347 diff --git a/js/communication.js b/js/communication.js index db9beb8..417e833 100644 --- a/js/communication.js +++ b/js/communication.js @@ -16,47 +16,58 @@ // 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. +// Regroupe la partie communication JSON client -> serveur de euphorik. +// Voir : http://dev.euphorik.ch/wiki/euk/Protocole /** * @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 = function(funError) { + this.funError = 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) { +euphorik.Communication.prototype.requete = function(action, json, funOk, funError, asynchrone, paramsSupp) { + var thisCommunication = this; if (asynchrone === undefined) { asynchrone = true; // asynchrone par défaut } - var mess = this.getbase(action); + var mess = this.getBase(action); objectEach(json, function(nom, val) { mess[nom] = val; }); - - jQuery.ajax({ + + paramsAjax = { async: asynchrone, type: "POST", url: "request", dataType: "json", - data: { action : JSON.stringify(mess) } + 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 (thisCommunication.funError) { + thisCommunication.funError(data); + } } else if (funOk) { - funOk(data) + funOk(data); } } - }); -} + }; + + if (paramsSupp) { + objectEach(paramsSupp, function(nom, val) { + paramsAjax[nom] = val; + }); + } + + jQuery.ajax(paramsAjax); +}; + +euphorik.Communication.prototype.getBase = function(action) { + return { + "header" : { "action" : action, "version" : euphorik.conf.versionProtocole } + }; +}; \ No newline at end of file