Commit ff01a8c6 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

erp5storage: add support to properties beginning with "your_"

This allows to use properties from ERP5 that can be updated locally but won't
be saved by ERP5. eg: your_modification_date allows to obtain the modification date of the
object, but it won't be saved on the Object in ERP5 when updated.
parent c9d80334
......@@ -79,7 +79,8 @@
},
form_data_json = {},
field,
key;
key,
prefix_length;
form_data_json.form_id = {
"key": [form.form_id.key],
......@@ -89,15 +90,20 @@
for (key in form) {
if (form.hasOwnProperty(key)) {
field = form[key];
if ((key.indexOf('my_') === 0) &&
(field.editable) &&
prefix_length = 0;
if (key.indexOf('my_') === 0 && field.editable) {
prefix_length = 3;
}
if (key.indexOf('your_') === 0) {
prefix_length = 5;
}
if ((prefix_length !== 0) &&
(allowed_field_dict.hasOwnProperty(field.type))) {
form_data_json[key.substring(3)] = {
form_data_json[key.substring(prefix_length)] = {
"default": field["default"],
"key": field.key
};
converted_json[key.substring(3)] = field["default"];
converted_json[key.substring(prefix_length)] = field["default"];
}
}
}
......
......@@ -212,11 +212,17 @@
type: "DateTimeField"
},
your_reference: {
key: "field_your_title",
key: "field_your_reference",
"default": "bar",
editable: true,
type: "StringField"
},
your_reference_non_editable: {
key: "field_your_reference_non_editable",
"default": "bar",
editable: false,
type: "StringField"
},
sort_index: {
key: "field_sort_index",
"default": "foobar",
......@@ -247,6 +253,8 @@
.then(function (result) {
deepEqual(result, {
portal_type: "Person",
reference: "bar",
reference_non_editable: "bar",
title: "foo"
}, "Check document");
equal(server.requests.length, 2);
......@@ -1150,11 +1158,17 @@
type: "DateTimeField"
},
your_reference: {
key: "field_your_title",
key: "field_your_reference",
"default": "bar",
editable: true,
type: "StringField"
},
your_reference_non_editable: {
key: "field_your_reference_non_editable",
"default": "bar",
editable: false,
type: "StringField"
},
sort_index: {
key: "field_sort_index",
"default": "foobar",
......@@ -1182,9 +1196,9 @@
}, ""]);
stop();
expect(21);
expect(23);
this.jio.put(id, {title: "barè", id: "foo"})
this.jio.put(id, {title: "barè", id: "foo", reference: "bar2"})
.then(function (result) {
equal(result, id);
equal(server.requests.length, 3);
......@@ -1201,7 +1215,7 @@
ok(server.requests[2].requestBody instanceof FormData);
equal(server.requests[2].withCredentials, true);
equal(context.spy.callCount, 3, "FormData.append count");
equal(context.spy.callCount, 4, "FormData.append count");
equal(context.spy.firstCall.args[0], "form_id", "First append call");
equal(context.spy.firstCall.args[1], "Base_view", "First append call");
equal(context.spy.secondCall.args[0], "field_my_title",
......@@ -1210,6 +1224,9 @@
equal(context.spy.thirdCall.args[0], "field_my_id",
"Third append call");
equal(context.spy.thirdCall.args[1], "foo", "Third append call");
equal(context.spy.getCall(3).args[0], "field_your_reference",
"Fourth append call");
equal(context.spy.getCall(3).args[1], "bar2", "Fourth append call");
})
.fail(function (error) {
ok(false, error);
......@@ -1265,11 +1282,17 @@
type: "DateTimeField"
},
your_reference: {
key: "field_your_title",
key: "field_your_reference",
"default": "bar",
editable: true,
type: "StringField"
},
your_reference_non_editable: {
key: "field_your_reference_non_editable",
"default": "bar",
editable: false,
type: "StringField"
},
sort_index: {
key: "field_sort_index",
"default": "foobar",
......@@ -1389,7 +1412,7 @@
type: "DateTimeField"
},
your_reference: {
key: "field_your_title",
key: "field_your_reference",
"default": "bar",
editable: true,
type: "StringField"
......@@ -1425,13 +1448,14 @@
}, ""]);
stop();
expect(33);
expect(35);
this.jio.post({
title: "barè",
id: "foo",
portal_type: "Foo",
parent_relative_url: "foo_module"
parent_relative_url: "foo_module",
reference: "bar2"
})
.then(function (result) {
equal(result, id);
......@@ -1462,7 +1486,7 @@
ok(server.requests[4].requestBody instanceof FormData);
equal(server.requests[4].withCredentials, true);
equal(context.spy.callCount, 5, "FormData.append count");
equal(context.spy.callCount, 6, "FormData.append count");
equal(context.spy.firstCall.args[0], "portal_type",
"First append call");
......@@ -1480,6 +1504,9 @@
equal(context.spy.getCall(4).args[0], "field_my_id",
"Fifth append call");
equal(context.spy.getCall(4).args[1], "foo", "Fifth append call");
equal(context.spy.getCall(5).args[0], "field_your_reference",
"Sixth append call");
equal(context.spy.getCall(5).args[1], "bar2", "Sixth append call");
})
.fail(function (error) {
ok(false, error);
......@@ -1560,11 +1587,17 @@
type: "DateTimeField"
},
your_reference: {
key: "field_your_title",
key: "field_your_reference",
"default": "bar",
editable: true,
type: "StringField"
},
your_reference_non_editable: {
key: "field_your_reference_non_editable",
"default": "bar",
editable: false,
type: "StringField"
},
sort_index: {
key: "field_sort_index",
"default": "foobar",
......@@ -1661,6 +1694,8 @@
equal(result_list.length, 2);
deepEqual(result, {
portal_type: "Person",
reference: "bar",
reference_non_editable: "bar",
title: "foo"
}, "Check document");
deepEqual(result2, {
......
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