From 1878ea95fe229809d04ac8fc9626c3cac2f1f568 Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Thu, 14 Feb 2019 07:59:25 +0000 Subject: [PATCH] [IMP] website_slides: allow to set cover image for webpage slide Before this commit, the user can only create a webpage slide by setting its name, category and tags. On the channel grid, no tumbnail was shown. This commit allow the user to upload a cover image from the slide upload modal and to modify it from form view. the mimetype of webpage slide is now 'forced' through the modal to 'text/html' to avoid conflit with 'image/png' when setting the cover image. Task-1902304 --- .../static/src/js/slides_upload.js | 18 +++++++++++++---- .../static/src/xml/website_slides_upload.xml | 20 +++++++++++++++++++ .../views/slide_slide_views.xml | 4 ++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/addons/website_slides/static/src/js/slides_upload.js b/addons/website_slides/static/src/js/slides_upload.js index cdb37ff47cd..30901d80640 100644 --- a/addons/website_slides/static/src/js/slides_upload.js +++ b/addons/website_slides/static/src/js/slides_upload.js @@ -144,6 +144,11 @@ var SlideUploadDialog = Dialog.extend({ 'mime_type': this.file.type, 'datas': this.file.data }); + } else if (values['slide_type'] === 'webpage') { + _.extend(values, { + 'mime_type': 'text/html', + 'image': this.file.type === 'image/svg+xml' ? this._svgToPng() : this.file.data, + }); } else if (/^image\/.*/.test(this.file.type)) { _.extend(values, { 'slide_type': 'infographic', @@ -347,9 +352,12 @@ var SlideUploadDialog = Dialog.extend({ } }, _onChangeSlideUpload: function (ev) { + var self = this; this._alertRemove(); - var self = this; + var $input = $(ev.currentTarget); + var preventOnchange = $input.data('preventOnchange'); + var file = ev.target.files[0]; var isImage = /^image\/.*/.test(file.type); var loaded = false; @@ -440,9 +448,11 @@ var SlideUploadDialog = Dialog.extend({ }; } - var input = file.name; - var inputVal = input.substr(0, input.lastIndexOf('.')) || input; - this._formSetFieldValue('name', inputVal); + if (!preventOnchange) { + var input = file.name; + var inputVal = input.substr(0, input.lastIndexOf('.')) || input; + this._formSetFieldValue('name', inputVal); + } }, _onChangeSlideUrl: function (ev) { var self = this; diff --git a/addons/website_slides/static/src/xml/website_slides_upload.xml b/addons/website_slides/static/src/xml/website_slides_upload.xml index b427446e28f..966ff3362cd 100644 --- a/addons/website_slides/static/src/xml/website_slides_upload.xml +++ b/addons/website_slides/static/src/xml/website_slides_upload.xml @@ -103,6 +103,26 @@
+
+
+
+
+ Content Preview +
+
+
+
+
    +
  • +
    + +
    + +
  • +
+
+
+
diff --git a/addons/website_slides/views/slide_slide_views.xml b/addons/website_slides/views/slide_slide_views.xml index 180a525488e..33301591189 100644 --- a/addons/website_slides/views/slide_slide_views.xml +++ b/addons/website_slides/views/slide_slide_views.xml @@ -46,7 +46,7 @@ - +