Initial commit

This commit is contained in:
tarteo
2017-02-13 16:42:23 +01:00
parent 2cba2a331c
commit b9deeaa653
48 changed files with 274 additions and 205 deletions

View File

@@ -0,0 +1,82 @@
/* Shortcuts*/
.oe_systray_shortcuts .oe_star_off {
color: #eee;
}
.oe_shortcuts_toggle {
height: 20px;
margin-top: 3px;
padding: 0;
width: 24px;
cursor: pointer;
display: block;
background: url(/web/static/src/img/add-shortcut.png) no-repeat center center;
float: left;
}
.oe_shortcuts_remove{
background: url(/web/static/src/img/remove-shortcut.png) no-repeat center center;
}
.oe_shortcuts {
position: absolute;
margin: 0;
padding: 6px 15px;
top: 37px;
left: 197px;
right: 0;
height: 17px;
line-height: 1.2;
}
.oe_shortcuts ul {
display: block;
overflow: hidden;
list-style: none;
white-space: nowrap;
padding: 0;
margin: 0;
}
.oe_shortcuts li {
cursor: pointer;
display: -moz-inline-stack;
display: inline-block;
display: inline; /*IE7 */
color: #fff;
text-align: center;
border-left: 1px solid #909090;
padding: 0 4px;
font-size: 80%;
font-weight: normal;
vertical-align: top;
}
.oe_shortcuts li:hover {
background-color: #666;
}
.oe_shortcuts li:first-child {
border-left: none;
padding-left: 0;
}
.openerp .oe_topbar .oe_topbar_item {
display: block;
padding: 5px 10px 7px;
line-height: 20px;
height: 20px;
text-decoration: none;
color: #eeeeee;
vertical-align: top;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
-ms-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
}
.openerp .oe_topbar .oe_topbar_item:hover {
background: rgba(0, 0, 0, 0.2);
text-shadow: black 0px 0px 3px;
color: white;
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4) inset;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4) inset;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4) inset;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

View File

@@ -0,0 +1,159 @@
/*############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011-2012 OpenERP SA (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################################*/
odoo.define('web.shortcut', function(require) {
var widget = require('web.Widget'),
menu = require('web.UserMenu'),
client = require('web.WebClient'),
view_manager = require('web.ViewManager'),
model = require('web.DataModel');
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 model('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;
this.$el.find('.oe_systray_shortcut_menu').empty();
return this.model.call('get_user_shortcuts', [
]).done(function(shortcuts) {
_.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 menu_id = this.session.active_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 model('ir.ui.menu').query(['action']).filter([['id', '=', 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;
}
});
menu.include({
do_update: function() {
var self = this;
this._super.apply(this, arguments);
this.update_promise.done(function() {
if (self.shortcuts) {
self.shortcuts.trigger('load');
} else {
self.shortcuts = new ShortcutMenu(self);
self.shortcuts.prependTo(self.$el.parent());
}
});
},
});
client.include({
show_application: function() {
var self = this;
this._super.apply(this, arguments);
this.user_menu.on('click', this, function(action_id) {
self.do_action(action_id);
});
}
});
view_manager.include({
switch_mode: function (view_type, no_store) {
var self = this;
this._super.apply(this, arguments).done(function() {
self.shortcut_check(self.views[view_type]);
});
},
shortcut_check: function(view) {
var self = this;
console.log(this);
var shortcuts_menu = this.action_manager.webclient.user_menu.shortcuts;
// display shortcuts if on the first view for the action
var $shortcut_toggle = this.$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.hide();
return;
}
// Anonymous users don't have user_menu
if (shortcuts_menu) {
$shortcut_toggle.toggleClass('oe_shortcut_remove', shortcuts_menu.has(self.session.active_id));
$shortcut_toggle.unbind("click").click(function() {
if ($shortcut_toggle.hasClass("oe_shortcut_remove")) {
shortcuts_menu.trigger('remove', self.session.active_id);
} else {
shortcuts_menu.trigger('add', {
'user_id': self.session.uid,
'menu_id': self.session.active_id,
'name': self.action.name
});
}
$shortcut_toggle.toggleClass("oe_shortcut_remove");
});
}
}
});
return ShortcutMenu;
});

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates>
<t t-name="Systray.ShortcutMenu">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="/web_shortcut/static/src/img/add-shortcut.png"/>
</a>
<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="ViewManagerAction">
<t t-jquery="h2.oe_view_title" t-operation="prepend">
<a t-if="widget.flags.display_title !== false" class="oe_shortcut_toggle" title="Add / Remove Shortcut..."
href="javascript: void(0)"> </a>
</t>
</t>
</templates>