diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2018-02-23 12:29:25 +0100 |
|---|---|---|
| committer | Nicolas Martinelli <nim-odoo@users.noreply.github.com> | 2018-02-26 08:24:08 +0100 |
| commit | e2c2a2fc696a12d3fdd697e5da5354437a290047 (patch) | |
| tree | 4a8277d11f9a22c1ce9058e4beee7278ec388ef4 /addons/mail/static | |
| parent | a16013be6636db58a4252fafd67033c6643a1e48 (diff) | |
[FIX] mail: rotate image in preview
When uploading an image as attachment, the document viewer doesn't
support the EXIF data. Therefore, a picture taken with a non-zero angle
will not appear with the right orientation (preview or full-size image).
Unfortunately, supporting EXIF data is not trivial in Python or
JavaScript without external libraries. Therefore, we add a rotate button
which allows the user to rotate the image by 90°. Moreover, we add the
`image-orientation: from-image` CSS property, which is only supported by
Firefox.
opw-1814407
Diffstat (limited to 'addons/mail/static')
| -rw-r--r-- | addons/mail/static/src/js/document_viewer.js | 35 | ||||
| -rw-r--r-- | addons/mail/static/src/less/composer.less | 4 | ||||
| -rw-r--r-- | addons/mail/static/src/xml/thread.xml | 5 |
3 files changed, 43 insertions, 1 deletions
diff --git a/addons/mail/static/src/js/document_viewer.js b/addons/mail/static/src/js/document_viewer.js index 2fa34b613ba..0aac950cf5b 100644 --- a/addons/mail/static/src/js/document_viewer.js +++ b/addons/mail/static/src/js/document_viewer.js @@ -17,6 +17,7 @@ var DocumentViewer = Widget.extend({ 'click .o_viewer_video': '_onVideoClicked', 'click .move_next': '_onNext', 'click .move_previous': '_onPrevious', + 'click .o_rotate': '_onRotate', 'click .o_zoom_in': '_onZoomIn', 'click .o_zoom_out': '_onZoomOut', 'click .o_close_btn, .o_viewer_img_wrapper': '_onClose', @@ -104,6 +105,30 @@ var DocumentViewer = Widget.extend({ this._reset(); }, /** + * Get CSS transform property based on scale and angle + * + * @private + * @param {float} scale + * @param {float} angle + */ + _getTransform: function(scale, angle) { + return 'scale3d(' + scale + ', ' + scale + ', 1) rotate(' + angle + 'deg)' + }, + /** + * Rotate image clockwise by provided angle + * + * @private + * @param {float} angle + */ + _rotate: function (angle) { + this._reset(); + var new_angle = (this.angle || 0) + angle; + this.$('.o_viewer_img').css('transform', this._getTransform(this.scale, new_angle)); + this.$('.o_viewer_img').css('max-width', new_angle % 180 !== 0 ? $(document).height() : '100%'); + this.$('.o_viewer_img').css('max-height', new_angle % 180 !== 0 ? $(document).width() : '100%'); + this.angle = new_angle; + }, + /** * Zoom in/out image by provided scale * * @private @@ -111,7 +136,7 @@ var DocumentViewer = Widget.extend({ */ _zoom: function (scale) { if (scale > 0.5) { - this.$('.o_viewer_img').css('transform', 'scale3d(' + scale + ', ' + scale + ', 1)'); + this.$('.o_viewer_img').css('transform', this._getTransform(scale, this.angle || 0)); this.scale = scale; } }, @@ -284,6 +309,14 @@ var DocumentViewer = Widget.extend({ * @private * @param {MouseEvent} e */ + _onRotate: function (e) { + e.preventDefault(); + this._rotate(90); + }, + /** + * @private + * @param {MouseEvent} e + */ _onZoomIn: function (e) { e.preventDefault(); var scale = this.scale + ZOOM_STEP; diff --git a/addons/mail/static/src/less/composer.less b/addons/mail/static/src/less/composer.less index ec3b156af2a..a7ca9fb9787 100644 --- a/addons/mail/static/src/less/composer.less +++ b/addons/mail/static/src/less/composer.less @@ -269,6 +269,7 @@ img { width: @o-mail-attachment-image-size; height: @o-mail-attachment-image-size; + image-orientation: from-image; // Only supported in Firefox } .o_image_overlay{ display: none; @@ -370,6 +371,9 @@ .o-flex-display(); justify-content: center; align-items: center; + img { + image-orientation: from-image; // Only supported in Firefox + } img, video { max-width: 100%; max-height: 100%; diff --git a/addons/mail/static/src/xml/thread.xml b/addons/mail/static/src/xml/thread.xml index 6f5f5e71cfe..8408e149113 100644 --- a/addons/mail/static/src/xml/thread.xml +++ b/addons/mail/static/src/xml/thread.xml @@ -51,6 +51,11 @@ <div t-if="widget.activeAttachment.type == 'image'" class="o_viewer_toolbar"> <ul class="list-inline"> <li> + <a class="o_rotate" href="#"> + <i class="fa fa-2x fa-repeat"></i> + </a> + </li> + <li> <a class="o_zoom_out" href="#"> <i class="fa fa-2x fa-search-minus"></i> </a> |
