Commit b2c02989 authored by Roque's avatar Roque

erp5_officejs: update app customization via router settings

- allow custom app configurator
- allow to customize app form styles
- render listbox form field extra configuration
- fix date format rendering
- allow configuration form fields to have extra js code
- allow to customize listbox sub fields
parent 6a0c55f0
...@@ -31,7 +31,9 @@ ...@@ -31,7 +31,9 @@
app_action_list, app_action_list,
form_definition, form_definition,
current_version, current_version,
index; configurator,
index,
link = document.createElement("link");
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) +
window.location.host.length; window.location.host.length;
...@@ -40,18 +42,27 @@ ...@@ -40,18 +42,27 @@
"app_view_reference", "app_view_reference",
"parent_portal_type", "parent_portal_type",
'default_view_reference', 'default_view_reference',
'app_actions']) 'app_actions',
'app_configurator',
'css_file'])
.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[6]) {
link.type = "text/css";
link.rel = "stylesheet";
link.href = setting_list[6];
document.head.appendChild(link);
}
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
} }
}); });
......
...@@ -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>1014.23713.21372.42922</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>1707241158.16</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, data, blob_type, content_editable) { context_document, data, blob_type, content_editable) {
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,6 +51,21 @@ ...@@ -50,6 +51,21 @@
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.values.extra) {
eval(field_definition.values.extra);
}
return result; return result;
} }
...@@ -134,38 +150,66 @@ ...@@ -134,38 +150,66 @@
.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;
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; var i, date, len = result.data.total_rows, date_key_array,
status_key_array = ['status', 'category'], status;
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"));
field_gadget_param: { date_key_array.forEach((date_key) => {
allow_empty_time: 0, if (result.data.rows[i].value.hasOwnProperty(date_key)) {
ampm_time_style: 0, date = new Date(result.data.rows[i].value[date_key]);
css_class: "date_field", result.data.rows[i].value[date_key] = {
date_only: 0, field_gadget_param: {
description: "The Date", allow_empty_time: 0,
editable: 0, ampm_time_style: 0,
hidden: 0, css_class: "date_field",
hidden_day_is_last_day: 0, date_only: 0,
"default": date.toUTCString(), description: "The Date",
key: "modification_date", editable: 0,
required: 0, hidden: 0,
timezone_style: 0, hidden_day_is_last_day: 0,
title: "Modification Date", "default": date.toUTCString(),
type: "DateTimeField" key: "date",
} required: 0,
}; timezone_style: 0,
result.data.rows[i].value["listbox_uid:list"] = { title: "Date",
key: "listbox_uid:list", type: "DateTimeField"
value: 2713 }
}; };
} result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
value: 2713
};
}
});
//TODO make it customizable from config
status_key_array.forEach((status_key) => {
if (result.data.rows[i].value.hasOwnProperty(status_key)) {
status = result.data.rows[i].value[status_key];
result.data.rows[i].value[status_key] = {
field_gadget_param: {
css_class: "",
description: "",
hidden: 0,
"default": status,
key: status_key,
url: "gadget_erp5_field_status.html",
title: "Status",
type: "GadgetField"
}
};
result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
value: 2713
};
}
});
} }
return result; return result;
}); });
...@@ -357,4 +401,4 @@ ...@@ -357,4 +401,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.24557.22502.33262</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>1711051105.18</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