Commit 4b87075b authored by Roque's avatar Roque

erp5_officejs: update app customization via router settings

- allow custom app configurator
- render listbox form field extra configuration
- fix date format rendering
- allow configuration form fields to have extra js code
- allow to customize listbox column styles
- allow to customize listbox jio_alldocs
- fix custom view handling
- fix gadget field rendering
parent f2318991
...@@ -165,9 +165,7 @@ ...@@ -165,9 +165,7 @@
parent_portal_type: portal_type parent_portal_type: portal_type
}; };
if (view_categorie_list.includes(action_settings.action_type)) { if (view_categorie_list.includes(action_settings.action_type)) {
if (app_view === action_settings.action) {
action_settings.page = "ojs_local_controller"; action_settings.page = "ojs_local_controller";
}
action_info_dict.view_list[action_settings.action] = action_info_dict.view_list[action_settings.action] =
action_settings; action_settings;
} else { } else {
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>zope</string> </value> <value> <unicode>zope</unicode> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -258,7 +258,7 @@ ...@@ -258,7 +258,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>987.1958.49484.49100</string> </value> <value> <string>1015.45953.43925.42052</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -278,7 +278,7 @@ ...@@ -278,7 +278,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1601668696.35</float> <float>1712334861.52</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
app_action_list, app_action_list,
form_definition, form_definition,
current_version, current_version,
configurator,
index; index;
current_version = window.location.href.replace(window.location.hash, ""); current_version = window.location.href.replace(window.location.hash, "");
index = current_version.indexOf(window.location.host) + index = current_version.indexOf(window.location.host) +
...@@ -40,18 +41,20 @@ ...@@ -40,18 +41,20 @@
"app_view_reference", "app_view_reference",
"parent_portal_type", "parent_portal_type",
'default_view_reference', 'default_view_reference',
'app_actions']) 'app_actions',
'app_configurator'])
.push(function (setting_list) { .push(function (setting_list) {
app_view = options.action || setting_list[1]; app_view = options.action || setting_list[1];
parent_portal_type = setting_list[2]; parent_portal_type = setting_list[2];
default_view = setting_list[3]; default_view = setting_list[3];
app_action_list = setting_list[4]; app_action_list = setting_list[4];
configurator = setting_list[5] || 'ojs_configurator';
if (setting_list[0] !== current_version) { if (setting_list[0] !== current_version) {
//if app version has changed, force storage selection //if app version has changed, force storage selection
return gadget.redirect({ return gadget.redirect({
'command': 'display', 'command': 'display',
'options': { 'options': {
'page': 'ojs_configurator', 'page': configurator,
'auto_repair': true 'auto_repair': true
} }
}); });
...@@ -121,6 +124,7 @@ ...@@ -121,6 +124,7 @@
var fragment = document.createElement('div'), var fragment = document.createElement('div'),
gadget = this, gadget = this,
view_gadget_url = "gadget_officejs_form_view.html", view_gadget_url = "gadget_officejs_form_view.html",
//TODO: this should be a list, not only one custom view
custom_gadget_url = gadget.state.form_definition.portal_type_dict custom_gadget_url = gadget.state.form_definition.portal_type_dict
.custom_view_gadget; .custom_view_gadget;
while (this.element.firstChild) { while (this.element.firstChild) {
......
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>zope</string> </value> <value> <unicode>zope</unicode> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1005.39859.38086.29457</string> </value> <value> <string>1015.46091.52896.5922</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -256,7 +256,7 @@ ...@@ -256,7 +256,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1673426666.06</float> <float>1712343165.23</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console */ /*global document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console, escape */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */ /*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console) { (function (document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console, escape) {
"use strict"; "use strict";
function renderField(field_id, field_definition, function renderField(field_id, field_definition, context_document,
context_document, data, blob_type, content_editable) { data, blob_type, content_editable, gadget) {
var key, raw_value, override, final_value, item_list, result = {}; var key, raw_value, override, final_value, item_list, result = {}, i,
extra_query, param_name, doc_key;
for (key in field_definition.values) { for (key in field_definition.values) {
if (field_definition.values.hasOwnProperty(key)) { if (field_definition.values.hasOwnProperty(key)) {
// order to get the final value (based on Field.py get_value) // order to get the final value (based on Field.py get_value)
...@@ -50,11 +51,39 @@ ...@@ -50,11 +51,39 @@
result.type = "EditorField"; result.type = "EditorField";
} }
} }
if (field_definition.type == "ListBox") {
if (field_definition.values.default_params) {
for (i = 0; i < field_definition.values.default_params.length; i += 1) {
param_name = field_definition.values.default_params[i][0];
doc_key = field_definition.values.default_params[i][1];
if (context_document.hasOwnProperty(doc_key) && context_document[doc_key]) {
extra_query = ` AND ${param_name}:"${context_document[doc_key]}"`;
result.query += escape(extra_query);
}
}
}
}
if (field_definition.type == "GadgetField") {
//TODO allow both, user renderjs_extra + doc info-jio_key
if (!field_definition.renderjs_extra) {
var extra_dict = {};
Object.assign(extra_dict, gadget.state.doc);
extra_dict.jio_key = gadget.state.options.jio_key;
field_definition.values.renderjs_extra = JSON.stringify(extra_dict);
result.renderjs_extra = JSON.stringify(extra_dict);
}
}
if (field_definition.values.extra) {
eval(field_definition.values.extra);
}
if (field_definition.values.style_columns) {
gadget.state.style_columns = field_definition.values.style_columns;
}
return result; return result;
} }
function renderForm(form_definition, context_document, data, blob_type, function renderForm(form_definition, context_document, data, blob_type,
content_editable) { content_editable, gadget) {
var i, j, field_list, field_info, my_element, element_id, rendered_field, var i, j, field_list, field_info, my_element, element_id, rendered_field,
raw_properties = form_definition.fields_raw_properties, raw_properties = form_definition.fields_raw_properties,
form_json = { form_json = {
...@@ -79,7 +108,7 @@ ...@@ -79,7 +108,7 @@
field_info = raw_properties[my_element]; field_info = raw_properties[my_element];
rendered_field = renderField(element_id, field_info, rendered_field = renderField(element_id, field_info,
context_document, data, blob_type, context_document, data, blob_type,
content_editable); content_editable, gadget);
form_json.erp5_document._embedded._view[my_element] = form_json.erp5_document._embedded._view[my_element] =
rendered_field; rendered_field;
} }
...@@ -129,21 +158,36 @@ ...@@ -129,21 +158,36 @@
.declareAcquiredMethod("updateHeader", "updateHeader") .declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlForList", "getUrlForList") .declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs") .declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") .declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment") .declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting") .declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted') .declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
// XXX Hardcoded for modification_date rendering // XXX fix date rendering
.allowPublicAcquisition("jio_allDocs", function (param_list) { .allowPublicAcquisition("jio_allDocs", function (param_list) {
var gadget = this; var gadget = this;
if (gadget.state.style_columns && gadget.state.style_columns[0][0] === 'jio_allDocs') {
return new RSVP.Queue()
.push(function () {
return gadget.declareGadget(gadget.state.style_columns[0][1]);
})
.push(function (jio_alldocs) {
return jio_alldocs.jio_allDocs(param_list, gadget);
});
}
return gadget.jio_allDocs(param_list[0]) return gadget.jio_allDocs(param_list[0])
.push(function (result) { .push(function (result) {
var i, date, len = result.data.total_rows; // render dates with proper format
var i, date, len = result.data.total_rows, date_key_array;
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
if (result.data.rows[i].value.hasOwnProperty("modification_date")) { date_key_array = Object.keys(
date = new Date(result.data.rows[i].value.modification_date); result.data.rows[i].value).filter((k) => k.includes("date") ||
result.data.rows[i].value.modification_date = { k.includes("Date"));
date_key_array.forEach((date_key) => {
if (result.data.rows[i].value.hasOwnProperty(date_key)) {
date = new Date(result.data.rows[i].value[date_key]);
result.data.rows[i].value[date_key] = {
field_gadget_param: { field_gadget_param: {
allow_empty_time: 0, allow_empty_time: 0,
ampm_time_style: 0, ampm_time_style: 0,
...@@ -154,10 +198,10 @@ ...@@ -154,10 +198,10 @@
hidden: 0, hidden: 0,
hidden_day_is_last_day: 0, hidden_day_is_last_day: 0,
"default": date.toUTCString(), "default": date.toUTCString(),
key: "modification_date", key: "date",
required: 0, required: 0,
timezone_style: 0, timezone_style: 0,
title: "Modification Date", title: "Date",
type: "DateTimeField" type: "DateTimeField"
} }
}; };
...@@ -166,6 +210,10 @@ ...@@ -166,6 +210,10 @@
value: 2713 value: 2713
}; };
} }
});
if (gadget.state.style_columns) {
eval(gadget.state.style_columns[0][0]);
}
} }
return result; return result;
}); });
...@@ -250,7 +298,7 @@ ...@@ -250,7 +298,7 @@
} }
form_json = renderForm(gadget.state.form_definition, gadget.state.doc, form_json = renderForm(gadget.state.form_definition, gadget.state.doc,
gadget.state.data, gadget.state.blob_type, gadget.state.data, gadget.state.blob_type,
content_editable); content_editable, gadget);
while (gadget.element.firstChild) { while (gadget.element.firstChild) {
gadget.element.removeChild(gadget.element.firstChild); gadget.element.removeChild(gadget.element.firstChild);
} }
...@@ -267,13 +315,14 @@ ...@@ -267,13 +315,14 @@
.declareMethod("renderSubGadget", function (options, subgadget, form_json) { .declareMethod("renderSubGadget", function (options, subgadget, form_json) {
var gadget = this, erp5_document = form_json.erp5_document, var gadget = this, erp5_document = form_json.erp5_document,
portal_type_dict = form_json.form_definition.portal_type_dict, portal_type_dict = form_json.form_definition.portal_type_dict,
page_title; page_title = '';
if (options.doc && options.doc.title) { if (options.doc && options.doc.title) {
page_title = options.doc.title; page_title = options.doc.title;
} else if (options.doc && options.doc.header_title) { } else if (options.doc && options.doc.header_title) {
page_title = options.doc.header_title; page_title = options.doc.header_title;
} else { }
page_title = portal_type_dict.title; if (portal_type_dict.title) {
page_title = portal_type_dict.title + page_title;
} }
return subgadget.render({ return subgadget.render({
jio_key: options.jio_key, jio_key: options.jio_key,
...@@ -288,7 +337,9 @@ ...@@ -288,7 +337,9 @@
// render the header // render the header
.push(function () { .push(function () {
var url_for_parameter_list = [ var url_for_parameter_list = [
{command: 'change', options: {page: "tab"}}, {command: 'change', options: {page: "action_officejs",
jio_key: options.jio_key,
portal_type: options.portal_type}},
{command: 'change', options: {page: "action_officejs", {command: 'change', options: {page: "action_officejs",
jio_key: options.jio_key, jio_key: options.jio_key,
portal_type: options.portal_type}}, portal_type: options.portal_type}},
...@@ -335,7 +386,9 @@ ...@@ -335,7 +386,9 @@
if (portal_type_dict.has_more_views) { if (portal_type_dict.has_more_views) {
header_dict.tab_url = url_list[0]; header_dict.tab_url = url_list[0];
} }
header_dict.save_action = portal_type_dict.editable === 1; if (portal_type_dict.editable === 1) {
header_dict.save_action = true;
}
if (portal_type_dict.has_more_actions || if (portal_type_dict.has_more_actions ||
portal_type_dict.has_more_views) { portal_type_dict.has_more_views) {
header_dict.actions_url = url_list[1]; header_dict.actions_url = url_list[1];
...@@ -357,4 +410,4 @@ ...@@ -357,4 +410,4 @@
}); });
}); });
}(document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console)); }(document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console, escape));
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>zope</string> </value> <value> <unicode>zope</unicode> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -258,7 +258,7 @@ ...@@ -258,7 +258,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>991.25773.59047.44168</string> </value> <value> <string>1015.54474.36356.6365</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -278,7 +278,7 @@ ...@@ -278,7 +278,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1672736671.72</float> <float>1712846175.79</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