Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
A pergunta foi fechada por motivo: Question / Code not indented
por Satish Prajapati em 06/08/2025 02:35:27
950 Visualizações

I am not understanding how can i Migrate BasicController in Odoo 18. 
This functionality is to keep the scroll position intact when user reloads the page, and show dialog when user closes odoo tab. 

If you can give just a method names from below code which are available in odoo 18 that would be great.

Below code is version 15.0

/** @odoo-module **/

import BasicController from 'web.BasicController';
import FormController from 'web.FormController';
import { patch } from 'web.utils';
import core from 'web.core';
import Dialog from 'web.Dialog';

var qweb = core.qweb;
var _t = core._t;

patch(BasicController.prototype, 'BasicController', {
reload: function () {
const prom = this._super.apply(this, arguments);
const $content = this.$('.o_content');
prom.finally($content.scrollTop.bind($content, $content.scrollTop()))
return prom;
},
leavePageConfirmation: async function(){
var self = this;
return new Promise(function (resolve, reject) {
var buttons = [{
classes: 'btn-primary',
click: () => {
resolve(true);
},
close: true,
text: _t('Leave'),
},
{
close: true,
text: _t('Stay'),
click: () => {
reject();
},
}];
new Dialog(self, _.extend({
size: 'medium',
buttons: buttons,
$content: $(qweb.render('leavePageConfirmation')),
title: _t("Alert"),
})).open({shouldFocusButtons:true});
});
},
saveChanges: async function (recordId) {
// waits for _applyChanges to finish
await this.mutex.getUnlockedDef();
recordId = recordId || this.handle;

if (this.isDirty(recordId)) {
if(this.mode == "edit"){
await this.leavePageConfirmation();
return Promise.resolve();
}
await this.savingDef;
await this.saveRecord(recordId, {
stayInEdit: true,
reload: false,
});
}
},
});

patch(FormController.prototype, 'FormController', {
update: function () {
const prom = this._super.apply(this, arguments);
const $content = this.$('.o_content');
prom.finally($content.scrollTop.bind($content, $content.scrollTop()))
return prom;
},
});
Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
0
nov. 24
2046
3
out. 23
5096
1
nov. 24
2357
0
mar. 25
987
1
out. 24
1403