From f6d3aa452cbc616efb07ed90f23b6f5c2bfbd458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 7 Apr 2021 23:34:51 +0200 Subject: [PATCH] Add attachment preview issue10203 review332271014 --- CHANGELOG | 1 + src/sao.less | 16 ++++++ src/screen.js | 6 +-- src/tab.js | 125 ++++++++++++++++++++++++++++++++++++++++++++++- src/view/form.js | 6 +-- 5 files changed, 145 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 06f59e32f3..2ada6f6d68 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add attachment preview * Support document widget * Support icon of type URL * Allow sending email with existing attachments diff --git a/src/sao.less b/src/sao.less index 77c34a59ca..f30d758c68 100644 --- a/src/sao.less +++ b/src/sao.less @@ -336,6 +336,15 @@ img.icon { overflow-y: auto; } +@media screen and (max-width: @screen-sm-max) { + .attachment-preview:not(:empty) { + border-color: @panel-default-border; + border-style: solid; + border-width: 0 0 1px 0; + margin-bottom: 5px; + } +} + .list-form { overflow-y: auto; -moz-user-select: none; @@ -654,6 +663,13 @@ img.icon { object-fit: scale-down; object-position: center top; width: 100%; + height: 75vh; + @media screen and (max-width: @screen-sm-max) { + height: 50vh; + } + @media screen and (max-width: @screen-xs-max) { + height: 25vh; + } } } label { diff --git a/src/screen.js b/src/screen.js index 54bd02d8e6..31e16d2b20 100644 --- a/src/screen.js +++ b/src/screen.js @@ -1133,11 +1133,11 @@ } if (!jQuery.isEmptyObject(domain)) { - if (!jQuery.isEmptyObject(this.attributes.domain)) { - domain = ['AND', domain, this.attributes.domain]; + if (!jQuery.isEmptyObject(this.domain)) { + domain = ['AND', domain, this.domain]; } } else { - domain = this.attributes.domain || []; + domain = this.domain; } if (this.screen_container.but_active.hasClass('active')) { if (!jQuery.isEmptyObject(domain)) { diff --git a/src/tab.js b/src/tab.js index e3f1a3e8da..03ca2d8a18 100644 --- a/src/tab.js +++ b/src/tab.js @@ -119,9 +119,12 @@ var toolbar = this.create_toolbar().appendTo(this.el); this.title = toolbar.find('.title'); - this.content = jQuery('
', { - 'class': 'panel-body', + this.main = jQuery('
', { + 'class': 'panel-body row', }).appendTo(this.el); + this.content = jQuery('
', { + 'class': 'col-xs-12', + }).appendTo(this.main); if (this.info_bar) { this.el.append(this.info_bar.el); @@ -463,6 +466,8 @@ this.info_bar = new Sao.Window.InfoBar(); this.create_tabcontent(); + this.attachment_screen = null; + screen.message_callback = this.record_message.bind(this); screen.switch_callback = function() { if (this === Sao.Tab.tabs.get_current()) { @@ -709,6 +714,12 @@ .on('drop', this.attach_drop.bind(this)); return toolbar; }, + create_tabcontent: function() { + Sao.Tab.Form._super.create_tabcontent.call(this); + this.attachment_preview = jQuery('
', { + 'class': 'col-xs-12 attachment-preview', + }).prependTo(this.main); + }, compare: function(attributes) { if (!attributes) { return false; @@ -1053,6 +1064,20 @@ this.refresh_resources(true); }.bind(this)); }.bind(this); + var preview = function() { + if (this.attachment_preview.children().length) { + this.attachment_preview.empty(); + this.attachment_screen = null; + this.attachment_preview.removeClass('col-md-4 col-md-push-8'); + this.content.removeClass('col-md-8 col-md-pull-4'); + } else { + this.attachment_preview.append( + this._attachment_preview_el()); + this.refresh_attachment_preview(); + this.attachment_preview.addClass('col-md-4 col-md-push-8'); + this.content.addClass('col-md-8 col-md-pull-4'); + } + }.bind(this); var dropdown = this.buttons.attach.parents('.dropdown'); if (!evt) { window.setTimeout(function() { @@ -1108,6 +1133,17 @@ 'href': '#', 'tabindex': -1, }).text(Sao.i18n.gettext('Add...')))); + menu.append(jQuery('
  • ', { + 'role': 'presentation', + }).append(jQuery('', { + 'role': 'menuitem', + 'href': '#', + 'tabindex': -1, + }).text(Sao.i18n.gettext("Preview")) + .click(function(evt) { + evt.preventDefault(); + preview(); + }))); menu.append(jQuery('
  • ', { 'role': 'presentation', }).append(jQuery('', { @@ -1196,6 +1232,87 @@ evt.dataTransfer.clearData(); } }, + _attachment_preview_el: function() { + var el = jQuery('
    ', { + 'class': 'text-center', + }); + var buttons = jQuery('
    ', { + 'class': 'btn-group', + }).appendTo(el); + + var but_prev = jQuery('