diff --git a/web_field_tooltip/README.rst b/web_field_tooltip/README.rst index 7bc78982bdb0..f2f2f367e9ff 100644 --- a/web_field_tooltip/README.rst +++ b/web_field_tooltip/README.rst @@ -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** @@ -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 diff --git a/web_field_tooltip/__manifest__.py b/web_field_tooltip/__manifest__.py index 20cdcdaefb1e..2acac6fe37d0 100644 --- a/web_field_tooltip/__manifest__.py +++ b/web_field_tooltip/__manifest__.py @@ -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", ], }, } diff --git a/web_field_tooltip/migrations/17.0.1.0.0/post-migrate.py b/web_field_tooltip/migrations/17.0.1.0.0/post-migrate.py new file mode 100644 index 000000000000..fb8b42767505 --- /dev/null +++ b/web_field_tooltip/migrations/17.0.1.0.0/post-migrate.py @@ -0,0 +1,12 @@ +# Copyright 2024 Manuel Regidor +# 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)}) diff --git a/web_field_tooltip/models/ir_model_fields_tooltip.py b/web_field_tooltip/models/ir_model_fields_tooltip.py index ce7a87169dd3..017f954504a8 100644 --- a/web_field_tooltip/models/ir_model_fields_tooltip.py +++ b/web_field_tooltip/models/ir_model_fields_tooltip.py @@ -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): diff --git a/web_field_tooltip/readme/DESCRIPTION.md b/web_field_tooltip/readme/DESCRIPTION.md index a1afab609132..6ef5a1b9b261 100644 --- a/web_field_tooltip/readme/DESCRIPTION.md +++ b/web_field_tooltip/readme/DESCRIPTION.md @@ -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. diff --git a/web_field_tooltip/readme/USAGE.md b/web_field_tooltip/readme/USAGE.md index 77b2bdf4644e..80804230b373 100644 --- a/web_field_tooltip/readme/USAGE.md +++ b/web_field_tooltip/readme/USAGE.md @@ -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. diff --git a/web_field_tooltip/static/description/index.html b/web_field_tooltip/static/description/index.html index cdc28f5f1327..5c629b574933 100644 --- a/web_field_tooltip/static/description/index.html +++ b/web_field_tooltip/static/description/index.html @@ -370,7 +370,7 @@

Web Field Tooltip

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

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

