Browse Source
Merge pull request #564 from tarteo/90_mig_web_shortcuts
Merge pull request #564 from tarteo/90_mig_web_shortcuts
[9.0][MIG][web_shortcut]pull/690/head
Eric @ Elico Corp
7 years ago
committed by
GitHub
56 changed files with 485 additions and 498 deletions
-
4web_shortcut/LICENSE
-
64web_shortcut/README.rst
-
5web_shortcut/__init__.py
-
24web_shortcut/__openerp__.py
-
4web_shortcut/i18n/ar.po
-
4web_shortcut/i18n/bs.po
-
4web_shortcut/i18n/cs.po
-
4web_shortcut/i18n/da.po
-
4web_shortcut/i18n/de.po
-
4web_shortcut/i18n/el.po
-
4web_shortcut/i18n/en_GB.po
-
4web_shortcut/i18n/es.po
-
4web_shortcut/i18n/fi.po
-
4web_shortcut/i18n/fr.po
-
4web_shortcut/i18n/gl.po
-
4web_shortcut/i18n/hr.po
-
4web_shortcut/i18n/hu.po
-
4web_shortcut/i18n/it.po
-
4web_shortcut/i18n/lt.po
-
4web_shortcut/i18n/mk.po
-
4web_shortcut/i18n/mn.po
-
4web_shortcut/i18n/nl.po
-
4web_shortcut/i18n/pl.po
-
4web_shortcut/i18n/pt.po
-
4web_shortcut/i18n/pt_BR.po
-
4web_shortcut/i18n/ro.po
-
4web_shortcut/i18n/ru.po
-
4web_shortcut/i18n/sl.po
-
4web_shortcut/i18n/sv.po
-
4web_shortcut/i18n/th.po
-
4web_shortcut/i18n/tr.po
-
4web_shortcut/i18n/vi.po
-
6web_shortcut/i18n/web_shortcut.pot
-
4web_shortcut/i18n/zh_CN.po
-
4web_shortcut/i18n/zh_TW.po
-
6web_shortcut/models/__init__.py
-
16web_shortcut/models/ir_ui_menu.py
-
37web_shortcut/models/web_shortcut.py
-
2web_shortcut/security/ir.model.access.csv
-
0web_shortcut/static/description/icon.png
-
26web_shortcut/static/src/css/web_shortcut.css
-
167web_shortcut/static/src/js/web_shortcut.js
-
25web_shortcut/static/src/xml/web_shortcut.xml
-
13web_shortcut/templates/assets.xml
-
5web_shortcut/tests/__init__.py
-
31web_shortcut/tests/test_web_shortcut.py
-
7web_shortcuts/README.rst
-
21web_shortcuts/__init__.py
-
37web_shortcuts/__openerp__.py
-
30web_shortcuts/model/__init__.py
-
66web_shortcuts/model/web_shortcut.py
-
82web_shortcuts/static/src/css/web_shortcuts.css
-
BINweb_shortcuts/static/src/img/add-shortcut.png
-
150web_shortcuts/static/src/js/web_shortcuts.js
-
27web_shortcuts/static/src/xml/web_shortcuts.xml
-
12web_shortcuts/view/web_shortcuts.xml
@ -1,5 +1,5 @@ |
|||||
OpenERP, Open Source Management Solution |
|
||||
Copyright © 2010-2011 OpenERP SA (<http://openerp.com>). |
|
||||
|
Odoo, Open Source Management Solution |
||||
|
Copyright © 2010-2011 Odoo SA (<http://odoo.com>). |
||||
|
|
||||
This program is free software: you can redistribute it and/or modify |
This program is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU Affero General Public License as |
it under the terms of the GNU Affero General Public License as |
@ -0,0 +1,64 @@ |
|||||
|
.. 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 |
||||
|
<https://github.com/OCA/web/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 <d.sluijk@onestein.nl> |
||||
|
* Odoo SA |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
**This module is a port from Odoo SA and as such, it is not included in the OCA CLA. That means we do not have a copy of the copyright on it like all other OCA modules.** |
@ -0,0 +1,5 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2010 Odoo SA (<http://odoo.com>). |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import models |
@ -0,0 +1,24 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2010-2011 Odoo SA (<http://odoo.com>). |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
{ |
||||
|
'name': 'Shortcut Menu', |
||||
|
'version': '9.0.1.0.0', |
||||
|
'category': 'Web', |
||||
|
'author': 'Odoo SA,Odoo Community Association (OCA)', |
||||
|
'website': 'http://openerp.com', |
||||
|
'depends': [ |
||||
|
'base', |
||||
|
'web' |
||||
|
], |
||||
|
'data': [ |
||||
|
'security/ir.model.access.csv', |
||||
|
'templates/assets.xml', |
||||
|
], |
||||
|
'qweb': [ |
||||
|
'static/src/xml/web_shortcut.xml' |
||||
|
], |
||||
|
'installable': True, |
||||
|
'auto_install': False, |
||||
|
'license': 'AGPL-3', |
||||
|
} |
@ -0,0 +1,6 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2014 Acsone SA/NV (http://www.acsone.eu) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import web_shortcut |
||||
|
from . import ir_ui_menu |
@ -0,0 +1,16 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2004-today Odoo SA (<http://www.odoo.com>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from openerp import models, api |
||||
|
|
||||
|
|
||||
|
class IrUiView(models.Model): |
||||
|
_inherit = 'ir.ui.menu' |
||||
|
|
||||
|
@api.multi |
||||
|
def unlink(self): |
||||
|
res = super(IrUiView, self).unlink() |
||||
|
shortcuts = self.env['web.shortcut'].search([('menu_id', '=', False)]) |
||||
|
shortcuts.unlink() |
||||
|
return res |
@ -0,0 +1,37 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2004-today Odoo SA (<http://www.odoo.com>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from openerp import models, fields, api |
||||
|
|
||||
|
|
||||
|
class WebShortcut(models.Model): |
||||
|
_name = 'web.shortcut' |
||||
|
|
||||
|
name = fields.Char('Shortcut Name', size=64) |
||||
|
menu_id = fields.Many2one('ir.ui.menu', ondelete='cascade') |
||||
|
user_id = fields.Many2one('res.users', 'User Ref.', required=True, |
||||
|
ondelete='cascade', select=True, |
||||
|
default=lambda obj, cr, uid, context: uid) |
||||
|
|
||||
|
_sql_constraints = [ |
||||
|
('shortcut_unique', 'unique(menu_id,user_id)', |
||||
|
'Shortcut for this menu already exists!'), |
||||
|
] |
||||
|
|
||||
|
@api.model |
||||
|
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() |
||||
|
_name = _name[0][1] if len(_name) else '' |
||||
|
_id = shortcut.menu_id.id |
||||
|
res.append( |
||||
|
{ |
||||
|
'id': shortcut.id, |
||||
|
'name': _name, |
||||
|
'menu_id': (_id, _name) |
||||
|
} |
||||
|
) |
||||
|
return res |
@ -1,2 +1,2 @@ |
|||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink |
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink |
||||
access_web_shortcut,access_web_shortcut,model_web_shortcut,,1,1,1,1 |
|
||||
|
access_web_shortcut,access_web_shortcut,model_web_shortcut,,1,1,1,1 |
Before Width: 80 | Height: 80 | Size: 5.2 KiB After Width: 80 | Height: 80 | Size: 5.2 KiB |
@ -0,0 +1,26 @@ |
|||||
|
.oe_shortcut_toggle { |
||||
|
height: 20px; |
||||
|
margin-top: 9px; |
||||
|
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; |
||||
|
} |
@ -0,0 +1,167 @@ |
|||||
|
/* 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'), |
||||
|
UserMenu = require('web.UserMenu'), |
||||
|
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'); |
||||
|
|
||||
|
|
||||
|
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; |
||||
|
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 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; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
UserMenu.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() { |
||||
|
self.shortcuts.trigger('load'); |
||||
|
}); |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
WebClient.include({ |
||||
|
show_application: function() { |
||||
|
var self = this; |
||||
|
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; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
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.$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
|
||||
|
var shortcuts_menu = this.action_manager.webclient.user_menu.shortcuts; |
||||
|
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': session.uid, |
||||
|
'menu_id': session.active_id, |
||||
|
'name': session.name |
||||
|
}); |
||||
|
} |
||||
|
$shortcut_toggle.toggleClass("oe_shortcut_remove"); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
ActionManager.include({ |
||||
|
do_action: function() { |
||||
|
this.$el.find('.oe_shortcut_toggle').addClass('hidden'); |
||||
|
return this._super.apply(this, arguments); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
return ShortcutMenu; |
||||
|
}); |
@ -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.oe-view-title" 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> |
@ -0,0 +1,13 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<template id="assets_backend" inherit_id="web.assets_backend"> |
||||
|
<xpath expr="." position="inside"> |
||||
|
<link rel="stylesheet" href="/web_shortcut/static/src/css/web_shortcut.css"/> |
||||
|
<script type="text/javascript" src="/web_shortcut/static/src/js/web_shortcut.js"></script> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,5 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2017-today Onestein (<http://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from . import test_web_shortcut |
@ -0,0 +1,31 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2017-today Onestein (<http://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from openerp.tests.common import TransactionCase |
||||
|
|
||||
|
|
||||
|
class TestWebShortcut(TransactionCase): |
||||
|
def setUp(self, *args, **kwargs): |
||||
|
super(TestWebShortcut, self).setUp(*args, **kwargs) |
||||
|
self.shortcut_obj = self.env['web.shortcut'] |
||||
|
self.menu_obj = self.env['ir.ui.menu'] |
||||
|
|
||||
|
self.menu = self.env.ref('base.menu_ir_property') |
||||
|
self.user = self.env.ref('base.user_root') |
||||
|
|
||||
|
self.shortcut_obj.search([('user_id', '=', self.user.id)]).unlink() |
||||
|
|
||||
|
def test_web_shortcut(self): |
||||
|
res = self.shortcut_obj.get_user_shortcuts() |
||||
|
self.assertEqual(len(res), 0) |
||||
|
self.shortcut_obj.create({ |
||||
|
'name': 'Test', |
||||
|
'menu_id': self.menu.id, |
||||
|
'user_id': self.env.user.id |
||||
|
}) |
||||
|
res = self.shortcut_obj.get_user_shortcuts() |
||||
|
self.assertEqual(len(res), 1) |
||||
|
self.menu.unlink() |
||||
|
res = self.shortcut_obj.get_user_shortcuts() |
||||
|
self.assertEqual(len(res), 0) |
@ -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. |
|
@ -1,21 +0,0 @@ |
|||||
############################################################################## |
|
||||
# |
|
||||
# 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/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
|
||||
from . import model |
|
@ -1,37 +0,0 @@ |
|||||
# -*- 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': '8.0.1.0.0', |
|
||||
'category': 'Tools', |
|
||||
'author': "OpenERP SA,Odoo Community Association (OCA)", |
|
||||
'website': 'http://openerp.com', |
|
||||
'depends': ['base'], |
|
||||
'data': [ |
|
||||
'security/ir.model.access.csv', |
|
||||
'view/web_shortcuts.xml', |
|
||||
], |
|
||||
'qweb': ['static/src/xml/web_shortcuts.xml'], |
|
||||
'installable': False, |
|
||||
'auto_install': False, |
|
||||
} |
|
||||
|
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
|
@ -1,30 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# |
|
||||
# |
|
||||
# Authors: Adrien Peiffer |
|
||||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) |
|
||||
# All Rights Reserved |
|
||||
# |
|
||||
# WARNING: This program as such is intended to be used by professional |
|
||||
# programmers who take the whole responsibility of assessing all potential |
|
||||
# consequences resulting from its eventual inadequacies and bugs. |
|
||||
# End users who are looking for a ready-to-use solution with commercial |
|
||||
# guarantees and support are strongly advised to contact a Free Software |
|
||||
# Service Company. |
|
||||
# |
|
||||
# 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/>. |
|
||||
# |
|
||||
# |
|
||||
|
|
||||
from . import web_shortcut |
|
@ -1,66 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# Copyright (C) 2004-today OpenERP SA (<http://www.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/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
|
||||
from openerp import models, fields, api |
|
||||
|
|
||||
|
|
||||
class WebShortcut(models.Model): |
|
||||
_name = 'web.shortcut' |
|
||||
|
|
||||
name = fields.Char('Shortcut Name', size=64) |
|
||||
menu_id = fields.Many2one('ir.ui.menu', ondelete='cascade') |
|
||||
user_id = fields.Many2one('res.users', 'User Ref.', required=True, |
|
||||
ondelete='cascade', select=True, |
|
||||
default=lambda obj, cr, uid, context: uid) |
|
||||
|
|
||||
_sql_constraints = [ |
|
||||
('shortcut_unique', 'unique(menu_id,user_id)', |
|
||||
'Shortcut for this menu already exists!'), |
|
||||
] |
|
||||
|
|
||||
@api.model |
|
||||
def get_user_shortcuts(self, user_id): |
|
||||
shortcuts = self.search([('user_id', '=', user_id)]) |
|
||||
res = [] |
|
||||
for shortcut in shortcuts.filtered('menu_id'): |
|
||||
_name = shortcut.menu_id.name_get() |
|
||||
_name = _name[0][1] if len(_name) else '' |
|
||||
_id = shortcut.menu_id.id |
|
||||
res.append( |
|
||||
{ |
|
||||
'id': shortcut.id, |
|
||||
'name': _name, |
|
||||
'menu_id': (_id, _name) |
|
||||
} |
|
||||
) |
|
||||
return res |
|
||||
|
|
||||
|
|
||||
class IrUiView(models.Model): |
|
||||
_inherit = 'ir.ui.menu' |
|
||||
|
|
||||
@api.multi |
|
||||
def unlink(self): |
|
||||
res = super(IrUiView, self).unlink() |
|
||||
shortcuts = self.env['web.shortcut'].search([('menu_id', '=', False)]) |
|
||||
for shortcut in shortcuts: |
|
||||
shortcut.unlink() |
|
||||
return res |
|
@ -1,82 +0,0 @@ |
|||||
/* 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; |
|
||||
} |
|
||||
|
|
Before Width: 16 | Height: 16 | Size: 337 B |
@ -1,150 +0,0 @@ |
|||||
/*############################################################################ |
|
||||
# |
|
||||
# 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.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"); |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
}; |
|
@ -1,27 +0,0 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||
<!-- vim:fdl=1: |
|
||||
--> |
|
||||
<templates id="template" xml:space="preserve"> |
|
||||
<t t-name="Systray.Shortcuts"> |
|
||||
<li class="dropdown"> |
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> |
|
||||
<img src="/web_shortcuts/static/src/img/add-shortcut.png"/> |
|
||||
</a> |
|
||||
<ul class="oe_systray_shortcuts_items dropdown-menu"> |
|
||||
</ul> |
|
||||
</li> |
|
||||
</t> |
|
||||
<t t-name="Systray.Shortcuts.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_shortcuts_toggle" title="Add / Remove Shortcut..." |
|
||||
href="javascript: void(0)"> </a> |
|
||||
</t> |
|
||||
</t> |
|
||||
</templates> |
|
@ -1,12 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<openerp> |
|
||||
<data> |
|
||||
<!-- Include JS file for the custom view to select domain from filters --> |
|
||||
<template id="assets_backend" name="filter_selection" inherit_id="web.assets_backend"> |
|
||||
<xpath expr="." position="inside"> |
|
||||
<link rel="stylesheet" href="/web_shortcuts/static/src/css/web_shortcuts.css"/> |
|
||||
<script type="text/javascript" src="/web_shortcuts/static/src/js/web_shortcuts.js"></script> |
|
||||
</xpath> |
|
||||
</template> |
|
||||
</data> |
|
||||
</openerp> |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue