diff --git a/web_widget_open_tab/README.rst b/web_widget_open_tab/README.rst index 6945c06a0..b7e716d7b 100644 --- a/web_widget_open_tab/README.rst +++ b/web_widget_open_tab/README.rst @@ -14,7 +14,7 @@ Widget Open on new Tab :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github - :target: https://github.com/OCA/web/tree/15.0/web_widget_open_tab + :target: https://github.com/OCA/web/tree/16.0/web_widget_open_tab :alt: OCA/web .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png :target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_widget_open_tab @@ -82,6 +82,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/web `_ project on GitHub. +This module is part of the `OCA/web `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_open_tab/__manifest__.py b/web_widget_open_tab/__manifest__.py index 3bfe26235..8ad5863f6 100644 --- a/web_widget_open_tab/__manifest__.py +++ b/web_widget_open_tab/__manifest__.py @@ -12,6 +12,9 @@ "depends": ["web"], "demo": ["demo/res_users_view.xml"], "assets": { - "web.assets_backend": ["web_widget_open_tab/static/src/js/widget.js"], + "web.assets_backend": [ + "web_widget_open_tab/static/src/xml/open_tab_widget.xml", + "web_widget_open_tab/static/src/js/open_tab_widget.esm.js", + ], }, } diff --git a/web_widget_open_tab/readme/CONTRIBUTORS.rst b/web_widget_open_tab/readme/CONTRIBUTORS.rst index 271468bb5..fa8a6cdea 100644 --- a/web_widget_open_tab/readme/CONTRIBUTORS.rst +++ b/web_widget_open_tab/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Enric Tobella * Raf Ven +* Dhara Solanki diff --git a/web_widget_open_tab/static/description/index.html b/web_widget_open_tab/static/description/index.html index 81c051d4e..2526d489b 100644 --- a/web_widget_open_tab/static/description/index.html +++ b/web_widget_open_tab/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

This addon introduces a new widget. When added to a field in a tree view, the field appears as a button which opens the record in a new tab. When clicking on the line (but not on the button), the record is opened in the same window (as in native Odoo).

@@ -423,7 +423,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/web project on GitHub.

+

This module is part of the OCA/web project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/web_widget_open_tab/static/src/js/open_tab_widget.esm.js b/web_widget_open_tab/static/src/js/open_tab_widget.esm.js new file mode 100644 index 000000000..1bb997362 --- /dev/null +++ b/web_widget_open_tab/static/src/js/open_tab_widget.esm.js @@ -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); diff --git a/web_widget_open_tab/static/src/js/widget.js b/web_widget_open_tab/static/src/js/widget.js deleted file mode 100644 index 822def867..000000000 --- a/web_widget_open_tab/static/src/js/widget.js +++ /dev/null @@ -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 = $("", { - 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; -}); diff --git a/web_widget_open_tab/static/src/xml/open_tab_widget.xml b/web_widget_open_tab/static/src/xml/open_tab_widget.xml new file mode 100644 index 000000000..b4e419784 --- /dev/null +++ b/web_widget_open_tab/static/src/xml/open_tab_widget.xml @@ -0,0 +1,14 @@ + +