From b9deeaa653689c2882ed365dc9c3919917f6a87f Mon Sep 17 00:00:00 2001 From: tarteo Date: Mon, 13 Feb 2017 16:42:23 +0100 Subject: [PATCH 01/16] Initial commit --- {web_shortcuts => web_shortcut}/LICENSE | 0 web_shortcut/README.rst | 61 +++++++ {web_shortcuts => web_shortcut}/__init__.py | 2 +- .../__openerp__.py | 21 ++- {web_shortcuts => web_shortcut}/i18n/ar.po | 0 {web_shortcuts => web_shortcut}/i18n/bs.po | 0 {web_shortcuts => web_shortcut}/i18n/cs.po | 0 {web_shortcuts => web_shortcut}/i18n/da.po | 0 {web_shortcuts => web_shortcut}/i18n/de.po | 0 {web_shortcuts => web_shortcut}/i18n/el.po | 0 {web_shortcuts => web_shortcut}/i18n/en_GB.po | 0 {web_shortcuts => web_shortcut}/i18n/es.po | 0 {web_shortcuts => web_shortcut}/i18n/fi.po | 0 {web_shortcuts => web_shortcut}/i18n/fr.po | 0 {web_shortcuts => web_shortcut}/i18n/gl.po | 0 {web_shortcuts => web_shortcut}/i18n/hr.po | 0 {web_shortcuts => web_shortcut}/i18n/hu.po | 0 {web_shortcuts => web_shortcut}/i18n/it.po | 0 {web_shortcuts => web_shortcut}/i18n/lt.po | 0 {web_shortcuts => web_shortcut}/i18n/mk.po | 0 {web_shortcuts => web_shortcut}/i18n/mn.po | 0 {web_shortcuts => web_shortcut}/i18n/nl.po | 0 {web_shortcuts => web_shortcut}/i18n/pl.po | 0 {web_shortcuts => web_shortcut}/i18n/pt.po | 0 {web_shortcuts => web_shortcut}/i18n/pt_BR.po | 0 {web_shortcuts => web_shortcut}/i18n/ro.po | 0 {web_shortcuts => web_shortcut}/i18n/ru.po | 0 {web_shortcuts => web_shortcut}/i18n/sl.po | 0 {web_shortcuts => web_shortcut}/i18n/sv.po | 0 {web_shortcuts => web_shortcut}/i18n/th.po | 0 {web_shortcuts => web_shortcut}/i18n/tr.po | 0 {web_shortcuts => web_shortcut}/i18n/vi.po | 0 .../i18n/web_shortcuts.pot | 0 {web_shortcuts => web_shortcut}/i18n/zh_CN.po | 0 {web_shortcuts => web_shortcut}/i18n/zh_TW.po | 0 .../model => web_shortcut/models}/__init__.py | 0 .../models}/web_shortcut.py | 0 .../security/ir.model.access.csv | 0 .../static/description/icon.png | Bin .../static/src/css/web_shortcut.css | 0 .../static/src/img/add-shortcut.png | Bin web_shortcut/static/src/js/web_shortcut.js | 159 ++++++++++++++++++ web_shortcut/static/src/xml/web_shortcut.xml | 27 +++ web_shortcut/templates/assets.xml | 13 ++ web_shortcuts/README.rst | 7 - web_shortcuts/static/src/js/web_shortcuts.js | 150 ----------------- .../static/src/xml/web_shortcuts.xml | 27 --- web_shortcuts/view/web_shortcuts.xml | 12 -- 48 files changed, 274 insertions(+), 205 deletions(-) rename {web_shortcuts => web_shortcut}/LICENSE (100%) create mode 100644 web_shortcut/README.rst rename {web_shortcuts => web_shortcut}/__init__.py (97%) rename {web_shortcuts => web_shortcut}/__openerp__.py (82%) rename {web_shortcuts => web_shortcut}/i18n/ar.po (100%) rename {web_shortcuts => web_shortcut}/i18n/bs.po (100%) rename {web_shortcuts => web_shortcut}/i18n/cs.po (100%) rename {web_shortcuts => web_shortcut}/i18n/da.po (100%) rename {web_shortcuts => web_shortcut}/i18n/de.po (100%) rename {web_shortcuts => web_shortcut}/i18n/el.po (100%) rename {web_shortcuts => web_shortcut}/i18n/en_GB.po (100%) rename {web_shortcuts => web_shortcut}/i18n/es.po (100%) rename {web_shortcuts => web_shortcut}/i18n/fi.po (100%) rename {web_shortcuts => web_shortcut}/i18n/fr.po (100%) rename {web_shortcuts => web_shortcut}/i18n/gl.po (100%) rename {web_shortcuts => web_shortcut}/i18n/hr.po (100%) rename {web_shortcuts => web_shortcut}/i18n/hu.po (100%) rename {web_shortcuts => web_shortcut}/i18n/it.po (100%) rename {web_shortcuts => web_shortcut}/i18n/lt.po (100%) rename {web_shortcuts => web_shortcut}/i18n/mk.po (100%) rename {web_shortcuts => web_shortcut}/i18n/mn.po (100%) rename {web_shortcuts => web_shortcut}/i18n/nl.po (100%) rename {web_shortcuts => web_shortcut}/i18n/pl.po (100%) rename {web_shortcuts => web_shortcut}/i18n/pt.po (100%) rename {web_shortcuts => web_shortcut}/i18n/pt_BR.po (100%) rename {web_shortcuts => web_shortcut}/i18n/ro.po (100%) rename {web_shortcuts => web_shortcut}/i18n/ru.po (100%) rename {web_shortcuts => web_shortcut}/i18n/sl.po (100%) rename {web_shortcuts => web_shortcut}/i18n/sv.po (100%) rename {web_shortcuts => web_shortcut}/i18n/th.po (100%) rename {web_shortcuts => web_shortcut}/i18n/tr.po (100%) rename {web_shortcuts => web_shortcut}/i18n/vi.po (100%) rename {web_shortcuts => web_shortcut}/i18n/web_shortcuts.pot (100%) rename {web_shortcuts => web_shortcut}/i18n/zh_CN.po (100%) rename {web_shortcuts => web_shortcut}/i18n/zh_TW.po (100%) rename {web_shortcuts/model => web_shortcut/models}/__init__.py (100%) rename {web_shortcuts/model => web_shortcut/models}/web_shortcut.py (100%) rename {web_shortcuts => web_shortcut}/security/ir.model.access.csv (100%) rename {web_shortcuts => web_shortcut}/static/description/icon.png (100%) rename web_shortcuts/static/src/css/web_shortcuts.css => web_shortcut/static/src/css/web_shortcut.css (100%) rename {web_shortcuts => web_shortcut}/static/src/img/add-shortcut.png (100%) create mode 100644 web_shortcut/static/src/js/web_shortcut.js create mode 100644 web_shortcut/static/src/xml/web_shortcut.xml create mode 100644 web_shortcut/templates/assets.xml delete mode 100644 web_shortcuts/README.rst delete mode 100644 web_shortcuts/static/src/js/web_shortcuts.js delete mode 100644 web_shortcuts/static/src/xml/web_shortcuts.xml delete mode 100644 web_shortcuts/view/web_shortcuts.xml diff --git a/web_shortcuts/LICENSE b/web_shortcut/LICENSE similarity index 100% rename from web_shortcuts/LICENSE rename to web_shortcut/LICENSE diff --git a/web_shortcut/README.rst b/web_shortcut/README.rst new file mode 100644 index 00000000..3e4ae7c9 --- /dev/null +++ b/web_shortcut/README.rst @@ -0,0 +1,61 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============= +Shortcut Menu +============= + +Adds a button to the top menu which opens a menu containing the user's shortcuts. + +Configuration +============= + +To configure this module, you need to: + +#. Go to any view; +#. click on the star icon besides the title to add / remove a shortcut. + +Usage +===== + +To use this module, you need to: + +#. Click on the star icon in the right corner of the top menu; +#. click the shortcut you want. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Adrien Peiffer +* Dennis Sluijk + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. \ No newline at end of file diff --git a/web_shortcuts/__init__.py b/web_shortcut/__init__.py similarity index 97% rename from web_shortcuts/__init__.py rename to web_shortcut/__init__.py index 0c453b00..aa9b673b 100644 --- a/web_shortcuts/__init__.py +++ b/web_shortcut/__init__.py @@ -18,4 +18,4 @@ # ############################################################################## -from . import model +from . import models diff --git a/web_shortcuts/__openerp__.py b/web_shortcut/__openerp__.py similarity index 82% rename from web_shortcuts/__openerp__.py rename to web_shortcut/__openerp__.py index e9c28d98..0c44ac58 100644 --- a/web_shortcuts/__openerp__.py +++ b/web_shortcut/__openerp__.py @@ -19,18 +19,23 @@ # ############################################################################## { - 'name': 'Web Shortcuts', - 'version': '8.0.1.0.0', - 'category': 'Tools', + 'name': 'Shortcut Menu', + 'version': '9.0.1.0.0', + 'category': 'Web', 'author': "OpenERP SA,Odoo Community Association (OCA)", 'website': 'http://openerp.com', - 'depends': ['base'], + 'depends': [ + 'base', + 'web' + ], 'data': [ 'security/ir.model.access.csv', - 'view/web_shortcuts.xml', - ], - 'qweb': ['static/src/xml/web_shortcuts.xml'], - 'installable': False, + 'templates/assets.xml', + ], + 'qweb': [ + 'static/src/xml/web_shortcut.xml' + ], + 'installable': True, 'auto_install': False, } diff --git a/web_shortcuts/i18n/ar.po b/web_shortcut/i18n/ar.po similarity index 100% rename from web_shortcuts/i18n/ar.po rename to web_shortcut/i18n/ar.po diff --git a/web_shortcuts/i18n/bs.po b/web_shortcut/i18n/bs.po similarity index 100% rename from web_shortcuts/i18n/bs.po rename to web_shortcut/i18n/bs.po diff --git a/web_shortcuts/i18n/cs.po b/web_shortcut/i18n/cs.po similarity index 100% rename from web_shortcuts/i18n/cs.po rename to web_shortcut/i18n/cs.po diff --git a/web_shortcuts/i18n/da.po b/web_shortcut/i18n/da.po similarity index 100% rename from web_shortcuts/i18n/da.po rename to web_shortcut/i18n/da.po diff --git a/web_shortcuts/i18n/de.po b/web_shortcut/i18n/de.po similarity index 100% rename from web_shortcuts/i18n/de.po rename to web_shortcut/i18n/de.po diff --git a/web_shortcuts/i18n/el.po b/web_shortcut/i18n/el.po similarity index 100% rename from web_shortcuts/i18n/el.po rename to web_shortcut/i18n/el.po diff --git a/web_shortcuts/i18n/en_GB.po b/web_shortcut/i18n/en_GB.po similarity index 100% rename from web_shortcuts/i18n/en_GB.po rename to web_shortcut/i18n/en_GB.po diff --git a/web_shortcuts/i18n/es.po b/web_shortcut/i18n/es.po similarity index 100% rename from web_shortcuts/i18n/es.po rename to web_shortcut/i18n/es.po diff --git a/web_shortcuts/i18n/fi.po b/web_shortcut/i18n/fi.po similarity index 100% rename from web_shortcuts/i18n/fi.po rename to web_shortcut/i18n/fi.po diff --git a/web_shortcuts/i18n/fr.po b/web_shortcut/i18n/fr.po similarity index 100% rename from web_shortcuts/i18n/fr.po rename to web_shortcut/i18n/fr.po diff --git a/web_shortcuts/i18n/gl.po b/web_shortcut/i18n/gl.po similarity index 100% rename from web_shortcuts/i18n/gl.po rename to web_shortcut/i18n/gl.po diff --git a/web_shortcuts/i18n/hr.po b/web_shortcut/i18n/hr.po similarity index 100% rename from web_shortcuts/i18n/hr.po rename to web_shortcut/i18n/hr.po diff --git a/web_shortcuts/i18n/hu.po b/web_shortcut/i18n/hu.po similarity index 100% rename from web_shortcuts/i18n/hu.po rename to web_shortcut/i18n/hu.po diff --git a/web_shortcuts/i18n/it.po b/web_shortcut/i18n/it.po similarity index 100% rename from web_shortcuts/i18n/it.po rename to web_shortcut/i18n/it.po diff --git a/web_shortcuts/i18n/lt.po b/web_shortcut/i18n/lt.po similarity index 100% rename from web_shortcuts/i18n/lt.po rename to web_shortcut/i18n/lt.po diff --git a/web_shortcuts/i18n/mk.po b/web_shortcut/i18n/mk.po similarity index 100% rename from web_shortcuts/i18n/mk.po rename to web_shortcut/i18n/mk.po diff --git a/web_shortcuts/i18n/mn.po b/web_shortcut/i18n/mn.po similarity index 100% rename from web_shortcuts/i18n/mn.po rename to web_shortcut/i18n/mn.po diff --git a/web_shortcuts/i18n/nl.po b/web_shortcut/i18n/nl.po similarity index 100% rename from web_shortcuts/i18n/nl.po rename to web_shortcut/i18n/nl.po diff --git a/web_shortcuts/i18n/pl.po b/web_shortcut/i18n/pl.po similarity index 100% rename from web_shortcuts/i18n/pl.po rename to web_shortcut/i18n/pl.po diff --git a/web_shortcuts/i18n/pt.po b/web_shortcut/i18n/pt.po similarity index 100% rename from web_shortcuts/i18n/pt.po rename to web_shortcut/i18n/pt.po diff --git a/web_shortcuts/i18n/pt_BR.po b/web_shortcut/i18n/pt_BR.po similarity index 100% rename from web_shortcuts/i18n/pt_BR.po rename to web_shortcut/i18n/pt_BR.po diff --git a/web_shortcuts/i18n/ro.po b/web_shortcut/i18n/ro.po similarity index 100% rename from web_shortcuts/i18n/ro.po rename to web_shortcut/i18n/ro.po diff --git a/web_shortcuts/i18n/ru.po b/web_shortcut/i18n/ru.po similarity index 100% rename from web_shortcuts/i18n/ru.po rename to web_shortcut/i18n/ru.po diff --git a/web_shortcuts/i18n/sl.po b/web_shortcut/i18n/sl.po similarity index 100% rename from web_shortcuts/i18n/sl.po rename to web_shortcut/i18n/sl.po diff --git a/web_shortcuts/i18n/sv.po b/web_shortcut/i18n/sv.po similarity index 100% rename from web_shortcuts/i18n/sv.po rename to web_shortcut/i18n/sv.po diff --git a/web_shortcuts/i18n/th.po b/web_shortcut/i18n/th.po similarity index 100% rename from web_shortcuts/i18n/th.po rename to web_shortcut/i18n/th.po diff --git a/web_shortcuts/i18n/tr.po b/web_shortcut/i18n/tr.po similarity index 100% rename from web_shortcuts/i18n/tr.po rename to web_shortcut/i18n/tr.po diff --git a/web_shortcuts/i18n/vi.po b/web_shortcut/i18n/vi.po similarity index 100% rename from web_shortcuts/i18n/vi.po rename to web_shortcut/i18n/vi.po diff --git a/web_shortcuts/i18n/web_shortcuts.pot b/web_shortcut/i18n/web_shortcuts.pot similarity index 100% rename from web_shortcuts/i18n/web_shortcuts.pot rename to web_shortcut/i18n/web_shortcuts.pot diff --git a/web_shortcuts/i18n/zh_CN.po b/web_shortcut/i18n/zh_CN.po similarity index 100% rename from web_shortcuts/i18n/zh_CN.po rename to web_shortcut/i18n/zh_CN.po diff --git a/web_shortcuts/i18n/zh_TW.po b/web_shortcut/i18n/zh_TW.po similarity index 100% rename from web_shortcuts/i18n/zh_TW.po rename to web_shortcut/i18n/zh_TW.po diff --git a/web_shortcuts/model/__init__.py b/web_shortcut/models/__init__.py similarity index 100% rename from web_shortcuts/model/__init__.py rename to web_shortcut/models/__init__.py diff --git a/web_shortcuts/model/web_shortcut.py b/web_shortcut/models/web_shortcut.py similarity index 100% rename from web_shortcuts/model/web_shortcut.py rename to web_shortcut/models/web_shortcut.py diff --git a/web_shortcuts/security/ir.model.access.csv b/web_shortcut/security/ir.model.access.csv similarity index 100% rename from web_shortcuts/security/ir.model.access.csv rename to web_shortcut/security/ir.model.access.csv diff --git a/web_shortcuts/static/description/icon.png b/web_shortcut/static/description/icon.png similarity index 100% rename from web_shortcuts/static/description/icon.png rename to web_shortcut/static/description/icon.png diff --git a/web_shortcuts/static/src/css/web_shortcuts.css b/web_shortcut/static/src/css/web_shortcut.css similarity index 100% rename from web_shortcuts/static/src/css/web_shortcuts.css rename to web_shortcut/static/src/css/web_shortcut.css diff --git a/web_shortcuts/static/src/img/add-shortcut.png b/web_shortcut/static/src/img/add-shortcut.png similarity index 100% rename from web_shortcuts/static/src/img/add-shortcut.png rename to web_shortcut/static/src/img/add-shortcut.png diff --git a/web_shortcut/static/src/js/web_shortcut.js b/web_shortcut/static/src/js/web_shortcut.js new file mode 100644 index 00000000..4c32aa3f --- /dev/null +++ b/web_shortcut/static/src/js/web_shortcut.js @@ -0,0 +1,159 @@ +/*############################################################################ +# +# 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 . +# +############################################################################*/ + +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; +}); diff --git a/web_shortcut/static/src/xml/web_shortcut.xml b/web_shortcut/static/src/xml/web_shortcut.xml new file mode 100644 index 00000000..c471658f --- /dev/null +++ b/web_shortcut/static/src/xml/web_shortcut.xml @@ -0,0 +1,27 @@ + + + + + + + +
  • + + + +
  • +
    + + + + + +
    diff --git a/web_shortcut/templates/assets.xml b/web_shortcut/templates/assets.xml new file mode 100644 index 00000000..4fe95b3e --- /dev/null +++ b/web_shortcut/templates/assets.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/web_shortcuts/README.rst b/web_shortcuts/README.rst deleted file mode 100644 index e3e36f90..00000000 --- a/web_shortcuts/README.rst +++ /dev/null @@ -1,7 +0,0 @@ -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. \ No newline at end of file diff --git a/web_shortcuts/static/src/js/web_shortcuts.js b/web_shortcuts/static/src/js/web_shortcuts.js deleted file mode 100644 index 943def16..00000000 --- a/web_shortcuts/static/src/js/web_shortcuts.js +++ /dev/null @@ -1,150 +0,0 @@ -/*############################################################################ -# -# 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.model = new instance.web.Model('web.shortcut'); - }, - start: function() { - var self = this; - this._super(); - this.trigger('load'); - this.$el.on('click', '.oe_systray_shortcuts_items a', function() { - self.trigger('click', $(this)); - }); - }, - load: function() { - var self = this; - this.$el.find('.oe_systray_shortcuts_items').empty(); - return this.model.call('get_user_shortcuts', [ - instance.session.uid, - instance.web.pyeval.eval('context', {}) - ]).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_shortcuts_items').append(); - var $sc = $(QWeb.render('Systray.Shortcuts.Item', {'shortcut': sc})); - $sc.appendTo(self.$el.find('.oe_systray_shortcuts_items')); - }, - remove: function (menu_id) { - var menu_id = this.session.active_id; - var $shortcut = this.$el.find('.oe_systray_shortcuts_items 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, - id = $link.data('id'); - self.session.active_id = id; - // TODO: Use do_action({menu_id: id, type: 'ir.actions.menu'}) - new instance.web.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(','); - var action_id = parseInt(action_str_parts[1]) - self.rpc('/web/action/load', {'action_id': action_id}).done(function(action) { - instance.webclient.on_menu_action({action_id: action.id}); - }); - }); - this.$el.find('.oe_systray_shortcuts').trigger('mouseout'); - }, - has: function(menu_id) { - return !!this.$el.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.done(function() { - if (self.shortcuts) { - self.shortcuts.trigger('load'); - } else { - self.shortcuts = new instance.web_shortcuts.Shortcuts(self); - self.shortcuts.appendTo(instance.webclient.$el.find('.oe_systray')); - } - }); - }, -}); - -instance.web.ViewManagerAction.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; - 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.$el.find('.oe_shortcuts_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; - } - // Anonymous users don't have user_menu - if (shortcuts_menu) { - $shortcut_toggle.toggleClass('oe_shortcuts_remove', shortcuts_menu.has(self.session.active_id)); - $shortcut_toggle.unbind("click").click(function() { - if ($shortcut_toggle.hasClass("oe_shortcuts_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_shortcuts_remove"); - }); - } - } -}); - -}; diff --git a/web_shortcuts/static/src/xml/web_shortcuts.xml b/web_shortcuts/static/src/xml/web_shortcuts.xml deleted file mode 100644 index 1aa7a8cd..00000000 --- a/web_shortcuts/static/src/xml/web_shortcuts.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - -
  • - - - -
  • -
    - - - - - -
    diff --git a/web_shortcuts/view/web_shortcuts.xml b/web_shortcuts/view/web_shortcuts.xml deleted file mode 100644 index bd27657c..00000000 --- a/web_shortcuts/view/web_shortcuts.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - From 79639d95cbdbb96bd7a50b3b4e100fc6660e39b4 Mon Sep 17 00:00:00 2001 From: tarteo Date: Mon, 13 Feb 2017 16:56:34 +0100 Subject: [PATCH 02/16] [MIG] Loading shortcuts --- web_shortcut/models/web_shortcut.py | 4 ++-- web_shortcut/static/src/xml/web_shortcut.xml | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/web_shortcut/models/web_shortcut.py b/web_shortcut/models/web_shortcut.py index 9065e2de..ffe6a854 100644 --- a/web_shortcut/models/web_shortcut.py +++ b/web_shortcut/models/web_shortcut.py @@ -37,8 +37,8 @@ class WebShortcut(models.Model): ] @api.model - def get_user_shortcuts(self, user_id): - shortcuts = self.search([('user_id', '=', user_id)]) + def get_user_shortcuts(self): + shortcuts = self.search([('user_id', '=', self.env.user.id)]) res = [] for shortcut in shortcuts.filtered('menu_id'): _name = shortcut.menu_id.name_get() diff --git a/web_shortcut/static/src/xml/web_shortcut.xml b/web_shortcut/static/src/xml/web_shortcut.xml index c471658f..82012653 100644 --- a/web_shortcut/static/src/xml/web_shortcut.xml +++ b/web_shortcut/static/src/xml/web_shortcut.xml @@ -18,10 +18,20 @@ + + + + + + + + From cf1cd07dd282eb129b7545c18cb05b26bbdfbc0c Mon Sep 17 00:00:00 2001 From: tarteo Date: Thu, 23 Feb 2017 15:39:09 +0100 Subject: [PATCH 03/16] [FIX] Add to shortcuts button --- web_shortcut/static/src/css/web_shortcut.css | 6 +-- web_shortcut/static/src/js/web_shortcut.js | 48 ++++++++++++++------ web_shortcut/static/src/xml/web_shortcut.xml | 16 ++----- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/web_shortcut/static/src/css/web_shortcut.css b/web_shortcut/static/src/css/web_shortcut.css index ae5a3cef..fbf93d2c 100644 --- a/web_shortcut/static/src/css/web_shortcut.css +++ b/web_shortcut/static/src/css/web_shortcut.css @@ -2,9 +2,9 @@ .oe_systray_shortcuts .oe_star_off { color: #eee; } -.oe_shortcuts_toggle { +.oe_shortcut_toggle { height: 20px; - margin-top: 3px; + margin-top: 9px; padding: 0; width: 24px; cursor: pointer; @@ -12,7 +12,7 @@ background: url(/web/static/src/img/add-shortcut.png) no-repeat center center; float: left; } -.oe_shortcuts_remove{ +.oe_shortcut_remove{ background: url(/web/static/src/img/remove-shortcut.png) no-repeat center center; } .oe_shortcuts { diff --git a/web_shortcut/static/src/js/web_shortcut.js b/web_shortcut/static/src/js/web_shortcut.js index 4c32aa3f..bf3a2105 100644 --- a/web_shortcut/static/src/js/web_shortcut.js +++ b/web_shortcut/static/src/js/web_shortcut.js @@ -23,6 +23,7 @@ odoo.define('web.shortcut', function(require) { menu = require('web.UserMenu'), client = require('web.WebClient'), view_manager = require('web.ViewManager'), + qweb = require('web.core').qweb, model = require('web.DataModel'); @@ -63,7 +64,7 @@ odoo.define('web.shortcut', function(require) { display: function(sc) { var self = this; this.$el.find('.oe_systray_shortcut_menu').append(); - var $sc = $(QWeb.render('Systray.ShortcutMenu.Item', {'shortcut': sc})); + var $sc = $(qweb.render('Systray.ShortcutMenu.Item', {'shortcut': sc})); $sc.appendTo(self.$el.find('.oe_systray_shortcut_menu')); }, remove: function (menu_id) { @@ -77,7 +78,7 @@ odoo.define('web.shortcut', function(require) { var self = this, action_id = $link.data('id'); - new model('ir.ui.menu').query(['action']).filter([['id', '=', id]]).context(null).all().then(function(menu) { + new model('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]); @@ -91,16 +92,17 @@ odoo.define('web.shortcut', function(require) { menu.include({ + start: function() { + var res = this._super.apply(this, arguments); + this.shortcuts = new ShortcutMenu(self); + this.shortcuts.prependTo(this.$el.parent()); + return res; + }, 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()); - } + self.shortcuts.trigger('load'); }); }, }); @@ -109,27 +111,39 @@ odoo.define('web.shortcut', function(require) { 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); + var res = this._super.apply(this, arguments); + this.user_menu.shortcuts.on('click', this, function(action_id) { + self.do_action(action_id, { + clear_breadcrumbs: true, + replace_breadcrumb: true + }); }); + return res; } }); view_manager.include({ + start: function() { + var res = this._super.apply(this, arguments); + console.log(this); + return res; + }, switch_mode: function (view_type, no_store) { var self = this; - this._super.apply(this, arguments).done(function() { + return this._super.apply(this, arguments).done(function() { self.shortcut_check(self.views[view_type]); }); }, shortcut_check: function(view) { + console.log('shortcut_check'); 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_manager) { + console.log(this); + return; + } + var $shortcut_toggle = this.action_manager.$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)) { @@ -137,7 +151,10 @@ odoo.define('web.shortcut', function(require) { return; } // Anonymous users don't have user_menu + var shortcuts_menu = this.action_manager.webclient.user_menu.shortcuts; + console.log(self.session); if (shortcuts_menu) { + console.log(self.session.active_id); $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")) { @@ -152,6 +169,7 @@ odoo.define('web.shortcut', function(require) { $shortcut_toggle.toggleClass("oe_shortcut_remove"); }); } + console.log('done_shortcut_check'); } }); diff --git a/web_shortcut/static/src/xml/web_shortcut.xml b/web_shortcut/static/src/xml/web_shortcut.xml index 82012653..ba32ade6 100644 --- a/web_shortcut/static/src/xml/web_shortcut.xml +++ b/web_shortcut/static/src/xml/web_shortcut.xml @@ -18,20 +18,14 @@ - - - + + console.log(ctx); + + - From ca87adfec57bd3af700185201edf7a22673b08b1 Mon Sep 17 00:00:00 2001 From: tarteo Date: Thu, 23 Feb 2017 16:19:45 +0100 Subject: [PATCH 04/16] [REM] Replaced image with fa icon --- web_shortcut/static/src/css/web_shortcut.css | 80 +++---------------- web_shortcut/static/src/img/add-shortcut.png | Bin 337 -> 0 bytes web_shortcut/static/src/js/web_shortcut.js | 31 ++++--- web_shortcut/static/src/xml/web_shortcut.xml | 9 +-- 4 files changed, 32 insertions(+), 88 deletions(-) delete mode 100644 web_shortcut/static/src/img/add-shortcut.png diff --git a/web_shortcut/static/src/css/web_shortcut.css b/web_shortcut/static/src/css/web_shortcut.css index fbf93d2c..bd9cedf8 100644 --- a/web_shortcut/static/src/css/web_shortcut.css +++ b/web_shortcut/static/src/css/web_shortcut.css @@ -1,82 +1,26 @@ -/* Shortcuts*/ -.oe_systray_shortcuts .oe_star_off { - color: #eee; -} .oe_shortcut_toggle { height: 20px; margin-top: 9px; - padding: 0; width: 24px; cursor: pointer; display: block; - background: url(/web/static/src/img/add-shortcut.png) no-repeat center center; + font-size: 20px; 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; + color: #a8a8a8; } -.oe_shortcuts li:hover { - background-color: #666; -} -.oe_shortcuts li:first-child { - border-left: none; - padding-left: 0; +.oe_shortcut_toggle:focus { + color: #a8a8a8; } - -.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; +.oe_shortcut_toggle:hover { + color: #ffd700; } -.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; + +.oe_shortcut_remove { + color: #ffd700; } +.oe_shortcut_remove:focus { + color: #ffd700; +} diff --git a/web_shortcut/static/src/img/add-shortcut.png b/web_shortcut/static/src/img/add-shortcut.png deleted file mode 100644 index 07b8ed40207def8233cb873e8233e6b19ec3e0b9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 337 zcmV-X0j~auP)6t8(LDsc#nGl)9+!M5z8 zVg=9k@E2l5X3Uasr`|<3E1Jz$o7P^6)DdveWEXtNc_i*d%{%yVP5}g4z#Q0c(vx9N z<-z^~u%$L=QuJF6j|rEn{seJ{u6u0iDS8ltQ}fOM!R`-%2OWLZu^stz=rYE%3Eswt jeJ|o @@ -20,10 +18,7 @@ - - console.log(ctx); - - From 1611185af842f1b55ad11950ef80d9d8502e3df6 Mon Sep 17 00:00:00 2001 From: tarteo Date: Thu, 23 Feb 2017 16:41:00 +0100 Subject: [PATCH 05/16] [IMP] Clean pu --- web_shortcut/README.rst | 2 +- web_shortcut/static/src/js/web_shortcut.js | 14 ++++++++------ web_shortcut/static/src/xml/web_shortcut.xml | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/web_shortcut/README.rst b/web_shortcut/README.rst index 3e4ae7c9..6bf7a37f 100644 --- a/web_shortcut/README.rst +++ b/web_shortcut/README.rst @@ -6,7 +6,7 @@ Shortcut Menu ============= -Adds a button to the top menu which opens a menu containing the user's shortcuts. +Adds a button to the top menu which opens a menu containing the user's shortcuts. Configuration ============= diff --git a/web_shortcut/static/src/js/web_shortcut.js b/web_shortcut/static/src/js/web_shortcut.js index e66855a2..13fbcb3c 100644 --- a/web_shortcut/static/src/js/web_shortcut.js +++ b/web_shortcut/static/src/js/web_shortcut.js @@ -26,7 +26,8 @@ odoo.define('web.shortcut', function(require) { action_manager = require('web.ActionManager'), core = require('web.core'), qweb = core.qweb, - model = require('web.DataModel'); + model = require('web.DataModel'), + session = require('web.session'); var ShortcutMenu = widget.extend({ @@ -143,8 +144,9 @@ odoo.define('web.shortcut', function(require) { // display shortcuts if on the first view for the action var $shortcut_toggle = this.action_manager.$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)) { + !(view.view_type === this.view_stack[0].view_type && + view.view_id === this.view_stack[0].view_id) + ) { $shortcut_toggle.addClass('hidden'); return; } @@ -159,9 +161,9 @@ odoo.define('web.shortcut', function(require) { 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 + 'user_id': session.uid, + 'menu_id': session.active_id, + 'name': session.name }); } $shortcut_toggle.toggleClass("oe_shortcut_remove"); diff --git a/web_shortcut/static/src/xml/web_shortcut.xml b/web_shortcut/static/src/xml/web_shortcut.xml index 70d3da38..916cd38b 100644 --- a/web_shortcut/static/src/xml/web_shortcut.xml +++ b/web_shortcut/static/src/xml/web_shortcut.xml @@ -1,7 +1,6 @@ - +