[ADD] Shortcuts as a module

bzr revid: fme@openerp.com-20120503114251-p6yueoreiyu4dya0
This commit is contained in:
Fabien Meghazi 2012-05-03 13:42:51 +02:00
parent e9273066a9
commit 533a9273d9
9 changed files with 334 additions and 0 deletions

View File

@ -0,0 +1,15 @@
OpenERP, Open Source Management Solution
Copyright © 2010-2011 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 Lice
along with this program. If not, see <http://www.gnu.org/licenses/>.

View File

@ -0,0 +1,22 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010 OpenERP s.a. (<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/>.
#
##############################################################################
import controllers
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2011 OpenERP s.a. (<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/>.
#
##############################################################################
{
'name': 'Web Shortcuts',
'version': '1.0',
'category': 'Tools',
'complexity': "easy",
'description': """
Enable shortcuts feature in the web client
==========================================
Add a Shortcut icon in the systray in order to access the user's shortcuts (if any).
Add a Shortcut icon besides the views title in order to add/remove a shortcut.
""",
'author': 'OpenERP SA',
'website': 'http://openerp.com',
'depends': ['base'],
'update_xml': [],
'js' : [
'static/src/js/web_shortcuts.js',
],
'css' : [
'static/src/css/web_shortcuts.css',
],
'qweb' : [
"static/src/xml/*.xml",
],
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,3 @@
import main
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,18 @@
try:
# embedded
import openerp.addons.web.common.http as openerpweb
import openerp.addons.web.controllers.main as webmain
except ImportError:
# standalone
import web.common.http as openerpweb
import web.controllers.main as webmain
class Shortcuts(openerpweb.Controller):
_cp_path = "/web/shortcuts"
@openerpweb.jsonrequest
def list(self, req):
return req.session.model('ir.ui.view_sc').get_sc(
req.session._uid, "ir.ui.menu", req.session.eval_context(req.context))
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,57 @@
/* Shortcuts*/
.oe_systray_shortcuts {
margin: 3px;
}
.oe-shortcut-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-shortcut-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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -0,0 +1,145 @@
/*############################################################################
#
# 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/>.
#
############################################################################*/
openerp.web_shortcuts = function (instance) {
var QWeb = instance.web.qweb,
_t = instance.web._t;
instance.web_shortcuts.Shortcuts = instance.web.Widget.extend({
template: 'Systray.Shortcuts',
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.on('click', this, this.click);
this.dataset = new instance.web.DataSet(this, 'ir.ui.view_sc');
},
start: function() {
var self = this;
this._super();
this.trigger('load');
this.$element.on('click', '.oe_systray_shortcuts_items a', function() {
self.trigger('click', $(this));
});
},
load: function() {
var self = this;
this.$element.find('.oe_systray_shortcuts_items').empty();
return this.rpc('/web/shortcuts/list', {}, function(shortcuts) {
_.each(shortcuts, function(sc) {
self.trigger('display', sc);
});
});
},
add: function (sc) {
var self = this;
this.dataset.create(sc, function (out) {
self.trigger('display', {
name : sc.name,
id : out.result,
res_id : sc.res_id
});
});
},
display: function(sc) {
var self = this;
this.$element.find('.oe_systray_shortcuts_items').append()
var $sc = $(QWeb.render('Systray.Shortcuts.Item', {'shortcut': sc}));
$sc.appendTo(self.$element.find('.oe_systray_shortcuts_items'));
},
remove: function (menu_id) {
var menu_id = this.session.active_id;
var $shortcut = this.$element.find('.oe_systray_shortcuts_items li a[data-id=' + menu_id + ']');
var shortcut_id = $shortcut.data('shortcut-id');
$shortcut.remove();
this.dataset.unlink([shortcut_id]);
},
click: function($link) {
var self = this,
id = $link.data('id');
self.session.active_id = id;
self.rpc('/web/menu/action', {'menu_id': id}, function(ir_menu_data) {
if (ir_menu_data.action.length){
instance.webclient.menu.on_action(ir_menu_data.action[0][2]);
}
});
this.$element.find('.oe_systray_shortcuts').trigger('mouseout');
},
has: function(menu_id) {
return !!this.$element.find('a[data-id=' + menu_id + ']').length;
}
});
instance.web.UserMenu.include({
do_update: function() {
var self = this;
this._super.apply(this, arguments);
this.update_promise.then(function() {
if (self.shortcuts) {
self.shortcuts.trigger('load');
} else {
self.shortcuts = new instance.web_shortcuts.Shortcuts(self);
self.shortcuts.appendTo(instance.webclient.$element.find('.oe_systray'));
}
});
},
});
instance.web.ViewManagerAction.include({
on_mode_switch: function (view_type, no_store) {
var self = this;
this._super.apply(this, arguments).then(function() {
self.shortcut_check(self.views[view_type]);
});
},
shortcut_check : function(view) {
var self = this;
var shortcuts_menu = instance.webclient.user_menu.shortcuts;
var grandparent = this.getParent() && this.getParent().getParent();
// display shortcuts if on the first view for the action
var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
if (!this.action.name ||
!(view.view_type === this.views_src[0].view_type
&& view.view_id === this.views_src[0].view_id)) {
$shortcut_toggle.hide();
return;
}
$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,
'res_id': self.session.active_id,
'resource': 'ir.ui.menu',
'name': self.action.name
});
}
$shortcut_toggle.toggleClass("oe-shortcut-remove");
});
}
});
};

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-name="Systray.Shortcuts">
<div class="oe_systray_shortcuts oe_systray_dropdown">
<a href="#"><img src="/web_shortcuts/static/src/img/icon.png" width="22" height="22" border="0"/></a>
<ul class="oe_systray_shortcuts_items oe_systray_dropdown_options"/>
</div>
</t>
<t t-name="Systray.Shortcuts.Item">
<li>
<a href="#" t-att-data-id="shortcut.res_id" 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>