Commit 6f0f7764 authored by Roque's avatar Roque

erp5_officejs: removing hardcoded json forms in discussion tool

- the json form is built from the form definition (hardcoded for now) and the context-document info
- only on post view gadget for now
parent e1334117
......@@ -18,6 +18,80 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("generateJsonRenderForm", function (gadget) {
//hardcoded form_definition (this should come from erp5 form)
var form_definition = {
_debug: "traverse",
pt: "form_view",
title: "Post",
group_list: [[
"left",
[["my_title", {meta_type: "StringField"}], ["my_reference", {meta_type: "StringField"}]]
], [
"bottom",
[["my_text_content", {meta_type: "ProxyField"}]]
]],
//this field_info is totally made up, but somewhere in the definition there must be
//information about the fields. So, foreach field: key->info
field_info_dict: {
"my_title": {
"title": "Title",
"default": "Undefined title",
"editable": 1,
"key": "title",
"type": "StringField"
},
"my_text_content": {
"editable": 1,
"key": "text_content",
"renderjs_extra": '{"editor": "fck_editor",' +
'"maximize": true}',
"type": "GadgetField",
"url": "gadget_editor.html",
"sandbox": "public"
}
},
action: "Base_edit",
update_action: "",
_links: {
action_object_delete_action: {
href: "https://somewhere.com/",
icon: "",
name: "delete action name",
title: "Delete action title"
},
action_object_search: {
href: "https://somewhere.com/",
icon: "",
name: "search action name",
title: "Search action title"
} //etc
}
},
form_json = {
erp5_document: {
"_embedded": {"_view": {}},
"_links": {}
},
form_definition: form_definition
};
for (var i = 0; i < form_definition.group_list.length; i++) {
var fields = form_definition.group_list[i][1];
for (var j = 0; j < fields.length; j++) {
var my_element = fields[j][0], element_id;
if (my_element.startsWith("my_")) {
element_id = my_element.replace("my_", "");
}
if (gadget.state.doc.hasOwnProperty(element_id)) {
var field_info = form_definition.field_info_dict[my_element];
field_info["default"] = gadget.state.doc[element_id];
form_json.erp5_document._embedded._view[my_element] = field_info;
}
}
}
return form_json;
})
.declareMethod("render", function (options) {
return this.changeState({
jio_key: options.jio_key,
......@@ -47,51 +121,14 @@
})
.onStateChange(function () {
var gadget = this;
var gadget = this,
form_json;
return gadget.generateJsonRenderForm(gadget)
.push(function (result) {
form_json = result;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render({
erp5_document: {
"_embedded": {"_view": {
"my_title": {
"description": "",
"title": "Title",
"default": gadget.state.doc.title,
"css_class": "",
"required": 1,
"editable": 1,
"key": "title",
"hidden": 0,
"type": "StringField"
},
"my_text_content": {
"default": gadget.state.doc.text_content,
"css_class": "",
"required": 0,
"editable": 1,
"key": "text_content",
"hidden": 0,
"renderjs_extra": '{"editor": "fck_editor",' +
'"maximize": true}',
"type": "GadgetField",
"url": "gadget_editor.html",
"sandbox": "public"
}
}},
"_links": {
"type": { name: "" }
}
},
form_definition: {
group_list: [[
"left",
[["my_title"]]
], [
"bottom",
[["my_text_content"]]
]]
}
});
return form_gadget.render(form_json);
})
.push(function () {
return RSVP.all([
......@@ -110,4 +147,5 @@
});
});
});
});
}(window, rJS, RSVP));
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>973.13279.14894.17732</string> </value>
<value> <string>973.20517.6195.2508</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1548335462.14</float>
<float>1548768313.55</float>
<string>UTC</string>
</tuple>
</state>
......
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