-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] web_field_tooltip: Migration to 16.0
- Loading branch information
Showing
24 changed files
with
402 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../web_field_tooltip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from . import base | ||
from . import ir_http | ||
from . import ir_model_fields_tooltip | ||
from . import res_users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from odoo import api, models | ||
|
||
|
||
class Base(models.AbstractModel): | ||
_inherit = "base" | ||
|
||
@api.model | ||
def fields_get(self, allfields=None, attributes=None): | ||
res = super().fields_get(allfields=allfields, attributes=attributes) | ||
fnames = res.keys() | ||
tooltips_data = ( | ||
self.env["ir.model.fields.tooltip"] | ||
.sudo() | ||
.search_read( | ||
[ | ||
("model", "=", self._name), | ||
("field_name", "in", list(fnames)), | ||
], | ||
[], | ||
) | ||
) | ||
for tooltip_data in tooltips_data: | ||
tooltip_fname = tooltip_data["field_name"] | ||
res[tooltip_fname]["field_tooltip"] = tooltip_data | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +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 that can contain links and | ||
the name of the user that last updated it. | ||
field of a model. The tooltip displays an html field. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
web_field_tooltip/static/src/components/field_tooltip/field_tooltip.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** @odoo-module */ | ||
|
||
import {Component, markup} from "@odoo/owl"; | ||
|
||
import {FormViewDialog} from "@web/views/view_dialogs/form_view_dialog"; | ||
import {session} from "@web/session"; | ||
import {usePopover} from "@web/core/popover/popover_hook"; | ||
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 = usePopover(); | ||
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"; |
35 changes: 35 additions & 0 deletions
35
web_field_tooltip/static/src/components/field_tooltip/field_tooltip.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
sup.field-tooltip { | ||
.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; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
web_field_tooltip/static/src/components/field_tooltip/field_tooltip.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates> | ||
|
||
<t t-name="web_field_tooltip.FieldTooltip" owl="1"> | ||
<sup | ||
class="field-tooltip" | ||
t-on-click="(ev) => this.onClickTooltip(ev)" | ||
t-on-mouseenter="(ev) => this.onMouseEnter(ev)" | ||
t-on-mouseleave="(ev) => this.onMouseLeave(ev)" | ||
> | ||
<a | ||
class="fa fa fa-question-circle tooltip-icon text-info" | ||
t-att-has-tooltip="props.hasFieldTooltip" | ||
/> | ||
</sup> | ||
</t> | ||
|
||
<t t-name="web_field_tooltip.FieldTooltipPopover" owl="1"> | ||
<div class="popup-div"> | ||
<div class="popover-title"> | ||
<span t-esc="props.title" /> | ||
</div> | ||
<p class="popover-content"> | ||
<t t-out="props.help or ''" /> | ||
</p> | ||
</div> | ||
</t> | ||
|
||
</templates> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.