diff --git a/runbot/__manifest__.py b/runbot/__manifest__.py index 25a07b90..5085df56 100644 --- a/runbot/__manifest__.py +++ b/runbot/__manifest__.py @@ -64,6 +64,7 @@ 'assets': { 'web.assets_backend': [ 'runbot/static/src/libs/diff_match_patch/diff_match_patch.js', + 'runbot/static/src/js/views/**/*', 'runbot/static/src/js/fields/*', ], 'runbot.assets_frontend': [ diff --git a/runbot/static/src/js/views/form_controller.js b/runbot/static/src/js/views/form_controller.js new file mode 100644 index 00000000..f7a1ea72 --- /dev/null +++ b/runbot/static/src/js/views/form_controller.js @@ -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); + } + } +})