mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[MIG] web_shortcut (#626)
This commit is contained in:
committed by
Pedro M. Baeza
parent
07a9379508
commit
2c7f2a7d08
34
web_shortcut/static/src/css/web_shortcut.css
Normal file
34
web_shortcut/static/src/css/web_shortcut.css
Normal file
@@ -0,0 +1,34 @@
|
||||
.oe_shortcut_toggle {
|
||||
height: 20px;
|
||||
margin-top: 2px;
|
||||
width: 24px;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
font-size: 20px;
|
||||
float: left;
|
||||
color: #a8a8a8;
|
||||
}
|
||||
|
||||
.oe_shortcut_toggle:focus {
|
||||
color: #a8a8a8;
|
||||
}
|
||||
|
||||
.oe_shortcut_toggle:hover {
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.oe_shortcut_remove {
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.oe_shortcut_remove:focus {
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.o_control_panel .breadcrumb {
|
||||
width: calc(50% - 24px);
|
||||
}
|
||||
|
||||
.o_control_panel.o_breadcrumb_full .breadcrumb {
|
||||
width: calc(100% - 24px);
|
||||
}
|
||||
187
web_shortcut/static/src/js/web_shortcut.js
Normal file
187
web_shortcut/static/src/js/web_shortcut.js
Normal file
@@ -0,0 +1,187 @@
|
||||
/* Copyright 2004-today Odoo SA (<http://www.odoo.com>)
|
||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||
|
||||
odoo.define('web.shortcut', function (require) {
|
||||
var Widget = require('web.Widget'),
|
||||
WebClient = require('web.WebClient'),
|
||||
ViewManager = require('web.ViewManager'),
|
||||
ActionManager = require('web.ActionManager'),
|
||||
core = require('web.core'),
|
||||
qweb = core.qweb,
|
||||
DataModel = require('web.DataModel'),
|
||||
session = require('web.session'),
|
||||
SystrayMenu = require('web.SystrayMenu');
|
||||
|
||||
var ShortcutMenu = Widget.extend({
|
||||
template: 'Systray.ShortcutMenu',
|
||||
init: function () {
|
||||
this._super();
|
||||
this.on('load', this, this.load);
|
||||
this.on('add', this, this.add);
|
||||
this.on('display', this, this.display);
|
||||
this.on('remove', this, this.remove);
|
||||
this.model = new DataModel('web.shortcut');
|
||||
},
|
||||
start: function () {
|
||||
var self = this;
|
||||
this._super();
|
||||
this.trigger('load');
|
||||
this.$el.on('click', '.oe_systray_shortcut_menu a', function () {
|
||||
self.click($(this));
|
||||
});
|
||||
},
|
||||
load: function () {
|
||||
var self = this;
|
||||
return this.model.call('get_user_shortcuts', []).done(function (shortcuts) {
|
||||
self.$el.find('.oe_systray_shortcut_menu').empty();
|
||||
_.each(shortcuts, function (sc) {
|
||||
self.trigger('display', sc);
|
||||
});
|
||||
});
|
||||
},
|
||||
add: function (sc) {
|
||||
var self = this;
|
||||
this.model.call('create', [sc]).then(function (out) {
|
||||
self.trigger('load');
|
||||
});
|
||||
},
|
||||
display: function (sc) {
|
||||
var self = this;
|
||||
this.$el.find('.oe_systray_shortcut_menu').append();
|
||||
var $sc = $(qweb.render('Systray.ShortcutMenu.Item', {shortcut: sc}));
|
||||
$sc.appendTo(self.$el.find('.oe_systray_shortcut_menu'));
|
||||
},
|
||||
remove: function (menu_id) {
|
||||
var $shortcut = this.$el.find('.oe_systray_shortcut_menu li a[data-id=' + menu_id + ']');
|
||||
var shortcut_id = $shortcut.data('shortcut-id');
|
||||
$shortcut.remove();
|
||||
this.model.call('unlink', [shortcut_id]);
|
||||
},
|
||||
click: function ($link) {
|
||||
var self = this,
|
||||
action_id = $link.data('id');
|
||||
new DataModel('ir.ui.menu').query(['action']).filter([['id', '=', action_id]]).context(null).all().then(function (menu) {
|
||||
var action_str = menu[0].action;
|
||||
var action_str_parts = action_str.split(',');
|
||||
action_id = parseInt(action_str_parts[1]);
|
||||
self.trigger('click', action_id);
|
||||
});
|
||||
},
|
||||
has: function (menu_id) {
|
||||
return !!this.$el.find('a[data-id=' + menu_id + ']').length;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
SystrayMenu.Items.push(ShortcutMenu);
|
||||
|
||||
|
||||
WebClient.include({
|
||||
current_action_updated: function (action) {
|
||||
if (this.menu.systray_menu) {
|
||||
this.shortcut_menu = _.find(this.menu.systray_menu.widgets, function (item) {
|
||||
return item instanceof ShortcutMenu;
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.shortcut_menu = _.find(this.systray_menu.widgets, function (item) {
|
||||
return item instanceof ShortcutMenu;
|
||||
});
|
||||
}
|
||||
},
|
||||
show_application: function () {
|
||||
var self = this;
|
||||
return this._super.apply(this, arguments).then(function () {
|
||||
if (self.menu.systray_menu) {
|
||||
self.shortcut_menu = _.find(self.menu.systray_menu.widgets, function (item) {
|
||||
return item instanceof ShortcutMenu;
|
||||
});
|
||||
}
|
||||
else {
|
||||
self.shortcut_menu = _.find(self.systray_menu.widgets, function (item) {
|
||||
return item instanceof ShortcutMenu;
|
||||
});
|
||||
}
|
||||
self.shortcut_menu.on('click', self, function (action_id) {
|
||||
self.do_action(action_id, {
|
||||
clear_breadcrumbs: true,
|
||||
replace_breadcrumb: true
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ViewManager.include({
|
||||
switch_mode: function (view_type, no_store) {
|
||||
var self = this;
|
||||
return this._super.apply(this, arguments).done(function () {
|
||||
self.shortcut_check(self.views[view_type]);
|
||||
});
|
||||
},
|
||||
shortcut_check: function (view) {
|
||||
var self = this;
|
||||
|
||||
// Child view managers
|
||||
if (!this.action_manager) {
|
||||
return;
|
||||
}
|
||||
|
||||
// display shortcuts if on the first view for the action
|
||||
var $shortcut_toggle = this.action_manager.main_control_panel.$el.find('.oe_shortcut_toggle');
|
||||
if (!this.action.name || !(view.view_type === this.view_stack[0].view_type &&
|
||||
view.view_id === this.view_stack[0].view_id)
|
||||
) {
|
||||
$shortcut_toggle.addClass('hidden');
|
||||
return;
|
||||
}
|
||||
$shortcut_toggle.removeClass('hidden');
|
||||
|
||||
// Anonymous users don't have user_menu
|
||||
// Check whether it's the 'main' action_manager
|
||||
var shortcuts_menu = this.action_manager.webclient && this.action_manager.webclient.shortcut_menu;
|
||||
if (shortcuts_menu) {
|
||||
$shortcut_toggle.toggleClass('oe_shortcut_remove', shortcuts_menu.has(self.session.active_id));
|
||||
$shortcut_toggle.unbind("click").click(function () {
|
||||
var menu_id = session.active_id;
|
||||
// In the case we come from a parent menu, no action is linked to the menu
|
||||
// We must take the first child menu
|
||||
if (self.action_manager.webclient.menu_data) {
|
||||
for (var i = 0; i < self.action_manager.webclient.menu_data.children.length; i++) {
|
||||
if (self.action_manager.webclient.menu_data.children[i].id === session.active_id) {
|
||||
menu_temp = self.action_manager.webclient.menu_data.children[i].children[0];
|
||||
menu_id = menu_temp.id;
|
||||
if (menu_temp.children[0]){
|
||||
menu_id = menu_temp.children[0].id
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($shortcut_toggle.hasClass("oe_shortcut_remove")) {
|
||||
shortcuts_menu.trigger('remove', menu_id);
|
||||
}
|
||||
else {
|
||||
shortcuts_menu.trigger('add', {
|
||||
'user_id': session.uid,
|
||||
'menu_id': menu_id,
|
||||
'name': session.name
|
||||
});
|
||||
}
|
||||
$shortcut_toggle.toggleClass("oe_shortcut_remove");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ActionManager.include({
|
||||
do_action: function () {
|
||||
this.main_control_panel.$el.find('.oe_shortcut_toggle').addClass('hidden');
|
||||
return this._super.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
return ShortcutMenu;
|
||||
});
|
||||
25
web_shortcut/static/src/xml/web_shortcut.xml
Normal file
25
web_shortcut/static/src/xml/web_shortcut.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
|
||||
<t t-name="Systray.ShortcutMenu">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle o_priority_star fa fa-star" data-toggle="dropdown"/>
|
||||
<ul class="oe_systray_shortcut_menu dropdown-menu">
|
||||
</ul>
|
||||
</li>
|
||||
</t>
|
||||
<t t-name="Systray.ShortcutMenu.Item">
|
||||
<li>
|
||||
<a href="#" t-att-data-id="shortcut.menu_id[0]" t-att-data-shortcut-id="shortcut.id">
|
||||
<t t-esc="shortcut.name"/>
|
||||
</a>
|
||||
</li>
|
||||
</t>
|
||||
<t t-extend="ControlPanel">
|
||||
<t t-jquery="ol.breadcrumb" t-operation="before">
|
||||
<a class="oe_shortcut_toggle hidden o_priority_star fa fa-star" title="Add / Remove Shortcut..."
|
||||
href="javascript: void(0)"> </a>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
Reference in New Issue
Block a user