Commit 64cc2e3b authored by Romain Courteaud's avatar Romain Courteaud

ERP5Storage: support listbox_uid:list parameters.

Array parameters are converted to multiple FormData.append calls.
parent 1ef272aa
...@@ -299,10 +299,17 @@ ...@@ -299,10 +299,17 @@
.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(),
i,
key; key;
for (key in form_data) { for (key in form_data) {
if (form_data.hasOwnProperty(key)) { if (form_data.hasOwnProperty(key)) {
data.append(key, form_data[key]); if (Array.isArray(form_data[key])) {
for (i = 0; i < form_data[key].length; i += 1) {
data.append(key, form_data[key][i]);
}
} else {
data.append(key, form_data[key]);
}
} }
} }
return jIO.util.ajax({ return jIO.util.ajax({
......
...@@ -515,6 +515,53 @@ ...@@ -515,6 +515,53 @@
}); });
}); });
test("putAttachment convert array property", function () {
var submit_url = domain + "/Form_view/Base_edit",
id = "fake",
form_json = {
"multiple_value": ["fooé", "barè"]
},
context = this,
server = this.server;
this.server.respondWith("POST", submit_url, [204, {
"Content-Type": "text/xml"
}, ""]);
stop();
expect(11);
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.calledTwice, "FormData.append count " +
context.spy.callCount);
equal(context.spy.firstCall.args[0], "multiple_value",
"First append call");
equal(context.spy.firstCall.args[1], "fooé", "First append call");
equal(context.spy.secondCall.args[0], "multiple_value",
"Second append call");
equal(context.spy.secondCall.args[1], "barè", "Second append call");
equal(server.requests[0].withCredentials, true);
})
.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