Skip to content

Commit c9150b9

Browse files
agau-odoodetrouxdev
authored andcommitted
[REF] web_editor: convert SelectTemplate option to Owl
task-3850413
1 parent a094064 commit c9150b9

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

addons/web_editor/static/src/js/editor/snippets.options.js

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ export class UserValue {
742742
* Opens the widget (only meaningful for widgets that can be opened).
743743
*/
744744
open() {
745-
this.env.userValueWidgetOpening();
745+
this.env.userValueWidgetOpening(this);
746746
this._state.opened = true;
747747
}
748748
/**
@@ -10164,28 +10164,36 @@ export class MultipleItems extends SnippetOption {
1016410164
_removeItemCallback($target) {}
1016510165
}
1016610166

10167-
legacyRegistry.SelectTemplate = SnippetOptionWidget.extend({
10168-
custom_events: Object.assign({}, SnippetOptionWidget.prototype.custom_events, {
10169-
'user_value_widget_opening': '_onWidgetOpening',
10170-
}),
10167+
export class SelectTemplateComponent extends SnippetOptionComponent {
10168+
setup() {
10169+
super.setup();
10170+
useChildSubEnv({
10171+
userValueWidgetOpening: (userValue) => {
10172+
this.env.userValueWidgetOpening(userValue);
10173+
this.props.snippetOption.instance.onUserValueWidgetOpening(userValue);
10174+
},
10175+
});
10176+
}
10177+
}
1017110178

10179+
export class SelectTemplate extends SnippetOption {
1017210180
/**
10173-
* @constructor
10181+
* @override
1017410182
*/
10175-
init() {
10176-
this._super(...arguments);
10183+
static defaultRenderingComponent = SelectTemplateComponent;
10184+
10185+
constructor() {
10186+
super(...arguments);
1017710187
this.containerSelector = '';
1017810188
this.selectTemplateWidgetName = '';
10179-
this.orm = this.bindService("orm");
10180-
},
10181-
/**
10182-
* @constructor
10183-
*/
10184-
async start() {
10189+
this.orm = this.env.services.orm;
10190+
}
10191+
10192+
async willStart() {
10193+
await super.willStart(...arguments);
1018510194
this.containerEl = this.containerSelector ? this.$target.find(this.containerSelector)[0] : this.$target[0];
1018610195
this._templates = {};
10187-
return this._super(...arguments);
10188-
},
10196+
}
1018910197

1019010198
//--------------------------------------------------------------------------
1019110199
// Options
@@ -10234,7 +10242,7 @@ legacyRegistry.SelectTemplate = SnippetOptionWidget.extend({
1023410242
// added by other options or custo).
1023510243
this.beforePreviewNodes = null;
1023610244
}
10237-
},
10245+
}
1023810246

1023910247
//--------------------------------------------------------------------------
1024010248
// Private
@@ -10245,7 +10253,7 @@ legacyRegistry.SelectTemplate = SnippetOptionWidget.extend({
1024510253
*
1024610254
* @private
1024710255
* @param {string} xmlid
10248-
* @returns {string}
10256+
* @returns {Promise<string>}
1024910257
*/
1025010258
async _getTemplate(xmlid) {
1025110259
if (!this._templates[xmlid]) {
@@ -10257,21 +10265,20 @@ legacyRegistry.SelectTemplate = SnippetOptionWidget.extend({
1025710265
);
1025810266
}
1025910267
return this._templates[xmlid];
10260-
},
10268+
}
1026110269

1026210270
//--------------------------------------------------------------------------
1026310271
// Handlers
1026410272
//--------------------------------------------------------------------------
1026510273

1026610274
/**
10267-
* @private
10268-
* @param {OdooEvent} ev
10275+
* @override
1026910276
*/
10270-
_onWidgetOpening(ev) {
10271-
if (this._templatesLoading || ev.target.getName() !== this.selectTemplateWidgetName) {
10277+
onUserValueWidgetOpening(userValue) {
10278+
if (this._templatesLoading || userValue.getName() !== this.selectTemplateWidgetName) {
1027210279
return;
1027310280
}
10274-
const templateParams = ev.target.getMethodsParams('selectTemplate');
10281+
const templateParams = userValue.getMethodsParams('selectTemplate');
1027510282
const proms = templateParams.possibleValues.map(async xmlid => {
1027610283
if (!xmlid) {
1027710284
return;
@@ -10282,8 +10289,8 @@ legacyRegistry.SelectTemplate = SnippetOptionWidget.extend({
1028210289
await this._getTemplate(xmlid);
1028310290
});
1028410291
this._templatesLoading = Promise.all(proms);
10285-
},
10286-
});
10292+
}
10293+
}
1028710294

1028810295
/*
1028910296
* Abstract option to be extended by the Carousel and gallery options (through

0 commit comments

Comments
 (0)