-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[16.0][MIG] web_field_tooltip: Migration to 16.0 #2783
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75a08cc
[ADD] web_field_tooltip
baimont 4af5fe0
[IMP] web_field_tooltip - one rpc call
baimont 95a11fb
[IMP] display a helper to add a tooltip on a field. Display the toolt…
benwillig a1bc845
[REF] use FormViewDialog instead of do_action, allow to unlink a tool…
benwillig 746bfa6
[UPD] Update web_field_tooltip.pot
f65f71b
[BOT] post-merge updates
OCA-git-bot e729006
[MIG] web_field_tooltip: Migration to 16.0
benwillig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @benwillig, I created this PR to follow up your change to re-declaring the
field_name
(since thefield_name
below was not deleted, causing yourstore=True
change to seem to be overwritten). but I wonder why this change is made because when thefield_name
is not stored, the module still functions properly