Commit 50944886 authored by Romain Courteaud's avatar Romain Courteaud

ERP5Storage: add support for FileField

parent 050d8c9d
...@@ -370,16 +370,25 @@ ...@@ -370,16 +370,25 @@
.push(function (evt) { .push(function (evt) {
var form_data = JSON.parse(evt.target.result), var form_data = JSON.parse(evt.target.result),
data = new FormData(), data = new FormData(),
array,
i, i,
key; key,
value;
for (key in form_data) { for (key in form_data) {
if (form_data.hasOwnProperty(key)) { if (form_data.hasOwnProperty(key)) {
if (Array.isArray(form_data[key])) { if (Array.isArray(form_data[key])) {
for (i = 0; i < form_data[key].length; i += 1) { array = form_data[key];
data.append(key, form_data[key][i]); } else {
array = [form_data[key]];
} }
for (i = 0; i < array.length; i += 1) {
value = array[i];
if (typeof value === "object") {
data.append(key, jIO.util.dataURItoBlob(value.url),
value.file_name);
} else { } else {
data.append(key, form_data[key]); data.append(key, value);
}
} }
} }
} }
......
...@@ -575,6 +575,62 @@ ...@@ -575,6 +575,62 @@
}); });
}); });
test("putAttachment convert data URL", function () {
var submit_url = domain + "/Form_view/Base_edit",
id = "fake",
form_json = {
my_foo_file: {
url: 'data:text/plain;charset=utf-8;base64,Zm9v',
file_name: 'bar.stream'
}
},
context = this,
server = this.server;
this.server.respondWith("POST", submit_url, [204, {
"Content-Type": "text/xml"
}, ""]);
stop();
expect(12);
this.jio.putAttachment(
id,
submit_url,
new Blob([JSON.stringify(form_json)])
)
.then(function () {
equal(server.requests.length, 1);
equal(server.requests[0].method, "POST");
equal(server.requests[0].url, submit_url);
equal(server.requests[0].status, 204);
ok(server.requests[0].requestBody instanceof FormData);
ok(context.spy.calledOnce, "FormData.append count " +
context.spy.callCount);
equal(context.spy.firstCall.args[0], "my_foo_file",
"First append call");
ok(context.spy.firstCall.args[1] instanceof Blob,
"First append call");
equal(context.spy.firstCall.args[1].type, "text/plain;charset=utf-8",
"First append call");
equal(context.spy.firstCall.args[2], "bar.stream",
"First append call");
equal(server.requests[0].withCredentials, true);
return jIO.util.readBlobAsText(context.spy.firstCall.args[1]);
})
.then(function (evt) {
equal(evt.target.result, 'foo');
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// erp5Storage.getAttachment // erp5Storage.getAttachment
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
......
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