From 533a9273d942e5ec49ffc0b030d6152d2007c9e2 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 3 May 2012 13:42:51 +0200 Subject: [PATCH] [ADD] Shortcuts as a module bzr revid: fme@openerp.com-20120503114251-p6yueoreiyu4dya0 --- addons/web_shortcuts/LICENSE | 15 ++ addons/web_shortcuts/__init__.py | 22 +++ addons/web_shortcuts/__openerp__.py | 50 ++++++ addons/web_shortcuts/controllers/__init__.py | 3 + addons/web_shortcuts/controllers/main.py | 18 +++ .../static/src/css/web_shortcuts.css | 57 +++++++ addons/web_shortcuts/static/src/img/icon.png | Bin 0 -> 5369 bytes .../static/src/js/web_shortcuts.js | 145 ++++++++++++++++++ .../static/src/xml/web_shortcuts.xml | 24 +++ 9 files changed, 334 insertions(+) create mode 100644 addons/web_shortcuts/LICENSE create mode 100644 addons/web_shortcuts/__init__.py create mode 100644 addons/web_shortcuts/__openerp__.py create mode 100644 addons/web_shortcuts/controllers/__init__.py create mode 100644 addons/web_shortcuts/controllers/main.py create mode 100644 addons/web_shortcuts/static/src/css/web_shortcuts.css create mode 100644 addons/web_shortcuts/static/src/img/icon.png create mode 100644 addons/web_shortcuts/static/src/js/web_shortcuts.js create mode 100644 addons/web_shortcuts/static/src/xml/web_shortcuts.xml diff --git a/addons/web_shortcuts/LICENSE b/addons/web_shortcuts/LICENSE new file mode 100644 index 00000000000..ff64be448e9 --- /dev/null +++ b/addons/web_shortcuts/LICENSE @@ -0,0 +1,15 @@ +OpenERP, Open Source Management Solution +Copyright © 2010-2011 OpenERP SA (). + +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 . diff --git a/addons/web_shortcuts/__init__.py b/addons/web_shortcuts/__init__.py new file mode 100644 index 00000000000..6c74add0cca --- /dev/null +++ b/addons/web_shortcuts/__init__.py @@ -0,0 +1,22 @@ +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010 OpenERP s.a. (). +# +# 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 . +# +############################################################################## +import controllers + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/web_shortcuts/__openerp__.py b/addons/web_shortcuts/__openerp__.py new file mode 100644 index 00000000000..150b30909e9 --- /dev/null +++ b/addons/web_shortcuts/__openerp__.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2011 OpenERP s.a. (). +# +# 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 . +# +############################################################################## +{ + '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: diff --git a/addons/web_shortcuts/controllers/__init__.py b/addons/web_shortcuts/controllers/__init__.py new file mode 100644 index 00000000000..9f828025b8e --- /dev/null +++ b/addons/web_shortcuts/controllers/__init__.py @@ -0,0 +1,3 @@ +import main + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/web_shortcuts/controllers/main.py b/addons/web_shortcuts/controllers/main.py new file mode 100644 index 00000000000..23f4bbd3fbe --- /dev/null +++ b/addons/web_shortcuts/controllers/main.py @@ -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: diff --git a/addons/web_shortcuts/static/src/css/web_shortcuts.css b/addons/web_shortcuts/static/src/css/web_shortcuts.css new file mode 100644 index 00000000000..e2deff8d406 --- /dev/null +++ b/addons/web_shortcuts/static/src/css/web_shortcuts.css @@ -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; +} + diff --git a/addons/web_shortcuts/static/src/img/icon.png b/addons/web_shortcuts/static/src/img/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..44347e95f4586548085405afc3960bf9f3be042e GIT binary patch literal 5369 zcmVwP)wDUYb*indI^$3rfEK3~Y!yKi6qF&1fnZ4Pe9y4o zANz(z2t#fzB(A>iT6^W@+;jH%o$vX5_x|m@fBOn4CI64?Vf3^Co#9_E7DFb~b9J7N zG0Wa&{R1!YLM+8PDdoPNw(W3;-sXY#{+k#%cLJ*d76IV_64q{JST*y|!h;Bm{t3beGH)W|fWE+pp0=|idKH1A>i7zP+4r2xkuroHz^I%=pJFP$ zP)`xi&~p|ZiC#mX5W-hq%>-eDFiXw?@_O+2w`?s*QrLY zAn=B-GPzF)eT}k-2;B!10PXRq5Ab95nGBl2xht5C|3TD6Q2!Xij zT?)cz~GP{ogVbU9wV@>Kj#Bj2l1`&YN*tvmL8c+CIvKOybSwkws_E47&qm zRW?m^8i^zzG9(=fncg_%Lo2973s*B@;Eo}dftGe?0GdvL`JX|Lc;MjvTnJ#6O;KS> zGKT6rI%)el7MWD%CE_3*%zo1dS_BqNWdJ=S<5N!H*x{nGu7(kMZ~(f$pCZFcfH(mH z+s{izz_l@|CIN8anKS?uLWts1{XD0fz^mqRncu=^mQGf^ZXyEMAXCR~|JsXiz)3(d zhF&xnEm+Q(gQzz&1U=w|LP|+po$%do1DDnfWWJ$M?YU@&CPduK&_1)s4Vl00VgJj2 zoTIfL_c~lBRXtTDl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MU6j4+rIgKC*V)^COaJqRUXTU;`NsbN X7N_QJWu=O_00000NkvXXu0mjfz5O5B literal 0 HcmV?d00001 diff --git a/addons/web_shortcuts/static/src/js/web_shortcuts.js b/addons/web_shortcuts/static/src/js/web_shortcuts.js new file mode 100644 index 00000000000..948e6ab3d82 --- /dev/null +++ b/addons/web_shortcuts/static/src/js/web_shortcuts.js @@ -0,0 +1,145 @@ +/*############################################################################ +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2011-2012 OpenERP SA (). +# +# 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 . +# +############################################################################*/ + +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"); + }); + } +}); + +}; diff --git a/addons/web_shortcuts/static/src/xml/web_shortcuts.xml b/addons/web_shortcuts/static/src/xml/web_shortcuts.xml new file mode 100644 index 00000000000..656fded1d75 --- /dev/null +++ b/addons/web_shortcuts/static/src/xml/web_shortcuts.xml @@ -0,0 +1,24 @@ + + + + +
+ +
    +
+
+ +
  • + + + +
  • +
    + + + + + +