Commit fe30b1fc authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_renderjs_ui: duplicate files by adding language prefix

parent a6049d0c
/*jslint indent: 2*/ /*jslint indent: 2*/
/*global self, caches, fetch, Promise, URL, location, Response*/ /*global self, caches, fetch, Promise, URL, location, Response, console*/
(function (self, caches, fetch, Promise, URL, location, Response) { (function (self, caches, fetch, Promise, URL, location, Response) {
"use strict"; "use strict";
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
// CLIENT_CACHE_MAPPING_NAME must not start with `prefix` // CLIENT_CACHE_MAPPING_NAME must not start with `prefix`
// else it may be used as a normal content cache. // else it may be used as a normal content cache.
CLIENT_CACHE_MAPPING_NAME = '__erp5js_' + location.toString(), CLIENT_CACHE_MAPPING_NAME = '__erp5js_' + location.toString(),
CACHE_NAME = prefix + '_0001', CACHE_NAME = prefix + '_0007',
CACHE_MAP = {}, CACHE_MAP = {},
// Files required to make this app work offline // Files required to make this app work offline
REQUIRED_LANGUAGE_PREFIX_LIST = ['', 'fr/'],
REQUIRED_FILES = [ REQUIRED_FILES = [
'favicon.ico', 'favicon.ico',
'font-awesome/font-awesome-webfont.eot', 'font-awesome/font-awesome-webfont.eot',
...@@ -158,12 +159,14 @@ ...@@ -158,12 +159,14 @@
], ],
required_url_list = [], required_url_list = [],
i, i,
len = REQUIRED_FILES.length; j;
for (i = 0; i < len; i += 1) { for (i = 0; i < REQUIRED_FILES.length; i += 1) {
required_url_list.push( for (j = 0; j < REQUIRED_LANGUAGE_PREFIX_LIST.length; j += 1) {
new URL(REQUIRED_FILES[i], location.toString()).toString() required_url_list.push(
); new URL(REQUIRED_LANGUAGE_PREFIX_LIST[j] + REQUIRED_FILES[i], location.toString()).toString()
);
}
} }
self.addEventListener('install', function (event) { self.addEventListener('install', function (event) {
// Perform install step: loading each required file into cache // Perform install step: loading each required file into cache
...@@ -181,13 +184,13 @@ ...@@ -181,13 +184,13 @@
.then(function (cache) { .then(function (cache) {
// Add all offline dependencies to the cache // Add all offline dependencies to the cache
return Promise.all( return Promise.all(
REQUIRED_FILES required_url_list
.map(function (url) { .map(function (url) {
/* Return a promise that's fulfilled /* Return a promise that's fulfilled
when each url is cached. when each url is cached.
*/ */
// Use cache.add because safari does not support cache.addAll. // Use cache.add because safari does not support cache.addAll.
console.log("Install " + CACHE_NAME + " = " + url); // console.log("Install " + CACHE_NAME + " = " + url);
return cache.add(url); return cache.add(url);
}) })
); );
...@@ -253,12 +256,12 @@ ...@@ -253,12 +256,12 @@
// and don't get cache_key from CACHE_MAP and erp5js_cache. // and don't get cache_key from CACHE_MAP and erp5js_cache.
cache_key = CACHE_MAP[client_id]; cache_key = CACHE_MAP[client_id];
} }
console.log("Client Id = " + client_id); // console.log("Client Id = " + client_id);
/*
if (cache_key) { if (cache_key) {
console.log("cache_key from CACHE_MAP " + cache_key); console.log("cache_key from CACHE_MAP " + cache_key);
} }
*/
if ((event.request.method !== 'GET') || if ((event.request.method !== 'GET') ||
(required_url_list.indexOf(url.toString()) === -1)) { (required_url_list.indexOf(url.toString()) === -1)) {
// Try not to use the untrustable fetch function // Try not to use the untrustable fetch function
...@@ -282,7 +285,7 @@ ...@@ -282,7 +285,7 @@
// We use Cache Storage as a persistent database. // We use Cache Storage as a persistent database.
cache_key = response.statusText; cache_key = response.statusText;
CACHE_MAP[client_id] = cache_key; CACHE_MAP[client_id] = cache_key;
console.log("cache_key from Cache Storage " + cache_key); // console.log("cache_key from Cache Storage " + cache_key);
} }
}); });
}); });
...@@ -295,7 +298,7 @@ ...@@ -295,7 +298,7 @@
return caches.keys() return caches.keys()
.then(function (keys) { .then(function (keys) {
keys = keys.filter(function (key) {return key.startsWith(prefix); }); keys = keys.filter(function (key) {return key.startsWith(prefix); });
console.log("KEYS = " + keys); // console.log("KEYS = " + keys);
if (keys.length) { if (keys.length) {
cache_key = keys.sort().reverse()[0]; cache_key = keys.sort().reverse()[0];
if (client_id) { if (client_id) {
...@@ -323,7 +326,7 @@ ...@@ -323,7 +326,7 @@
// Don't give request object itself. Firefox's Cache Storage // Don't give request object itself. Firefox's Cache Storage
// does not work properly when VARY contains Accept-Language. // does not work properly when VARY contains Accept-Language.
// Give URL string instead, then cache.match works on both Firefox and Chrome. // Give URL string instead, then cache.match works on both Firefox and Chrome.
console.log("MATCH " + cache_key + " " + url); // console.log("MATCH " + cache_key + " " + url);
return cache.match(event.request.url); return cache.match(event.request.url);
}) })
.then(function (response) { .then(function (response) {
...@@ -333,7 +336,7 @@ ...@@ -333,7 +336,7 @@
} }
// Not in cache - return the result from the live server // Not in cache - return the result from the live server
// `fetch` is essentially a "fallback" // `fetch` is essentially a "fallback"
console.log("MISS " + cache_key + " " + url); // console.log("MISS " + cache_key + " " + url);
return fetch(event.request); return fetch(event.request);
}) })
); );
......
...@@ -148,171 +148,183 @@ ...@@ -148,171 +148,183 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>publish_alive</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>publish_alive</string> </value>
<key> <string>actor</string> </key> </item>
<value> <string>zope</string> </value> <item>
</item> <key> <string>actor</string> </key>
<item> <value> <string>zope</string> </value>
<key> <string>comment</string> </key> </item>
<value> <string></string> </value> <item>
</item> <key> <string>comment</string> </key>
<item> <value> <string></string> </value>
<key> <string>error_message</string> </key> </item>
<value> <string></string> </value> <item>
</item> <key> <string>error_message</string> </key>
<item> <value> <string></string> </value>
<key> <string>time</string> </key> </item>
<value> <item>
<object> <key> <string>time</string> </key>
<klass> <value>
<global name="DateTime" module="DateTime.DateTime"/> <object>
</klass> <klass>
<tuple> <global name="DateTime" module="DateTime.DateTime"/>
<none/> </klass>
</tuple> <tuple>
<state> <none/>
<tuple> </tuple>
<float>1458658259.73</float> <state>
<string>UTC</string> <tuple>
</tuple> <float>1458658259.73</float>
</state> <string>UTC</string>
</object> </tuple>
</value> </state>
</item> </object>
<item> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>published_alive</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>published_alive</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>edit</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>edit</string> </value>
<key> <string>actor</string> </key> </item>
<value> <string>zope</string> </value> <item>
</item> <key> <string>actor</string> </key>
<item> <value> <string>zope</string> </value>
<key> <string>comment</string> </key> </item>
<value> <item>
<none/> <key> <string>comment</string> </key>
</value> <value>
</item> <none/>
<item> </value>
<key> <string>error_message</string> </key> </item>
<value> <string></string> </value> <item>
</item> <key> <string>error_message</string> </key>
<item> <value> <string></string> </value>
<key> <string>serial</string> </key> </item>
<value> <string>976.56996.62202.65433</string> </value> <item>
</item> <key> <string>serial</string> </key>
<item> <value> <string>981.29187.20499.52753</string> </value>
<key> <string>state</string> </key> </item>
<value> <string>current</string> </value> <item>
</item> <key> <string>state</string> </key>
<item> <value> <string>current</string> </value>
<key> <string>time</string> </key> </item>
<value> <item>
<object> <key> <string>time</string> </key>
<klass> <value>
<global name="DateTime" module="DateTime.DateTime"/> <object>
</klass> <klass>
<tuple> <global name="DateTime" module="DateTime.DateTime"/>
<none/> </klass>
</tuple> <tuple>
<state> <none/>
<tuple> </tuple>
<float>1562322109.66</float> <state>
<string>UTC</string> <tuple>
</tuple> <float>1580141240.29</float>
</state> <string>UTC</string>
</object> </tuple>
</value> </state>
</item> </object>
</dictionary> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="5" aka="AAAAAAAAAAU="> <record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>detect_converted_file</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>detect_converted_file</string> </value>
<key> <string>actor</string> </key> </item>
<value> <string>zope</string> </value> <item>
</item> <key> <string>actor</string> </key>
<item> <value> <string>zope</string> </value>
<key> <string>comment</string> </key> </item>
<value> <string></string> </value> <item>
</item> <key> <string>comment</string> </key>
<item> <value> <string></string> </value>
<key> <string>error_message</string> </key> </item>
<value> <string></string> </value> <item>
</item> <key> <string>error_message</string> </key>
<item> <value> <string></string> </value>
<key> <string>external_processing_state</string> </key> </item>
<value> <string>converted</string> </value> <item>
</item> <key> <string>external_processing_state</string> </key>
<item> <value> <string>converted</string> </value>
<key> <string>serial</string> </key> </item>
<value> <string>0.0.0.0</string> </value> <item>
</item> <key> <string>serial</string> </key>
<item> <value> <string>0.0.0.0</string> </value>
<key> <string>time</string> </key> </item>
<value> <item>
<object> <key> <string>time</string> </key>
<klass> <value>
<global name="DateTime" module="DateTime.DateTime"/> <object>
</klass> <klass>
<tuple> <global name="DateTime" module="DateTime.DateTime"/>
<none/> </klass>
</tuple> <tuple>
<state> <none/>
<tuple> </tuple>
<float>1458654672.71</float> <state>
<string>UTC</string> <tuple>
</tuple> <float>1458654672.71</float>
</state> <string>UTC</string>
</object> </tuple>
</value> </state>
</item> </object>
</dictionary> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
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