[12.0] web_widget_open_tab: Allow to open tab on dashboards or trees inside other forms

pull/1924/head
Enric Tobella 2020-02-21 10:08:36 +01:00 committed by Raf Ven
parent 3fc9b800fe
commit 5e9e204e41
5 changed files with 31 additions and 24 deletions

View File

@ -1,4 +1,4 @@
# Copyright 2019 Creu Blanca # Copyright 2019-2020 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
@ -9,10 +9,7 @@
'license': 'AGPL-3', 'license': 'AGPL-3',
'author': 'Creu Blanca,Odoo Community Association (OCA)', 'author': 'Creu Blanca,Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/web', 'website': 'https://github.com/OCA/web',
'depends': [ 'depends': ['web'],
'web' 'data': ['templates/assets.xml'],
], 'demo': ['demo/res_users_view.xml'],
'data': [
'views/assets.xml',
],
} }

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_users_tree" model="ir.ui.view">
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_tree" />
<field name="arch" type="xml">
<field name="name" position="before">
<field name="id" widget="open_tab"/>
</field>
</field>
</record>
</odoo>

View File

@ -11,6 +11,7 @@ odoo.define('web_widget_open_tab.FieldOpenTab', function(require) {
var FieldOpenTab = AbstractField.extend({ var FieldOpenTab = AbstractField.extend({
description: "", description: "",
// We want to maintain it black in order to show nothing on the header
supportedFieldTypes: ['integer'], supportedFieldTypes: ['integer'],
events: _.extend({}, AbstractField.prototype.events, { events: _.extend({}, AbstractField.prototype.events, {
'click': '_onClick', 'click': '_onClick',
@ -19,13 +20,21 @@ odoo.define('web_widget_open_tab.FieldOpenTab', function(require) {
return true; return true;
}, },
_getReference: function () { _getReference: function () {
var url = new URL(window.location.href); var url = window.location.href;
return url.hash.replace(/view_type=\w+/i, "view_type=form") + '&id=' + this.res_id; var searchParams = new URLSearchParams(url.split('#')[1]);
searchParams.set('view_type', 'form');
searchParams.set('id', this.res_id);
if (! searchParams.has('model') || searchParams.get('model') !== this.model) {
searchParams.set('model', this.model);
searchParams.delete('action');
}
return url.split('#')[0] + '#' + searchParams.toString();
}, },
_renderReadonly: function () { _renderReadonly: function () {
var $content = $( var $content = $("<a/>", {
'<a href="'+ this._getReference() + '">' "href": this._getReference(),
).addClass('open_tab_widget fa fa-eye'); "class": "open_tab_widget fa fa-eye",
});
var self = this; var self = this;
$content.tooltip({ $content.tooltip({
delay: { show: 1000, hide: 0 }, delay: { show: 1000, hide: 0 },
@ -42,7 +51,7 @@ odoo.define('web_widget_open_tab.FieldOpenTab', function(require) {
}); });
}, },
}); });
this.$el.append($content) this.$el.append($content);
}, },
_onClick: function (ev) { _onClick: function (ev) {
ev.preventDefault(); ev.preventDefault();

View File

@ -1,10 +0,0 @@
.open_tab_widget {
.child {
visibility: hidden;
}
&:hover {
.child {
visibility: visible;
}
}
}

View File

@ -4,7 +4,6 @@
<template id="assets_backend" name="tree icon assets" inherit_id="web.assets_backend"> <template id="assets_backend" name="tree icon assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<script type="text/javascript" src="/web_widget_open_tab/static/src/js/widget.js"/> <script type="text/javascript" src="/web_widget_open_tab/static/src/js/widget.js"/>
<link href="/web_widget_open_tab/static/src/less/open_tab.less" rel="stylesheet" type="text/less"/>
</xpath> </xpath>
</template> </template>