Browse Source

[RFR] Use event to query uncommitted changes

pull/4/head
Stefan Rijnhart 11 years ago
parent
commit
24450d14f6
  1. 42
      web_confirm_window_close/static/src/js/web_confirm_window_close.js

42
web_confirm_window_close/static/src/js/web_confirm_window_close.js

@ -6,29 +6,35 @@
*/
openerp.web_confirm_window_close = function(openerp) {
//3 essential differences between 6.1 and 7.0
// - widget_parent replaced by ViewManager
// - $element. replaced by $el
// - $(window).bind replaced by $(window).on
openerp.web.FormView.include({
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() {
if (this.ViewManager
&& this.ViewManager.active_view == 'form'
&& this.$el.hasClass('oe_form_dirty'))
// Firefox will show a generic confirmation dialog
// When any text is returned here.
return openerp.web._t(
"You have unsaved data in this window. " +
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() {
res = this._super();
if (!(this.embedded_view)) {
$(window).on("beforeunload", _.bind(
this.warning_on_close, this));
}
$(window).on("beforeunload", _.bind(
this.warning_on_close, this));
return res;
}

Loading…
Cancel
Save