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 24, 2024
1 parent e74989d commit fe9f378
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 242 deletions.
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",
],
},
}
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

This file was deleted.

This file was deleted.

This file was deleted.

60 changes: 44 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,41 @@ 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;
},

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.

28 changes: 0 additions & 28 deletions web_field_tooltip/static/src/views/list/list_renderer.xml

This file was deleted.

0 comments on commit fe9f378

Please sign in to comment.