Commit 5aaeb9d2 authored by Tristan Cavelier's avatar Tristan Cavelier

erp5_web_renderjs_ui: handle responseType on putAttachment

ERP5Storage.putAttachment is going to return a blob instead of a
string in the resulting event.target.response. This patch allows
to handle blob responses and keep backward compatibility.
parent 3f022e22
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, RSVP, URI, calculatePageTitle */
(function (window, rJS, RSVP, URI, calculatePageTitle) {
/*global window, rJS, RSVP, URI, calculatePageTitle, jIO */
(function (window, rJS, RSVP, URI, calculatePageTitle, jIO) {
"use strict";
rJS(window)
......@@ -158,12 +158,23 @@
})
.push(function (evt) {
var location = evt.target.getResponseHeader("X-Location"),
if (evt.target.responseType === "blob") {
return RSVP.all([
evt,
jIO.util.readBlobAsText(evt.target.response)
]);
}
return [evt, {target: {result: evt.target.response}}];
})
.push(function (result_list) {
var evt = result_list[0],
responseText = result_list[1].target.result,
location = evt.target.getResponseHeader("X-Location"),
jio_key,
list = [],
message;
try {
message = JSON.parse(evt.target.response).portal_status_message;
message = JSON.parse(responseText).portal_status_message;
} catch (ignore) {
}
list.push(form_gadget.notifySubmitted(message));
......@@ -196,7 +207,13 @@
return form_gadget.notifyChange(message + '.');
})
.push(function () {
return form_gadget.displayFormulatorValidationError(JSON.parse(error.target.responseText));
if (error.target.responseType === "blob") {
return jIO.util.readBlobAsText(error.target.response);
}
return {target: {result: error.target.response}};
})
.push(function (event) {
return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result));
});
}
throw error;
......@@ -205,4 +222,4 @@
}, false, true);
}(window, rJS, RSVP, URI, calculatePageTitle));
\ No newline at end of file
}(window, rJS, RSVP, URI, calculatePageTitle, jIO));
\ No newline at end of file
......@@ -135,9 +135,16 @@
]);
})
.push(function (result_list) {
if (result_list[1].target.responseType === "blob") {
return jIO.util.readBlobAsText(result_list[1].target.response);
} else {
return {target: {result: result_list[1].target.response}};
}
})
.push(function (event) {
var message;
try {
message = JSON.parse(result_list[1].target.responseText).portal_status_message;
message = JSON.parse(event.target.result).portal_status_message;
} catch (ignore) {
}
return form_gadget.notifySubmitted(message);
......@@ -162,7 +169,14 @@
return form_gadget.notifyChange(message + '.');
})
.push(function () {
return form_gadget.displayFormulatorValidationError(JSON.parse(error.target.responseText));
if (error.target.responseType === "blob") {
return jIO.util.readBlobAsText(error.target.response);
} else {
return {target: {result: error.target.response}};
}
})
.push(function (event) {
return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result));
});
}
}
......
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