Permalink
Browse files

⬆️1️⃣2️⃣ web_website

  • Loading branch information...
yelizariev committed Oct 23, 2018
1 parent 033bd05 commit 0ac207137bba5cac5a552e065d24868a3643b6a9
@@ -75,4 +75,4 @@ Changelog: `<doc/changelog.rst>`_
Notifications on updates: `via Atom <https://github.com/it-projects-llc/misc-addons/commits/10.0/web_website.atom>`_, `by Email <https://blogtrottr.com/?subscribe=https://github.com/it-projects-llc/misc-addons/commits/10.0/web_website.atom>`_
Tested on Odoo 10.0 2da4eb58989af1fc0280f5fec12deca2aa6eae88
Tested on Odoo 12.0 d75de9ae5370869eaa220f5fdfb335d1b7e40acf
@@ -6,7 +6,7 @@
"category": "Hidden",
# "live_test_url": "",
"images": [],
"version": "11.0.3.0.0",
"version": "12.0.3.0.0",
"application": False,
"author": "IT-Projects LLC, Ivan Yelizariev",
@@ -44,5 +44,5 @@
"uninstall_hook": None,
"auto_install": False,
"installable": False,
"installable": True,
}
@@ -40,6 +40,7 @@ def write(self, vals):
class CompanyDependent(models.Model):
_name = 'test.company_dependent'
_description = 'Test Class with company_dependent fields'
foo = fields.Char(company_dependent=True)
user_id = fields.Many2one('res.users', company_dependent=True)
@@ -8,9 +8,8 @@
class WebsiteDependentMixin(models.AbstractModel):
"""Mixin Class with helpers to convert previously normal fields to website-depedent"""
_name = 'website_dependent.mixin'
_description = 'Mixin Class with helpers to convert previously normal fields to website-depedent'
def _prop_label(self, field_name, company=None, website=None):
self.ensure_one()
@@ -3,14 +3,24 @@
odoo.define('web_website.SwitchWebsiteMenu', function(require) {
"use strict";
var config = require('web.config');
var session = require('web.session');
var SystrayMenu = require('web.SystrayMenu');
var Widget = require('web.Widget');
var core = require('web.core');
var _t = core._t;
var SwitchWebsiteMenu = Widget.extend({
template: 'SwitchWebsiteMenu',
events: {
'click .dropdown-item[data-menu]': '_onClick',
},
init: function () {
this._super.apply(this, arguments);
this.isMobile = config.device.isMobile;
this._onClick = _.debounce(this._onClick, 1500, true);
},
willStart: function() {
if (!session.user_websites) {
return $.Deferred().reject();
@@ -19,47 +29,54 @@ var SwitchWebsiteMenu = Widget.extend({
},
start: function() {
var self = this;
this.$el.on('click', '.dropdown-menu li a[data-menu]', _.debounce(function(ev) {
ev.preventDefault();
var website_id = $(ev.currentTarget).data('website-id') || false; // write method ignores undefinded
self._rpc({
model: 'res.users',
method: 'write',
args: [[session.uid], {'backend_website_id': website_id}],
})
.then(function() {
location.reload();
});
}, 1500, true));
var all_websites_text = _t('All Websites');
var topbar = self.$('.oe_topbar_name');
var current_website = session.user_websites.current_website;
if (current_website)
self.$('.oe_topbar_name').text(current_website[1]);
else
self.$('.oe_topbar_name').html('<em>' + all_websites_text + '</em>');
var websites_list = '';
if (this.isMobile) {
websites_list = '<li class="bg-info">' +
_t('Tap on the list to change website') + '</li>';
}
else if (current_website){
self.$('.oe_topbar_name').text(current_website[1]);
} else {
self.$('.oe_topbar_name').html('<em>' + all_websites_text + '</em>');
}
var websites = session.user_websites.allowed_websites;
websites.unshift(false);
_.each(websites, function(website) {
var a = '';
if (!website && !current_website || website[0] === session.user_websites.current_website[0]) {
a = '<i class="fa fa-check o_current_company"></i>';
a = '<i class="fa fa-check mr8"></i>';
} else {
a = '<span class="o_company"/>';
}
if (!website){
websites_list += '<li><a href="#" class="all_websites" data-menu="website">' + a + '<em>' + all_websites_text + '</em></a></li>';
websites_list += '<a href="#" class="dropdown-item all_websites" data-menu="website">' + a + '<em>' + all_websites_text + '</em></a>';
} else {
websites_list += '<li><a href="#" data-menu="website" data-website-id="' + website[0] + '">' + a + website[1] + '</a></li>';
websites_list += '<a href="#" class="dropdown-item" data-menu="website" data-website-id="' + website[0] + '">' + a + website[1] + '</a>';
}
});
self.$('.dropdown-menu').html(websites_list);
return this._super();
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
_onClick: function (ev) {
ev.preventDefault();
var website_id = $(ev.currentTarget).data('website-id') || false; // write method ignores undefinded
this._rpc({
model: 'res.users',
method: 'write',
args: [[session.uid], {'backend_website_id': website_id}],
}).then(function() {
location.reload();
});
},
});
SystrayMenu.Items.push(SwitchWebsiteMenu);
@@ -5,10 +5,10 @@
<t t-name="SwitchWebsiteMenu">
<li class="o_switch_website_menu">
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="#">
<span class="oe_topbar_name"/> <span class="caret"></span>
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="#" aria-label="Dropdown menu" title="Dropdown menu">
<span t-attf-class="#{widget.isMobile ? 'fa fa-building-o' : 'oe_topbar_name'}"/>
</a>
<ul class="dropdown-menu" role="menu"/>
<div class="dropdown-menu dropdown-menu-right" role="menu"/>
</li>
</t>

0 comments on commit 0ac2071

Please sign in to comment.