mirror of https://github.com/OCA/web.git
[IMP] web_widget_open_tab: black, isort
parent
92f0af2b3c
commit
95e946a121
|
@ -2,14 +2,14 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Widget Open on new Tab',
|
||||
'summary': """
|
||||
"name": "Widget Open on new Tab",
|
||||
"summary": """
|
||||
Allow to open record from trees on new tab from tree views""",
|
||||
'version': '12.0.1.0.1',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'Creu Blanca,Odoo Community Association (OCA)',
|
||||
'website': 'https://github.com/OCA/web',
|
||||
'depends': ['web'],
|
||||
'data': ['templates/assets.xml'],
|
||||
'demo': ['demo/res_users_view.xml'],
|
||||
"version": "12.0.1.0.1",
|
||||
"license": "AGPL-3",
|
||||
"author": "Creu Blanca,Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/web",
|
||||
"depends": ["web"],
|
||||
"data": ["templates/assets.xml"],
|
||||
"demo": ["demo/res_users_view.xml"],
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?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 name="id" widget="open_tab" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
@ -1,62 +1,65 @@
|
|||
odoo.define('web_widget_open_tab.FieldOpenTab', 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 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 FieldOpenTab = AbstractField.extend({
|
||||
description: "",
|
||||
// We want to maintain it black in order to show nothing on the header
|
||||
supportedFieldTypes: ['integer'],
|
||||
supportedFieldTypes: ["integer"],
|
||||
events: _.extend({}, AbstractField.prototype.events, {
|
||||
'click': '_onClick',
|
||||
click: "_onClick",
|
||||
}),
|
||||
isSet: function () {
|
||||
isSet: function() {
|
||||
return true;
|
||||
},
|
||||
_getReference: function () {
|
||||
_getReference: function() {
|
||||
var url = window.location.href;
|
||||
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');
|
||||
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();
|
||||
return url.split("#")[0] + "#" + searchParams.toString();
|
||||
},
|
||||
_renderReadonly: function () {
|
||||
_renderReadonly: function() {
|
||||
var $content = $("<a/>", {
|
||||
"href": this._getReference(),
|
||||
"class": "open_tab_widget fa fa-eye",
|
||||
href: this._getReference(),
|
||||
class: "open_tab_widget fa fa-eye",
|
||||
});
|
||||
var self = this;
|
||||
$content.tooltip({
|
||||
delay: { show: 1000, hide: 0 },
|
||||
title: function () {
|
||||
return qweb.render('WidgetButton.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')
|
||||
}
|
||||
help: _t("Click in order to open on new tab"),
|
||||
type: _t("Widget"),
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
this.$el.append($content);
|
||||
},
|
||||
_onClick: function (ev) {
|
||||
_onClick: function(ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
var element = $(ev.currentTarget).find('a');
|
||||
var element = $(ev.currentTarget).find("a");
|
||||
if (element != null && element[0].href != null) {
|
||||
window.open(this._getReference());
|
||||
}
|
||||
|
@ -65,17 +68,16 @@ odoo.define('web_widget_open_tab.FieldOpenTab', function(require) {
|
|||
ListRenderer.include({
|
||||
// We want to simplify the header of this kind of elements
|
||||
// and disallow sorting
|
||||
_renderHeaderCell: function (node) {
|
||||
_renderHeaderCell: function(node) {
|
||||
var $th = this._super.apply(this, arguments);
|
||||
if (node.attrs.widget === 'open_tab') {
|
||||
$th.removeClass('o_column_sortable');
|
||||
if (node.attrs.widget === "open_tab") {
|
||||
$th.removeClass("o_column_sortable");
|
||||
$th[0].width = 1;
|
||||
}
|
||||
return $th;
|
||||
},
|
||||
});
|
||||
|
||||
field_registry.add('open_tab', FieldOpenTab);
|
||||
field_registry.add("open_tab", FieldOpenTab);
|
||||
return FieldOpenTab;
|
||||
|
||||
});
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<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">
|
||||
<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>
|
||||
</template>
|
||||
|
||||
</odoo>
|
||||
|
|
Loading…
Reference in New Issue