mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[MIG] web_widget_open_tab: Migration to 16.0
This commit is contained in:
45
web_widget_open_tab/static/src/js/open_tab_widget.esm.js
Normal file
45
web_widget_open_tab/static/src/js/open_tab_widget.esm.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import {registry} from "@web/core/registry";
|
||||
import {standardFieldProps} from "@web/views/fields/standard_field_props";
|
||||
import {_lt} from "@web/core/l10n/translation";
|
||||
import {Component} from "@odoo/owl";
|
||||
|
||||
export class OpenTabWidget extends Component {
|
||||
openNewTab(ev) {
|
||||
ev.stopPropagation();
|
||||
}
|
||||
_getReference() {
|
||||
var url = window.location.href;
|
||||
var searchParams = new URLSearchParams(url.split("#")[1]);
|
||||
searchParams.set("view_type", "form");
|
||||
searchParams.set("id", this.props.value);
|
||||
if (
|
||||
!searchParams.has("model") ||
|
||||
searchParams.get("model") !== this.props.record.resModel
|
||||
) {
|
||||
searchParams.set("model", this.props.record.resModel);
|
||||
searchParams.delete("action");
|
||||
}
|
||||
return url.split("#")[0] + "#" + searchParams.toString();
|
||||
}
|
||||
loadAttrs(ev) {
|
||||
$(ev.target).tooltip();
|
||||
}
|
||||
}
|
||||
|
||||
OpenTabWidget.template = "web_widget_open_tab.openTab";
|
||||
OpenTabWidget.props = {
|
||||
...standardFieldProps,
|
||||
title: {type: String, optional: true},
|
||||
};
|
||||
|
||||
OpenTabWidget.displayName = _lt("Open Tab");
|
||||
OpenTabWidget.supportedTypes = ["integer"];
|
||||
OpenTabWidget.extractProps = () => {
|
||||
return {
|
||||
title: _lt("Click to open on new tab"),
|
||||
};
|
||||
};
|
||||
|
||||
registry.category("fields").add("open_tab", OpenTabWidget);
|
||||
@@ -1,83 +0,0 @@
|
||||
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 FieldOpenTab = AbstractField.extend({
|
||||
description: "",
|
||||
// We want to maintain it black in order to show nothing on the header
|
||||
supportedFieldTypes: ["integer"],
|
||||
events: _.extend({}, AbstractField.prototype.events, {
|
||||
click: "_onClick",
|
||||
}),
|
||||
isSet: function () {
|
||||
return true;
|
||||
},
|
||||
_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");
|
||||
}
|
||||
return url.split("#")[0] + "#" + searchParams.toString();
|
||||
},
|
||||
_renderReadonly: function () {
|
||||
var $content = $("<a/>", {
|
||||
href: this._getReference(),
|
||||
class: "open_tab_widget fa fa-external-link",
|
||||
});
|
||||
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) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
var element = $(ev.currentTarget).find("a");
|
||||
if (element !== null && element[0].href !== null) {
|
||||
window.open(this._getReference());
|
||||
}
|
||||
},
|
||||
});
|
||||
ListRenderer.include({
|
||||
// We want to simplify the header of this kind of elements
|
||||
// and disallow sorting
|
||||
_renderHeaderCell: function (node) {
|
||||
var $th = this._super.apply(this, arguments);
|
||||
if (node.attrs.widget === "open_tab") {
|
||||
$th.removeClass("o_column_sortable");
|
||||
$th[0].width = 1;
|
||||
}
|
||||
return $th;
|
||||
},
|
||||
});
|
||||
|
||||
field_registry.add("open_tab", FieldOpenTab);
|
||||
return FieldOpenTab;
|
||||
});
|
||||
14
web_widget_open_tab/static/src/xml/open_tab_widget.xml
Normal file
14
web_widget_open_tab/static/src/xml/open_tab_widget.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<template>
|
||||
<t t-name="web_widget_open_tab.openTab" owl="1">
|
||||
<a
|
||||
class="btn open_tab_widget fa fa-external-link"
|
||||
t-att-href="_getReference()"
|
||||
target="_blank"
|
||||
t-on-click="openNewTab"
|
||||
t-att-title="props.title"
|
||||
t-on-mouseenter="ev => this.loadAttrs(ev)"
|
||||
>
|
||||
</a>
|
||||
</t>
|
||||
</template>
|
||||
Reference in New Issue
Block a user