Commit 12a395e1 authored by Roque's avatar Roque

erp5_officejs: removing hardcoded json forms in discussion tool

- post list view gadget and details
parent 6f0f7764
...@@ -22,16 +22,14 @@ ...@@ -22,16 +22,14 @@
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getSetting('portal_type'), gadget.getSetting('portal_type'),
gadget.getSetting('parent_relative_url'), gadget.getSetting('parent_relative_url')
gadget.getSetting('text_content', "")
]); ]);
}) })
.push(function (result) { .push(function (result) {
var doc = { var doc = {
title: "Untitled Document", title: "Untitled Document",
portal_type: result[0], portal_type: result[0],
parent_relative_url: result[1], parent_relative_url: result[1]
text_content: result[2]
}; };
return gadget.jio_post(doc); return gadget.jio_post(doc);
}) })
......
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>973.13148.27135.54732</string> </value> <value> <string>973.25023.19197.63385</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1548335477.57</float> <float>1549038779.7</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -10,47 +10,70 @@ ...@@ -10,47 +10,70 @@
.declareAcquiredMethod("updateHeader", "updateHeader") .declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter") .declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSetting", "getSetting")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.allowPublicAcquisition("jio_allDocs", function (param_list) { .declareMethod("generateJsonRenderForm", function (gadget) {
var gadget = this; //hardcoded form_definition (this should come from erp5 form)
return gadget.jio_allDocs(param_list[0]) var form_definition = {
.push(function (result) { _debug: "traverse",
var i, date, len = result.data.total_rows; pt: "form_view",
for (i = 0; i < len; i += 1) { title: "Post",
if (result.data.rows[i].value.hasOwnProperty("modification_date")) { group_list: [[
date = new Date(result.data.rows[i].value.modification_date); "bottom",
result.data.rows[i].value.modification_date = { [["my_listbox"]]
field_gadget_param: { ]],
allow_empty_time: 0, //this field_info is totally made up, but somewhere in the definition there must be
ampm_time_style: 0, //information about the fields. So, foreach field: key->info
css_class: "date_field", field_info_dict: {
date_only: 0, "my_listbox": {
description: "The Date", "column_list": [['title', 'Title'], ['modification_date', 'Modification Date']],
editable: 0, "show_anchor": 0,
hidden: 0, "default_params": {},
hidden_day_is_last_day: 0, "editable": 1,
"default": date.toUTCString(), "editable_column_list": [],
key: "modification_date", "key": "field_listbox",
required: 0, "lines": 30,
timezone_style: 0, "list_method": "portal_catalog",
title: "Modification Date", // is this correct? the query should come from the form definition, right?
type: "DateTimeField" "query": "urn:jio:allDocs?query=portal_type%3A%22HTML Post%22",
} "portal_type": [],
}; "search_column_list": [['title', 'Title'], ['modification_date', 'Modification Date']],
result.data.rows[i].value["listbox_uid:list"] = { "sort_column_list": [['title', 'Title'], ['modification_date', 'Modification Date']],
key: "listbox_uid:list", "sort": [['modification_date', 'descending']],
value: 2713 "title": "Posts",
}; "type": "ListBox"
}
} }
return result; },
}); action: "Base_edit",
update_action: "",
_links: {}
},
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_", "");
}
var field_info = form_definition.field_info_dict[my_element];
if (gadget.state.hasOwnProperty("doc") && gadget.state.doc.hasOwnProperty(element_id)) {
field_info["default"] = gadget.state.doc[element_id];
}
form_json.erp5_document._embedded._view[my_element] = field_info;
}
}
return form_json;
}) })
.allowPublicAcquisition('notifySubmit', function () { .allowPublicAcquisition('notifySubmit', function () {
...@@ -72,56 +95,16 @@ ...@@ -72,56 +95,16 @@
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getDeclaredGadget('form_list'), gadget.getDeclaredGadget('form_list'),
gadget.getSetting("portal_type") gadget.generateJsonRenderForm(gadget)
]); ]);
}) })
.push(function (result) { .push(function (result) {
var column_list = [ return result[0].render(result[1]);
['title', 'Title'],
['modification_date', 'Modification Date']
];
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"listbox": {
"column_list": column_list,
"show_anchor": 0,
"default_params": {},
"editable": 1,
"editable_column_list": [],
"key": "field_listbox",
"lines": 30,
"list_method": "portal_catalog",
"query": "urn:jio:allDocs?query=portal_type%3A%22" +
result[1] + "%22",
"portal_type": [],
"search_column_list": column_list,
"sort_column_list": column_list,
"sort": [['modification_date', 'descending']],
"title": "Posts",
"type": "ListBox"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"bottom",
[["listbox"]]
]]
}
});
}) })
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getUrlFor({command: "change", options: {"page": "ojs_add_post"}}), gadget.getUrlFor({command: "change", options: {"page": "ojs_add_post"}}),
gadget.getSetting('document_title_plural'), gadget.getSetting('document_title_plural'),
gadget.getUrlFor({command: "change", options: {"page": "ojs_upload_convert"}}),
gadget.getSetting('upload_dict', false) gadget.getSetting('upload_dict', false)
]); ]);
}) })
......
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>973.12023.55154.25190</string> </value> <value> <string>973.25050.40927.26658</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1548320460.62</float> <float>1549040323.25</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
title: "Post", title: "Post",
group_list: [[ group_list: [[
"left", "left",
[["my_title", {meta_type: "StringField"}], ["my_reference", {meta_type: "StringField"}]] [["my_title", {meta_type: "StringField"}]]
], [ ], [
"bottom", "bottom",
[["my_text_content", {meta_type: "ProxyField"}]] [["my_text_content", {meta_type: "ProxyField"}]]
...@@ -82,11 +82,11 @@ ...@@ -82,11 +82,11 @@
if (my_element.startsWith("my_")) { if (my_element.startsWith("my_")) {
element_id = my_element.replace("my_", ""); element_id = my_element.replace("my_", "");
} }
if (gadget.state.doc.hasOwnProperty(element_id)) { var field_info = form_definition.field_info_dict[my_element];
var field_info = form_definition.field_info_dict[my_element]; if (gadget.state.hasOwnProperty("doc") && gadget.state.doc.hasOwnProperty(element_id)) {
field_info["default"] = gadget.state.doc[element_id]; field_info["default"] = gadget.state.doc[element_id];
form_json.erp5_document._embedded._view[my_element] = field_info;
} }
form_json.erp5_document._embedded._view[my_element] = field_info;
} }
} }
return form_json; return form_json;
......
...@@ -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.20517.6195.2508</string> </value> <value> <string>973.24979.41047.29781</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>1548768313.55</float> <float>1549036257.66</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