Skip to content

Commit

Permalink
[IMP]web_field_tooltip: refactoring for v17
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelregidor committed Jul 26, 2024
1 parent e74989d commit 4e592d7
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 248 deletions.
4 changes: 2 additions & 2 deletions web_field_tooltip/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Web Field Tooltip
|badge1| |badge2| |badge3| |badge4| |badge5|

This module gives the possibility to add tooltips next to fields labels
on any field of a model. The tooltip displays an html field.
on any field of a model.

**Table of contents**

Expand All @@ -48,7 +48,7 @@ To use this module, you need to:
- You can also go directly on the form view of a model on which you
want to add a tooltip and use the Manage tooltips Action to add a new
tooltip, or edit or delete existing tooltips for this model.
- For manager users, they can decide to display an helper to add a
- For manager users, they can decide to display a helper to add a
tooltip on a field as some fields are not displayed with a label.

Known issues / Roadmap
Expand Down
5 changes: 0 additions & 5 deletions web_field_tooltip/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
],
"assets": {
"web.assets_backend": [
"/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.esm.js",
"/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.scss",
"/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.xml",
"/web_field_tooltip/static/src/views/form/form_controller.esm.js",
"/web_field_tooltip/static/src/views/form/form_label.esm.js",
"/web_field_tooltip/static/src/views/form/form_label.xml",
"/web_field_tooltip/static/src/views/list/list_renderer.esm.js",
"/web_field_tooltip/static/src/views/list/list_renderer.xml",
],
},
}
12 changes: 12 additions & 0 deletions web_field_tooltip/migrations/17.0.1.0.0/post-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Manuel Regidor <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import SUPERUSER_ID, api
from odoo.tools import html2plaintext


def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})
tooltips = env["ir.model.fields.tooltip"].search([])
for tooltip in tooltips:
tooltip.write({"tooltip_text": html2plaintext(tooltip.tooltip_text)})
2 changes: 1 addition & 1 deletion web_field_tooltip/models/ir_model_fields_tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class IrModelFieldsTooltip(models.Model):
help="Set active to false to hide the Tooltip without removing it.",
)
field_name = fields.Char(related="field_id.name")
tooltip_text = fields.Html(required=True)
tooltip_text = fields.Text(required=True, translate=True)

@api.model
def default_get(self, fields_list):
Expand Down
2 changes: 1 addition & 1 deletion web_field_tooltip/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This module gives the possibility to add tooltips next to fields labels
on any field of a model. The tooltip displays an html field.
on any field of a model.
2 changes: 1 addition & 1 deletion web_field_tooltip/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ To use this module, you need to:
- You can also go directly on the form view of a model on which you want
to add a tooltip and use the Manage tooltips Action to add a new
tooltip, or edit or delete existing tooltips for this model.
- For manager users, they can decide to display an helper to add a
- For manager users, they can decide to display a helper to add a
tooltip on a field as some fields are not displayed with a label.
4 changes: 2 additions & 2 deletions web_field_tooltip/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ <h1 class="title">Web Field Tooltip</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/web/tree/17.0/web_field_tooltip"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_field_tooltip"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module gives the possibility to add tooltips next to fields labels
on any field of a model. The tooltip displays an html field.</p>
on any field of a model.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -396,7 +396,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<li>You can also go directly on the form view of a model on which you
want to add a tooltip and use the Manage tooltips Action to add a new
tooltip, or edit or delete existing tooltips for this model.</li>
<li>For manager users, they can decide to display an helper to add a
<li>For manager users, they can decide to display a helper to add a
tooltip on a field as some fields are not displayed with a label.</li>
</ul>
</div>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

84 changes: 68 additions & 16 deletions web_field_tooltip/static/src/views/form/form_label.esm.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/** @odoo-module **/

import {FieldTooltip} from "../../components/field_tooltip/field_tooltip.esm";

import {FormLabel} from "@web/views/form/form_label";
import {FormViewDialog} from "@web/views/view_dialogs/form_view_dialog";
import {patch} from "@web/core/utils/patch";

import {session} from "@web/session";
import {useService} from "@web/core/utils/hooks";

const web_field_tooltip = {
setup() {
super.setup();
this.canManageTooltip = session.can_manage_tooltips;
if (session.can_manage_tooltips) {
this.dialogService = useService("dialog");
}
},

get showTooltipAddHelper() {
return session.tooltip_show_add_helper;
},
Expand All @@ -17,20 +24,65 @@ const web_field_tooltip = {
return Boolean(props.record.fields[props.fieldName].field_tooltip);
},

get getFieldTooltipProps() {
const props = this.props;
const record = props.record;
return {
hasFieldTooltip: this.hasFieldTooltip,
resModel: record.resModel,
field: record.fields[props.fieldName],
fieldName: props.fieldName,
};
get tooltipHelp() {
let help = super.tooltipHelp;
const field = this.props.record.fields[this.props.fieldName];
if (field.field_tooltip) {
help = [help, field.field_tooltip.tooltip_text].filter((x) => x).join("\n");
}
return help;
},

get hasTooltip() {
let has_too_tip = super.hasTooltip;
if (this.showTooltipAddHelper && !has_too_tip) {
has_too_tip = true;
}
return has_too_tip;
},

get tooltipInfo() {
if (odoo.debug) {
if (this.hasFieldTooltip) {
const field = this.props.record.fields[this.props.fieldName];
if (this.props.fieldInfo.help) {
this.props.fieldInfo.help = [
this.props.fieldInfo.help,
field.field_tooltip.tooltip_text,
]
.filter((x) => x)
.join("\n");
} else {
this.props.record.fields[this.props.fieldName].help = [
field.help,
field.field_tooltip.tooltip_text,
]
.filter((x) => x)
.join("\n");
}
}
}
return super.tooltipInfo;
},

onClickTooltip(ev) {
ev.preventDefault();
ev.stopPropagation();
if (!this.canManageTooltip) {
return;
}
const field = this.props.record.fields[this.props.fieldName];
const fieldTooltip = field.field_tooltip;
const tooltipId = (fieldTooltip && fieldTooltip.id) || false;
this.dialogService.add(FormViewDialog, {
resModel: "ir.model.fields.tooltip",
resId: tooltipId,
context: {
default_model: this.props.record.resModel,
default_field_name: field.name,
},
});
},
};

patch(FormLabel.prototype, web_field_tooltip);

FormLabel.components = Object.assign({}, FormLabel.components, {
FieldTooltip,
});
6 changes: 2 additions & 4 deletions web_field_tooltip/static/src/views/form/form_label.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//sup" position="before">
<t t-if="hasFieldTooltip or showTooltipAddHelper">
<FieldTooltip t-props="getFieldTooltipProps" />
</t>
<xpath expr="//sup" position="attributes">
<attribute name="t-on-click">(ev) => this.onClickTooltip(ev)</attribute>
</xpath>
</t>

Expand Down
38 changes: 0 additions & 38 deletions web_field_tooltip/static/src/views/list/list_renderer.esm.js

This file was deleted.

Loading

0 comments on commit 4e592d7

Please sign in to comment.