Commit ef98a460 authored by Tristan Cavelier's avatar Tristan Cavelier

erp5storage.js uses jQuery ajax with "json" dataType now

parent 314f31ac
...@@ -116,8 +116,8 @@ jIO.addStorageType("erp5", function (spec, my) { ...@@ -116,8 +116,8 @@ jIO.addStorageType("erp5", function (spec, my) {
*/ */
priv.makeAjaxObject = function (json, method, ajax_object) { priv.makeAjaxObject = function (json, method, ajax_object) {
ajax_object.type = "POST"; ajax_object.type = "POST";
ajax_object.dataType = "text"; ajax_object.dataType = "json";
ajax_object.data = JSON.stringify(json); ajax_object.data = [{"name": "doc", "value": JSON.stringify(json)}];
ajax_object.url = priv.url + "/JIO_" + method + ajax_object.url = priv.url + "/JIO_" + method +
"?_=" + Date.now(); "?_=" + Date.now();
ajax_object.async = ajax_object.async === false ? false : true; ajax_object.async = ajax_object.async === false ? false : true;
...@@ -222,11 +222,17 @@ jIO.addStorageType("erp5", function (spec, my) { ...@@ -222,11 +222,17 @@ jIO.addStorageType("erp5", function (spec, my) {
* @method erp5.genericRequest * @method erp5.genericRequest
* @param {object} doc The document object * @param {object} doc The document object
* @param {string} method The ERP5 request method * @param {string} method The ERP5 request method
* @param {boolean} parse Parse the data received if true
*/ */
erp5.genericRequest = function (json, method, parse) { erp5.genericRequest = function (json, method) {
var jql = priv.makeJQLikeCallback(), error = null; var jql = priv.makeJQLikeCallback(), error = null;
priv.ajax(json, method).always(function (one, state, three) { priv.ajax(json, method).always(function (one, state, three) {
if (state === "parsererror") {
return jql.respond(priv.createError(
24,
"Cannot parse data",
"Corrupted data"
), undefined);
}
if (state !== "success") { if (state !== "success") {
error = priv.ajaxErrorToJioError( error = priv.ajaxErrorToJioError(
one, one,
...@@ -238,21 +244,10 @@ jIO.addStorageType("erp5", function (spec, my) { ...@@ -238,21 +244,10 @@ jIO.addStorageType("erp5", function (spec, my) {
} }
return jql.respond(error, undefined); return jql.respond(error, undefined);
} }
if (parse) { if (one.err !== null) {
try { return jql.respond(one.err, undefined);
one = JSON.parse(one);
} catch (e) {
return jql.respond(priv.createError(
24,
"Cannot parse data",
"Corrupted data"
), undefined);
}
}
if (typeof one.status === "number" && typeof one.error === "string") {
return jql.respond(one, undefined);
} }
return jql.respond(undefined, one); return jql.respond(undefined, one.response);
}); });
return jql.to_return; return jql.to_return;
}; };
...@@ -267,8 +262,7 @@ jIO.addStorageType("erp5", function (spec, my) { ...@@ -267,8 +262,7 @@ jIO.addStorageType("erp5", function (spec, my) {
priv.genericCommand = function (json, method) { priv.genericCommand = function (json, method) {
erp5.genericRequest( erp5.genericRequest(
json, json,
method, method
method !== "getAttachment" // parse received data if not getAttachment
).always(function (err, response) { ).always(function (err, response) {
if (err) { if (err) {
return that.error(err); return that.error(err);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment