Commit 698b9ef0 authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_renderjs_ui: use relative url with .. to fetch gadgets

Drop base tag, because it will probably break all erp5js forks, which hardcode url strings
parent ed7cfc97
......@@ -4,8 +4,7 @@
<meta charset="utf-8">
<meta name="google" content="notranslate">
<meta name="viewport" content="width=device-width, initial-scale=1">
${extra_base_tag}
<link rel="shortcut icon" href="favicon.ico">
<link rel="shortcut icon" href="${base_prefix}favicon.ico">
<meta name="theme-color" content="#085078">
<title>${application_title}</title>
......@@ -16,6 +15,7 @@
${webapp_manifest_full_link_tag}
<script data-renderjs-configuration="application_title" type="text/x-renderjs-configuration">${application_title}</script>
<script data-renderjs-configuration="base_prefix" type="text/x-renderjs-configuration">${base_prefix}</script>
<script data-renderjs-configuration="panel_gadget" type="text/x-renderjs-configuration">${panel_gadget}</script>
<script data-renderjs-configuration="action_view" type="text/x-renderjs-configuration">${action_view}</script>
<script data-renderjs-configuration="default_view_reference" type="text/x-renderjs-configuration">${default_view_reference}</script>
......@@ -27,16 +27,16 @@
<script data-renderjs-configuration="website_url_set" type="text/x-renderjs-configuration">${website_url_set}</script>
<script data-renderjs-configuration="service_worker_url" type="text/x-renderjs-configuration">${service_worker_url}</script>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="erp5_launcher_nojqm.js"></script>
<script src="${base_prefix}rsvp.js"></script>
<script src="${base_prefix}renderjs.js"></script>
<script src="${base_prefix}erp5_launcher_nojqm.js"></script>
</head>
<body>
<div data-role="page">
<div data-gadget-url="gadget_jio.html"
<div data-gadget-url="${base_prefix}gadget_jio.html"
data-gadget-scope="setting_gadget"
data-gadget-sandbox="public"></div>
......@@ -44,7 +44,7 @@
data-gadget-scope="router"
data-gadget-sandbox="public"></div>
<div data-gadget-async-url="gadget_erp5_notification.html"
<div data-gadget-async-url="${base_prefix}gadget_erp5_notification.html"
data-gadget-scope="notification"
data-gadget-sandbox="public"></div>
......@@ -61,7 +61,7 @@
data-gadget-sandbox="public"></div>
<div data-gadget-async-url="gadget_erp5_editor_panel.html"
<div data-gadget-async-url="${base_prefix}gadget_erp5_editor_panel.html"
data-gadget-scope="editor_panel"
data-gadget-sandbox="public"></div>
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>980.64171.26567.13107</string> </value>
<value> <string>981.33187.14689.53538</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -258,7 +258,7 @@
</tuple>
<state>
<tuple>
<float>1580304587.06</float>
<float>1580399803.54</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -12,11 +12,22 @@
panel_visible: false,
setting_id: "setting/" + document.head.querySelector(
'script[data-renderjs-configuration="application_title"]'
).textContent,
base_prefix: document.head.querySelector(
'script[data-renderjs-configuration="base_prefix"]'
).textContent
});
function renderMainGadget(gadget, url, options) {
var page_gadget;
if (gadget.state.base_prefix) {
// For now, we assume the url is always relative
// Until one router starts to return absolute url
url = new URL(
url,
new URL(gadget.state.base_prefix, window.location.href).href
).href;
}
return gadget.declareGadget(url, {
scope: MAIN_SCOPE
})
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>980.43952.30132.41164</string> </value>
<value> <string>981.33505.56582.2560</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1577760448.33</float>
<float>1580400534.96</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -7,10 +7,9 @@
// CLIENT_CACHE_MAPPING_NAME must not start with `prefix`
// else it may be used as a normal content cache.
CLIENT_CACHE_MAPPING_NAME = '__erp5js_' + location.toString(),
CACHE_NAME = prefix + '_0007',
CACHE_NAME = prefix + '_0013',
CACHE_MAP = {},
// Files required to make this app work offline
REQUIRED_LANGUAGE_PREFIX_LIST = ['', 'fr/'],
REQUIRED_FILES = [
'favicon.ico',
'font-awesome/font-awesome-webfont.eot',
......@@ -155,18 +154,17 @@
'jiodev.js',
'renderjs.js',
'rsvp.js',
'./'
'./',
'fr/',
'fa/'
],
required_url_list = [],
i,
j;
i;
for (i = 0; i < REQUIRED_FILES.length; i += 1) {
for (j = 0; j < REQUIRED_LANGUAGE_PREFIX_LIST.length; j += 1) {
required_url_list.push(
new URL(REQUIRED_LANGUAGE_PREFIX_LIST[j] + REQUIRED_FILES[i], location.toString()).toString()
);
}
required_url_list.push(
new URL(REQUIRED_FILES[i], location.toString()).toString()
);
}
self.addEventListener('install', function (event) {
// Perform install step: loading each required file into cache
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>981.29187.20499.52753</string> </value>
<value> <string>981.33513.20390.42547</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1580141240.29</float>
<float>1580400643.91</float>
<string>UTC</string>
</tuple>
</state>
......
import json
import re
from urlparse import urljoin
if REQUEST is None:
REQUEST = context.REQUEST
......@@ -31,23 +32,32 @@ view_as_web_method = default_web_page.getTypeBasedMethod(
fallback_script_id="WebPage_viewAsWeb"
)
selected_language = portal.Localizer.get_selected_language()
# base tag
if selected_language == default_language:
base_prefix = ""
else:
base_prefix = '../'
mapping_dict = {
"base_prefix": base_prefix,
"frontpage_gadget": web_section.getLayoutProperty("configuration_frontpage_gadget_url", default="worklist"),
"jio_document_page_gadget": web_section.getLayoutProperty("configuration_default_jio_document_page_gadget_url", default="form"),
"application_title": web_section.getLayoutProperty("configuration_application_title", default="ERP5"),
"action_view": web_section.getLayoutProperty("configuration_view_action_category", default="object_view"),
"default_view_reference": web_section.getLayoutProperty("configuration_default_view_action_reference", default="view"),
"hateoas_url": web_section.getLayoutProperty("configuration_hateoas_url", default="hateoas/"),
"panel_gadget": web_section.getLayoutProperty("configuration_panel_gadget_url", default="gadget_erp5_panel.html"),
"router_gadget": web_section.getLayoutProperty("configuration_router_gadget_url", default="gadget_erp5_router.html"),
"header_gadget": web_section.getLayoutProperty("configuration_header_gadget_url", default="gadget_erp5_header.html"),
"jio_gadget": web_section.getLayoutProperty("configuration_jio_gadget_url", default="gadget_jio.html"),
"translation_gadget": web_section.getLayoutProperty("configuration_translation_gadget_url", default="gadget_translation.html"),
"panel_gadget": urljoin(base_prefix, web_section.getLayoutProperty("configuration_panel_gadget_url", default="gadget_erp5_panel.html")),
"router_gadget": urljoin(base_prefix, web_section.getLayoutProperty("configuration_router_gadget_url", default="gadget_erp5_router.html")),
"header_gadget": urljoin(base_prefix, web_section.getLayoutProperty("configuration_header_gadget_url", default="gadget_erp5_header.html")),
"jio_gadget": urljoin(base_prefix, web_section.getLayoutProperty("configuration_jio_gadget_url", default="gadget_jio.html")),
"translation_gadget": urljoin(base_prefix, web_section.getLayoutProperty("configuration_translation_gadget_url", default="gadget_translation.html")),
"manifest_url": web_section.getLayoutProperty("configuration_manifest_url", default="gadget_erp5.appcache"),
"stylesheet_url": web_section.getLayoutProperty("configuration_stylesheet_url", default="gadget_erp5_nojqm.css"),
"service_worker_url": web_section.getLayoutProperty("configuration_service_worker_url", default=""),
"stylesheet_url": urljoin(base_prefix, web_section.getLayoutProperty("configuration_stylesheet_url", default="gadget_erp5_nojqm.css")),
"service_worker_url": urljoin(base_prefix, web_section.getLayoutProperty("configuration_service_worker_url", default="")),
"language_map": json.dumps({tmp['id']: portal.Base_translateString(tmp['title'], lang = tmp['id']) for tmp in portal.Localizer.get_languages_map() if tmp['id'] in available_language_set}),
"default_selected_language": portal.Localizer.get_selected_language(),
"default_selected_language": selected_language,
"website_url_set": json.dumps(website_url_set),
"site_description": web_section.getLayoutProperty("description", default=""),
"site_keywords": web_section.getLayoutProperty("subject", default=""),
......@@ -65,12 +75,6 @@ if configuration_webapp_manifest_url is None:
else:
mapping_dict["webapp_manifest_full_link_tag"] = '<link rel="manifest" href="' + configuration_webapp_manifest_url + '">'
# base tag
if mapping_dict["default_selected_language"] == default_language:
mapping_dict["extra_base_tag"] = ""
else:
mapping_dict["extra_base_tag"] = '<base href="../">'
# Wallpaper
# It can not be done in Javascript, due to CSP protection.
# data- attribute can not be accessed outside the content property
......
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