[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
This commit is contained in:
Julien Legros
2014-10-06 15:57:16 +02:00
parent 93f02c0c35
commit 42d404e08d
5 changed files with 92 additions and 9 deletions
View File
+35
View File
@@ -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
}
@@ -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');
});
}
});
};
+10
View File
@@ -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>
+38 -9
View File
@@ -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();
}
});
})();