You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

  1. /*
  2. Copyright (C) 2013 Therp BV
  3. License: GNU AFFERO GENERAL PUBLIC LICENSE
  4. Version 3 or any later version
  5. */
  6. openerp.web_confirm_window_close = function(instance) {
  7. instance.web.FormView.include({
  8. init: function(parent, dataset, view_id, options) {
  9. res = this._super(parent, dataset, view_id, options);
  10. instance.web.bus.on('report_uncommitted_changes', this, function(e) {
  11. if (this.$el.is('.oe_form_dirty')) {
  12. e.preventDefault();
  13. }
  14. });
  15. return res;
  16. }
  17. }),
  18. instance.web.WebClient.include({
  19. warning_on_close: function() {
  20. var $e = $.Event('report_uncommitted_changes');
  21. instance.web.bus.trigger('report_uncommitted_changes', $e);
  22. if ($e.isDefaultPrevented()) {
  23. return instance.web._t(
  24. "You have unsaved data in this window. " +
  25. "Do you really want to leave?");
  26. }
  27. },
  28. start: function() {
  29. res = this._super();
  30. $(window).on("beforeunload", _.bind(
  31. this.warning_on_close, this));
  32. return res;
  33. }
  34. });
  35. }