Commit 4b3afea6 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
- allow dev user to set custom header options
- truncate long string fields in listboxes rendering
parent 306aa82c
......@@ -165,9 +165,7 @@
parent_portal_type: portal_type
};
if (view_categorie_list.includes(action_settings.action_type)) {
if (app_view === action_settings.action) {
action_settings.page = "ojs_local_controller";
}
action_info_dict.view_list[action_settings.action] =
action_settings;
} else {
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -258,7 +258,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>987.1958.49484.49100</string> </value>
<value> <string>1015.45953.43925.42052</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -278,7 +278,7 @@
</tuple>
<state>
<tuple>
<float>1601668696.35</float>
<float>1712334861.52</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -31,6 +31,7 @@
app_action_list,
form_definition,
current_version,
configurator,
index;
current_version = window.location.href.replace(window.location.hash, "");
index = current_version.indexOf(window.location.host) +
......@@ -40,18 +41,20 @@
"app_view_reference",
"parent_portal_type",
'default_view_reference',
'app_actions'])
'app_actions',
'app_configurator'])
.push(function (setting_list) {
app_view = options.action || setting_list[1];
parent_portal_type = setting_list[2];
default_view = setting_list[3];
app_action_list = setting_list[4];
configurator = setting_list[5] || 'ojs_configurator';
if (setting_list[0] !== current_version) {
//if app version has changed, force storage selection
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_configurator',
'page': configurator,
'auto_repair': true
}
});
......@@ -121,6 +124,7 @@
var fragment = document.createElement('div'),
gadget = this,
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_view_gadget;
while (this.element.firstChild) {
......
......@@ -222,7 +222,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1005.39859.38086.29457</string> </value>
<value> <string>1015.46091.52896.5922</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1673426666.06</float>
<float>1712343165.23</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -22,6 +22,7 @@
.getElementById("panel-template-body-desktop")
.innerHTML);
//TODO this is the same in action_officejs page, move to common
function getElementList(gadget, element_list) {
var i = 0,
element_info_list = [],
......
......@@ -219,7 +219,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -233,7 +233,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1001.57742.17876.27579</string> </value>
<value> <string>1014.1943.59170.64648</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -253,7 +253,7 @@
</tuple>
<state>
<tuple>
<float>1658943108.94</float>
<float>1713536268.81</float>
<string>UTC</string>
</tuple>
</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 */
(function (document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console) {
(function (document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console, escape) {
"use strict";
function renderField(field_id, field_definition,
context_document, data, blob_type, content_editable) {
var key, raw_value, override, final_value, item_list, result = {};
function renderField(field_id, field_definition, context_document,
data, blob_type, content_editable, gadget) {
var key, raw_value, override, final_value, item_list, result = {}, i,
extra_query, param_name, doc_key;
for (key in field_definition.values) {
if (field_definition.values.hasOwnProperty(key)) {
// order to get the final value (based on Field.py get_value)
......@@ -50,11 +51,39 @@
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;
}
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,
raw_properties = form_definition.fields_raw_properties,
form_json = {
......@@ -79,7 +108,7 @@
field_info = raw_properties[my_element];
rendered_field = renderField(element_id, field_info,
context_document, data, blob_type,
content_editable);
content_editable, gadget);
form_json.erp5_document._embedded._view[my_element] =
rendered_field;
}
......@@ -129,21 +158,44 @@
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
// XXX Hardcoded for modification_date rendering
// XXX fix date rendering
.allowPublicAcquisition("jio_allDocs", function (param_list) {
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])
.push(function (result) {
var i, date, len = result.data.total_rows;
function truncate(str, n) {
return (str.length > n) ? str.slice(0, n - 1) + '...' : str;
}
var i, date, len = result.data.total_rows, date_key_array;
for (i = 0; i < len; i += 1) {
if (result.data.rows[i].value.hasOwnProperty("modification_date")) {
date = new Date(result.data.rows[i].value.modification_date);
result.data.rows[i].value.modification_date = {
// truncate long strings
for (var key in result.data.rows[i].value) {
result.data.rows[i].value[key] =
truncate(result.data.rows[i].value[key], 40);
}
// render dates with proper format
date_key_array = Object.keys(
result.data.rows[i].value).filter((k) => k.includes("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: {
allow_empty_time: 0,
ampm_time_style: 0,
......@@ -154,10 +206,10 @@
hidden: 0,
hidden_day_is_last_day: 0,
"default": date.toUTCString(),
key: "modification_date",
key: "date",
required: 0,
timezone_style: 0,
title: "Modification Date",
title: "Date",
type: "DateTimeField"
}
};
......@@ -166,6 +218,10 @@
value: 2713
};
}
});
if (gadget.state.style_columns) {
eval(gadget.state.style_columns[0][0]);
}
}
return result;
});
......@@ -250,7 +306,7 @@
}
form_json = renderForm(gadget.state.form_definition, gadget.state.doc,
gadget.state.data, gadget.state.blob_type,
content_editable);
content_editable, gadget);
while (gadget.element.firstChild) {
gadget.element.removeChild(gadget.element.firstChild);
}
......@@ -267,13 +323,14 @@
.declareMethod("renderSubGadget", function (options, subgadget, form_json) {
var gadget = this, erp5_document = form_json.erp5_document,
portal_type_dict = form_json.form_definition.portal_type_dict,
page_title;
page_title = '', header_dict;
if (options.doc && options.doc.title) {
page_title = options.doc.title;
} else if (options.doc && 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({
jio_key: options.jio_key,
......@@ -288,7 +345,9 @@
// render the header
.push(function () {
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",
jio_key: options.jio_key,
portal_type: options.portal_type}},
......@@ -316,7 +375,7 @@
return gadget.getUrlForList(url_for_parameter_list);
})
.push(function (url_list) {
var header_dict = { "page_title": page_title };
header_dict = { "page_title": page_title };
if (options.form_type === 'dialog') {
//TODO: find correct url
header_dict.cancel_url = url_list[6];
......@@ -335,7 +394,9 @@
if (portal_type_dict.has_more_views) {
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 ||
portal_type_dict.has_more_views) {
header_dict.actions_url = url_list[1];
......@@ -353,8 +414,20 @@
}
}
}
return gadget.updateHeader(header_dict);
return gadget.declareGadget(portal_type_dict.custom_header);
})
.push(function (header_gadget) {
return header_gadget.getOptions(portal_type_dict, options, header_dict);
}, function (error) {
if (!portal_type_dict.custom_header) {
return header_dict;
} else {
throw error;
}
})
.push(function (header_options) {
return gadget.updateHeader(header_options);
});
});
}(document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console));
}(document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console, escape));
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -258,7 +258,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>991.25773.59047.44168</string> </value>
<value> <string>1016.10474.46597.2816</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -278,7 +278,7 @@
</tuple>
<state>
<tuple>
<float>1672736671.72</float>
<float>1714138267.55</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -36,6 +36,7 @@
);
}
//TODO this is the same in ojs_panel, move to common
function getHTMLElementList(gadget, element_list) {
var i = 0,
element_info_list = [],
......
......@@ -222,7 +222,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>979.63524.32203.29269</string> </value>
<value> <string>1015.45957.31009.8925</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1574423701.42</float>
<float>1713536281.01</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