Skip to content

Commit d3247e5

Browse files
committed
[MIG] web_help: Migration to 18.0
Changes for legacy view support [FIX] web_help: Fix for handling change in the way doAction works in v18
1 parent 416d14e commit d3247e5

File tree

8 files changed

+61
-56
lines changed

8 files changed

+61
-56
lines changed

web_help/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Onestein,Odoo Community Association (OCA)",
55
"category": "Technical",
66
"license": "AGPL-3",
7-
"version": "16.0.2.0.0",
7+
"version": "18.0.1.0.0",
88
"website": "https://github.com/OCA/web",
99
"depends": [
1010
"web",

web_help/static/src/change_password_trip.esm.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/** @odoo-module **/
21
import {Trip} from "@web_help/trip.esm";
2+
import {_t} from "@web/core/l10n/translation";
33
import {registry} from "@web/core/registry";
44

55
export class ChangePasswordTrip extends Trip {
66
setup() {
77
this.addStep({
88
selector: "th[data-name='new_passwd'], td[name='new_passwd']",
9-
content: this.env._t("Change the password here, make sure it's secure."),
9+
content: _t("Change the password here, make sure it's secure."),
1010
});
1111

1212
this.addStep({
1313
selector: "button[name='change_password_button']",
14-
content: this.env._t("Click here to confirm it."),
14+
content: _t("Click here to confirm it."),
1515
});
1616
}
1717
}
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
/** @odoo-module **/
2-
import LegacyControlPanel from "web.ControlPanel";
3-
import {ControlPanel} from "@web/search/control_panel/control_panel";
4-
import {findTrip} from "@web_help/helpers.esm";
51
import {Component, onWillStart, useState} from "@odoo/owl";
62
import {ActionDialog} from "@web/webclient/actions/action_dialog";
3+
import {ControlPanel} from "@web/search/control_panel/control_panel";
4+
import {findTrip} from "@web_help/helpers.esm";
5+
import {useService} from "@web/core/utils/hooks";
76

87
export class HelpButton extends Component {
8+
static props = {
9+
actionId: {type: [Number, String, Boolean], optional: true},
10+
resModel: {type: String, optional: true},
11+
viewType: {type: String, optional: true},
12+
btnClass: {type: String, optional: true},
13+
};
914
setup() {
15+
this.actionService = useService("action");
1016
this.state = useState({
1117
TripClass: null,
1218
});
1319
onWillStart(async () => {
14-
const foundTrip = await findTrip(this.props.resModel, this.props.viewType);
15-
this.state.TripClass = foundTrip;
20+
const actionId = this.props.actionId;
21+
const action = actionId
22+
? await this.actionService.loadAction(actionId)
23+
: {};
24+
if ("res_model" in action) {
25+
const foundTrip = await findTrip(action.res_model, this.props.viewType);
26+
this.state.TripClass = foundTrip;
27+
}
1628
});
1729
}
1830

@@ -27,5 +39,4 @@ export class HelpButton extends Component {
2739
HelpButton.template = "web_help.HelpButton";
2840

2941
Object.assign(ControlPanel.components, {HelpButton});
30-
Object.assign(LegacyControlPanel.components, {HelpButton});
3142
Object.assign(ActionDialog.components, {HelpButton});

web_help/static/src/components/help_button/help_button.xml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,14 @@
1111
<i class="fa fa-question" />
1212
</button>
1313
</t>
14-
<t t-inherit="web.ControlPanel.Regular" t-inherit-mode="extension">
15-
<xpath expr="//div[hasclass('o_cp_bottom_right')]" t-operation="inside">
16-
<nav class="btn-group">
17-
<HelpButton
18-
resModel="env.searchModel.resModel"
19-
viewType="env.config.viewType"
20-
/>
21-
</nav>
22-
</xpath>
23-
</t>
24-
<t t-inherit="web.ControlPanel.Small" t-inherit-mode="extension">
25-
<xpath expr="//div[hasclass('o_cp_bottom_right')]" t-operation="inside">
14+
<t t-inherit="web.ControlPanel" t-inherit-mode="extension">
15+
<xpath
16+
expr="//div[hasclass('o_control_panel_navigation')]"
17+
t-operation="inside"
18+
>
2619
<nav class="btn-group">
2720
<HelpButton
28-
resModel="env.searchModel.resModel"
21+
actionId="env.config.actionId"
2922
viewType="env.config.viewType"
3023
/>
3124
</nav>

web_help/static/src/components/highlighter/highlighter.esm.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
/** @odoo-module **/
21
import {Component, EventBus, useRef, useState} from "@odoo/owl";
32
import {registry} from "@web/core/registry";
3+
import {sprintf} from "@web/core/utils/strings";
44

55
export class Highlighter extends Component {
6+
static props = {
7+
bus: {type: EventBus},
8+
};
69
setup() {
710
this.state = useState({visible: false});
8-
this.bus = this.props.bus;
9-
this.bus.on("hide", this, () => this.hide());
10-
this.bus.on("highlight", this, (options) => this.highlight(options));
11+
this.props.bus.addEventListener("HIDE", this.hide.bind(this));
12+
this.props.bus.addEventListener(
13+
"HIGHLIGHT",
14+
({detail: {selector, content, animate, padding}}) =>
15+
this.highlight(selector, content, animate, padding)
16+
);
1117
this.highlightRef = useRef("highlightRef");
1218
this.overlayRef = useRef("overlay");
1319
}
@@ -47,7 +53,7 @@ export class Highlighter extends Component {
4753
return bounds;
4854
}
4955

50-
highlight({selector, content, animate = 250, padding = 10}) {
56+
highlight(selector, content, animate = 250, padding = 10) {
5157
const selection = $(selector);
5258

5359
if (!selection.length) {
@@ -64,15 +70,15 @@ export class Highlighter extends Component {
6470
$el.popover("dispose");
6571
$el.animate(
6672
{
67-
top: _.str.sprintf("%spx", Math.floor(bounds.y) - padding),
68-
left: _.str.sprintf("%spx", Math.floor(bounds.x) - padding),
69-
width: _.str.sprintf("%spx", Math.floor(bounds.width) + padding * 2),
70-
height: _.str.sprintf("%spx", Math.floor(bounds.height) + padding * 2),
73+
top: sprintf("%spx", Math.floor(bounds.y) - padding),
74+
left: sprintf("%spx", Math.floor(bounds.x) - padding),
75+
width: sprintf("%spx", Math.floor(bounds.width) + padding * 2),
76+
height: sprintf("%spx", Math.floor(bounds.height) + padding * 2),
7177
},
7278
animate ? animate : 0,
7379
function () {
7480
$el.popover(
75-
_.extend(this._getPopoverOptions(), {
81+
Object.assign({}, this._getPopoverOptions(), {
7682
content: content,
7783
})
7884
).popover("show");
@@ -116,9 +122,9 @@ export const highlighterService = {
116122
});
117123

118124
return {
119-
hide: () => bus.trigger("hide"),
125+
hide: () => bus.trigger("HIDE"),
120126
highlight: (selector, content, animate = 250, padding = 10) =>
121-
bus.trigger("highlight", {
127+
bus.trigger("HIGHLIGHT", {
122128
selector: selector,
123129
content: content,
124130
animate: animate,

web_help/static/src/helpers.esm.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/** @odoo-module **/
2-
import {registry} from "@web/core/registry";
31
import {Component} from "@odoo/owl";
2+
import {registry} from "@web/core/registry";
43

54
export async function findTrip(model, viewType) {
65
const trips = registry.category("trips").getAll();
@@ -9,7 +8,7 @@ export async function findTrip(model, viewType) {
98
);
109
const matchedTrips = trips.filter((trip, i) => selectorResults[i]);
1110
if (matchedTrips.length >= 1) {
12-
if (matchedTrips.length != 1) {
11+
if (matchedTrips.length !== 1) {
1312
console.warn("More than one trip found", model, viewType);
1413
}
1514
return matchedTrips[0].Trip;
@@ -33,8 +32,5 @@ export async function waitUntilAvailable(selector, ms = 50) {
3332
}
3433

3534
export async function doAction(xmlId, options = {}) {
36-
Component.env.bus.trigger("do-action", {
37-
action: xmlId,
38-
options: options,
39-
});
35+
Component.env.services.action.doAction(xmlId, options);
4036
}

web_help/static/src/trip.esm.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/** @odoo-module **/
1+
import {_t} from "@web/core/l10n/translation";
2+
import {ensureJQuery} from "@web/core/ensure_jquery";
23
import {renderToString} from "@web/core/utils/render";
34

45
export class Trip {
@@ -66,10 +67,8 @@ export class Trip {
6667
return Object.assign(
6768
{
6869
content: step.content,
69-
cbBtnText: this.isAtLastStep
70-
? this.env._t("Finish")
71-
: this.env._t("Got it"),
72-
closeBtnText: this.env._t("Close"),
70+
cbBtnText: this.isAtLastStep ? _t("Finish") : _t("Got it"),
71+
closeBtnText: _t("Close"),
7372
},
7473
step.renderContext
7574
);
@@ -82,7 +81,7 @@ export class Trip {
8281
cb = this.stop;
8382
}
8483
const step = this.steps[this.index];
85-
84+
await ensureJQuery();
8685
const $stepRender = $(
8786
renderToString(this._getStepTemplate(), this._getStepRenderContext())
8887
);

web_help/static/src/user_trip.esm.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
/** @odoo-module **/
21
import {Trip} from "@web_help/trip.esm";
2+
import {_t} from "@web/core/l10n/translation";
33
import {registry} from "@web/core/registry";
44

55
export class UserTrip extends Trip {
66
setup() {
77
this.addStep({
88
selector: ".o_list_button_add, .o-kanban-button-new",
9-
content: this.env._t("To create a new user click here."),
9+
content: _t("To create a new user click here."),
1010
});
1111

1212
this.addStep({
13-
selector: ".o_cp_searchview, .o_enable_searchview",
14-
content: this.env._t("Use the searchbar to find specific users."),
13+
selector: ".o_cp_searchview",
14+
content: _t("Use the searchbar to find specific users."),
1515
renderContext: {
16-
cbBtnText: this.env._t("Next"),
17-
closeBtnText: this.env._t("Cancel"),
16+
cbBtnText: _t("Next"),
17+
closeBtnText: _t("Cancel"),
1818
},
1919
});
2020

2121
this.addStep({
2222
selector: ".o_cp_switch_buttons",
23-
content: this.env._t("You can switch to different views here."),
23+
content: _t("You can switch to different views here."),
2424
});
2525
}
2626
}

0 commit comments

Comments
 (0)