[RFR] Use event to query uncommitted changes

pull/4/head
Stefan Rijnhart 2013-08-30 16:14:39 +02:00
parent b3a3c731d9
commit 24450d14f6
1 changed files with 24 additions and 18 deletions

View File

@ -6,29 +6,35 @@
*/ */
openerp.web_confirm_window_close = function(openerp) { openerp.web_confirm_window_close = function(instance) {
//3 essential differences between 6.1 and 7.0
// - widget_parent replaced by ViewManager instance.web.FormView.include({
// - $element. replaced by $el init: function(parent, dataset, view_id, options) {
// - $(window).bind replaced by $(window).on res = this._super(parent, dataset, view_id, options);
openerp.web.FormView.include({ 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() { warning_on_close: function() {
if (this.ViewManager var $e = $.Event('report_uncommitted_changes');
&& this.ViewManager.active_view == 'form' instance.web.bus.trigger('report_uncommitted_changes', $e);
&& this.$el.hasClass('oe_form_dirty')) if ($e.isDefaultPrevented()) {
// Firefox will show a generic confirmation dialog return instance.web._t(
// When any text is returned here.
return openerp.web._t(
"You have unsaved data in this window. " + "You have unsaved data in this window. " +
"Do you really want to leave?"); "Do you really want to leave?");
}
}, },
start: function() { start: function() {
res = this._super(); res = this._super();
if (!(this.embedded_view)) {
$(window).on("beforeunload", _.bind( $(window).on("beforeunload", _.bind(
this.warning_on_close, this)); this.warning_on_close, this));
}
return res; return res;
} }