mirror of
https://gitlab.com/flectra-hq/flectra.git
synced 2026-11-02 20:30:20 -06:00
103 lines
4.0 KiB
XML
103 lines
4.0 KiB
XML
<?xml version="1.0" encoding="utf-8" ?>
|
|
<flectra>
|
|
<!--
|
|
Chatter Position - Start
|
|
-->
|
|
<template id="webclient_bootstrap" inherit_id="web.webclient_bootstrap" name="Chatter Position">
|
|
<xpath expr="//t[@t-set='body_classname']" position="attributes">
|
|
<attribute name="t-value" add="+ ' o_chatter_position_' + (request.env.user.chatter_position or 'bottom')" separator=" " />
|
|
</xpath>
|
|
</template>
|
|
<!--
|
|
Chatter Position - End
|
|
-->
|
|
|
|
<!--
|
|
Progressive Web App - Start
|
|
-->
|
|
<template id="web_layout_pwa" name="Web layout PWA" inherit_id="web.layout">
|
|
<xpath expr="//head" position="inside">
|
|
<!-- Add meta tags and icons -->
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
|
<t t-set="pwa_config" t-value="request.env['pwa.config'].sudo().search([('pwa_company_id', '=', request.env.user.company_id.id)]) or False" />
|
|
<t t-if="pwa_config != False">
|
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
|
<meta name="apple-mobile-web-app-title"
|
|
t-attf-content="#{pwa_config.pwa_name or 'Flectra'}" />
|
|
<link rel="apple-touch-icon"
|
|
t-attf-href="#{'/web/image/pwa.config/'+str(pwa_config.id)+'/pwa_icon_192'
|
|
if pwa_config.pwa_icon_192
|
|
else '/web_flectra/static/src/img/icons/icon-192x192.png'}" />
|
|
<!-- Add link rel manifest -->
|
|
<link rel="manifest" t-att-href="'/manifest.json/'+str(request.env.user.company_id.id)" />
|
|
<!-- Add meta theme-color -->
|
|
<meta name="theme-color"
|
|
t-attf-content="#{pwa_config.pwa_theme_color or '#009efb'}" />
|
|
</t>
|
|
</xpath>
|
|
</template>
|
|
<template id="service_worker_settings" name="PWA service worker settings">
|
|
const CACHE_NAME = '<t t-esc="pwa_cache_name" />';
|
|
const FILES_TO_CACHE = [
|
|
<t t-foreach="pwa_files_to_cache" t-as="file_to_cache">
|
|
'<t t-esc="file_to_cache" />',
|
|
</t>
|
|
];
|
|
</template>
|
|
<template id="service_worker_install" name="PWA service worker install">
|
|
self.addEventListener('install', event => {
|
|
console.debug('[ServiceWorker] Install');
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then(function (cache) {
|
|
console.debug('[ServiceWorker] Pre-caching offline page');
|
|
return cache.addAll(FILES_TO_CACHE);
|
|
})
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
</template>
|
|
<template id="service_worker_activate" name="PWA service worker activate">
|
|
self.addEventListener('activate', event => {
|
|
console.debug('[ServiceWorker] Activate');
|
|
event.waitUntil(
|
|
caches.keys().then(function(keyList) {
|
|
return Promise.all(keyList.map(function(key) {
|
|
if (key !== CACHE_NAME) {
|
|
console.debug('[ServiceWorker] Removing old cache', key);
|
|
return caches.delete(key);
|
|
}
|
|
}));
|
|
})
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
</template>
|
|
<template id="service_worker_fetch" name="PWA service worker fetch">
|
|
self.addEventListener('fetch', event => {
|
|
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
|
|
return;
|
|
}
|
|
console.debug('[ServiceWorker] Fetch', event.request.url);
|
|
event.respondWith(
|
|
caches.open(CACHE_NAME).then(function(cache) {
|
|
return cache.match(event.request)
|
|
.then(function(response) {
|
|
return response || fetch(event.request);
|
|
});
|
|
})
|
|
);
|
|
});
|
|
</template>
|
|
<template id="service_worker" name="PWA service worker">
|
|
'use strict';
|
|
<t t-call="web_flectra.service_worker_settings" />
|
|
<t t-call="web_flectra.service_worker_install" />
|
|
<t t-call="web_flectra.service_worker_activate" />
|
|
<t t-call="web_flectra.service_worker_fetch" />
|
|
</template>
|
|
<!--
|
|
Progressive Web App - End
|
|
-->
|
|
</flectra>
|