From 42d404e08dd577e1df0f11cc748878cfc0a6e751 Mon Sep 17 00:00:00 2001 From: Julien Legros Date: Wed, 1 Oct 2014 13:39:17 +0200 Subject: [PATCH] [FIX] web_tip: better event handling * Override message_fetch from mail.Thread in a dedicated limk module (mail_tip) and fire an event when the messages are loaded. This is necessary for tips on the chatter. * Override render_value form web.form.FieldStatus: Call reposition() when a FieldStatus object is done rendering. * Tip.reposition() method * Handle web bus resize event --- addons/mail_tip/__init__.py | 0 addons/mail_tip/__openerp__.py | 35 +++++++++++++++++ addons/mail_tip/static/src/js/mail_tip.js | 9 +++++ addons/mail_tip/views/mail_tip.xml | 10 +++++ addons/web_tip/static/src/js/tip.js | 47 ++++++++++++++++++----- 5 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 addons/mail_tip/__init__.py create mode 100644 addons/mail_tip/__openerp__.py create mode 100644 addons/mail_tip/static/src/js/mail_tip.js create mode 100644 addons/mail_tip/views/mail_tip.xml diff --git a/addons/mail_tip/__init__.py b/addons/mail_tip/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/addons/mail_tip/__openerp__.py b/addons/mail_tip/__openerp__.py new file mode 100644 index 00000000000..bc2b28537ca --- /dev/null +++ b/addons/mail_tip/__openerp__.py @@ -0,0 +1,35 @@ +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2014 OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Mail Tips', + 'category': 'Usability', + 'description': """ +OpenERP link module for web tips. +================================= + +""", + 'version': '0.1', + 'author': 'OpenERP SA', + 'depends': ['web_tip', 'mail'], + 'data': [ + 'views/mail_tip.xml', + ], + 'auto_install': True +} diff --git a/addons/mail_tip/static/src/js/mail_tip.js b/addons/mail_tip/static/src/js/mail_tip.js new file mode 100644 index 00000000000..f41c8652c34 --- /dev/null +++ b/addons/mail_tip/static/src/js/mail_tip.js @@ -0,0 +1,9 @@ +openerp.web_tip = function(session) { + session.mail.Thread.include({ + message_fetch: function() { + return this._super.apply(this, arguments).done(function() { + openerp.web.bus.trigger('chatter_messages_fetched'); + }); + } + }); +}; diff --git a/addons/mail_tip/views/mail_tip.xml b/addons/mail_tip/views/mail_tip.xml new file mode 100644 index 00000000000..8574341cde6 --- /dev/null +++ b/addons/mail_tip/views/mail_tip.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/addons/web_tip/static/src/js/tip.js b/addons/web_tip/static/src/js/tip.js index da2ac7f655e..6ad94dd998f 100644 --- a/addons/web_tip/static/src/js/tip.js +++ b/addons/web_tip/static/src/js/tip.js @@ -93,7 +93,13 @@ formView.on('view_content_has_changed', self, function() { self.eval_tip(null, model, mode, type); }); - self.eval_tip(null, model, mode, type); + if ($('.oe_chatter').length > 0) { + instance.web.bus.on('chatter_messages_fetched', this, function() { + self.eval_tip(null, model, mode, type); + }); + } else { + self.eval_tip(null, model, mode, type); + } }, // stub @@ -183,16 +189,9 @@ $(scroll).scrollTo(self.$element); } - var _top = self.$element.offset().top -5; - var _left = self.$element.offset().left -5; - var _width = self.$element.outerWidth() + 10; - var _height = self.$element.outerHeight() + 10; - self.$helper = $("
", { class: 'oe_tip_helper' }); self.$element.after(self.$helper); - self.$helper.offset({top: _top , left: _left}); - self.$helper.width(_width); - self.$helper.height(_height); + self._set_helper_position(); self.$overlay = $("
", { class: 'oe_tip_overlay' }); $('body').append(self.$overlay); @@ -247,6 +246,11 @@ def.resolve(); } }); + + // resize + instance.web.bus.on('resize', this, function() { + self.reposition(); + }); } else { def.reject(); } @@ -266,6 +270,24 @@ $(document).off('keyup.web_tip'); Tips.call('consume', [tip.id], {}); tip.is_consumed = true; + }, + + reposition: function() { + var self = this; + if (self.tip_mutex.def.state() === 'pending') { + self._set_helper_position(); + } + }, + + _set_helper_position : function() { + var offset = this.$element.offset(); + var _top = offset.top - 5; + var _left = offset.left - 5; + var _width = this.$element.outerWidth() + 10; + var _height = this.$element.outerHeight() + 10; + this.$helper.offset({top: _top , left: _left}); + this.$helper.width(_width); + this.$helper.height(_height); } }); @@ -275,4 +297,11 @@ this.tip_handler = new instance.web.Tip(); } }); + + instance.web.form.FieldStatus = instance.web.form.FieldStatus.extend({ + render_value: function() { + this._super(); + instance.webclient.tip_handler.reposition(); + } + }); })();