Commit 73e720ba authored by Roque's avatar Roque

erp5_officejs: get rid of hardcoded post module rendering (WIP)

- use generic form view to render post list form
parent eb3a5942
/*global window, rJS, RSVP */ /*global window, document, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) { (function (window, document, rJS, RSVP) {
"use strict"; "use strict";
rJS(window) rJS(window)
...@@ -17,10 +17,9 @@ ...@@ -17,10 +17,9 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("generateJsonRenderForm", function (gadget) { //HARDCODED UNTIL form_def is stored in local storage
//this will be the id of the thread that contains this post list .declareMethod("getFormDefinition", function (gadget) {
var fake_thread_uid = "thread-" + ("0000" + ((Math.random() * Math.pow(36, 4)) | 0).toString(36)).slice(-4), var fake_thread_uid = "thread-" + ("0000" + ((Math.random() * Math.pow(36, 4)) | 0).toString(36)).slice(-4),
// get these (portal_type, etc) from getSettings
action_info = { action_info = {
page: "handle_action", page: "handle_action",
action: "new", action: "new",
...@@ -28,7 +27,6 @@ ...@@ -28,7 +27,6 @@
parent_portal_type: "Post Module", parent_portal_type: "Post Module",
my_source_reference: fake_thread_uid my_source_reference: fake_thread_uid
}, },
//hardcoded form_definition (this should come from erp5 form)
form_definition = { form_definition = {
_debug: "traverse", _debug: "traverse",
pt: "form_view", pt: "form_view",
...@@ -37,146 +35,91 @@ ...@@ -37,146 +35,91 @@
"bottom", "bottom",
[["my_listbox"]] [["my_listbox"]]
]], ]],
//this field_info is totally made up, but somewhere in the definition there must be //this fields_raw_properties is totally made up, but somewhere in the definition there must be
//information about the fields. So, foreach field: key->info //information about the fields. So, foreach field: key->info
field_info_dict: { fields_raw_properties: {
"my_listbox": { "my_listbox": {
"column_list": [['title', 'Title'], ['modification_date', 'Modification Date']], "type": "ListBox",
"show_anchor": 0, "key": "field_listbox", // or my_listbox ??
"default_params": {}, "values": {
"editable": 1, "column_list": [['title', 'Title'], ['modification_date', 'Modification Date']],
"editable_column_list": [], "show_anchor": 0,
"key": "field_listbox", "default_params": {},
"lines": 30, "editable": 1,
"list_method": "portal_catalog", "editable_column_list": [],
// is this correct? the query should come from the form definition, right? //"key": "field_listbox",
"query": "urn:jio:allDocs?query=portal_type%3A%22HTML Post%22", "lines": 30,
"portal_type": [], "list_method": "portal_catalog",
"search_column_list": [['title', 'Title'], ['modification_date', 'Modification Date']], // is this correct? the query should come from the form definition, right?
"sort_column_list": [['title', 'Title'], ['modification_date', 'Modification Date']], "query": "urn:jio:allDocs?query=portal_type%3A%22HTML Post%22",
"sort": [['modification_date', 'descending']], "portal_type": [],
"title": "Posts", "search_column_list": [['title', 'Title'], ['modification_date', 'Modification Date']],
"type": "ListBox" "sort_column_list": [['title', 'Title'], ['modification_date', 'Modification Date']],
"sort": [['modification_date', 'descending']],
"title": "Posts"
//"type": "ListBox"
},
"tales": {},
"overrides": {},
"message_values": {}
} }
}, },
action: "Base_edit", action: "Base_edit",
update_action: "", update_action: "",
_links: { "type": { name: "" }, "action_object_new_content_action": action_info } _links: { "type": { name: "" }, "action_object_new_content_action": action_info }
},
form_json = {
erp5_document: {
"_embedded": {"_view": {}},
"_links": {}
},
form_definition: form_definition
}; };
for (var i = 0; i < form_definition.group_list.length; i++) { return form_definition;
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;
form_json.erp5_document._links = form_definition._links;
}
}
return form_json;
}) })
.allowPublicAcquisition('notifySubmit', function () { .declareMethod("render", function (options) {
return this.triggerSubmit(); var gadget = this,
default_view = "jio_view",
common_utils_gadget_url = "gadget_officejs_common_utils.html",
child_gadget_url = 'gadget_erp5_pt_form_list.html';
return gadget.declareGadget(common_utils_gadget_url)
.push(function (gadget_utils) {
return gadget.getFormDefinition();
//return gadget_utils.getFormDefinition(jio_document.portal_type, default_view);
})
.push(function (form_definition) {
return gadget.changeState({
jio_key: options.jio_key,
child_gadget_url: child_gadget_url,
form_definition: form_definition,
form_type: 'list',
editable: false,
view: default_view,
front_page: true,
has_more_views: false, //this should come from form_def
has_more_actions: false //this should come from form_def
});
});
}) })
.declareMethod("triggerSubmit", function () { .onStateChange(function () {
var argument_list = arguments; var fragment = document.createElement('div'),
return this.getDeclaredGadget('form_list') gadget = this,
.push(function (gadget) { options;
return gadget.triggerSubmit.apply(gadget, argument_list); while (this.element.firstChild) {
this.element.removeChild(this.element.firstChild);
}
this.element.appendChild(fragment);
return gadget.declareGadget("gadget_officejs_form_view.html", {element: fragment,
scope: 'form_view'})
.push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state);
}); });
}) })
.declareMethod("render", function () { .declareMethod("triggerSubmit", function () {
var gadget = this, var argument_list = arguments;
erp5_document; return this.getDeclaredGadget('form_view')
return new RSVP.Queue() .push(function (view_gadget) {
.push(function () { return view_gadget.getDeclaredGadget('fg');
return RSVP.all([
gadget.getDeclaredGadget('form_list'),
gadget.generateJsonRenderForm(gadget)
]);
})
.push(function (result) {
erp5_document = result[1].erp5_document;
return result[0].render(result[1]);
})
// render the header
.push(function () {
var url_for_parameter_list = [
{command: 'change', options: {page: "tab"}},
{command: 'change', options: {page: "action"}},
{command: 'history_previous'},
{command: 'selection_previous'},
{command: 'selection_next'},
{command: 'change', options: {page: "export"}},
{command: 'display', options: {}}
];
if (erp5_document._links && erp5_document._links.action_object_new_content_action) {
url_for_parameter_list.push({command: 'change', options: erp5_document._links.action_object_new_content_action});
}
return RSVP.all([
gadget.getUrlForList(url_for_parameter_list),
gadget.isDesktopMedia(),
gadget.getSetting('document_title_plural'),
gadget.getSetting('upload_dict', false)
]);
}) })
.push(function (result_list) { .push(function (gadget) {
var is_form_list = true, //TODO: configuration must indicate if is a form or list view return gadget.triggerSubmit.apply(gadget, argument_list);
url_list = result_list[0], header_dict;
if (is_form_list) {
header_dict = {
panel_action: true,
jump_url: "",
fast_input_url: "",
filter_action: true,
page_title: result_list[2]
};
if (result_list[4]) {
header_dict.upload_url = result_list[3];
}
} else {
header_dict = {
selection_url: url_list[2],
previous_url: url_list[3],
next_url: url_list[4],
page_title: gadget.state.doc.title
};
if (false) { //TODO: configuration must indicate if there are more views
header_dict.tab_url = url_list[0];
}
if (gadget.state.editable === "true") {
header_dict.save_action = true;
}
}
if (false) { //TODO: configuration must indicate if there are more actions
header_dict.actions_url = url_list[1];
}
if (url_list[7]) {
header_dict.add_url = url_list[7];
}
if (result_list[1]) {
header_dict.export_url = (
erp5_document._links.action_object_jio_report ||
erp5_document._links.action_object_jio_exchange ||
erp5_document._links.action_object_jio_print
) ? url_list[5] : '';
}
return gadget.updateHeader(header_dict);
}); });
}); });
}(window, rJS, RSVP));
\ No newline at end of file }(window, document, rJS, RSVP));
\ No newline at end of file
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.17663.19549.38007</string> </value> <value> <string>975.33670.15324.9233</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>1556202309.43</float> <float>1557077120.63</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
}) })
.declareMethod("renderSubGadget", function (options, subgadget, form_json) { .declareMethod("renderSubGadget", function (options, subgadget, form_json) {
var this_gadget = this, erp5_document = form_json.erp5_document; var this_gadget = this, erp5_document = form_json.erp5_document, add_url;
return subgadget.render({ return subgadget.render({
jio_key: options.jio_key, jio_key: options.jio_key,
doc: options.doc, doc: options.doc,
...@@ -138,6 +138,7 @@ ...@@ -138,6 +138,7 @@
erp5_document = form_json.erp5_document; erp5_document = form_json.erp5_document;
if (erp5_document._links && erp5_document._links.action_object_new_content_action) { if (erp5_document._links && erp5_document._links.action_object_new_content_action) {
url_for_parameter_list.push({command: 'change', options: erp5_document._links.action_object_new_content_action}); url_for_parameter_list.push({command: 'change', options: erp5_document._links.action_object_new_content_action});
add_url = true;
} }
return RSVP.all([ return RSVP.all([
this_gadget.getUrlForList(url_for_parameter_list), this_gadget.getUrlForList(url_for_parameter_list),
...@@ -160,10 +161,12 @@ ...@@ -160,10 +161,12 @@
panel_action: true, panel_action: true,
jump_url: "", jump_url: "",
fast_input_url: "", fast_input_url: "",
front_url: url_list[6],
filter_action: true, filter_action: true,
page_title: result_list[2] page_title: result_list[2]
}; };
if (!options.front_page) {
header_dict.front_url = url_list[6];
}
} else { } else {
header_dict = { header_dict = {
selection_url: url_list[2], selection_url: url_list[2],
...@@ -181,7 +184,7 @@ ...@@ -181,7 +184,7 @@
if (options.has_more_actions) { if (options.has_more_actions) {
header_dict.actions_url = url_list[1]; header_dict.actions_url = url_list[1];
} }
if (url_list[url_list.length - 1]) { if (add_url) {
header_dict.add_url = url_list[url_list.length - 1]; header_dict.add_url = url_list[url_list.length - 1];
} }
if (result_list[1]) { if (result_list[1]) {
......
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.29199.21743.1211</string> </value> <value> <string>975.33665.55580.31300</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>1556807969.14</float> <float>1557076245.43</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