[IMP] runbot: prevent saving on switching tab

Auto save mechanism when switching tab is unwanted in runbot, most of
the time we will use other tabs to get the data necessary for the record
we are modifying/creating and we don't care about saving yet.
We also prevent closing the window if the record is dirty.
Auto save in pager and context switch is still kept.
This commit is contained in:
William Braeckman 2025-03-12 09:52:24 +01:00 committed by xdo
parent d8d9f411b1
commit ea9b714e6c
2 changed files with 20 additions and 0 deletions

View File

@ -64,6 +64,7 @@
'assets': { 'assets': {
'web.assets_backend': [ 'web.assets_backend': [
'runbot/static/src/libs/diff_match_patch/diff_match_patch.js', 'runbot/static/src/libs/diff_match_patch/diff_match_patch.js',
'runbot/static/src/js/views/**/*',
'runbot/static/src/js/fields/*', 'runbot/static/src/js/fields/*',
], ],
'runbot.assets_frontend': [ 'runbot.assets_frontend': [

View File

@ -0,0 +1,19 @@
/** @odoo-module **/
import { FormController } from '@web/views/form/form_controller';
import { patch } from '@web/core/utils/patch';
patch(FormController.prototype, {
// Prevent saving on tab switching
beforeVisibilityChange: () => {},
// Prevent closing page with dirty fields
async beforeUnload(ev) {
if (await this.model.root.isDirty()) {
ev.preventDefault();
ev.returnValue = 'Unsaved changes';
} else {
super.beforeUnload(ev);
}
}
})