Browse Source
[10.0][IMP] web_switch_company_warning module
[10.0][IMP] web_switch_company_warning module
[FIX] for enterprise Odoo versions [IMP] add user switch detection and change module namepull/1287/head
Adrià Gil Sorribes
6 years ago
12 changed files with 110 additions and 94 deletions
-
2setup/_metapackage/setup.py
-
48web_switch_company_warning/static/src/js/switch_company_warning.js
-
22web_switch_company_warning/static/src/js/switch_company_warning_worker.js
-
11web_switch_context_warning/README.rst
-
0web_switch_context_warning/__init__.py
-
12web_switch_context_warning/__manifest__.py
-
16web_switch_context_warning/i18n/web_switch_context_warning.pot
-
0web_switch_context_warning/static/description/icon.png
-
59web_switch_context_warning/static/src/js/switch_context_warning.js
-
26web_switch_context_warning/static/src/js/switch_context_warning_worker.js
-
4web_switch_context_warning/static/src/xml/switch_company_warning.xml
-
4web_switch_context_warning/view/view.xml
@ -1,48 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
odoo.define('web_switch_company_warning.widget', function (require) { |
|||
var Widget = require('web.Widget'); |
|||
var UserMenu = require('web.UserMenu'); |
|||
//Show a big banner in the top of the page if the company has been
|
|||
//changed in another tab or window (in the same browser)
|
|||
|
|||
if (!window.SharedWorker) { |
|||
//not supported
|
|||
return; |
|||
} |
|||
var SwitchCompanyWarningWidget = Widget.extend({ |
|||
template:'web_switch_company_warning.warningWidget', |
|||
init: function() { |
|||
this._super(); |
|||
var self = this; |
|||
var w = new SharedWorker('/web_switch_company_warning/static/src/js/switch_company_warning_worker.js'); |
|||
w.port.addEventListener('message', function (msg) { |
|||
if (msg.data.type !== 'newCtx') { |
|||
return; |
|||
} |
|||
if(msg.data.newCtx === self.generateSignature()) { |
|||
self.$el.hide(); |
|||
} else { |
|||
self.$el.show(); |
|||
} |
|||
}); |
|||
w.port.start(); |
|||
w.port.postMessage(this.generateSignature()); |
|||
}, |
|||
generateSignature: function() { |
|||
return [this.session.company_id, this.session.db].join(); |
|||
} |
|||
}); |
|||
|
|||
UserMenu.include({ |
|||
init: function(parent) { |
|||
this._super(parent); |
|||
var switchCompanyWarning = new SwitchCompanyWarningWidget(); |
|||
switchCompanyWarning.appendTo('#oe_main_menu_navbar'); |
|||
} |
|||
|
|||
}); |
|||
|
|||
return SwitchCompanyWarningWidget; |
|||
}); |
|||
|
@ -1,22 +0,0 @@ |
|||
"use strict"; |
|||
//Show a big banner in the top of the page if the company has been
|
|||
//changed in another tab or window (in the same browser)
|
|||
|
|||
var con = []; |
|||
var lastCtx = null; |
|||
|
|||
addEventListener("connect", function(ee) { |
|||
var port = ee.ports[0]; |
|||
con.push(port); |
|||
|
|||
port.onmessage = function (e) { |
|||
var newCtx = e.data; |
|||
|
|||
if (lastCtx && newCtx !== lastCtx) { |
|||
con.forEach(function (eport) { |
|||
eport.postMessage({type: "newCtx", "newCtx": newCtx, "lastCtx": lastCtx}); |
|||
}); |
|||
} |
|||
lastCtx = newCtx; |
|||
}; |
|||
}, false); |
Before Width: 128 | Height: 128 | Size: 9.2 KiB After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -0,0 +1,59 @@ |
|||
odoo.define('web_switch_context_warning.widget', function (require) { |
|||
'use strict'; |
|||
|
|||
var Widget = require('web.Widget'); |
|||
var UserMenu = require('web.UserMenu'); |
|||
// Show a big banner in the top of the page if the company has been
|
|||
// changed in another tab or window (in the same browser)
|
|||
|
|||
if (!window.SharedWorker) { |
|||
// Not supported
|
|||
return; |
|||
} |
|||
var SwitchCompanyWarningWidget = Widget.extend({ |
|||
template:'web_switch_context_warning.warningWidget', |
|||
init: function () { |
|||
this._super(); |
|||
var self = this; |
|||
var w = new SharedWorker('/web_switch_context_warning/static/src/js/switch_company_warning_worker.js'); |
|||
w.port.addEventListener('message', function (msg) { |
|||
if (msg.data.type !== 'newCtx') { |
|||
return; |
|||
} |
|||
if (msg.data.newCtx === self.generateSignature()) { |
|||
self.$el.hide(); |
|||
} else { |
|||
self.$el.show(); |
|||
} |
|||
}); |
|||
w.port.start(); |
|||
w.port.postMessage(this.generateSignature()); |
|||
}, |
|||
generateSignature: function () { |
|||
return [this.session.uid, this.session.company_id, this.session.db].join(); |
|||
}, |
|||
}); |
|||
|
|||
UserMenu.include({ |
|||
init: function(parent) { |
|||
this._super(parent); |
|||
var switchCompanyWarning = new SwitchCompanyWarningWidget(); |
|||
// Check if Odoo version is Enterprise
|
|||
var isEnterprise = odoo.session_info.server_version_info[5] === 'e'; |
|||
if (isEnterprise) { |
|||
switchCompanyWarning.insertAfter('.o_main_navbar'); |
|||
} else { |
|||
// Choose where to append depending on whether web_responsive is installed or not
|
|||
if (document.getElementById('oe_main_menu_navbar')) { |
|||
switchCompanyWarning.appendTo('#oe_main_menu_navbar'); |
|||
} else { |
|||
switchCompanyWarning.insertAfter('.main-nav'); |
|||
} |
|||
} |
|||
} |
|||
|
|||
}); |
|||
|
|||
return SwitchCompanyWarningWidget; |
|||
}); |
|||
|
@ -0,0 +1,26 @@ |
|||
// Show a big banner in the top of the page if the company has been
|
|||
// changed in another tab or window (in the same browser)
|
|||
var con = []; |
|||
var lastCtx = null; |
|||
|
|||
addEventListener("connect", function (ee) { |
|||
"use strict"; |
|||
|
|||
var port = ee.ports[0]; |
|||
con.push(port); |
|||
|
|||
port.onmessage = function (e) { |
|||
var newCtx = e.data; |
|||
|
|||
if (lastCtx && newCtx !== lastCtx) { |
|||
con.forEach(function (eport) { |
|||
eport.postMessage({ |
|||
type: "newCtx", |
|||
"newCtx": newCtx, |
|||
"lastCtx": lastCtx |
|||
}); |
|||
}); |
|||
} |
|||
lastCtx = newCtx; |
|||
}; |
|||
}, false); |
@ -1,8 +1,8 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<template> |
|||
<t t-name="web_switch_company_warning.warningWidget"> |
|||
<t t-name="web_switch_context_warning.warningWidget"> |
|||
<div class="container-fluid bg-warning" style="text-align: center; display:none;"> |
|||
<h3>You switched to a different company or database with another tab or window</h3> |
|||
<h3>You switched to a different user, company or database with another tab or window</h3> |
|||
<p><button onclick="location.reload(true);" class="btn">Reload</button> to refresh your session</p> |
|||
</div> |
|||
</t> |
@ -1,9 +1,9 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<openerp> |
|||
<data> |
|||
<template id="assets_backend" name="web_switch_company_warning assets" inherit_id="web.assets_backend"> |
|||
<template id="assets_backend" name="web_switch_context_warning assets" inherit_id="web.assets_backend"> |
|||
<xpath expr="." position="inside"> |
|||
<script type="text/javascript" src="/web_switch_company_warning/static/src/js/switch_company_warning.js"></script> |
|||
<script type="text/javascript" src="/web_switch_context_warning/static/src/js/switch_context_warning.js"></script> |
|||
</xpath> |
|||
</template> |
|||
</data> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue