From 576ce50356b50d82b22df8d079868990d8a76e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 6 Apr 2012 11:41:12 +0200 Subject: [PATCH] [FIX] Fixed invite button not working after an interal redirection, due to a non-existent action. All sahre buttons are now hidden, unless an action is defined. bzr revid: tde@openerp.com-20120406094112-v2yz130irskanxuj --- addons/mail/mail_thread.py | 2 +- addons/share/static/src/css/share.css | 5 + addons/share/static/src/js/share.js | 144 +++++++++++++++----------- 3 files changed, 90 insertions(+), 61 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 20341bb01f4..19c333af51b 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -695,7 +695,7 @@ class mail_thread(osv.osv): # escape if in install mode or note writing was not successfull if 'install_mode' in context: return True - if not isinstance(msg_ids(list)): + if not isinstance(msg_ids, (list)): return True # get already existing notigications notification_ids = notification_obj.search(cr, uid, [('message_id', 'in', msg_ids)], context=context) diff --git a/addons/share/static/src/css/share.css b/addons/share/static/src/css/share.css index c275fed8bf4..379b3fbb86b 100644 --- a/addons/share/static/src/css/share.css +++ b/addons/share/static/src/css/share.css @@ -1,3 +1,8 @@ button.oe-share-mail { width: 120px; + display: none; +} + +a.oe-share_link, a.oe-share { + display: none; } diff --git a/addons/share/static/src/js/share.js b/addons/share/static/src/js/share.js index 8346b177f8e..3563a4bb859 100644 --- a/addons/share/static/src/js/share.js +++ b/addons/share/static/src/js/share.js @@ -1,7 +1,9 @@ openerp.share = function(session) { -function launch_wizard(self, view, user_type, invite) { + var has_action_id = false; + + function launch_wizard(self, view, user_type, invite) { var action = view.getParent().action; var Share = new session.web.DataSet(self, 'share.wizard', view.dataset.get_context()); var domain = new session.web.CompoundDomain(view.dataset.domain); @@ -30,68 +32,90 @@ function launch_wizard(self, view, user_type, invite) { }); }); }); -} - -function has_share(yes, no) { - if (!session.connection.share_flag) { - session.connection.share_flag = $.Deferred(function() { - var func = new session.web.Model("share.wizard").get_func("has_share"); - func(session.connection.uid).pipe(function(res) { - if(res) { - session.connection.share_flag.resolve(); - } else { - session.connection.share_flag.reject(); - } - }); - }); } - session.connection.share_flag.done(yes).fail(no); -} -session.web.Sidebar = session.web.Sidebar.extend({ - add_default_sections: function() { - this._super(); - var self = this; - has_share(function() { - self.add_items('other', [{ - label: 'Share', - callback: self.on_sidebar_click_share, - classname: 'oe-share', - }]); - }); - }, - on_sidebar_click_share: function(item) { - var view = this.getParent() - launch_wizard(this, view); - }, -}); + function has_share(yes, no) { + if (!session.connection.share_flag) { + session.connection.share_flag = $.Deferred(function() { + var func = new session.web.Model("share.wizard").get_func("has_share"); + func(session.connection.uid).pipe(function(res) { + if(res) { + session.connection.share_flag.resolve(); + } else { + session.connection.share_flag.reject(); + } + }); + }); + } + session.connection.share_flag.done(yes).fail(no); + } -session.web.ViewManagerAction.include({ - start: function() { - var self = this; - has_share(function() { - self.$element.find('a.oe-share_link').click(self.on_click_share_link); - self.$element.find('a.oe-share').click(self.on_click_share); - self.$element.delegate('button.oe-share-mail', 'click', self.on_click_share_mail); - }, function() { - self.$element.find('a.oe-share_link').remove(); - self.$element.find('a.oe-share').remove(); - }); - return this._super.apply(this, arguments); - }, - on_click_share_link: function(e) { - e.preventDefault(); - launch_wizard(this, this.views[this.active_view].controller, 'embedded', false); - }, - on_click_share: function(e) { - e.preventDefault(); - launch_wizard(this, this.views[this.active_view].controller, 'emails', false); - }, - on_click_share_mail: function(e) { - e.preventDefault(); - launch_wizard(this, this.views[this.active_view].controller, 'emails', true); - }, -}); + session.web.Sidebar = session.web.Sidebar.extend({ + add_default_sections: function() { + this._super(); + var self = this; + has_share(function() { + self.add_items('other', [{ + label: 'Share', + callback: self.on_sidebar_click_share, + classname: 'oe-share', + }]); + }); + }, + on_sidebar_click_share: function(item) { + var view = this.getParent() + launch_wizard(this, view); + }, + }); + session.mail.RecordThread.include( { + start: function() { + start_res = this._super.apply(this, arguments); + if (has_action_id) { + this.$element.find('button.oe-share-mail').show(); + } + return start_res; + } + }); + + session.web.ViewManagerAction.include({ + start: function() { + var self = this; + this.check_if_action_is_defined(); + has_share(function() { + self.$element.find('a.oe-share_link').click(self.on_click_share_link); + self.$element.find('a.oe-share').click(self.on_click_share); + self.$element.delegate('button.oe-share-mail', 'click', self.on_click_share_mail); + }, function() { + self.$element.find('a.oe-share_link').remove(); + self.$element.find('a.oe-share').remove(); + }); + return this._super.apply(this, arguments); + }, + + check_if_action_is_defined: function() { + if (this.action && this.action.id) { + has_action_id = true; + this.$element.find('a.oe-share_link').show(); + this.$element.find('a.oe-share').show(); + } + else { + has_action_id = false; + } + }, + + on_click_share_link: function(e) { + e.preventDefault(); + launch_wizard(this, this.views[this.active_view].controller, 'embedded', false); + }, + on_click_share: function(e) { + e.preventDefault(); + launch_wizard(this, this.views[this.active_view].controller, 'emails', false); + }, + on_click_share_mail: function(e) { + e.preventDefault(); + launch_wizard(this, this.views[this.active_view].controller, 'emails', true); + }, + }); };