Rename web_pwa -> web_pwa_oca

This commit is contained in:
eLBati
2020-06-05 08:12:22 +02:00
committed by sergio-teruel
parent 7d9053cb69
commit 4ec8d1ab8b
23 changed files with 1074 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
odoo.define('web_pwa_oca.systray.install', function (require) {
"use strict";
var core = require('web.core');
var session = require('web.session');
var UserMenu = require('web.UserMenu');
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/service-worker.js')
.then(function (reg) {
console.log('Service worker registered.', reg);
});
});
}
var deferredInstallPrompt = null;
UserMenu.include({
start: function () {
window.addEventListener('beforeinstallprompt', this.saveBeforeInstallPromptEvent);
return this._super.apply(this, arguments);
},
saveBeforeInstallPromptEvent: function(evt) {
deferredInstallPrompt = evt;
this.$.find('#pwa_install_button')[0].removeAttribute('hidden');
},
_onMenuInstallpwa: function () {
deferredInstallPrompt.prompt();
// Hide the install button, it can't be called twice.
this.el.setAttribute('hidden', true);
// Log user response to prompt.
deferredInstallPrompt.userChoice
.then(function (choice) {
if (choice.outcome === 'accepted') {
console.log('User accepted the A2HS prompt', choice);
} else {
console.log('User dismissed the A2HS prompt', choice);
}
deferredInstallPrompt = null;
});
},
});
});

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="web_pwa_oca.systray.install">
<a href="#" role="menuitem" id="pwa_install_button" data-menu="installpwa" class="dropdown-item" hidden="1">Install PWA</a>
</t>
<t t-extend="UserMenu.Actions">
<t t-jquery="a[data-menu='settings']" t-operation="after">
<t t-call="web_pwa_oca.systray.install"/>
</t>
</t>
</templates>