Pierrick Brun
4 years ago
committed by
KevinKhao
13 changed files with 136 additions and 113 deletions
-
3base_user_role_profile/data/data.xml
-
8base_user_role_profile/models/ir_http.py
-
5base_user_role_profile/models/role.py
-
10base_user_role_profile/models/user.py
-
82base_user_role_profile/static/src/js/switch_profile_menu.js
-
18base_user_role_profile/static/src/xml/templates.xml
-
36base_user_role_profile/tests/test_user_role.py
-
14base_user_role_profile/views/assets.xml
-
16base_user_role_profile/views/profile.xml
-
13base_user_role_profile/views/role.xml
-
35base_user_role_profile/views/user.xml
-
1setup/base_user_role_profile/odoo/addons/base_user_role_profile
-
6setup/base_user_role_profile/setup.py
@ -1,79 +1,85 @@ |
|||
odoo.define('web.SwitchProfileMenu', function(require) { |
|||
odoo.define("web.SwitchProfileMenu", function (require) { |
|||
"use strict"; |
|||
|
|||
var config = require('web.config'); |
|||
var core = require('web.core'); |
|||
var session = require('web.session'); |
|||
var SystrayMenu = require('web.SystrayMenu'); |
|||
var Widget = require('web.Widget') |
|||
var config = require("web.config"); |
|||
var core = require("web.core"); |
|||
var session = require("web.session"); |
|||
var SystrayMenu = require("web.SystrayMenu"); |
|||
var Widget = require("web.Widget"); |
|||
var _t = core._t; |
|||
|
|||
var SwitchProfileMenu = Widget.extend({ |
|||
template: 'SwitchProfileMenu', |
|||
template: "SwitchProfileMenu", |
|||
events: { |
|||
'click .dropdown-item[data-menu]': '_onClick', |
|||
"click .dropdown-item[data-menu]": "_onClick", |
|||
}, |
|||
|
|||
init: function() { |
|||
init: function () { |
|||
this._super.apply(this, arguments); |
|||
this.isMobile = config.device.isMobile; |
|||
this._onClick = _.debounce(this._onClick, 1500, true); |
|||
}, |
|||
|
|||
willStart: function() { |
|||
willStart: function () { |
|||
return session.user_profiles ? this._super() : $.Deferred().reject(); |
|||
}, |
|||
|
|||
start: function() { |
|||
var profilesList = ''; |
|||
start: function () { |
|||
var profilesList = ""; |
|||
if (this.isMobile) { |
|||
profilesList = '<li class="bg-info">' + |
|||
_t('Tap on the list to change profile') + '</li>'; |
|||
profilesList = |
|||
'<li class="bg-info">' + |
|||
_t("Tap on the list to change profile") + |
|||
"</li>"; |
|||
} else { |
|||
this.$('.oe_topbar_name').text(session.user_profiles.current_profile[1]); |
|||
this.$(".oe_topbar_name").text( |
|||
session.user_profiles.current_profile[1] |
|||
); |
|||
} |
|||
_.each(session.user_profiles.allowed_profiles, function(profile) { |
|||
var a = ''; |
|||
_.each(session.user_profiles.allowed_profiles, function (profile) { |
|||
var a = ""; |
|||
if (profile[0] == session.user_profiles.current_profile[0]) { |
|||
a = '<i class="fa fa-check mr8"></i>'; |
|||
} else { |
|||
a = '<span style="margin-right: 24px;"/>'; |
|||
} |
|||
profilesList += '<a role="menuitem" href="#" class="dropdown-item" data-menu="profile" data-profile-id="' + |
|||
profile[0] + '">' + a + profile[1] + '</a>'; |
|||
profilesList += |
|||
'<a role="menuitem" href="#" class="dropdown-item" data-menu="profile" data-profile-id="' + |
|||
profile[0] + |
|||
'">' + |
|||
a + |
|||
profile[1] + |
|||
"</a>"; |
|||
}); |
|||
this.$('.dropdown-menu').html(profilesList); |
|||
this.$(".dropdown-menu").html(profilesList); |
|||
return this._super(); |
|||
}, |
|||
|
|||
_onClick: function(ev) { |
|||
_onClick: function (ev) { |
|||
var self = this; |
|||
ev.preventDefault(); |
|||
var profileID = $(ev.currentTarget).data('profile-id'); |
|||
var profileID = $(ev.currentTarget).data("profile-id"); |
|||
// We use this instead of the location.reload() because permissions change
|
|||
// and we might land on a menu that we don't have permissions for. Thus it
|
|||
// is cleaner to reload any root menu
|
|||
this._rpc({ |
|||
model: 'res.users', |
|||
method: 'action_profile_change', |
|||
args: [ |
|||
[session.uid], { |
|||
'profile_id': profileID |
|||
} |
|||
], |
|||
}) |
|||
.done( |
|||
function(result) { |
|||
self.trigger_up('do_action', { |
|||
action: result, |
|||
}) |
|||
} |
|||
) |
|||
model: "res.users", |
|||
method: "action_profile_change", |
|||
args: [ |
|||
[session.uid], |
|||
{ |
|||
profile_id: profileID, |
|||
}, |
|||
], |
|||
}).done(function (result) { |
|||
self.trigger_up("do_action", { |
|||
action: result, |
|||
}); |
|||
}); |
|||
}, |
|||
}); |
|||
|
|||
SystrayMenu.Items.push(SwitchProfileMenu); |
|||
|
|||
return SwitchProfileMenu; |
|||
|
|||
}); |
@ -1,12 +1,22 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<templates id="template" xml:space="preserve"> |
|||
|
|||
<t t-name="SwitchProfileMenu"> |
|||
<li class="o_switch_profile_menu"> |
|||
<a role="button" 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 |
|||
role="button" |
|||
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> |
|||
<div class="dropdown-menu dropdown-menu-right" role="menu"/> |
|||
<div class="dropdown-menu dropdown-menu-right" role="menu" /> |
|||
</li> |
|||
</t> |
|||
|
|||
|
@ -1,9 +1,15 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
|
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<odoo> |
|||
<template id="assets_backend" name="User Role Profile assets" inherit_id="web.assets_backend"> |
|||
<template |
|||
id="assets_backend" |
|||
name="User Role Profile assets" |
|||
inherit_id="web.assets_backend" |
|||
> |
|||
<xpath expr="." position="inside"> |
|||
<script type="text/javascript" src="/base_user_role_profile/static/src/js/switch_profile_menu.js"/> |
|||
<script |
|||
type="text/javascript" |
|||
src="/base_user_role_profile/static/src/js/switch_profile_menu.js" |
|||
/> |
|||
</xpath> |
|||
</template> |
|||
</odoo> |
@ -0,0 +1 @@ |
|||
../../../../base_user_role_profile |
@ -0,0 +1,6 @@ |
|||
import setuptools |
|||
|
|||
setuptools.setup( |
|||
setup_requires=['setuptools-odoo'], |
|||
odoo_addon=True, |
|||
) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue