From 3d8b80ebdafa2fbc1578878f47837c8f902a28c3 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Fri, 10 Jan 2020 12:45:51 +0100 Subject: [PATCH] [11.0][FIX] open_tab: Open new tab with the wheel --- web_widget_open_tab/README.rst | 2 +- web_widget_open_tab/readme/USAGE.rst | 2 +- .../static/description/index.html | 2 +- web_widget_open_tab/static/src/js/widget.js | 42 ++++++++++++++----- .../static/src/less/open_tab.less | 10 +++++ web_widget_open_tab/views/assets.xml | 1 + 6 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 web_widget_open_tab/static/src/less/open_tab.less diff --git a/web_widget_open_tab/README.rst b/web_widget_open_tab/README.rst index d69f3bc2c..58b30701d 100644 --- a/web_widget_open_tab/README.rst +++ b/web_widget_open_tab/README.rst @@ -38,7 +38,7 @@ Usage Edit the tree view and add the widget as the first field, usually, we should use: .. code-block:: xml - + Now, we can open when clicking with the mouse wheel over the eye. On a usual click the record will be opened without changes (keeping the breadcrumbs). diff --git a/web_widget_open_tab/readme/USAGE.rst b/web_widget_open_tab/readme/USAGE.rst index aa3776f81..bd13b6079 100644 --- a/web_widget_open_tab/readme/USAGE.rst +++ b/web_widget_open_tab/readme/USAGE.rst @@ -1,7 +1,7 @@ Edit the tree view and add the widget as the first field, usually, we should use: .. code-block:: xml - + Now, we can open when clicking with the mouse wheel over the eye. On a usual click the record will be opened without changes (keeping the breadcrumbs). diff --git a/web_widget_open_tab/static/description/index.html b/web_widget_open_tab/static/description/index.html index 3309ee10c..71541c1d1 100644 --- a/web_widget_open_tab/static/description/index.html +++ b/web_widget_open_tab/static/description/index.html @@ -387,7 +387,7 @@ ul.auto-toc {

Edit the tree view and add the widget as the first field, usually, we should use: .. code-block:: xml

-<field name=”id” widget=”open”/>
+<field name=”id” widget=”open_tab”/>

Now, we can open when clicking with the mouse wheel over the eye. On a usual click the record will be opened without changes (keeping the breadcrumbs).

diff --git a/web_widget_open_tab/static/src/js/widget.js b/web_widget_open_tab/static/src/js/widget.js index 7619f0438..4941d8fe9 100644 --- a/web_widget_open_tab/static/src/js/widget.js +++ b/web_widget_open_tab/static/src/js/widget.js @@ -1,11 +1,15 @@ -odoo.define('web_widget_open_tab.FieldOpen', function(require) { +odoo.define('web_widget_open_tab.FieldOpenTab', function(require) { "use strict"; var AbstractField = require('web.AbstractField'); var field_registry = require('web.field_registry'); var ListRenderer = require('web.ListRenderer'); + var core = require('web.core'); + var config = require('web.config'); + var qweb = core.qweb; + var _t = core._t; - var FieldOpen = AbstractField.extend({ + var FieldOpenTab = AbstractField.extend({ description: "", supportedFieldTypes: ['integer'], events: _.extend({}, AbstractField.prototype.events, { @@ -14,10 +18,30 @@ odoo.define('web_widget_open_tab.FieldOpen', function(require) { isSet: function () { return true; }, + _getReference: function () { + var url = new URL(window.location.href); + return url.hash.replace(/view_type=\w+/i, "view_type=form") + '&id=' + this.res_id; + }, _renderReadonly: function () { var $content = $( - '' - ).addClass('fa fa-eye'); + '' + ).addClass('open_tab_widget fa fa-eye'); + var self = this; + $content.tooltip({ + delay: { show: 1000, hide: 0 }, + title: function () { + return qweb.render('WidgetButton.tooltip', { + debug: config.debug, + state: self.record, + node: { + attrs: { + 'help': _t('Click in order to open on new tab'), + 'type': _t('Widget') + } + }, + }); + }, + }); this.$el.append($content) }, _onClick: function (ev) { @@ -25,9 +49,7 @@ odoo.define('web_widget_open_tab.FieldOpen', function(require) { ev.stopPropagation(); var element = $(ev.currentTarget).find('a'); if (element != null && element[0].href != null) { - var url = new URL(window.location.href); - var href = url.hash.replace("list", "form") + '&id=' + this.res_id; - window.open(href); + window.open(this._getReference()); } }, }); @@ -36,7 +58,7 @@ odoo.define('web_widget_open_tab.FieldOpen', function(require) { // and disallow sorting _renderHeaderCell: function (node) { var $th = this._super.apply(this, arguments); - if (node.attrs.widget === 'open') { + if (node.attrs.widget === 'open_tab') { $th.removeClass('o_column_sortable'); $th[0].width = 1; } @@ -44,7 +66,7 @@ odoo.define('web_widget_open_tab.FieldOpen', function(require) { }, }); - field_registry.add('open', FieldOpen); - return FieldOpen; + field_registry.add('open_tab', FieldOpenTab); + return FieldOpenTab; }); diff --git a/web_widget_open_tab/static/src/less/open_tab.less b/web_widget_open_tab/static/src/less/open_tab.less new file mode 100644 index 000000000..b4bb6fd11 --- /dev/null +++ b/web_widget_open_tab/static/src/less/open_tab.less @@ -0,0 +1,10 @@ +.open_tab_widget { + .child { + visibility: hidden; + } + &:hover { + .child { + visibility: visible; + } + } +} diff --git a/web_widget_open_tab/views/assets.xml b/web_widget_open_tab/views/assets.xml index 8f6b9b5a2..31ea81804 100644 --- a/web_widget_open_tab/views/assets.xml +++ b/web_widget_open_tab/views/assets.xml @@ -4,6 +4,7 @@