Browse Source
Merge pull request #631 from StefanRijnhart/10.0-web_confirm_window_close
Merge pull request #631 from StefanRijnhart/10.0-web_confirm_window_close
10.0 web confirm window closepull/644/head
Sylvain LE GAL
8 years ago
committed by
GitHub
5 changed files with 92 additions and 70 deletions
-
60web_confirm_window_close/README.rst
-
45web_confirm_window_close/__manifest__.py
-
BINweb_confirm_window_close/static/description/icon.png
-
44web_confirm_window_close/static/src/js/web_confirm_window_close.js
-
9web_confirm_window_close/views/assets.xml
@ -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 |
||||
|
<https://github.com/OCA/web/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Stefan Rijnhart <stefan@opener.amsterdam> |
||||
|
|
||||
|
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. |
@ -1,45 +1,18 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# This module copyright (C) 2013 Therp BV (<http://therp.nl>). |
|
||||
# |
|
||||
# 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 <http://www.gnu.org/licenses/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
|
||||
|
# coding: utf-8 |
||||
|
# Copyright 2013 Therp BV (<http://therp.nl>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
{ |
{ |
||||
'name': 'Check for unsaved data when closing browser window', |
'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)", |
'author': "Therp BV,Odoo Community Association (OCA)", |
||||
'category': 'Usability', |
'category': 'Usability', |
||||
'website': 'https://launchpad.net/web-addons', |
|
||||
|
'website': 'https://github.com/oca/web', |
||||
'license': 'AGPL-3', |
'license': 'AGPL-3', |
||||
'installable': False, |
|
||||
|
'installable': True, |
||||
|
'data': [ |
||||
|
'views/assets.xml', |
||||
|
], |
||||
'depends': [ |
'depends': [ |
||||
'web', |
'web', |
||||
], |
], |
||||
'js': [ |
|
||||
'static/src/js/web_confirm_window_close.js' |
|
||||
], |
|
||||
} |
} |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -1,42 +1,22 @@ |
|||||
/* |
|
||||
|
// Copyright 2013 Therp BV (<http://therp.nl>)
|
||||
|
// 2017 Opener B.V. (<https://opener.amsterdam>)
|
||||
|
// 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')) { |
|
||||
|
WebClient.include({ |
||||
|
warning_on_close: function(e) { |
||||
|
if ($('html').find('.oe_form_dirty').length) { |
||||
e.preventDefault(); |
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?"); |
|
||||
} |
|
||||
}, |
}, |
||||
|
|
||||
start: function() { |
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; |
return res; |
||||
} |
} |
||||
|
|
||||
}); |
}); |
||||
} |
|
||||
|
}); |
@ -0,0 +1,9 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
|
||||
|
<odoo> |
||||
|
<template id="assets_backend" name="web_confirm_window_close assets" inherit_id="web.assets_backend"> |
||||
|
<xpath expr="." position="inside"> |
||||
|
<script type="text/javascript" src="/web_confirm_window_close/static/src/js/web_confirm_window_close.js"></script> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue