summaryrefslogtreecommitdiff
path: root/addons/mail/static/src
diff options
context:
space:
mode:
authorThanhDodeurOdoo <tso@odoo.com>2018-08-14 11:26:55 +0200
committerThanhDodeurOdoo <tso@odoo.com>2018-09-07 16:06:47 +0200
commit16aeecc73d4cf95e55f447315c983fae4ca471f7 (patch)
tree307ce38ff6d53bff5368e2488ce47b63da1ff1b8 /addons/mail/static/src
parent469d7acb89822ec11179d7bf2355e2b0eb9053df (diff)
[REF] base, mail: Documents (enterprise) related changes
-removed force_ext from ir.http. -added signature arg to web/image to differentiate cache entries by URL. -added an embed youtube viewer for youtube URL's -added a PDF splitter to the PDF viewer UI -added tests for mail's Document Viewer -added a "signature" param to web/image to go around the browser cache -thumbnail field of ir.attachment is now stored in the filestore as a distinct attachment. task 1853490 Co-authored-by: Pierre Paridans <app@odoo.com>
Diffstat (limited to 'addons/mail/static/src')
-rw-r--r--addons/mail/static/src/js/document_viewer.js58
-rw-r--r--addons/mail/static/src/scss/composer.scss34
-rw-r--r--addons/mail/static/src/xml/thread.xml9
3 files changed, 92 insertions, 9 deletions
diff --git a/addons/mail/static/src/js/document_viewer.js b/addons/mail/static/src/js/document_viewer.js
index fc8f9940d81..e2c03e24d6a 100644
--- a/addons/mail/static/src/js/document_viewer.js
+++ b/addons/mail/static/src/js/document_viewer.js
@@ -13,6 +13,7 @@ var DocumentViewer = Widget.extend({
template: "DocumentViewer",
events: {
'click .o_download_btn': '_onDownload',
+ 'click .o_split_btn': '_onSplitPDF',
'click .o_viewer_img': '_onImageClicked',
'click .o_viewer_video': '_onVideoClicked',
'click .move_next': '_onNext',
@@ -43,10 +44,25 @@ var DocumentViewer = Widget.extend({
init: function (parent, attachments, activeAttachmentID) {
this._super.apply(this, arguments);
this.attachment = _.filter(attachments, function (attachment) {
- var match = attachment.mimetype.match("(image|video|application/pdf|text)");
+ var match = attachment.type == 'url' ? attachment.url.match("(youtu|.png|.jpg|.gif)") : attachment.mimetype.match("(image|video|application/pdf|text)");
if (match) {
attachment.type = match[1];
+ if (match[1].match("(.png|.jpg|.gif)")) {
+ attachment.type = 'image';
+ }
+ if (match[1] === 'youtu') {
+ var youtube_array = attachment.url.split('/');
+ var youtube_token = youtube_array[youtube_array.length-1];
+ if (youtube_token.indexOf('watch') !== -1) {
+ youtube_token = youtube_token.split('v=')[1];
+ var amp = youtube_token.indexOf('&')
+ if (amp !== -1){
+ youtube_token = youtube_token.substring(0, amp);
+ }
+ }
+ attachment.youtube = youtube_token;
+ }
return true;
}
});
@@ -64,6 +80,18 @@ var DocumentViewer = Widget.extend({
this.$('[data-toggle="tooltip"]').tooltip({delay: 0});
return this._super.apply(this, arguments);
},
+ /**
+ * @override
+ */
+ destroy: function () {
+ if (this.isDestroyed()) {
+ return;
+ }
+ this.trigger_up('document_viewer_closed');
+ this.$el.modal('hide');
+ this.$el.remove();
+ this._super.apply(this, arguments);
+ },
//--------------------------------------------------------------------------
// Private
@@ -156,19 +184,15 @@ var DocumentViewer = Widget.extend({
*/
_onClose: function (e) {
e.preventDefault();
- this.$el.modal('hide');
- this.trigger_up('document_viewer_closed');
+ this.destroy();
},
/**
* When popup close complete destroyed modal even DOM footprint too
+ *
* @private
*/
_onDestroy: function () {
- if (this.isDestroyed()) {
- return;
- }
- this.$el.modal('hide');
- this.$el.remove();
+ this.destroy();
},
/**
* @private
@@ -305,6 +329,24 @@ var DocumentViewer = Widget.extend({
* @private
* @param {MouseEvent} e
*/
+ _onSplitPDF: function (e) {
+ e.stopPropagation();
+ var self = this;
+ var indices = $("input[name=Indices]").val();
+ var remainder = $("input[type=checkbox][name=remainder]").is(":checked");
+ this._rpc({
+ model: 'ir.attachment',
+ method: 'split_pdf',
+ args: [this.activeAttachment.id, indices, remainder],
+ }).always(function () {
+ self.trigger_up('document_viewer_attachment_changed');
+ self.destroy();
+ });
+ },
+ /**
+ * @private
+ * @param {MouseEvent} e
+ */
_onStartDrag: function (e) {
e.preventDefault();
this.enableDrag = true;
diff --git a/addons/mail/static/src/scss/composer.scss b/addons/mail/static/src/scss/composer.scss
index 9925813bb73..5fd0ca0e8af 100644
--- a/addons/mail/static/src/scss/composer.scss
+++ b/addons/mail/static/src/scss/composer.scss
@@ -452,6 +452,32 @@ $o-mail-attachment-margin: 5px;
font-size: $h1-font-size;
font-weight: 300;
}
+
+ .o_image_caption {
+ bottom: 20%;
+ position: absolute;
+
+ .o_split_pdf_area {
+ background-color: #3a3a3a;
+ margin: 5px;
+ padding: 6px;
+ margin-left: 50px;
+
+ .o_split_btn {
+ vertical-align: baseline;
+ }
+
+ .o_page_number_input {
+ width: 13%;
+ color: black;
+ display: inline;
+ }
+
+ .o_remainder_input {
+ vertical-align: middle;
+ }
+ }
+ }
}
.o_loading_img {
@@ -492,6 +518,14 @@ $o-mail-attachment-margin: 5px;
box-shadow: 1px 1px 20px 1px #000;
}
+ .o_viewer_text {
+ width: 80%;
+ height: 100%;
+ border: 0px;
+ box-shadow: 1px 1px 20px 1px #000;
+ background-color: white;
+ }
+
.o_viewer_video {
height: 80%;
}
diff --git a/addons/mail/static/src/xml/thread.xml b/addons/mail/static/src/xml/thread.xml
index 242e97449f5..78295a037c7 100644
--- a/addons/mail/static/src/xml/thread.xml
+++ b/addons/mail/static/src/xml/thread.xml
@@ -32,6 +32,11 @@
<i class="fa fa-video-camera mr8" t-if="widget.activeAttachment.type == 'video'" role="img" aria-label="Video" title="Video"/>
<t t-esc="widget.activeAttachment.name"/>
<a role="button" href="#" class="o_download_btn ml8 small" data-toggle="tooltip" data-placement="right" title="Download"><i class="fa fa-fw fa-download" role="img" aria-label="Download"/></a>
+ <span t-if="widget.activeAttachment.type == 'application/pdf'" class="o_split_pdf_area">
+ <label for="Indices">Extract pages:&amp;nbsp;</label><input class="o_page_number_input" name="Indices" placeholder="e.g. 1-5, 7, 8-9"/>
+ <label for="remainder">All pages:&amp;nbsp;</label><input class="o_remainder_input" type="checkbox" name="remainder" value="remainder"/>
+ <button class="btn btn-sm btn-primary o_split_btn" data-toggle="tooltip" title="Split">Split</button>
+ </span>
</span>
<a role="button" class="o_close_btn float-right" href="#" aria-label="Close" title="Close">×</a>
</div>
@@ -40,8 +45,10 @@
<div t-if="widget.activeAttachment.type == 'image'" class="o_loading_img text-center">
<i class="fa fa-circle-o-notch fa-spin text-gray-light fa-3x fa-fw" role="img" aria-label="Loading" title="Loading"/>
</div>
- <img t-if="widget.activeAttachment.type == 'image'" class="o_viewer_img" t-attf-src="/web/image/#{widget.activeAttachment.id}?unique=1" alt="Viewer"/>
+ <img t-if="widget.activeAttachment.type == 'image'" class="o_viewer_img" t-attf-src="/web/image/#{widget.activeAttachment.id}?unique=1&amp;signature=#{widget.activeAttachment.checksum}" alt="Viewer"/>
<iframe class="mt32 o_viewer_pdf" t-if="widget.activeAttachment.type == 'application/pdf'" t-attf-src="/web/static/lib/pdfjs/web/viewer.html?file=/web/content/#{widget.activeAttachment.id}" />
+ <iframe class="mt32 o_viewer_text" t-if="(widget.activeAttachment.type || '').indexOf('text') !== -1" t-attf-src="/web/content/#{widget.activeAttachment.id}" />
+ <iframe class="mt32 o_viewer_text" t-if="widget.activeAttachment.type == 'youtu'" allow="autoplay; encrypted-media" width="560" height="315" t-attf-src="https://www.youtube.com/embed/#{widget.activeAttachment.youtube}"/>
<video t-if="widget.activeAttachment.type == 'video'" class="o_viewer_video" controls="controls">
<source t-attf-src="/web/image/#{widget.activeAttachment.id}" t-att-data-type="widget.activeAttachment.mimetype"/>
</video>