mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[IMP] web_pwa_oca: Port changes from 12.0
This commit is contained in:
committed by
sergio-teruel
parent
c1afeed3c1
commit
1194498f2e
62
web_pwa_oca/static/src/js/worker/jquery-sw-compat.js
vendored
Normal file
62
web_pwa_oca/static/src/js/worker/jquery-sw-compat.js
vendored
Normal 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;
|
||||
})();
|
||||
40
web_pwa_oca/static/src/js/worker/pwa.js
Normal file
40
web_pwa_oca/static/src/js/worker/pwa.js
Normal 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;
|
||||
});
|
||||
Reference in New Issue
Block a user