From 6e12372f9563786192b24b18aef280397ee7997e Mon Sep 17 00:00:00 2001 From: stefanorigano Date: Tue, 3 Apr 2018 11:14:35 +0200 Subject: [PATCH] [IMP] mail: attachments list design With this commit, the attachments displayed in a thread (typically a chatter) are properly styled. --- addons/mail/static/src/js/thread.js | 7 + addons/mail/static/src/less/composer.less | 220 ++++++++++++++-------- addons/mail/static/src/less/thread.less | 6 + addons/mail/static/src/xml/thread.xml | 119 ++++++------ addons/mail/static/tests/chatter_tests.js | 4 +- 5 files changed, 213 insertions(+), 143 deletions(-) diff --git a/addons/mail/static/src/js/thread.js b/addons/mail/static/src/js/thread.js index 8e08ecfa73a..d4bd448d2f8 100644 --- a/addons/mail/static/src/js/thread.js +++ b/addons/mail/static/src/js/thread.js @@ -132,6 +132,13 @@ var Thread = Widget.extend({ } else { msg.display_author = !options.squash_close_messages; } + if (msg.attachment_ids) { + var sortedAttachments = _.partition(msg.attachment_ids, function (att) { + return att.mimetype && att.mimetype.split('/')[0] === 'image'; + }); + msg.images = sortedAttachments[0]; + msg.others = sortedAttachments[1]; + } prev_msg = msg; }); diff --git a/addons/mail/static/src/less/composer.less b/addons/mail/static/src/less/composer.less index 1692363446e..0ca031e6f09 100644 --- a/addons/mail/static/src/less/composer.less +++ b/addons/mail/static/src/less/composer.less @@ -230,106 +230,164 @@ // Attachment Icons (common for chat thread and chat composer) // ------------------------------------------------------------------ -@-webkit-keyframes oe_mail_attach_loading_anim { - 0% { background: @odoo-brand-optional } - 50% { background: darken(@odoo-brand-optional, 10%) } - 100% { background: @odoo-brand-optional } -} -@-moz-keyframes oe_mail_attach_loading_anim { - 0% { background: @odoo-brand-optional } - 50% { background: darken(@odoo-brand-optional, 10%) } - 100% { background: @odoo-brand-optional } -} -@-o-keyframes oe_mail_attach_loading_anim { - 0% { background: @odoo-brand-optional } - 50% { background: darken(@odoo-brand-optional, 10%) } - 100% { background: @odoo-brand-optional } -} -@keyframes oe_mail_attach_loading_anim { - 0% { background: @odoo-brand-optional } - 50% { background: darken(@odoo-brand-optional, 10%) } - 100% { background: @odoo-brand-optional } +@o-mail-attachment-image-size: 38px; +@o-mail-attachment-margin: 5px; + +.o_attachments_list, .o_attachments_previews { + margin: 0 -@o-mail-attachment-margin 0; + .o-flex-display(); + .o-flex-flow(row, wrap); } -@o-mail-attachment-image-size: 100px; .o_attachment { position: relative; - vertical-align: top; - display: inline-block; - text-align: center; - width: @o-mail-attachment-image-size; - margin: 5px; - .o_image_box { - position: relative; - 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; - } - &:hover .o_image_overlay { - display: block; - .o-position-absolute(@top: 0, @left: 0, @right:0, @bottom:0); - z-index: 20; - background: rgba(0, 0, 0, 0.5); - overflow: hidden; - cursor: pointer; - .o_attachment_download { - .o-position-absolute(@left: 10px, @bottom:5px); - } - .o_attachment_play { - .o-position-absolute(@top: 50%, @left: 50%); - transform: translate(-50%, -50%); - } - .o_overlay_download { - width: 100%; - height: 100%; - } - i { - color: #FFFFFF; - } - } + width: 100%; + padding: @o-mail-attachment-margin; + + @media (min-width: @screen-sm-min) { + width: 50%; } - .caption { - text-overflow: ellipsis; - white-space: nowrap; + @media (min-width: @screen-md-min) { + width: percentage(1/4); + } + + .o_attachment_wrap { overflow: hidden; - padding: 5px; - a { - color: @odoo-main-text-color; + position: relative; + border-bottom: 1px solid fade(black, 10%); + border-radius: 2px; + padding: 4px 6px 0 4px; + background-color: fade(black, 5%); + } + + &.o_attachment_editable .o_attachment_wrap { + padding-right: 40px; + } + + .o_image { + .square(@o-mail-attachment-image-size); + image-orientation: from-image; // Only supported in Firefox + &.o_hover { + .o-hover-opacity(@default-opacity: 1, @hover-opacity: 0.7); } } + + .o_attachment_view { + cursor: zoom-in; + } + + .caption { + .o-text-overflow(block); + + a { + .o-hover-text-color(@default-color: @odoo-main-text-color, @hover-color: @headings-color); + } + } + .o_attachment_progress_bar { display: none; } - .o_attachment_delete { - .o-position-absolute(@top: -10px, @right: -8px); - color: @odoo-main-text-color; - cursor: pointer; - opacity: 0; - .o-transition(opacity, 0.2s, linear); + + .o_attachment_uploaded, .o_attachment_delete { + .o-position-absolute(0,0,0, @left: auto); + .o-flex-display(); + .o-align-items(center); + .o-justify-content(center); + width: 45px; } + + .o_attachment_delete { + background: desaturate(@brand-primary, 50%); + color: white; + cursor: pointer; + font-size: 20px; + .o-transform(translateX(100%)); + .o-transition(all, 0.3s); + + &:hover { + background: @brand-primary; + } + } + &.o_attachment_uploading { .o_attachment_progress_bar { - display: block; - .o-position-absolute(@top: 18px, @left: 16px, @right: 16px); - height: 17px; - line-height: 13px; - color: white; - border-radius: @border-radius-base; - border: solid 1px grey; - box-shadow: 0px 1px 10px @odoo-shadow-color; - .o-animation(@name: oe_mail_attach_loading_anim, @duration: 1s, @timing-function: linear, @iteration-count: infinite); + display: inline-block; + margin: 0 0 0 8px; + border-radius: 2px; + vertical-align: bottom; + + > div { + font-size: 11px; + padding: 0 7px; + } } - .o_attachment_delete { + + .o_attachment_delete, .o_attachment_uploaded { display: none; } } + &:hover .o_attachment_delete { - opacity: 1; - .o-transition(opacity, 0.2s, linear); + .o-transition(all, 0.1s); + .o-transform(translateX(0)); + } +} + +.o_attachments_previews { + > .o_attachment { + width: 50%; + + @media (min-width: @screen-sm-min) { + width: percentage(1/3); + } + @media (min-width: @screen-md-min) { + width: percentage(1/4); + } + @media (min-width: @screen-lg-min) { + width: percentage(1/6); + } + + .o_attachment_wrap { + padding: 0; + border-radius: 2px; + border: 1px solid @gray-lighter-darker; + } + + .o_image_box { + overflow: hidden; + padding-top: 75%; + + .o_attachment_image { + .o-position-absolute(0,0,0,0); + background-size: cover; + background-position: center; + .o-transform(scale(1.05)); + .o-transition(all, 0.3s); + } + + &:hover .o_attachment_image { + .o-transform(scale(1)); + } + } + + .o_image_overlay { + .o-position-absolute(@top: 0, @left: 0, @right:0, @bottom:0); + .o-hover-opacity(@default-opacity: 0, @hover-opacity: 1); + .o-linear-gradient(180deg, fade(black, 20%), fade(black, 90%)); + .o-transition(all, 0.3s); + padding: 10px; + + .o_attachment_title { + .o-position-absolute(@bottom: 7px); + width: 80%; + .o-text-overflow(inline-block); + font-size: @font-size-small; + } + + .o_attachment_download { + .o-position-absolute(@right: 7px, @bottom:7px); + } + } } } diff --git a/addons/mail/static/src/less/thread.less b/addons/mail/static/src/less/thread.less index 81dee297011..b6bcff71e94 100644 --- a/addons/mail/static/src/less/thread.less +++ b/addons/mail/static/src/less/thread.less @@ -177,6 +177,12 @@ } } + .o_attachments_list, .o_attachments_previews { + &:last-child { + margin-bottom: @grid-gutter-width; + } + } + .o_thread_tooltip_container { display: inline; position: relative; diff --git a/addons/mail/static/src/xml/thread.xml b/addons/mail/static/src/xml/thread.xml index be2a81b4e92..51fa880302c 100644 --- a/addons/mail/static/src/xml/thread.xml +++ b/addons/mail/static/src/xml/thread.xml @@ -207,9 +207,18 @@ - - - + +
+ + + +
+
+ + + +
+
@@ -242,7 +251,7 @@
-
+
@@ -251,68 +260,58 @@
+ +
+
+
+
+
+ + + + +
+
+
+
+ + -
- -
- -
- - - +
+
+ + +
+
+
+ + + + +
+ +
+ + +
+
+ +
+
Uploading
-
- -
- - +
+ + +
- - -
-
- -
- - - -
-
-
-
- -
- - -
-
-
- - - +
+
×
- -
- -
-
- Uploading -
-
diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js index ddfba7b8af1..56ee5076479 100644 --- a/addons/mail/static/tests/chatter_tests.js +++ b/addons/mail/static/tests/chatter_tests.js @@ -684,7 +684,7 @@ QUnit.test('chatter: Attachment viewer', function (assert) { }); assert.strictEqual(form.$('.o_thread_message .o_attachment').length, 4, "there should be three attachment on message"); - assert.strictEqual(form.$('.o_thread_message .o_attachment .caption a').first().attr('href'), '/web/content/1?download=true', + assert.strictEqual(form.$('.o_thread_message .o_attachment a').first().attr('href'), '/web/content/1?download=true', "image caption should have correct download link"); // click on first image attachement form.$('.o_thread_message .o_attachment .o_image_box .o_image_overlay').first().click(); @@ -699,7 +699,7 @@ QUnit.test('chatter: Attachment viewer', function (assert) { // close attachment popup $('.o_modal_fullscreen .o_viewer-header .o_close_btn').click(); // click on pdf attachement - form.$('.o_thread_message .o_attachment .o_image_box .o_image_overlay').eq(3).click(); + form.$('span:contains(Test PDF 1)').click(); assert.strictEqual($('.o_modal_fullscreen iframe[data-src*="/web/content/4"]').length, 1, "Modal popup should open with the pdf preview"); // close attachment popup