forked from Techsystech/web
[MIG] web_tree_many2one_clickable: Migration to 16.0
[MIG] web_tree_many2one_clickable: Migration to 16.0 [MIG] web_tree_many2one_clickable: Migration to 16.0 [MIG] web_tree_many2one_clickable: Migration to 16.016.0
parent
a35adee9d7
commit
efe053e9db
|
@ -7,12 +7,13 @@
|
||||||
{
|
{
|
||||||
"name": "Clickable many2one fields for tree views",
|
"name": "Clickable many2one fields for tree views",
|
||||||
"summary": "Open the linked resource when clicking on their name",
|
"summary": "Open the linked resource when clicking on their name",
|
||||||
"version": "15.0.1.0.0",
|
"version": "16.0.1.0.0",
|
||||||
"category": "Hidden",
|
"category": "Hidden",
|
||||||
"website": "https://github.com/OCA/web",
|
"website": "https://github.com/OCA/web",
|
||||||
"author": "Therp BV, "
|
"author": "Therp BV, "
|
||||||
"Tecnativa, "
|
"Tecnativa, "
|
||||||
"Camptocamp, "
|
"Camptocamp, "
|
||||||
|
"Onestein, "
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"installable": True,
|
"installable": True,
|
||||||
|
@ -20,10 +21,12 @@
|
||||||
"data": [],
|
"data": [],
|
||||||
"assets": {
|
"assets": {
|
||||||
"web.assets_backend": [
|
"web.assets_backend": [
|
||||||
"web_tree_many2one_clickable/static/src/js/*.js",
|
"web_tree_many2one_clickable/static/src/components/"
|
||||||
],
|
"many2one_button/many2one_button.esm.js",
|
||||||
"web.assets_common": [
|
"web_tree_many2one_clickable/static/src/components/"
|
||||||
"web_tree_many2one_clickable/static/src/css/web_tree_many2one_clickable.scss",
|
"many2one_button/many2one_button.scss",
|
||||||
],
|
"web_tree_many2one_clickable/static/src/components/"
|
||||||
|
"many2one_button/many2one_button.xml",
|
||||||
|
]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,3 +5,4 @@
|
||||||
* Artem Kostyuk <a.kostyuk@mobilunity.com>
|
* Artem Kostyuk <a.kostyuk@mobilunity.com>
|
||||||
* Anand Kansagra <kansagraanand@hotmail.com>
|
* Anand Kansagra <kansagraanand@hotmail.com>
|
||||||
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
|
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
|
||||||
|
* Dennis Sluijk <d.sluijk@onestein.nl>
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/** @odoo-module */
|
||||||
|
/* Copyright 2013 Therp BV (<http://therp.nl>).
|
||||||
|
* Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
|
||||||
|
* Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||||
|
* Copyright 2017 Sodexis <dev@sodexis.com>
|
||||||
|
* Copyright 2018 Camptocamp SA
|
||||||
|
* Copyright 2019 Alexandre Díaz <alexandre.diaz@tecnativa.com>
|
||||||
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||||
|
|
||||||
|
import {ListRenderer} from "@web/views/list/list_renderer";
|
||||||
|
import {Component} from "@odoo/owl";
|
||||||
|
import {useService} from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
export class TreeMany2oneClickableButton extends Component {
|
||||||
|
setup() {
|
||||||
|
this.actionService = useService("action");
|
||||||
|
}
|
||||||
|
|
||||||
|
async onClick(ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
return this.actionService.doAction({
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
res_model: this.props.field.relation,
|
||||||
|
res_id: this.props.value[0],
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "target",
|
||||||
|
additionalContext: this.props.context || {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TreeMany2oneClickableButton.template = "web_tree_many2one_clickable.Button";
|
||||||
|
|
||||||
|
Object.assign(ListRenderer.components, {TreeMany2oneClickableButton});
|
|
@ -0,0 +1,10 @@
|
||||||
|
td.o_list_many2one {
|
||||||
|
button.web_tree_many2one_clickable {
|
||||||
|
margin-left: 0.5em;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover button.web_tree_many2one_clickable {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="web_tree_many2one_clickable.Button" owl="1">
|
||||||
|
<button
|
||||||
|
class="btn btn-sm btn-secondary fa fa-arrow-right web_tree_many2one_clickable"
|
||||||
|
t-on-click="onClick"
|
||||||
|
>
|
||||||
|
</button>
|
||||||
|
</t>
|
||||||
|
|
||||||
|
<t t-inherit="web.ListRenderer.RecordRow" t-inherit-mode="extension">
|
||||||
|
<xpath expr="//Field" position="after">
|
||||||
|
<TreeMany2oneClickableButton
|
||||||
|
record="record"
|
||||||
|
field="record.fields[column.name]"
|
||||||
|
value="record.data[column.name]"
|
||||||
|
t-if="record.fields[column.name].type == 'many2one' and record.data[column.name] and canUseFormatter(column, record) and !props.archInfo.fieldNodes[column.name].options.no_open"
|
||||||
|
/>
|
||||||
|
</xpath>
|
||||||
|
</t>
|
||||||
|
</templates>
|
|
@ -1,10 +0,0 @@
|
||||||
td.o_many2one_cell {
|
|
||||||
a {
|
|
||||||
margin-left: 0.5em;
|
|
||||||
visibility: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover a {
|
|
||||||
visibility: visible;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/* Copyright 2013 Therp BV (<http://therp.nl>).
|
|
||||||
* Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
|
|
||||||
* Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
|
||||||
* Copyright 2017 Sodexis <dev@sodexis.com>
|
|
||||||
* Copyright 2018 Camptocamp SA
|
|
||||||
* Copyright 2019 Alexandre Díaz <alexandre.diaz@tecnativa.com>
|
|
||||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
|
||||||
|
|
||||||
odoo.define("web_tree_many2one_clickable.many2one_clickable", function (require) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var ListRenderer = require("web.ListRenderer");
|
|
||||||
var ListFieldMany2One = require("web.relational_fields").ListFieldMany2One;
|
|
||||||
|
|
||||||
ListRenderer.include({
|
|
||||||
_renderBodyCell: function (record, node, colIndex, options) {
|
|
||||||
if (
|
|
||||||
!node.attrs.widget &&
|
|
||||||
node.attrs.name &&
|
|
||||||
this.state.fields[node.attrs.name] &&
|
|
||||||
this.state.fields[node.attrs.name].type === "many2one"
|
|
||||||
) {
|
|
||||||
// No explicit widget provided on a many2one field,
|
|
||||||
// force `many2one` widget
|
|
||||||
node.attrs.widget = "many2one";
|
|
||||||
}
|
|
||||||
return this._super(record, node, colIndex, options);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
ListFieldMany2One.include({
|
|
||||||
_renderReadonly: function () {
|
|
||||||
this._super.apply(this, arguments);
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (!this.noOpen && this.value) {
|
|
||||||
// Replace '<a>' element
|
|
||||||
this.$el.removeClass("o_form_uri");
|
|
||||||
this.$el = $("<span/>", {
|
|
||||||
html: this.$el.html(),
|
|
||||||
class: this.$el.attr("class") + " o_field_text",
|
|
||||||
name: this.$el.attr("name"),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Append button
|
|
||||||
var $a = $("<a/>", {
|
|
||||||
href: "#",
|
|
||||||
class: "o_form_uri btn btn-sm btn-secondary fa fa-angle-double-right",
|
|
||||||
}).on("click", function (ev) {
|
|
||||||
ev.preventDefault();
|
|
||||||
ev.stopPropagation();
|
|
||||||
|
|
||||||
self.do_action({
|
|
||||||
type: "ir.actions.act_window",
|
|
||||||
res_model: self.field.relation,
|
|
||||||
res_id: self.value.res_id,
|
|
||||||
views: [[false, "form"]],
|
|
||||||
target: "target",
|
|
||||||
context: self.record.getContext({
|
|
||||||
additionalContext: self.attrs.context || {},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.$el.append($a);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in New Issue