[IMP] web_pwa_oca: Port changes from 12.0

This commit is contained in:
Alexandre D. Díaz
2021-03-16 19:35:31 +01:00
committed by sergio-teruel
parent c1afeed3c1
commit 1194498f2e
29 changed files with 1191 additions and 543 deletions

View File

@@ -0,0 +1,62 @@
/* Copyright 2020 Tecnativa - Alexandre D. Díaz
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
// Compatibility layer to load some Odoo modules
// This is a hack, not a complete implementation!
// only expected to be used by boot.js
(function() {
"use strict";
function JQuery(selector, context) {
return new JQuery.prototype.init(selector, context);
}
JQuery.prototype = {
init: function(selector) {
if (typeof selector === "function") {
selector();
}
},
deparam: function(data) {
const params = data.split(",");
const res = [];
for (const param of params) {
res.push(param.split("="));
}
return _.object(res);
},
param: {
querystring: function() {
return "debug=1";
},
},
when: function(tasks) {
return Promise.all(tasks instanceof Array ? tasks : [tasks]).then(
results => {
return results.length === 1 ? results[0] : results;
}
);
},
};
class Deferred {
constructor() {
this.promise = new Promise((resolve, reject) => {
this.reject = reject;
this.resolve = resolve;
});
}
}
JQuery.prototype.Deferred = () => new Deferred();
self.$ = JQuery;
self.$.deparam = JQuery.prototype.deparam;
self.$.param = JQuery.prototype.param;
self.$.Deferred = JQuery.prototype.Deferred;
self.$.when = JQuery.prototype.when;
self.window = self;
})();

View File

@@ -0,0 +1,40 @@
/* Copyright 2020 Tecnativa - Alexandre D. Díaz
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
/**
* Services workers are a piece of software separated from the user page.
* Here can't use 'Odoo Bootstrap', so we can't work with 'require' system.
* When the service worker is called to be installed from the "pwa_manager"
* this class is instantiated.
*/
odoo.define("web_pwa_oca.PWA", function(require) {
"use strict";
const OdooClass = require("web.Class");
const PWA = OdooClass.extend({
// eslint-disable-next-line
init: function(params) {
// To be overridden
},
/**
* @returns {Promise}
*/
installWorker: function() {
// To be overridden
return Promise.resolve();
},
/**
* @returns {Promise}
*/
activateWorker: function() {
// To be overridden
return Promise.resolve();
},
});
return PWA;
});