diff --git a/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.esm.js b/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.esm.js deleted file mode 100644 index cfb9b25a6843..000000000000 --- a/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.esm.js +++ /dev/null @@ -1,85 +0,0 @@ -/** @odoo-module */ - -import {Component, markup} from "@odoo/owl"; - -import {FormViewDialog} from "@web/views/view_dialogs/form_view_dialog"; -import {session} from "@web/session"; -import {useService} from "@web/core/utils/hooks"; - -export class FieldTooltipPopover extends Component {} -FieldTooltipPopover.template = "web_field_tooltip.FieldTooltipPopover"; - -export class FieldTooltip extends Component { - setup() { - this.popover = useService("popover"); - this.tooltipPopover = null; - this.hasFieldTooltip = this.props.hasFieldTooltip; - this.canManageTooltip = session.can_manage_tooltips; - this.showAddHelper = - session.can_manage_tooltips && session.tooltip_show_add_helper; - this.fieldTooltip = this.props.field.field_tooltip; - - if (session.can_manage_tooltips) { - this.dialogService = useService("dialog"); - } - } - - get tooltipInfo() { - const props = this.props; - return { - title: props.field.string, - help: markup(this.tooltipText), - }; - } - - get tooltipText() { - return this.fieldTooltip.tooltip_text; - } - - onClickTooltip(e) { - e.preventDefault(); - e.stopPropagation(); - if (!this.canManageTooltip) { - return; - } - const tooltipId = (this.fieldTooltip && this.fieldTooltip.id) || false; - this.dialogService.add(FormViewDialog, { - resModel: "ir.model.fields.tooltip", - resId: tooltipId, - context: { - default_model: this.props.resModel, - default_field_name: this.props.fieldName, - }, - }); - } - - onMouseEnter(ev) { - if (!this.hasFieldTooltip) { - return; - } - this.closeTooltip(); - this.tooltipPopover = this.popover.add( - ev.currentTarget, - FieldTooltipPopover, - this.tooltipInfo, - { - closeOnClickAway: true, - position: "top", - title: "title", - } - ); - } - - onMouseLeave() { - this.closeTooltip(); - } - - closeTooltip() { - if (this.tooltipPopover) { - this.tooltipPopover(); - this.tooltipPopover = null; - } - } -} - -FieldTooltip.template = "web_field_tooltip.FieldTooltip"; diff --git a/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.scss b/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.scss deleted file mode 100644 index 26da3aaca2b1..000000000000 --- a/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.scss +++ /dev/null @@ -1,36 +0,0 @@ -sup.field-tooltip { - padding-top: 6px; - .tooltip-icon { - background: none; - border: none; - display: inline-block; - width: fit-content; - margin-left: 0px; - - &[has-tooltip] { - color: #666666 !important; - } - } - - &:hover { - cursor: pointer; - } -} - -.popup-div { - min-width: 100px; - min-height: 30px; - - > * { - padding: 5px; - } - - .popover-title { - font-weight: bold; - background-color: #f7f7f7; - } - - .popover-content { - background-color: white; - } -} diff --git a/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.xml b/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.xml deleted file mode 100644 index 4ab68c328e98..000000000000 --- a/web_field_tooltip/static/src/components/field_tooltip/field_tooltip.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - diff --git a/web_field_tooltip/static/src/views/form/form_label.esm.js b/web_field_tooltip/static/src/views/form/form_label.esm.js index c0b634b0e336..3ae0abdbf995 100644 --- a/web_field_tooltip/static/src/views/form/form_label.esm.js +++ b/web_field_tooltip/static/src/views/form/form_label.esm.js @@ -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; }, @@ -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, -}); diff --git a/web_field_tooltip/static/src/views/form/form_label.xml b/web_field_tooltip/static/src/views/form/form_label.xml index c724314e1e91..70bfdcb82da3 100644 --- a/web_field_tooltip/static/src/views/form/form_label.xml +++ b/web_field_tooltip/static/src/views/form/form_label.xml @@ -7,10 +7,8 @@ t-inherit-mode="extension" owl="1" > - - - - + + (ev) => this.onClickTooltip(ev) diff --git a/web_field_tooltip/static/src/views/list/list_renderer.esm.js b/web_field_tooltip/static/src/views/list/list_renderer.esm.js deleted file mode 100644 index c48baeaf15d9..000000000000 --- a/web_field_tooltip/static/src/views/list/list_renderer.esm.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @odoo-module **/ - -import {FieldTooltip} from "../../components/field_tooltip/field_tooltip.esm"; - -import {ListRenderer} from "@web/views/list/list_renderer"; -import {patch} from "@web/core/utils/patch"; - -import {session} from "@web/session"; - -const web_field_tooltip = { - showTooltipAddHelper() { - return session.tooltip_show_add_helper; - }, - - hasFieldTooltip(column) { - const fieldName = column.name; - const fields = this.props.list.fields; - return Boolean(fields[fieldName].field_tooltip); - }, - - getFieldTooltipProps(column) { - const props = this.props; - const fieldName = column.name; - const fields = props.list.fields; - return { - hasFieldTooltip: this.hasFieldTooltip(column), - resModel: props.list.resModel, - field: fields[fieldName], - fieldName: fieldName, - }; - }, -}; - -patch(ListRenderer.prototype, web_field_tooltip); - -ListRenderer.components = Object.assign({}, ListRenderer.components, { - FieldTooltip, -}); diff --git a/web_field_tooltip/static/src/views/list/list_renderer.xml b/web_field_tooltip/static/src/views/list/list_renderer.xml deleted file mode 100644 index a5203cd58c68..000000000000 --- a/web_field_tooltip/static/src/views/list/list_renderer.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - -
- - - -
-
- - d-block min-w-0 text-truncate - -
- -