diff --git a/web_confirm_window_close/README.rst b/web_confirm_window_close/README.rst new file mode 100644 index 00000000..b1e834f9 --- /dev/null +++ b/web_confirm_window_close/README.rst @@ -0,0 +1,60 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================================== +Check for unsaved data when closing browser window +================================================== + +This module will show a confirmation dialog when the user closes +a window with an Odoo form containing unsaved data. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/10.0 + +Known issues +============ +This module depends on the 'dirty' flag that Odoo sets on modified forms. Odoo +only sets this flag when the focus is changed, so if you modified only one +field and the focus is still on that field, you won't be prevented from closing +the browser window. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Stefan Rijnhart + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_confirm_window_close/__manifest__.py b/web_confirm_window_close/__manifest__.py index 47e682cb..65acab14 100644 --- a/web_confirm_window_close/__manifest__.py +++ b/web_confirm_window_close/__manifest__.py @@ -1,45 +1,18 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2013 Therp BV (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - +# coding: utf-8 +# Copyright 2013 Therp BV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Check for unsaved data when closing browser window', - 'description': ''' -This addon will show a confirmation dialog when the user closes -a window with an OpenERP form containing unsaved data. - -This functionality is browser dependent. Opera ignores it at all, -while Firefox displays a generic confirmation message. - -This module is compatible with OpenERP 7.0. -''', - 'version': '7.0.1', + 'version': '10.0.1.0.0', 'author': "Therp BV,Odoo Community Association (OCA)", 'category': 'Usability', - 'website': 'https://launchpad.net/web-addons', + 'website': 'https://github.com/oca/web', 'license': 'AGPL-3', - 'installable': False, + 'installable': True, + 'data': [ + 'views/assets.xml', + ], 'depends': [ 'web', - ], - 'js': [ - 'static/src/js/web_confirm_window_close.js' - ], + ], } diff --git a/web_confirm_window_close/static/description/icon.png b/web_confirm_window_close/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/web_confirm_window_close/static/description/icon.png differ diff --git a/web_confirm_window_close/static/src/js/web_confirm_window_close.js b/web_confirm_window_close/static/src/js/web_confirm_window_close.js index a8ceb7bb..3aba9f97 100644 --- a/web_confirm_window_close/static/src/js/web_confirm_window_close.js +++ b/web_confirm_window_close/static/src/js/web_confirm_window_close.js @@ -1,42 +1,22 @@ -/* +// Copyright 2013 Therp BV () +// 2017 Opener B.V. () +// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +odoo.define('web_confirm_window_close', function (require) { + "use strict"; + var WebClient = require('web.WebClient'); - Copyright (C) 2013 Therp BV - License: GNU AFFERO GENERAL PUBLIC LICENSE - Version 3 or any later version - -*/ - -openerp.web_confirm_window_close = function(instance) { - - instance.web.FormView.include({ - init: function(parent, dataset, view_id, options) { - res = this._super(parent, dataset, view_id, options); - instance.web.bus.on('report_uncommitted_changes', this, function(e) { - if (this.$el.is('.oe_form_dirty')) { - e.preventDefault(); - } - }); - return res; - } - }), - - instance.web.WebClient.include({ - warning_on_close: function() { - var $e = $.Event('report_uncommitted_changes'); - instance.web.bus.trigger('report_uncommitted_changes', $e); - if ($e.isDefaultPrevented()) { - return instance.web._t( - "You have unsaved data in this window. " + - "Do you really want to leave?"); + WebClient.include({ + warning_on_close: function(e) { + if ($('html').find('.oe_form_dirty').length) { + e.preventDefault(); } }, start: function() { - res = this._super(); - $(window).on("beforeunload", _.bind( - this.warning_on_close, this)); + var res = this._super(); + $(window).on("beforeunload", _.bind(this.warning_on_close, this)); return res; } }); -} +}); diff --git a/web_confirm_window_close/views/assets.xml b/web_confirm_window_close/views/assets.xml new file mode 100644 index 00000000..517153d5 --- /dev/null +++ b/web_confirm_window_close/views/assets.xml @@ -0,0 +1,9 @@ + + + + +