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 @@ ...@@ -18,6 +18,80 @@
// declared methods // 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) { .declareMethod("render", function (options) {
return this.changeState({ return this.changeState({
jio_key: options.jio_key, jio_key: options.jio_key,
...@@ -47,67 +121,31 @@ ...@@ -47,67 +121,31 @@
}) })
.onStateChange(function () { .onStateChange(function () {
var gadget = this; var gadget = this,
return gadget.getDeclaredGadget('form_view') form_json;
.push(function (form_gadget) { return gadget.generateJsonRenderForm(gadget)
return form_gadget.render({ .push(function (result) {
erp5_document: { form_json = result;
"_embedded": {"_view": { return gadget.getDeclaredGadget('form_view')
"my_title": { .push(function (form_gadget) {
"description": "", return form_gadget.render(form_json);
"title": "Title", })
"default": gadget.state.doc.title, .push(function () {
"css_class": "", return RSVP.all([
"required": 1, gadget.getUrlFor({command: 'history_previous'}),
"editable": 1, gadget.getUrlFor({command: 'selection_previous'}),
"key": "title", gadget.getUrlFor({command: 'selection_next'})
"hidden": 0, ]);
"type": "StringField" })
}, .push(function (url_list) {
"my_text_content": { return gadget.updateHeader({
"default": gadget.state.doc.text_content, page_title: gadget.state.doc.title,
"css_class": "", save_action: true,
"required": 0, selection_url: url_list[0],
"editable": 1, previous_url: url_list[1],
"key": "text_content", next_url: url_list[2]
"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"]]
]]
}
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: 'selection_previous'}),
gadget.getUrlFor({command: 'selection_next'})
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: gadget.state.doc.title,
save_action: true,
selection_url: url_list[0],
previous_url: url_list[1],
next_url: url_list[2]
});
}); });
}); });
}(window, rJS, RSVP)); }(window, rJS, RSVP));
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>973.13279.14894.17732</string> </value> <value> <string>973.20517.6195.2508</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1548335462.14</float> <float>1548768313.55</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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