summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Legros <jle@odoo.com>2014-10-01 13:39:17 +0200
committerJulien Legros <jle@odoo.com>2014-10-06 15:57:16 +0200
commit42d404e08dd577e1df0f11cc748878cfc0a6e751 (patch)
treeafd0290645c1b04f5af2846d9b639195b787b580
parent93f02c0c351c80857eca141b24126743458ec419 (diff)
[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
-rw-r--r--addons/mail_tip/__init__.py0
-rw-r--r--addons/mail_tip/__openerp__.py35
-rw-r--r--addons/mail_tip/static/src/js/mail_tip.js9
-rw-r--r--addons/mail_tip/views/mail_tip.xml10
-rw-r--r--addons/web_tip/static/src/js/tip.js47
5 files changed, 92 insertions, 9 deletions
diff --git a/addons/mail_tip/__init__.py b/addons/mail_tip/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/addons/mail_tip/__init__.py
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 (<http://openerp.com>).
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+{
+ '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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data>
+ <template id="assets_backend" name="mail tip assets" inherit_id="web.assets_backend">
+ <xpath expr="." position="inside">
+ <script type="text/javascript" src="/mail_tip/static/src/js/mail_tip.js"></script>
+ </xpath>
+ </template>
+ </data>
+</openerp>
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 = $("<div>", { 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 = $("<div>", { 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();
+ }
+ });
})();