Jiten (OpenERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-notifier-vja into lp:openerp-web.

Requested reviews:
  OpenERP R&D Web Team (openerp-dev-web)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-notifier-vja/+merge/105166

Implement form notifier.

Demo: 
- Open any record in edit mode, modify in it.
- Now without save/cancel, click on pager for next record or click on menu or 
click on any other action than It's give notification message for current 
modification.
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-notifier-vja/+merge/105166
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-notifier-vja.
=== modified file 'addons/web/static/src/js/chrome.js'
--- addons/web/static/src/js/chrome.js	2012-04-19 21:53:44 +0000
+++ addons/web/static/src/js/chrome.js	2012-05-09 06:18:20 +0000
@@ -40,7 +40,23 @@
             title: title,
             text: text
         }, opts);
-    }
+    },
+    do_notifier:function(e){
+        var self = e;
+            action_manager = self.action_manager;
+        if (self.getParent()){ 
+              var action_manager =  self.getParent().action_manager ||self;
+        }
+        if (action_manager.inner_viewmanager  && action_manager.inner_viewmanager.active_view == 'form') {
+            var active_view = action_manager.inner_viewmanager.active_view;
+                controller = action_manager.inner_viewmanager.views[active_view].controller;
+            if (!controller.can_be_discarded()) {
+                self.notifier = true;
+            } else {
+                self.notifier = false;
+            }
+        } 
+   },
 });
 
 instance.web.dialog = function(element) {
@@ -658,6 +674,11 @@
         this.trigger('menuClicked', id, $clicked_menu);
 
         if (id) {
+            var notification = new instance.web.Notification(this);
+            notification.do_notifier(this);
+            if (this.notifier) {
+                return false; 
+            }
             this.open_menu(id);
             this.current_menu = id;
             this.session.active_id = id;
@@ -692,6 +713,7 @@
     start: function() {
         var self = this;
         this._super.apply(this, arguments);
+        this.notification = new instance.web.Notification(this);
         $('html').bind('click', function() {
             self.$element.find('.oe_dropdown_options').hide();
         });
@@ -808,6 +830,10 @@
     },
     on_menu_settings: function() {
         var self = this;
+        this.notification.do_notifier(self);
+        if (this.notifier) {
+            return $.Deferred().reject();
+        }
         var action_manager = new instance.web.ActionManager(this);
         var dataset = new instance.web.DataSet (this,'res.users',this.context);
         dataset.call ('action_get','',function (result){
@@ -863,6 +889,10 @@
     on_menu_shortcut: function($link) {
         var self = this,
             id = $link.data('id');
+        self.notification.do_notifier(self);
+        if (self.notifier) {
+            return $.Deferred().reject();
+        }
         self.session.active_id = id;
         self.rpc('/web/menu/action', {'menu_id': id}, function(ir_menu_data) {
             if (ir_menu_data.action.length){
@@ -976,6 +1006,10 @@
     },
     on_logout: function() {
         var self = this;
+        this.notification.do_notifier(self);
+        if (this.notifier) {
+            return $.Deferred().reject();
+        }
         this.session.session_logout().then(function () {
             $(window).unbind('hashchange', self.on_hashchange);
             self.do_push_state({});

=== modified file 'addons/web/static/src/js/views.js'
--- addons/web/static/src/js/views.js	2012-04-25 10:11:50 +0000
+++ addons/web/static/src/js/views.js	2012-05-09 06:18:20 +0000
@@ -634,7 +634,12 @@
     },
     on_mode_switch: function (view_type, no_store) {
         var self = this;
-
+        if(this.active_view === 'form') {
+               var controller = this.views[this.active_view].controller;
+               if(!no_store && !controller.can_be_discarded()) {
+                    return $.Deferred().reject();
+               }
+        }
         return $.when(this._super(view_type, no_store)).then(function () {
             self.shortcut_check(self.views[view_type]);
 
@@ -830,6 +835,12 @@
     },
     on_item_action_clicked: function(item) {
         var self = this;
+        var controller = this.getParent();
+        if(controller.can_be_discarded) {
+            if(!controller.can_be_discarded()) {
+                 return $.Deferred().reject();
+            }
+        }
         self.getParent().sidebar_context().then(function (context) {
             var ids = self.getParent().get_selected_ids();
             if (ids.length == 0) {
@@ -1204,6 +1215,11 @@
         export_view.start();
     },
     on_sidebar_translate: function() {
+         if(this.getParent().active_view === 'form') {
+                if(!this.can_be_discarded()) {
+                    return $.Deferred().reject();
+                }
+        }
         return this.do_action({
             res_model : 'ir.translation',
             domain : [['type', '!=', 'object'], '|', ['name', '=', this.dataset.model], ['name', 'ilike', this.dataset.model + ',']],

=== modified file 'addons/web_process/static/src/js/process.js'
--- addons/web_process/static/src/js/process.js	2012-04-19 08:12:13 +0000
+++ addons/web_process/static/src/js/process.js	2012-05-09 06:18:20 +0000
@@ -30,8 +30,13 @@
             this.record_id = false;
             if(this.active_view == 'form') {
                 this.record_id = this.views[this.active_view].controller.datarecord.id;
+                var controller = this.views[this.active_view].controller;
+                if(!controller.can_be_discarded()) {
+                    return $.Deferred().reject();
+                } else {
+                    controller.$element.removeClass('oe_form_dirty');
+                }
             }
-
             $.when(this.help(), this.get_process_object()).pipe(function(help, process) {
                 self.process_help = help;
                 if(process && process.length) {

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to