3
0
Fork 0

[IMP] web_widget_open_tab: black, isort

16.0
Raf Ven 2020-09-29 13:42:50 +02:00 committed by dsolanki
parent 92f0af2b3c
commit 95e946a121
4 changed files with 56 additions and 49 deletions

View File

@ -2,14 +2,14 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Widget Open on new Tab', "name": "Widget Open on new Tab",
'summary': """ "summary": """
Allow to open record from trees on new tab from tree views""", Allow to open record from trees on new tab from tree views""",
'version': '12.0.1.0.1', "version": "12.0.1.0.1",
'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': ['web'], "depends": ["web"],
'data': ['templates/assets.xml'], "data": ["templates/assets.xml"],
'demo': ['demo/res_users_view.xml'], "demo": ["demo/res_users_view.xml"],
} }

View File

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

View File

@ -1,62 +1,65 @@
odoo.define('web_widget_open_tab.FieldOpenTab', function(require) { odoo.define("web_widget_open_tab.FieldOpenTab", function(require) {
"use strict"; "use strict";
var AbstractField = require('web.AbstractField'); var AbstractField = require("web.AbstractField");
var field_registry = require('web.field_registry'); var field_registry = require("web.field_registry");
var ListRenderer = require('web.ListRenderer'); var ListRenderer = require("web.ListRenderer");
var core = require('web.core'); var core = require("web.core");
var config = require('web.config'); var config = require("web.config");
var qweb = core.qweb; var qweb = core.qweb;
var _t = core._t; var _t = core._t;
var FieldOpenTab = AbstractField.extend({ var FieldOpenTab = AbstractField.extend({
description: "", description: "",
// We want to maintain it black in order to show nothing on the header // 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",
}), }),
isSet: function () { isSet: function() {
return true; return true;
}, },
_getReference: function () { _getReference: function() {
var url = window.location.href; var url = window.location.href;
var searchParams = new URLSearchParams(url.split('#')[1]); var searchParams = new URLSearchParams(url.split("#")[1]);
searchParams.set('view_type', 'form'); searchParams.set("view_type", "form");
searchParams.set('id', this.res_id); searchParams.set("id", this.res_id);
if (! searchParams.has('model') || searchParams.get('model') !== this.model) { if (
searchParams.set('model', this.model); !searchParams.has("model") ||
searchParams.delete('action'); searchParams.get("model") !== this.model
) {
searchParams.set("model", this.model);
searchParams.delete("action");
} }
return url.split('#')[0] + '#' + searchParams.toString(); return url.split("#")[0] + "#" + searchParams.toString();
}, },
_renderReadonly: function () { _renderReadonly: function() {
var $content = $("<a/>", { var $content = $("<a/>", {
"href": this._getReference(), href: this._getReference(),
"class": "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},
title: function () { title: function() {
return qweb.render('WidgetButton.tooltip', { return qweb.render("WidgetButton.tooltip", {
debug: config.debug, debug: config.debug,
state: self.record, state: self.record,
node: { node: {
attrs: { attrs: {
'help': _t('Click in order to open on new tab'), help: _t("Click in order to open on new tab"),
'type': _t('Widget') type: _t("Widget"),
} },
}, },
}); });
}, },
}); });
this.$el.append($content); this.$el.append($content);
}, },
_onClick: function (ev) { _onClick: function(ev) {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
var element = $(ev.currentTarget).find('a'); var element = $(ev.currentTarget).find("a");
if (element != null && element[0].href != null) { if (element != null && element[0].href != null) {
window.open(this._getReference()); window.open(this._getReference());
} }
@ -65,17 +68,16 @@ odoo.define('web_widget_open_tab.FieldOpenTab', function(require) {
ListRenderer.include({ ListRenderer.include({
// We want to simplify the header of this kind of elements // We want to simplify the header of this kind of elements
// and disallow sorting // and disallow sorting
_renderHeaderCell: function (node) { _renderHeaderCell: function(node) {
var $th = this._super.apply(this, arguments); var $th = this._super.apply(this, arguments);
if (node.attrs.widget === 'open_tab') { if (node.attrs.widget === "open_tab") {
$th.removeClass('o_column_sortable'); $th.removeClass("o_column_sortable");
$th[0].width = 1; $th[0].width = 1;
} }
return $th; return $th;
}, },
}); });
field_registry.add('open_tab', FieldOpenTab); field_registry.add("open_tab", FieldOpenTab);
return FieldOpenTab; return FieldOpenTab;
}); });

View File

@ -1,10 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" ?>
<odoo> <odoo>
<template
<template id="assets_backend" name="tree icon assets" inherit_id="web.assets_backend"> 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"
/>
</xpath> </xpath>
</template> </template>
</odoo> </odoo>