Commit e3921c42 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_hal_json_style: calculate link to allow Nexedi developer access the ERP5 field from it.

parent 751d975a
......@@ -337,8 +337,13 @@ url_template_dict = {
}
default_document_uri_template = url_template_dict["jio_get_template"]
Base_translateString = context.getPortalObject().Base_translateString
portal = context.getPortalObject()
portal_absolute_url = portal.absolute_url()
preference_tool = portal.portal_preferences
Base_translateString = portal.Base_translateString
preferred_html_style_developper_mode = preference_tool.getPreferredHtmlStyleDevelopperMode()
preferred_html_style_translator_mode = preference_tool.getPreferredHtmlStyleTranslatorMode()
def getRealRelativeUrl(document):
return '/'.join(portal.portal_url.getRelativeContentPath(document))
......@@ -446,6 +451,32 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None, k
"description": field.get_value("description"),
}
if preferred_html_style_developper_mode or meta_type == "ListBox":
form_relative_url = getFormRelativeUrl(form)
if preferred_html_style_developper_mode:
result["edit_field_href"] = '%s/%s/manage_main' % (form_relative_url, field.id)
result["edit_field_icon"] = "%s/images/editfield.png" % portal_absolute_url
if preferred_html_style_translator_mode:
erp5_ui = portal.Localizer.erp5_ui
selected_language = erp5_ui.get_selected_language()
result["translate_title_href"] = '%s/manage_messages?regex=^%s&lang=%s' % (
'/'.join(erp5_ui.getPhysicalPath()),
field.title(),
selected_language
)
result["translate_title_icon"] = "%s/images/translate.png" % portal_absolute_url
field_description = field.Field_getDescription()
if field_description:
result["translate_description_href"] = '%s/manage_messages?regex=^%s&lang=%s' % (
'/'.join(erp5_ui.getPhysicalPath()),
field_description,
selected_language
)
result["translate_description_icon"] = "%s/images/translate_tooltip.png" % portal_absolute_url
if "Field" in meta_type:
# fields have default value and can be required (unlike boxes)
result["required"] = field.get_value("required") if field.has_value("required") else None
......@@ -737,7 +768,7 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None, k
"root_url": site_root.absolute_url(),
"script_id": script.id,
"relative_url": getRealRelativeUrl(traversed_document).replace("/", "%2F"),
"form_relative_url": "%s/%s" % (getFormRelativeUrl(form), field.id),
"form_relative_url": "%s/%s" % (form_relative_url, field.id),
"list_method": list_method_name,
"default_param_json": urlsafe_b64encode(
json.dumps(ensureSerializable(list_method_query_dict))),
......@@ -1291,7 +1322,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# Always inform about portal
"portal": {
"href": default_document_uri_template % {
"root_url": portal.absolute_url(),
"root_url": portal_absolute_url,
# XXX the portal has an empty getRelativeUrl. Make it still compatible
# with restrictedTraverse
"relative_url": portal.getId(),
......
......@@ -111,7 +111,8 @@
css_class,
i,
queue,
new_div;
new_div,
field_href;
if (modification_dict.hasOwnProperty('first_call')) {
gadget.props = {
......@@ -131,6 +132,36 @@
}
this.props.label_element.setAttribute('for', gadget.state.scope);
if (field_json) {
if (field_json.hasOwnProperty('edit_field_href')) {
field_href = document.createElement("a");
field_href.href = field_json.edit_field_href;
field_href.title = "Edit this field";
field_href.appendChild(document.createElement("img"));
field_href.firstElementChild.src = field_json.edit_field_icon;
this.props.label_element.appendChild(field_href);
}
if (field_json.hasOwnProperty('translate_title_href')) {
field_href = document.createElement("a");
field_href.href = field_json.translate_title_href;
field_href.title = "Translate this field title";
field_href.appendChild(document.createElement("img"));
field_href.firstElementChild.src = field_json.translate_title_icon;
this.props.label_element.appendChild(field_href);
}
if (field_json.hasOwnProperty('translate_description_href')) {
field_href = document.createElement("a");
field_href.href = field_json.translate_description_href;
field_href.title = "Translate this field description";
field_href.appendChild(document.createElement("img"));
field_href.firstElementChild.src = field_json.translate_description_icon;
this.props.label_element.appendChild(field_href);
}
}
if (modification_dict.hasOwnProperty('css_class') && this.state.css_class) {
css_class = this.state.css_class.split(' ');
for (i = 0; i < css_class.length; i += 1) {
......
......@@ -1180,6 +1180,9 @@ div[data-gadget-scope='header'] .ui-header ul {
.gadget-content .ui-field-contain > label {
color: hsl(0, 0%, 42%);
}
.gadget-content .ui-field-contain > label > a {
padding-left: 3pt;
}
.gadget-content .required > .ui-field-contain > label {
font-weight: bold;
color: #1F1F1F;
......
......@@ -1365,7 +1365,10 @@ div[data-gadget-scope='header'] .ui-header {
.ui-field-contain {
& > label {
color: @colorlabel;
& > a {
// links inside label when dev mode is enable
padding-left: 3pt;
}
}
}
//Label styling in required and "invisible" field
......
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