[FIX] website_event: fix frontend track edition
When editing a field on a track, a traceback was raised because the fields website_menu and website_url are not present in the event.track model. Now we always use the event.event model and we get the event object id from the url. We also set the url as the current one to stay on the same page after reloading it. task-2942617 closes odoo/odoo#102545 X-original-commit: 5f1f082dbe268522f8fc7e63ad5f564b25020a22 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -9,21 +9,19 @@ options.registry.WebsiteEvent = options.Class.extend({
|
||||
*/
|
||||
async start() {
|
||||
const res = await this._super(...arguments);
|
||||
const eventObject = this._getEventObject();
|
||||
this.modelName = eventObject.model;
|
||||
this.eventId = eventObject.id;
|
||||
this.currentWebsiteUrl = this.ownerDocument.location.pathname;
|
||||
this.eventId = this._getEventObjectId();
|
||||
// Only need for one RPC request as the option will be destroyed if a
|
||||
// change is made.
|
||||
const rpcData = await this._rpc({
|
||||
model: this.modelName,
|
||||
model: 'event.event',
|
||||
method: 'read',
|
||||
args: [
|
||||
[this.eventId],
|
||||
['website_menu', 'website_url'],
|
||||
['website_menu'],
|
||||
],
|
||||
});
|
||||
this.eventUrl = rpcData[0]['website_url'];
|
||||
this.data.reload = this.eventUrl;
|
||||
this.data.reload = this.currentWebsiteUrl;
|
||||
this.websiteMenu = rpcData[0]['website_menu'];
|
||||
return res;
|
||||
},
|
||||
@@ -37,7 +35,7 @@ options.registry.WebsiteEvent = options.Class.extend({
|
||||
*/
|
||||
displaySubmenu(previewMode, widgetValue, params) {
|
||||
return this._rpc({
|
||||
model: this.modelName,
|
||||
model: 'event.event',
|
||||
method: 'toggle_website_menu',
|
||||
args: [[this.eventId], widgetValue],
|
||||
});
|
||||
@@ -59,14 +57,12 @@ options.registry.WebsiteEvent = options.Class.extend({
|
||||
return this._super(...arguments);
|
||||
},
|
||||
/**
|
||||
* Ensure that we get the event object id as we could be inside a sub-object of the event
|
||||
* like an event.track
|
||||
* @private
|
||||
*/
|
||||
_getEventObject() {
|
||||
const repr = this.ownerDocument.documentElement.dataset.mainObject;
|
||||
const m = repr.match(/(.+)\((\d+),(.*)\)/);
|
||||
return {
|
||||
model: m[1],
|
||||
id: m[2] | 0,
|
||||
};
|
||||
_getEventObjectId() {
|
||||
const objectIds = this.currentWebsiteUrl.match(/(?<=-)\d+(?![-\w\d])/);
|
||||
return parseInt(objectIds[0]) | 0;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user