Skip to content

Commit

Permalink
[FIX] web: Avoid open too fast zoom
Browse files Browse the repository at this point in the history
Picture of employees are maximazed directly which is annoying when
you move the mouse in kanban view.

Add the ability to put a waiting time before opening the zoom in
option of the field in the view (default value is 0).

closes odoo#45229

Taskid: 2191289
X-original-commit: a264b17
Signed-off-by: jbm-odoo <jbm-odoo@users.noreply.github.com>
  • Loading branch information
jbm-odoo authored and tivisse committed Feb 12, 2020
1 parent fdcab45 commit 9a4da88
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion addons/hr/views/hr_employee_public_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click o_kanban_record_has_image_fill o_hr_kanban_record">
<field name="image_128" widget="image" class="o_kanban_image_fill_left o_hr_rounded_circle" options="{'zoom': true, 'background': true, 'preventClicks': false}"/>
<field name="image_128" widget="image" class="o_kanban_image_fill_left o_hr_rounded_circle" options="{'zoom': true, 'zoom_delay': 1000, 'background': true, 'preventClicks': false}"/>

<div class="oe_kanban_details">
<div class="o_kanban_record_top">
Expand Down
2 changes: 1 addition & 1 deletion addons/hr/views/hr_employee_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click o_kanban_record_has_image_fill o_hr_kanban_record">
<field name="image_128" widget="image" class="o_kanban_image_fill_left o_hr_rounded_circle" options="{'zoom': true, 'background': true, 'preventClicks': false}"/>
<field name="image_128" widget="image" class="o_kanban_image_fill_left o_hr_rounded_circle" options="{'zoom': true, 'zoom_delay': 1000, 'background': true, 'preventClicks': false}"/>

<div class="oe_kanban_details">
<div class="o_kanban_record_top">
Expand Down
5 changes: 5 additions & 0 deletions addons/web/static/src/js/fields/basic_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -1917,13 +1917,18 @@ var FieldBinaryImage = AbstractFieldBinary.extend({
} else {
$img = this.$('img');
}
var zoomDelay = 0;
if (this.nodeOptions.zoom_delay) {
zoomDelay = this.nodeOptions.zoom_delay;
}

if(this.recordData[imageField]) {
$img.attr('data-zoom', 1);
$img.attr('data-zoom-image', url);

$img.zoomOdoo({
event: 'mouseenter',
timer: zoomDelay,
attach: '.o_content',
attachToTarget: true,
onShow: function () {
Expand Down
17 changes: 12 additions & 5 deletions addons/web/static/src/js/libs/zoomodoo.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ var defaults = {
// event to trigger zoom
event: 'click', //or mouseenter

// Timer before trigger zoom
timer: 0,

// Prevent clicks on the zoom image link.
preventClicks: true,

Expand Down Expand Up @@ -197,13 +200,17 @@ ZoomOdoo.prototype.show = function (e, testMouseOver) {
* @param {Event} e
*/
ZoomOdoo.prototype._onEnter = function (e) {
var self = this;
var touches = e.originalEvent.touches;

e.preventDefault();
this.isMouseOver = true;
if (!touches || touches.length === 1) {
e.preventDefault();
this.show(e, true);
}

setTimeout(function () {
if (self.isMouseOver && (!touches || touches.length === 1)) {
self.show(e, true);
}
}, this.opts.timer);

};

/**
Expand Down

0 comments on commit 9a4da88

Please sign in to comment.