MOD cleanage
[euphorik.git] / js / communication.js
index db9beb8..417e833 100644 (file)
 // 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
+// Regroupe la partie communication JSON client -> serveur de euphorik.\r
+// Voir : http://dev.euphorik.ch/wiki/euk/Protocole\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
+euphorik.Communication = function(funError) {\r
+   this.funError = 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
+euphorik.Communication.prototype.requete = function(action, json, funOk, funError, asynchrone, paramsSupp) {\r
+   var thisCommunication = this;\r
    if (asynchrone === undefined) {\r
       asynchrone = true; // asynchrone par défaut\r
    }\r
 \r
-   var mess = this.getbase(action);\r
+   var mess = this.getBase(action);\r
    objectEach(json, function(nom, val) {\r
       mess[nom] = val;\r
    });\r
-   \r
-   jQuery.ajax({\r
+      \r
+   paramsAjax = {\r
       async: asynchrone,\r
       type: "POST",\r
       url: "request",\r
       dataType: "json",\r
-      data: { action : JSON.stringify(mess) }\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 (thisCommunication.funError) {\r
+                  thisCommunication.funError(data);\r
+               }\r
             } else if (funOk) {\r
-               funOk(data)\r
+               funOk(data);\r
             }\r
          }\r
-   });\r
-}\r
+   };\r
+       \r
+   if (paramsSupp) {\r
+      objectEach(paramsSupp, function(nom, val) {\r
+         paramsAjax[nom] = val;\r
+      });\r
+   }\r
+   \r
+   jQuery.ajax(paramsAjax);\r
+};\r
+\r
+euphorik.Communication.prototype.getBase = function(action) {\r
+   return {\r
+      "header" : { "action" : action, "version" : euphorik.conf.versionProtocole }\r
+   };\r
+};
\ No newline at end of file