3
0
Fork 0

[MIG] web_widget_open_tab: Migration to 16.0

16.0
dsolanki 2023-03-15 14:13:40 +05:30
parent e4016f967c
commit d89c70386b
7 changed files with 68 additions and 88 deletions

View File

@ -14,7 +14,7 @@ Widget Open on new Tab
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github .. |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 :alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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 :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 mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/15.0/web_widget_open_tab>`_ project on GitHub. This module is part of the `OCA/web <https://github.com/OCA/web/tree/16.0/web_widget_open_tab>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -12,6 +12,9 @@
"depends": ["web"], "depends": ["web"],
"demo": ["demo/res_users_view.xml"], "demo": ["demo/res_users_view.xml"],
"assets": { "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",
],
}, },
} }

View File

@ -1,2 +1,3 @@
* Enric Tobella <etobella@creublanca.es> * Enric Tobella <etobella@creublanca.es>
* Raf Ven <raf.ven@dynapps.be> * Raf Ven <raf.ven@dynapps.be>
* Dhara Solanki <dhara.solanki@initos.com>

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_widget_open_tab"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_widget_open_tab"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/16.0/web_widget_open_tab"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_widget_open_tab"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This addon introduces a new widget. <p>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 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).</p> When clicking on the line (but not on the button), the record is opened in the same window (as in native Odoo).</p>
@ -423,7 +423,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_widget_open_tab">OCA/web</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/16.0/web_widget_open_tab">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View 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);

View File

@ -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;
});

View 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>