[IMP] web_editor, *: improve media dialog

* web_unsplash, website_sale

- Visual improvements and cleaning in each tab: video, documents,
  pictogram, images.

- Only one search input for both the local library and unsplash.

- Replace the idea of multiple pages by adding a 'Load More' button.

task-1896705
This commit is contained in:
Andrea Ulliana
2018-12-04 10:06:11 +00:00
committed by qsm-odoo
parent 7d6a9924e5
commit 1f847a1e2e
6 changed files with 390 additions and 242 deletions
+153 -145
View File
@@ -4,7 +4,7 @@ odoo.define('web_editor.widget', function (require) {
var ajax = require('web.ajax'); var ajax = require('web.ajax');
var base = require('web_editor.base'); var base = require('web_editor.base');
var core = require('web.core'); var core = require('web.core');
var Dialog = require('web.Dialog'); var DialogBase = require('web.Dialog');
var Widget = require('web.Widget'); var Widget = require('web.Widget');
var weContext = require("web_editor.context"); var weContext = require("web_editor.context");
@@ -26,7 +26,7 @@ function simulateMouseEvent(el, type) {
/** /**
* Extend Dialog class to handle save/cancel of edition components. * Extend Dialog class to handle save/cancel of edition components.
*/ */
Dialog = Dialog.extend({ var Dialog = DialogBase.extend({
/** /**
* @constructor * @constructor
*/ */
@@ -109,6 +109,9 @@ var AltDialog = Dialog.extend({
var MediaWidget = Widget.extend({ var MediaWidget = Widget.extend({
xmlDependencies: ['/web_editor/static/src/xml/editor.xml'], xmlDependencies: ['/web_editor/static/src/xml/editor.xml'],
events: {
'input input#icon-search': '_onSearchInput',
},
/** /**
* @constructor * @constructor
@@ -117,7 +120,7 @@ var MediaWidget = Widget.extend({
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.media = media; this.media = media;
this.$media = $(media); this.$media = $(media);
this.page = 0; this._onSearchInput = _.debounce(this._onSearchInput, 250);
}, },
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@@ -144,12 +147,6 @@ var MediaWidget = Widget.extend({
pagerRightEnabled: false, pagerRightEnabled: false,
}; };
}, },
/**
* @override
*/
goToPage: function (page) {
this.page = page;
},
/** /**
* @abstract * @abstract
* @param {string} needle * @param {string} needle
@@ -178,6 +175,17 @@ var MediaWidget = Widget.extend({
this.$media = $media; this.$media = $media;
this.media = $media[0]; this.media = $media[0];
}, },
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @private
*/
_onSearchInput: function (ev) {
this.search($(ev.currentTarget).val() || '');
},
}); });
/** /**
@@ -185,19 +193,20 @@ var MediaWidget = Widget.extend({
*/ */
var ImageWidget = MediaWidget.extend({ var ImageWidget = MediaWidget.extend({
template: 'web_editor.dialog.image', template: 'web_editor.dialog.image',
events: { events: _.extend({}, MediaWidget.prototype.events || {}, {
'click .o_upload_image_button': '_onUploadButtonClick', 'click .o_upload_media_button': '_onUploadButtonClick',
'click .o_upload_image_button_no_optimization': '_onUploadButtonNoOptimizationClick', 'click .o_upload_media_button_no_optimization': '_onUploadButtonNoOptimizationClick',
'change input[type=file]': '_onImageSelection', 'change input[type=file]': '_onImageSelection',
'click .o_upload_image_url_button': '_onUploadURLButtonClick', 'click .o_upload_media_url_button': '_onUploadURLButtonClick',
'input input.url': "_onSearchInput", 'input input.url': '_onChangeInputURL',
'click .existing-attachments [data-src]': '_onImageClick', 'click .existing-attachments [data-src]': '_onImageClick',
'dblclick .existing-attachments [data-src]': '_onImageDblClick', 'dblclick .existing-attachments [data-src]': '_onImageDblClick',
'click .o_existing_attachment_remove': '_onRemoveClick', 'click .o_existing_attachment_remove': '_onRemoveClick',
}, 'click .o_load_more': '_onLoadMore',
}),
IMAGES_PER_ROW: 6, IMAGES_PER_ROW: 6,
IMAGES_ROWS: 2, IMAGES_ROWS: 5,
/** /**
* @constructor * @constructor
@@ -205,7 +214,7 @@ var ImageWidget = MediaWidget.extend({
init: function (parent, media, options) { init: function (parent, media, options) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.IMAGES_PER_PAGE = this.IMAGES_PER_ROW * this.IMAGES_ROWS; this.IMAGES_DISPLAYED_TOTAL = this.IMAGES_PER_ROW * this.IMAGES_ROWS;
this.options = options; this.options = options;
this.accept = options.accept || (options.document ? '*/*' : 'image/*'); this.accept = options.accept || (options.document ? '*/*' : 'image/*');
@@ -265,22 +274,6 @@ var ImageWidget = MediaWidget.extend({
// Public // Public
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/**
* @override
*/
getControlPanelConfig: function () {
return _.extend(this._super.apply(this, arguments), {
pagerLeftEnabled: this.page > 0,
pagerRightEnabled: (this.page + 1) * this.IMAGES_PER_PAGE < this.records.length,
});
},
/**
* @override
*/
goToPage: function (page) {
this._super.apply(this, arguments);
this._renderImages();
},
/** /**
* @override * @override
*/ */
@@ -444,16 +437,28 @@ var ImageWidget = MediaWidget.extend({
*/ */
_renderImages: function () { _renderImages: function () {
var self = this; var self = this;
var startIndex = this.page * this.IMAGES_PER_PAGE;
var rows = _(this.records).chain() var rows = _(this.records).chain()
.slice(startIndex, startIndex + this.IMAGES_PER_PAGE) .slice(0, this.IMAGES_DISPLAYED_TOTAL)
.groupBy(function (a, index) { return Math.floor(index / self.IMAGES_PER_ROW); }) .groupBy(function (a, index) { return Math.floor(index / self.IMAGES_PER_ROW); })
.values() .values()
.value(); .value();
var noMoreImgToLoad = this.IMAGES_DISPLAYED_TOTAL >= this.records.length;
this.$('.o_load_more').toggleClass('d-none', noMoreImgToLoad);
this.$('.o_load_done_msg').toggleClass('d-none', !noMoreImgToLoad);
this.$('.form-text').empty(); this.$('.form-text').empty();
this.$('.existing-attachments').replaceWith(QWeb.render('web_editor.dialog.image.existing.content', {rows: rows})); //Rendering menu & content for 'Image' or 'Document' tab
var templateMenu = 'web_editor.dialog.files.submenu';
var templateContent = 'web_editor.dialog.files.existing.content';
this.$('.o_submenu').replaceWith(QWeb.render(templateMenu, {
accept: this.accept,
isDocument: this.options.document,
}));
this.$('.existing-attachments').replaceWith(QWeb.render(templateContent, {
rows: rows,
isDocument: this.options.document,
}));
var $divs = this.$('.o_image'); var $divs = this.$('.o_image');
var imageDefs = _.map($divs, function (el) { var imageDefs = _.map($divs, function (el) {
@@ -479,12 +484,12 @@ var ImageWidget = MediaWidget.extend({
/** /**
* @private * @private
*/ */
_toggleImage: function (attachment, clearSearch, force_select) { _toggleImage: function (attachment, clearSearch, forceSelect) {
if (this.multiImages) { if (this.multiImages) {
var img = _.select(this.images, function (v) { return v.id === attachment.id; }); var img = _.select(this.images, function (v) { return v.id === attachment.id; });
if (img.length) { if (img.length) {
if (!force_select) { if (!forceSelect) {
this.images.splice(this.images.indexOf(img[0]),1); this.images.splice(this.images.indexOf(img[0]), 1);
} }
} else { } else {
this.images.push(attachment); this.images.push(attachment);
@@ -501,14 +506,14 @@ var ImageWidget = MediaWidget.extend({
/** /**
* @private * @private
*/ */
_uploadImage: function () { _uploadFile: function () {
var self = this; var self = this;
/** /**
* @todo file upload cannot be handled with _rpc smoothly. This uses the * @todo file upload cannot be handled with _rpc smoothly. This uses the
* form posting in iframe trick to handle the upload. * form posting in iframe trick to handle the upload.
*/ */
var $iframe = this.$('iframe'); var $iframe = this.$('.o_file_upload_iframe');
$iframe.on('load', function () { $iframe.on('load', function () {
var iWindow = $iframe[0].contentWindow; var iWindow = $iframe[0].contentWindow;
var attachments = iWindow.attachments; var attachments = iWindow.attachments;
@@ -524,7 +529,7 @@ var ImageWidget = MediaWidget.extend({
_processFile(null, error || !attachments.length); _processFile(null, error || !attachments.length);
} }
self.images = attachments; self.images = attachments;
for (var i = 0 ; i < attachments.length ; i++) { for (var i = 0; i < attachments.length; i++) {
_processFile(attachments[i], error); _processFile(attachments[i], error);
} }
@@ -533,22 +538,25 @@ var ImageWidget = MediaWidget.extend({
} }
function _processFile(attachment, error) { function _processFile(attachment, error) {
var $button = self.$('.o_upload_image_button');
if (!error) { if (!error) {
$button.addClass('btn-success');
self._toggleImage(attachment, true); self._toggleImage(attachment, true);
} else { } else {
$button.addClass('btn-danger');
self.$el.addClass('o_has_error').find('.form-control, .custom-select').addClass('is-invalid'); self.$el.addClass('o_has_error').find('.form-control, .custom-select').addClass('is-invalid');
self.$el.find('.form-text').text(error); self.$el.find('.form-text').text(error);
} }
if (!self.multiImages) {
self.trigger_up('save_request');
}
} }
}); });
this.$el.submit(); this.$el.submit();
// Emptying file inputs
this.$('.o_file_input').val('');
},
/**
* @private
*/
_loadMoreImages: function () {
this.IMAGES_ROWS += 2;
this.IMAGES_DISPLAYED_TOTAL = this.IMAGES_ROWS * this.IMAGES_PER_ROW;
this._renderImages();
}, },
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@@ -558,12 +566,12 @@ var ImageWidget = MediaWidget.extend({
/** /**
* @private * @private
*/ */
_onImageClick: function (ev, force_select) { _onImageClick: function (ev, forceSelect) {
var $img = $(ev.currentTarget); var $img = $(ev.currentTarget);
var attachment = _.find(this.records, function (record) { var attachment = _.find(this.records, function (record) {
return record.id === $img.data('id'); return record.id === $img.data('id');
}); });
this._toggleImage(attachment, false, force_select); this._toggleImage(attachment, false, forceSelect);
}, },
/** /**
* @private * @private
@@ -580,44 +588,70 @@ var ImageWidget = MediaWidget.extend({
this.$el.addClass('nosave'); this.$el.addClass('nosave');
$form.removeClass('o_has_error').find('.form-control, .custom-select').removeClass('is-invalid'); $form.removeClass('o_has_error').find('.form-control, .custom-select').removeClass('is-invalid');
$form.find('.form-text').empty(); $form.find('.form-text').empty();
this.$('.o_upload_image_button').removeClass('btn-danger btn-success'); this.$('.o_upload_media_button').removeClass('btn-danger btn-success');
this._uploadImage(); this._uploadFile();
}, },
/** /**
* @private * @private
*/ */
_onRemoveClick: function (ev) { _onRemoveClick: function (ev) {
var self = this; var self = this;
var $helpBlock = this.$('.form-text').empty(); var message = _t("Are you sure you want to delete this file ?");
var $a = $(ev.currentTarget); DialogBase.confirm(this, message, {
var id = parseInt($a.data('id'), 10); confirm_callback: function () {
var attachment = _.findWhere(this.records, {id: id}); var $helpBlock = this.$('.form-text').empty();
var $a = $(ev.currentTarget);
var id = parseInt($a.data('id'), 10);
var attachment = _.findWhere(this.records, {id: id});
return this._rpc({ return self._rpc({
route: '/web_editor/attachment/remove', route: '/web_editor/attachment/remove',
params: { params: {
ids: [id], ids: [id],
}, },
}).then(function (prevented) { }).then(function (prevented) {
if (_.isEmpty(prevented)) { if (_.isEmpty(prevented)) {
self.records = _.without(self.records, attachment); self.records = _.without(self.records, attachment);
self._renderImages(); self.search('');
return; return;
}
$helpBlock.replaceWith(QWeb.render('web_editor.dialog.image.existing.error', {
views: prevented[id]
}));
});
} }
$helpBlock.replaceWith(QWeb.render('web_editor.dialog.image.existing.error', {
views: prevented[id]
}));
}); });
}, },
/** /**
* @private * @private
*/ */
_onSearchInput: function (ev) { _onChangeInputURL: function (ev) {
var $input = $(ev.currentTarget); var $input = $(ev.currentTarget);
var $button = $input.next('.input-group-append').children(); var $button = $input.next('.input-group-append').children();
var emptyValue = ($input.val() === ''); var inputValue = $input.val();
var emptyValue = (inputValue === '');
var $warning = this.$('.warning-url');
var $success = this.$('.success-url');
var $error = this.$('.error-url');
var $btn = this.$('.o_upload_media_url_button');
var regex = /^(?:https?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/;
var isURL = regex.test(inputValue);
var showWarningOrError = (inputValue.length !== 0 ? isURL : !isURL);
$button.toggleClass('btn-secondary', emptyValue).toggleClass('btn-primary', !emptyValue) $button.toggleClass('btn-secondary', emptyValue).toggleClass('btn-primary', !emptyValue)
.prop('disabled', emptyValue); .prop('disabled', emptyValue);
if (!this.options.document) {
_.each(['.gif', '.jpe', '.jpg', '.png'], function (format) {
var endsWith = inputValue.endsWith(format);
$button.text(endsWith ? _t("Add image") : _t("Add as document"));
});
} else {
$btn.prop('disabled', !isURL);
}
$success.toggleClass('d-none', !isURL);
$warning.toggleClass('d-none', showWarningOrError);
$error.toggleClass('d-none', showWarningOrError);
}, },
/** /**
* @private * @private
@@ -630,13 +664,19 @@ var ImageWidget = MediaWidget.extend({
*/ */
_onUploadButtonNoOptimizationClick: function () { _onUploadButtonNoOptimizationClick: function () {
this.$('input[name="disable_optimization"]').val('1'); this.$('input[name="disable_optimization"]').val('1');
this.$('.o_upload_image_button').click(); this.$('.o_upload_media_button').click();
}, },
/** /**
* @private * @private
*/ */
_onUploadURLButtonClick: function () { _onUploadURLButtonClick: function () {
this._uploadImage(); this._uploadFile();
},
/**
* @private
*/
_onLoadMore: function () {
this._loadMoreImages();
}, },
}); });
@@ -646,10 +686,10 @@ var ImageWidget = MediaWidget.extend({
*/ */
var IconWidget = MediaWidget.extend({ var IconWidget = MediaWidget.extend({
template: 'web_editor.dialog.font-icons', template: 'web_editor.dialog.font-icons',
events : { events: _.extend({}, MediaWidget.prototype.events || {}, {
'click .font-icons-icon': '_onIconClick', 'click .font-icons-icon': '_onIconClick',
'dblclick .font-icons-icon': '_onIconDblClick', 'dblclick .font-icons-icon': '_onIconDblClick',
}, }),
/** /**
* @constructor * @constructor
@@ -669,7 +709,7 @@ var IconWidget = MediaWidget.extend({
start: function () { start: function () {
this.$icons = this.$('.font-icons-icon'); this.$icons = this.$('.font-icons-icon');
var classes = (this.media && this.media.className || '').split(/\s+/); var classes = (this.media && this.media.className || '').split(/\s+/);
for (var i = 0 ; i < classes.length ; i++) { for (var i = 0; i < classes.length; i++) {
var cls = classes[i]; var cls = classes[i];
if (_.contains(this.alias, cls)) { if (_.contains(this.alias, cls)) {
this.selectedIcon = cls; this.selectedIcon = cls;
@@ -753,12 +793,12 @@ var IconWidget = MediaWidget.extend({
*/ */
_getFont: function (classNames) { _getFont: function (classNames) {
if (!(classNames instanceof Array)) { if (!(classNames instanceof Array)) {
classNames = (classNames||"").split(/\s+/); classNames = (classNames || "").split(/\s+/);
} }
var fontIcon, cssData; var fontIcon, cssData;
for (var k=0; k<this.iconsParser.length; k++) { for (var k = 0; k < this.iconsParser.length; k++) {
fontIcon = this.iconsParser[k]; fontIcon = this.iconsParser[k];
for (var s=0; s<fontIcon.cssData.length; s++) { for (var s = 0; s < fontIcon.cssData.length; s++) {
cssData = fontIcon.cssData[s]; cssData = fontIcon.cssData[s];
if (_.intersection(classNames, cssData.names).length) { if (_.intersection(classNames, cssData.names).length) {
return { return {
@@ -809,7 +849,7 @@ var IconWidget = MediaWidget.extend({
*/ */
var VideoWidget = MediaWidget.extend({ var VideoWidget = MediaWidget.extend({
template: 'web_editor.dialog.video', template: 'web_editor.dialog.video',
events : { events: {
'change .o_video_dialog_options input': '_onUpdateVideoOption', 'change .o_video_dialog_options input': '_onUpdateVideoOption',
'input textarea#o_video_text': '_onVideoCodeInput', 'input textarea#o_video_text': '_onVideoCodeInput',
'change textarea#o_video_text': '_onVideoCodeChange', 'change textarea#o_video_text': '_onVideoCodeChange',
@@ -867,10 +907,10 @@ var VideoWidget = MediaWidget.extend({
this._updateVideo(); this._updateVideo();
if (this.$('.o_video_dialog_iframe').is('iframe')) { if (this.$('.o_video_dialog_iframe').is('iframe')) {
this._replaceMedia($( this._replaceMedia($(
'<div class="media_iframe_video" data-oe-expression="' + this.$content.attr('src') + '">'+ '<div class="media_iframe_video" data-oe-expression="' + this.$content.attr('src') + '">' +
'<div class="css_editable_mode_display">&nbsp;</div>'+ '<div class="css_editable_mode_display">&nbsp;</div>' +
'<div class="media_iframe_video_size" contenteditable="false">&nbsp;</div>'+ '<div class="media_iframe_video_size" contenteditable="false">&nbsp;</div>' +
'<iframe src="' + this.$content.attr('src') + '" frameborder="0" contenteditable="false"></iframe>'+ '<iframe src="' + this.$content.attr('src') + '" frameborder="0" contenteditable="false"></iframe>' +
'</div>' '</div>'
)); ));
} }
@@ -950,12 +990,12 @@ var VideoWidget = MediaWidget.extend({
$video.attr('src', '//player.vimeo.com/video/' + vimMatch[3] + autoplay); $video.attr('src', '//player.vimeo.com/video/' + vimMatch[3] + autoplay);
videoType = 'vim'; videoType = 'vim';
} else if (dmMatch && dmMatch[2].length) { } else if (dmMatch && dmMatch[2].length) {
var just_id = dmMatch[2].replace('video/',''); var justId = dmMatch[2].replace('video/', '');
$video.attr('src', '//www.dailymotion.com/embed/video/' + just_id + autoplay); $video.attr('src', '//www.dailymotion.com/embed/video/' + justId + autoplay);
videoType = 'dm'; videoType = 'dm';
} else if (ykuMatch && ykuMatch[3].length) { } else if (ykuMatch && ykuMatch[3].length) {
var yku_id = ykuMatch[3].indexOf('.html?') >= 0 ? ykuMatch[3].substring(0, ykuMatch[3].indexOf('.html?')) : ykuMatch[3]; var ykuId = ykuMatch[3].indexOf('.html?') >= 0 ? ykuMatch[3].substring(0, ykuMatch[3].indexOf('.html?')) : ykuMatch[3];
$video.attr('src', '//player.youku.com/embed/' + yku_id); $video.attr('src', '//player.youku.com/embed/' + ykuId);
videoType = 'yku'; videoType = 'yku';
} else { } else {
return {errorCode: 1}; return {errorCode: 1};
@@ -994,7 +1034,7 @@ var VideoWidget = MediaWidget.extend({
// Reset the feedback // Reset the feedback
this.$content.empty(); this.$content.empty();
this.$('#o_video_form_group').removeClass('o_has_error o_has_success').find('.form-control, .custom-select').removeClass('is-invalid is-valid'); this.$('#o_video_form_group').removeClass('o_has_error o_has_success').find('.form-control, .custom-select').removeClass('is-invalid is-valid');
this.$('.o_video_dialog_options li').addClass('d-none'); this.$('.o_video_dialog_options div').addClass('d-none');
// Check video code // Check video code
var $textarea = this.$('textarea#o_video_text'); var $textarea = this.$('textarea#o_video_text');
@@ -1005,7 +1045,7 @@ var VideoWidget = MediaWidget.extend({
// Detect if we have an embed code rather than an URL // Detect if we have an embed code rather than an URL
var embedMatch = code.match(/(src|href)=["']?([^"']+)?/); var embedMatch = code.match(/(src|href)=["']?([^"']+)?/);
if (embedMatch && embedMatch[2].length > 0 && embedMatch[2].indexOf('instagram')){ if (embedMatch && embedMatch[2].length > 0 && embedMatch[2].indexOf('instagram')) {
embedMatch[1] = embedMatch[2]; // Instagram embed code is different embedMatch[1] = embedMatch[2]; // Instagram embed code is different
} }
var url = embedMatch ? embedMatch[1] : code; var url = embedMatch ? embedMatch[1] : code;
@@ -1020,10 +1060,10 @@ var VideoWidget = MediaWidget.extend({
hide_dm_share: this.$('input#o_video_hide_dm_share').is(':checked'), hide_dm_share: this.$('input#o_video_hide_dm_share').is(':checked'),
}); });
var $opt_box = this.$('.o_video_dialog_options'); var $optBox = this.$('.o_video_dialog_options');
// Show / Hide preview elements // Show / Hide preview elements
this.$el.find('.o_video_dialog_preview_text, .media_iframe_video_size').add($opt_box).toggleClass('d-none', !query.$video); this.$el.find('.o_video_dialog_preview_text, .media_iframe_video_size').add($optBox).toggleClass('d-none', !query.$video);
// Toggle validation classes // Toggle validation classes
this.$el.find('#o_video_form_group') this.$el.find('#o_video_form_group')
.toggleClass('o_has_error', !query.$video).find('.form-control, .custom-select').toggleClass('is-invalid', !query.$video) .toggleClass('o_has_error', !query.$video).find('.form-control, .custom-select').toggleClass('is-invalid', !query.$video)
@@ -1031,15 +1071,16 @@ var VideoWidget = MediaWidget.extend({
.toggleClass('o_has_success', !!query.$video).find('.form-control, .custom-select').toggleClass('is-valid', !!query.$video); .toggleClass('o_has_success', !!query.$video).find('.form-control, .custom-select').toggleClass('is-valid', !!query.$video);
// Individually show / hide options base on the video provider // Individually show / hide options base on the video provider
$opt_box.find('li.o_' + query.type + '_option').removeClass('d-none'); $optBox.find('div.o_' + query.type + '_option').removeClass('d-none');
// Hide the entire options box if no options are available // Hide the entire options box if no options are available
$opt_box.toggleClass('d-none', $opt_box.find('li:not(.d-none)').length === 0); $optBox.toggleClass('d-none', $optBox.find('div:not(.d-none)').length === 0);
$('.option_title').toggleClass('d-none');
if (query.type === 'yt') { if (query.type === 'yt') {
// Youtube only: If 'hide controls' is checked, hide 'fullscreen' // Youtube only: If 'hide controls' is checked, hide 'fullscreen'
// and 'youtube logo' options too // and 'youtube logo' options too
this.$('input#o_video_hide_fullscreen, input#o_video_hide_yt_logo').closest('li').toggleClass('d-none', this.$('input#o_video_hide_controls').is(':checked')); this.$('input#o_video_hide_fullscreen, input#o_video_hide_yt_logo').closest('div').toggleClass('d-none', this.$('input#o_video_hide_controls').is(':checked'));
} }
var $content = query.$video; var $content = query.$video;
@@ -1047,13 +1088,13 @@ var VideoWidget = MediaWidget.extend({
switch (query.errorCode) { switch (query.errorCode) {
case 0: case 0:
$content = $('<div/>', { $content = $('<div/>', {
class: 'alert alert-danger o_video_dialog_iframe', class: 'alert alert-danger o_video_dialog_iframe mb-2 mt-2',
text: _t("The provided url is not valid"), text: _t("The provided url is not valid"),
}); });
break; break;
case 1: case 1:
$content = $('<div/>', { $content = $('<div/>', {
class: 'alert alert-warning o_video_dialog_iframe', class: 'alert alert-warning o_video_dialog_iframe mb-2 mt-2',
text: _t("The provided url does not reference any supported video"), text: _t("The provided url does not reference any supported video"),
}); });
break; break;
@@ -1105,14 +1146,11 @@ var MediaDialog = Dialog.extend({
xmlDependencies: Dialog.prototype.xmlDependencies.concat( xmlDependencies: Dialog.prototype.xmlDependencies.concat(
['/web_editor/static/src/xml/editor.xml'] ['/web_editor/static/src/xml/editor.xml']
), ),
events : _.extend({}, Dialog.prototype.events, { events: _.extend({}, Dialog.prototype.events, {
'input input#icon-search': '_onSearchInput',
'shown.bs.tab a[data-toggle="tab"]': '_onTabChange', 'shown.bs.tab a[data-toggle="tab"]': '_onTabChange',
'click .previous:not(.disabled), .next:not(.disabled)': '_onPagerClick',
}), }),
custom_events: _.extend({}, Dialog.prototype.custom_events || {}, { custom_events: _.extend({}, Dialog.prototype.custom_events || {}, {
save_request: '_onSaveRequest', save_request: '_onSaveRequest',
update_control_panel: '_updateControlPanel',
}), }),
/** /**
@@ -1122,6 +1160,7 @@ var MediaDialog = Dialog.extend({
var self = this; var self = this;
this._super(parent, _.extend({}, { this._super(parent, _.extend({}, {
title: _t("Select a Media"), title: _t("Select a Media"),
save_text: _t("Add"),
}, options)); }, options));
if ($editable) { if ($editable) {
@@ -1168,8 +1207,6 @@ var MediaDialog = Dialog.extend({
} }
self.$('[href="#editor-media-' + tabToShow + '"]').tab('show'); self.$('[href="#editor-media-' + tabToShow + '"]').tab('show');
}); });
this._onSearchInput = _.debounce(this._onSearchInput, 250);
}, },
/** /**
* @override * @override
@@ -1266,31 +1303,12 @@ var MediaDialog = Dialog.extend({
*/ */
_setActive: function (widget) { _setActive: function (widget) {
this.active = widget; this.active = widget;
this.active.goToPage(0);
this._updateControlPanel();
},
/**
* @private
*/
_updateControlPanel: function () {
var cpConfig = this.active.getControlPanelConfig();
this.$('li.search').toggleClass('d-none', !cpConfig.searchEnabled);
this.$('.previous, .next').toggleClass('d-none', !cpConfig.pagerEnabled);
this.$('.previous').toggleClass("disabled", !cpConfig.pagerLeftEnabled);
this.$('.next').toggleClass("disabled", !cpConfig.pagerRightEnabled);
}, },
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Handlers // Handlers
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/**
* @private
*/
_onPagerClick: function (ev) {
this.active.goToPage(this.active.page + ($(ev.currentTarget).hasClass('previous') ? -1 : 1));
this._updateControlPanel();
},
/** /**
* @private * @private
*/ */
@@ -1298,16 +1316,6 @@ var MediaDialog = Dialog.extend({
ev.stopPropagation(); ev.stopPropagation();
this.save(); this.save();
}, },
/**
* @private
*/
_onSearchInput: function (ev) {
var self = this;
this.active.goToPage(0);
this.active.search($(ev.currentTarget).val() || '').then(function () {
self._updateControlPanel();
});
},
/** /**
* @private * @private
*/ */
@@ -1359,7 +1367,7 @@ var LinkDialog = Dialog.extend({
this.data.iniClassName = $(this.data.range.sc).filter("a").attr("class") || ""; this.data.iniClassName = $(this.data.range.sc).filter("a").attr("class") || "";
this.data.className = this.data.iniClassName.replace(/(^|\s+)btn(-[a-z0-9_-]*)?/gi, ' '); this.data.className = this.data.iniClassName.replace(/(^|\s+)btn(-[a-z0-9_-]*)?/gi, ' ');
var is_link = this.data.range.isOnAnchor(); var isLink = this.data.range.isOnAnchor();
var sc = r.sc; var sc = r.sc;
var so = r.so; var so = r.so;
@@ -1367,7 +1375,7 @@ var LinkDialog = Dialog.extend({
var eo = r.eo; var eo = r.eo;
var nodes; var nodes;
if (!is_link) { if (!isLink) {
if (sc.tagName) { if (sc.tagName) {
sc = dom.firstChild(so ? sc.childNodes[so] : sc); sc = dom.firstChild(so ? sc.childNodes[so] : sc);
so = 0; so = 0;
@@ -1381,7 +1389,7 @@ var LinkDialog = Dialog.extend({
so = 0; so = 0;
} }
if (ec.tagName) { if (ec.tagName) {
ec = dom.lastChild(eo ? ec.childNodes[eo-1] : ec); ec = dom.lastChild(eo ? ec.childNodes[eo - 1] : ec);
eo = ec.textContent.length; eo = ec.textContent.length;
} else if (eo !== ec.textContent.length) { } else if (eo !== ec.textContent.length) {
ec.splitText(eo); ec.splitText(eo);
@@ -1391,11 +1399,11 @@ var LinkDialog = Dialog.extend({
// browsers can't target a picture or void node // browsers can't target a picture or void node
if (dom.isVoid(sc) || dom.isImg(sc)) { if (dom.isVoid(sc) || dom.isImg(sc)) {
so = dom.listPrev(sc).length-1; so = dom.listPrev(sc).length - 1;
sc = sc.parentNode; sc = sc.parentNode;
} }
if (dom.isBR(ec)) { if (dom.isBR(ec)) {
eo = dom.listPrev(ec).length-1; eo = dom.listPrev(ec).length - 1;
ec = ec.parentNode; ec = ec.parentNode;
} else if (dom.isVoid(ec) || dom.isImg(sc)) { } else if (dom.isVoid(ec) || dom.isImg(sc)) {
eo = dom.listPrev(ec).length; eo = dom.listPrev(ec).length;
@@ -1414,15 +1422,15 @@ var LinkDialog = Dialog.extend({
if (nodes.length > 1 || dom.ancestor(nodes[0], dom.isImg)) { if (nodes.length > 1 || dom.ancestor(nodes[0], dom.isImg)) {
var text = ""; var text = "";
this.data.images = []; this.data.images = [];
for (var i=0; i<nodes.length; i++) { for (var i = 0; i < nodes.length; i++) {
if (dom.ancestor(nodes[i], dom.isImg)) { if (dom.ancestor(nodes[i], dom.isImg)) {
this.data.images.push(dom.ancestor(nodes[i], dom.isImg)); this.data.images.push(dom.ancestor(nodes[i], dom.isImg));
text += '[IMG]'; text += '[IMG]';
} else if (!is_link && nodes[i].nodeType === 1) { } else if (!isLink && nodes[i].nodeType === 1) {
// just use text nodes from listBetween // just use text nodes from listBetween
} else if (!is_link && i===0) { } else if (!isLink && i === 0) {
text += nodes[i].textContent.slice(so, Infinity); text += nodes[i].textContent.slice(so, Infinity);
} else if (!is_link && i===nodes.length-1) { } else if (!isLink && i === nodes.length - 1) {
text += nodes[i].textContent.slice(0, eo); text += nodes[i].textContent.slice(0, eo);
} else { } else {
text += nodes[i].textContent; text += nodes[i].textContent;
@@ -1534,7 +1542,7 @@ var LinkDialog = Dialog.extend({
var label = this.$('input[name="label"]').val() || url; var label = this.$('input[name="label"]').val() || url;
if (label && this.data.images) { if (label && this.data.images) {
for (var i = 0 ; i < this.data.images.length ; i++) { for (var i = 0; i < this.data.images.length; i++) {
label = label.replace(/</, "&lt;").replace(/>/, "&gt;").replace(/\[IMG\]/, this.data.images[i].outerHTML); label = label.replace(/</, "&lt;").replace(/>/, "&gt;").replace(/\[IMG\]/, this.data.images[i].outerHTML);
} }
} }
@@ -1600,7 +1608,7 @@ var CropImageDialog = Dialog.extend({
cssLibs: [ cssLibs: [
'/web_editor/static/lib/cropper/css/cropper.css', '/web_editor/static/lib/cropper/css/cropper.css',
], ],
events : _.extend({}, Dialog.prototype.events, { events: _.extend({}, Dialog.prototype.events, {
'click .o_crop_options [data-event]': '_onCropOptionClick', 'click .o_crop_options [data-event]': '_onCropOptionClick',
}), }),
@@ -1683,7 +1691,7 @@ var CropImageDialog = Dialog.extend({
if (this.$cropperImage.length) { if (this.$cropperImage.length) {
var data = this.$media.data(); var data = this.$media.data();
var ratio = 0; var ratio = 0;
for (var i = 0 ; i < this.aspectRatioList.length ; i++) { for (var i = 0; i < this.aspectRatioList.length; i++) {
if (this.aspectRatioList[i][1] === data.aspectRatio) { if (this.aspectRatioList[i][1] === data.aspectRatio) {
ratio = this.aspectRatioList[i][2]; ratio = this.aspectRatioList[i][2];
break; break;
@@ -1386,10 +1386,16 @@ body .modal {
margin-right: 10px; margin-right: 10px;
} }
} }
.o_size_fa_icon {
font-size: 1.4rem;
}
.o_size_dropdown_item {
font-size: 0.9rem;
}
} }
// VIDEO TAB // VIDEO TAB
#editor-media-video .card { #editor-media-video .o_video_dialog_container {
padding: 0; padding: 0;
display: flex; display: flex;
flex-flow: row wrap; flex-flow: row wrap;
+119 -72
View File
@@ -57,18 +57,6 @@
<li class="nav-item"><a role="tab" href="#editor-media-document" aria-controls="editor-media-document" data-toggle="tab" t-attf-class="nav-link#{widget.noDocuments ? ' d-none' : ''}">Document</a></li> <li class="nav-item"><a role="tab" href="#editor-media-document" aria-controls="editor-media-document" data-toggle="tab" t-attf-class="nav-link#{widget.noDocuments ? ' d-none' : ''}">Document</a></li>
<li class="nav-item"><a role="tab" href="#editor-media-icon" aria-controls="editor-media-icon" data-toggle="tab" t-attf-class="nav-link#{widget.noIcons ? ' d-none' : ''}">Pictogram</a></li> <li class="nav-item"><a role="tab" href="#editor-media-icon" aria-controls="editor-media-icon" data-toggle="tab" t-attf-class="nav-link#{widget.noIcons ? ' d-none' : ''}">Pictogram</a></li>
<li class="nav-item"><a role="tab" href="#editor-media-video" aria-controls="editor-media-video" data-toggle="tab" t-attf-class="nav-link#{widget.noVideos ? ' d-none' : ''}">Video</a></li> <li class="nav-item"><a role="tab" href="#editor-media-video" aria-controls="editor-media-video" data-toggle="tab" t-attf-class="nav-link#{widget.noVideos ? ' d-none' : ''}">Video</a></li>
<li class="nav-item ml-auto search">
<div class="form-group">
<input class="form-control" id="icon-search" type="search"/>
<span class="fa fa-search" title="Search" role="img" aria-label="Search"/>
</div>
</li>
<li class="nav-item search">
<div class="btn-group">
<a role="button" class="btn btn-secondary disabled previous" href="#"><i class="fa fa-angle-left"/>&#32;Previous</a>
<a role="button" class="btn btn-secondary disabled next" href="#">Next&#32;<i class="fa fa-angle-right"/></a>
</div>
</li>
</ul> </ul>
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content"> <div class="tab-content">
@@ -91,37 +79,81 @@
<input type="hidden" name="filters" t-att-value="widget.firstFilters.join('_')"/> <input type="hidden" name="filters" t-att-value="widget.firstFilters.join('_')"/>
<input t-if="widget.options.res_id" type="hidden" name="res_id" t-att-value="widget.options.res_id"/> <input t-if="widget.options.res_id" type="hidden" name="res_id" t-att-value="widget.options.res_id"/>
<input t-if="widget.options.res_model" type="hidden" name="res_model" t-att-value="widget.options.res_model"/> <input t-if="widget.options.res_model" type="hidden" name="res_model" t-att-value="widget.options.res_model"/>
<div class="o_media_image_card card w-100"> <div class="mt-4 w-100">
<div class="card-body p-0"> <div class="mb-4">
<div class="form-inline"> <div class="o_submenu"></div>
<input type="file" class="d-none" name="upload" t-att-accept="widget.accept" multiple="multiple"/> </div>
<div class="form-text"/>
<div class="existing-attachments">
<t t-call="web_editor.dialog.image.existing"/>
</div>
<div class="mt-4 text-center o_load_elements mx-auto">
<button class="btn btn-primary o_load_more" type="button">Load more...</button>
<div class="mt-4 o_load_done_msg d-none">
<span><i>All attachments have been loaded</i></span>
</div>
</div>
</div>
<iframe class="o_file_upload_iframe d-none" t-att-name="iframeName"/>
</form>
</t>
<t t-name="web_editor.dialog.files.submenu">
<div class="o_submenu">
<div class="row">
<div class="col-sm">
<div class="form-inline row no-gutters">
<input type="file" class="d-none o_file_input" name="upload" t-att-accept="accept" multiple="multiple"/>
<input type="hidden" name="disable_optimization" value=""/> <input type="hidden" name="disable_optimization" value=""/>
<div class="btn-group"> <div class="btn-group o_btn_group_image">
<button class="btn btn-primary o_upload_image_button" type="button">Upload an image</button> <button class="btn btn-primary o_upload_media_button" type="button">
<button class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" type="button"> <t t-if="isDocument">Upload a document</t>
<span class="sr-only">Alternate Upload</span> <t t-else="">Upload an image</t>
</button> </button>
<div class="dropdown-menu" role="menu"> <t t-if="!isDocument">
<a role="menuitem" class="dropdown-item o_upload_image_button_no_optimization">Upload image without optimization</a> <button class="btn btn-primary dropdown-toggle dropdown-toggle-split o_media_optimization" data-toggle="dropdown" type="button">
</div> <span class="sr-only">Alternate Upload</span>
</button>
<div class="dropdown-menu" role="menu">
<a role="menuitem" class="dropdown-item o_upload_media_button_no_optimization">Upload image without optimization</a>
</div>
</t>
</div> </div>
<span class="text-muted">— or —</span> <div class="input-group col-8 ml-2">
<label for="imageurl">Add an image URL</label> <input type="text" class="form-control url col-7" name="url" t-attf-placeholder="https://www.odoo.com/#{isDocument ? 'mydocument' : 'logo.png'}"/>
<div class="input-group"> <div class="input-group-append ml-2">
<input type="text" class="form-control url" id="imageurl" name="url" placeholder="https://www.odoo.com/logo.png" style="width: 250px;"/> <button type="button" class="btn btn-sm btn-secondary o_upload_media_url_button" disabled="disabled">
<div class="input-group-append"> <t t-if="isDocument">Add document</t>
<button type="button" class="btn btn-secondary o_upload_image_url_button" disabled="disabled">Add</button> <t t-else="">Add image</t>
</button>
</div>
<div class="ml-2 o_size_fa_icon">
<span class="success-url text-success d-none fa fa-check" title="The URL seems valid"/>
<t t-if="isDocument">
<span class="error-url text-danger d-none fa fa-times" title="This URL does not seem to work"/>
</t>
<t t-else="">
<span class="warning-url text-warning d-none fa fa-warning" title="The URL provided does not contain any image. It will be added in the document section."/>
</t>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="col-sm text-right">
<ul class="list-unstyled row">
<li class="nav-item ml-auto col-6 search">
<div class="form-group o_search_div">
<t t-set="searchPlaceholder">
<t t-if="isDocument">Search a document</t>
<t t-else="">Search an image</t>
</t>
<input class="form-control w-100" id="icon-search" type="search" t-att-placeholder="searchPlaceholder.trim()"/>
<span class="fa fa-search" title="Search" role="img" aria-label="Search"/>
</div>
</li>
</ul>
</div>
</div> </div>
<div class="form-text"/> </div>
<div class="existing-attachments">
<t t-call="web_editor.dialog.image.existing"/>
</div>
<iframe class="d-none" t-att-name="iframeName"/>
</form>
</t> </t>
<t t-name="web_editor.dialog.image.existing"> <t t-name="web_editor.dialog.image.existing">
<div role="dialog" class="modal" tabindex="-1"> <div role="dialog" class="modal" tabindex="-1">
@@ -136,19 +168,22 @@
<div class="form-text"/> <div class="form-text"/>
</main> </main>
<footer class="modal-footer"> <footer class="modal-footer">
<a data-dismiss="modal" href="#" aria-label="Discard">Discard</a> <button data-dismiss="modal" type="button" aria-label="Discard">Discard</button>
</footer> </footer>
</div> </div>
</div> </div>
</div> </div>
</t> </t>
<t t-name="web_editor.dialog.image.existing.content"> <t t-name="web_editor.dialog.files.existing.content">
<div class="existing-attachments"> <div class="existing-attachments">
<div class="row mt16" t-as="row" t-foreach="rows"> <div class="row mt16 ml-auto" t-as="row" t-foreach="rows">
<div class="col-2 o_existing_attachment_cell" t-as="attachment" t-foreach="row"> <div class="col-2 o_existing_attachment_cell" t-as="attachment" t-foreach="row">
<i t-if="attachment.res_model === 'ir.ui.view'" class="fa fa-times o_existing_attachment_remove" title="This file is a public view attachment" role="img" aria-label="This file is a public view attachment" t-att-data-id="attachment.id"/> <i t-if="attachment.res_model === 'ir.ui.view'" class="fa fa-trash o_existing_attachment_remove" title="This file is a public view attachment" role="img" aria-label="This file is a public view attachment" t-att-data-id="attachment.id"/>
<i t-else="" class="fa fa-times o_existing_attachment_remove" title="This file is attached to the current record" role="img" aria-label="This file is attached to the current record" t-att-data-id="attachment.id"/> <i t-else="" class="fa fa-trash o_existing_attachment_remove" title="This file is attached to the current record" role="img" aria-label="This file is attached to the current record" t-att-data-id="attachment.id"/>
<div class="o_attachment_border" t-att-style="attachment.res_model === 'ir.ui.view' ? null : 'border: 1px solid #5cb85c;'"><div t-att-data-src="attachment.src" t-att-data-url="attachment.url" role="img" t-att-aria-label="attachment.name" t-att-title="attachment.name" t-att-data-id="attachment.id" t-att-data-mimetype="attachment.mimetype" class="o_image o_image_loading"/></div> <div class="o_attachment_border" t-att-style="attachment.res_model === 'ir.ui.view' ? null : 'border: 1px solid #5cb85c;'"><div t-att-data-src="attachment.src" t-att-data-url="attachment.url" role="img" t-att-aria-label="attachment.name" t-att-title="attachment.name" t-att-data-id="attachment.id" t-att-data-mimetype="attachment.mimetype" class="o_image o_image_loading"/></div>
<t t-if="isDocument">
<small class="o_file_name"><t t-esc="attachment.name"/></small>
</t>
</div> </div>
</div> </div>
</div> </div>
@@ -169,7 +204,15 @@
<!-- Icon choosing part of the Media Dialog --> <!-- Icon choosing part of the Media Dialog -->
<t t-name="web_editor.dialog.font-icons"> <t t-name="web_editor.dialog.font-icons">
<form action="#"> <form action="#" class="mt-2">
<div class="d-flex flex-row-reverse">
<li class="nav-item search list-unstyled col-3 p-2">
<div class="form-group">
<input class="form-control" id="icon-search" type="search" placeholder="Search a pictogram"/>
<span class="fa fa-search" title="Search" role="img" aria-label="Search"/>
</div>
</li>
</div>
<div class="font-icons-icons"> <div class="font-icons-icons">
<t t-call="web_editor.dialog.font-icons.icons"> <t t-call="web_editor.dialog.font-icons.icons">
<t t-set="iconsParser" t-value="widget.iconsParser"/> <t t-set="iconsParser" t-value="widget.iconsParser"/>
@@ -189,42 +232,46 @@
</t> </t>
<!-- Video choosing part of the Media Dialog --> <!-- Video choosing part of the Media Dialog -->
<div t-name="web_editor.dialog.video" class="card"> <div t-name="web_editor.dialog.video" class="o_video_dialog_container mt-4">
<form action="#" class="form-inline card-body"> <form action="#" class="form-inline w-100">
<div class="o_video_dialog_form"> <div class="o_video_dialog_form">
<div class="form-group" id="o_video_form_group"> <div class="form-group mb-2" id="o_video_form_group">
<label class="mt8" for="o_video_text">Video code <small class="text-muted">(URL or Embed)</small></label> <label>Video code </label>
<small class="ml-1 form-text text-muted"> (URL or Embed)</small>
<label class="ml-2 col-form-label o_validate_feedback position-static" for="o_video_text">
<i class="fa fa-check text-success" role="img" aria-label="Checked" title="Checked"/>
<i class="fa fa-exclamation-triangle text-danger" role="img" aria-label="Attention" title="Attention"/>
</label>
<textarea class="form-control url" id="o_video_text" placeholder="Copy-paste your URL or embed code here"/> <textarea class="form-control url" id="o_video_text" placeholder="Copy-paste your URL or embed code here"/>
<label class="col-form-label o_validate_feedback" for="o_video_text"><i class="fa fa-check" role="img" aria-label="Checked" title="Checked"/><i class="fa fa-exclamation-triangle" role="img" aria-label="Attention" title="Attention"/></label>
</div> </div>
<div class="text-right"> <div class="text-right">
<small class="text-muted">Accepts <b><i>Youtube</i></b>, <b><i>Instagram</i></b>, <b><i>Vine.co</i></b>, <b><i>Vimeo</i></b>, <b><i>Dailymotion</i></b> and <b><i>Youku</i></b> videos</small> <small class="text-muted">Accepts <b><i>Youtube</i></b>, <b><i>Instagram</i></b>, <b><i>Vine.co</i></b>, <b><i>Vimeo</i></b>, <b><i>Dailymotion</i></b> and <b><i>Youku</i></b> videos</small>
</div> </div>
<div class="o_video_dialog_options d-none mt48"> <div class="o_video_dialog_options d-none mt-4">
<small class="text-muted">Options</small> <div class="option_title mb-2 d-flex">
<ul class="list-group"> <label>Options</label>
<li class="list-group-item o_yt_option o_vim_option o_dm_option"> </div>
<label class="o_switch mb0"><input id="o_video_autoplay" type="checkbox"/><span/>Autoplay</label> <div class="o_yt_option o_vim_option o_dm_option d-flex">
</li> <label class="o_switch mb0"><input id="o_video_autoplay" type="checkbox"/><span/>Autoplay</label>
<li class="list-group-item o_yt_option o_vim_option"> </div>
<label class="o_switch mb0"><input id="o_video_loop" type="checkbox"/><span/>Loop</label> <div class="o_yt_option o_vim_option d-flex">
</li> <label class="o_switch mb0"><input id="o_video_loop" type="checkbox"/><span/>Loop</label>
<li class="list-group-item o_yt_option o_dm_option"> </div>
<label class="o_switch mb0"><input id="o_video_hide_controls" type="checkbox"/><span/>Hide player controls</label> <div class="o_yt_option o_dm_option d-flex">
</li> <label class="o_switch mb0"><input id="o_video_hide_controls" type="checkbox"/><span/>Hide player controls</label>
<li class="list-group-item o_yt_option"> </div>
<label class="o_switch mb0"><input id="o_video_hide_fullscreen" type="checkbox"/><span/>Hide fullscreen button</label> <div class="o_yt_option d-flex">
</li> <label class="o_switch mb0"><input id="o_video_hide_fullscreen" type="checkbox"/><span/>Hide fullscreen button</label>
<li class="list-group-item o_yt_option"> </div>
<label class="o_switch mb0"><input id="o_video_hide_yt_logo" type="checkbox"/><span/>Hide Youtube logo</label> <div class="o_yt_option d-flex">
</li> <label class="o_switch mb0"><input id="o_video_hide_yt_logo" type="checkbox"/><span/>Hide Youtube logo</label>
<li class="list-group-item o_dm_option"> </div>
<label class="o_switch mb0"><input id="o_video_hide_dm_logo" type="checkbox"/><span/>Hide Dailymotion logo</label> <div class="o_dm_option d-flex">
</li> <label class="o_switch mb0"><input id="o_video_hide_dm_logo" type="checkbox"/><span/>Hide Dailymotion logo</label>
<li class="list-group-item o_dm_option"> </div>
<label class="o_switch mb0"><input id="o_video_hide_dm_share" type="checkbox"/><span/>Hide sharing button</label> <div class="o_dm_option d-flex">
</li> <label class="o_switch mb0"><input id="o_video_hide_dm_share" type="checkbox"/><span/>Hide sharing button</label>
</ul> </div>
</div> </div>
</div> </div>
<div id="video-preview"> <div id="video-preview">
@@ -307,7 +354,7 @@
<div class="form-group text-center"> <div class="form-group text-center">
<label>Preview</label> <label>Preview</label>
<div style="overflow: auto; max-width: 100%; max-height: 200px;"> <div style="overflow: auto; max-width: 100%; max-height: 200px;">
<a href="#" id="link-preview" aria-label="Preview" title="Preview"/> <a href="#" type="button" id="link-preview" aria-label="Preview" title="Preview"/>
</div> </div>
</div> </div>
</div> </div>
@@ -3,22 +3,26 @@ odoo.define('web_unsplash.image_widgets', function (require) {
var core = require('web.core'); var core = require('web.core');
var UnsplashAPI = require('unsplash.api'); var UnsplashAPI = require('unsplash.api');
var weWidgets = require('web_editor.widget');
var ImageWidget = require('web_editor.widget').ImageWidget;
var QWeb = core.qweb; var QWeb = core.qweb;
var unsplashAPI = null; var unsplashAPI = null;
ImageWidget.include({ weWidgets.ImageWidget.include({
xmlDependencies: ImageWidget.prototype.xmlDependencies.concat( xmlDependencies: weWidgets.ImageWidget.prototype.xmlDependencies.concat(
['/web_unsplash/static/src/xml/unsplash_image_widget.xml'] ['/web_unsplash/static/src/xml/unsplash_image_widget.xml']
), ),
events: _.extend({}, ImageWidget.prototype.events, { events: _.extend({}, weWidgets.ImageWidget.prototype.events, {
'input input.unsplash_search': '_onChangeUnsplashSearch',
'dblclick .unsplash_img_container [data-imgid]': '_onUnsplashImgDblClick', 'dblclick .unsplash_img_container [data-imgid]': '_onUnsplashImgDblClick',
'click .unsplash_img_container [data-imgid]': '_onUnsplashImgClick', 'click .unsplash_img_container [data-imgid]': '_onUnsplashImgClick',
'click button.save_unsplash': '_onSaveUnsplash', 'click button.save_unsplash': '_onSaveUnsplash',
'click button.access_key': '_onSetAccessKey',
'click .o_load_more': '_onLoadMore',
'click .o_search_from_unsplash': '_onSearchFromUnsplash',
'click .o_search_an_image': '_onSearchImage',
'keyup input#icon-search, .o_dropdown_search': '_onPressKeySearch',
}), }),
/** /**
* @override * @override
*/ */
@@ -28,6 +32,7 @@ ImageWidget.include({
isMaxed: false, isMaxed: false,
query: false, query: false,
}; };
// TODO This is a `hack` to prevent the UnsplashAPI to be destroyed every time // TODO This is a `hack` to prevent the UnsplashAPI to be destroyed every time
// the media dialog is closed. // the media dialog is closed.
// Indeed, UnsplashAPI has a cache system to recude unsplash call, it is // Indeed, UnsplashAPI has a cache system to recude unsplash call, it is
@@ -84,7 +89,7 @@ ImageWidget.include({
route: '/web_unsplash/attachment/add', route: '/web_unsplash/attachment/add',
params: { params: {
unsplashurls: self._unsplash.selectedImages, unsplashurls: self._unsplash.selectedImages,
res_model : self.options.res_model, res_model: self.options.res_model,
res_id: self.options.res_id, res_id: self.options.res_id,
query: self._unsplash.query, query: self._unsplash.query,
} }
@@ -134,7 +139,7 @@ ImageWidget.include({
.values() .values()
.value(); .value();
self.$('.unsplash_img_container').html(QWeb.render('web_unsplash.dialog.image.content', { rows: rows })); self.$('.unsplash_img_container').html(QWeb.render('web_unsplash.dialog.image.content', {rows: rows}));
self._highlightSelectedImages(); self._highlightSelectedImages();
}).fail(function (err) { }).fail(function (err) {
self.$('.unsplash_img_container').html(QWeb.render('web_unsplash.dialog.error.content', { status: err })); self.$('.unsplash_img_container').html(QWeb.render('web_unsplash.dialog.error.content', { status: err }));
@@ -146,10 +151,26 @@ ImageWidget.include({
* @private * @private
*/ */
_toggleAttachmentContaines: function (hideUnsplash) { _toggleAttachmentContaines: function (hideUnsplash) {
this.$('.existing-attachments').toggleClass('o_hidden', !hideUnsplash); this.$('.existing-attachments').toggleClass('d-none', !hideUnsplash);
this.$('.unsplash_img_container').toggleClass('o_hidden', hideUnsplash); this.$('.unsplash_img_container').toggleClass('d-none', hideUnsplash);
this.$('.o_load_more').toggleClass('d-none', hideUnsplash);
this.$('.o_load_done_msg').toggleClass('d-none', !hideUnsplash);
this.trigger_up('update_control_panel'); this.trigger_up('update_control_panel');
}, },
/**
* @private
*/
_toggleLoadMoreBtnUnsplash: function (display) {
this.$('.o_load_done_msg').toggleClass('d-none', display);
},
/**
* @private
*/
_toggleSearchDropdown: function (show) {
var inputValue = this.$('#icon-search').val();
this.$('.o_search_value_input').text(inputValue);
this.$('.o_dropdown_search').toggleClass('show', show);
},
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Handlers // Handlers
@@ -189,15 +210,16 @@ ImageWidget.include({
_onChangeUnsplashSearch: _.debounce(function () { _onChangeUnsplashSearch: _.debounce(function () {
// oldPage saves the original image widget pager. // oldPage saves the original image widget pager.
// Emptying the unsplash search will set the pager to its previous state // Emptying the unsplash search will set the pager to its previous state
this._unsplash.query = this.$('.unsplash_search').val().trim(); this._unsplash.query = this.$('#icon-search').val().trim();
if (this._unsplash.query) { if (this._unsplash.query) {
this.oldPage = this.page; this.oldPage = this.page;
this.page = 1; this.page = 1;
this._renderImages(); this._renderImages();
} else { } else {
this.page = this.oldPage || 0; this.page = this.oldPage || 1;
this._toggleAttachmentContaines(true); this._toggleAttachmentContaines(true);
} }
this._toggleLoadMoreBtnUnsplash(true);
}, 1000), }, 1000),
/** /**
* @private * @private
@@ -205,14 +227,14 @@ ImageWidget.include({
_onUnsplashImgClick: function (ev) { _onUnsplashImgClick: function (ev) {
var imgid = $(ev.currentTarget).data('imgid'); var imgid = $(ev.currentTarget).data('imgid');
var url = $(ev.currentTarget).data('url'); var url = $(ev.currentTarget).data('url');
var download_url = $(ev.currentTarget).data('download-url'); var downloadUrl = $(ev.currentTarget).data('download-url');
if (!this.multiImages) { if (!this.multiImages) {
this._unsplash.selectedImages = {}; this._unsplash.selectedImages = {};
} }
if (imgid in this._unsplash.selectedImages) { if (imgid in this._unsplash.selectedImages) {
delete this._unsplash.selectedImages[imgid]; delete this._unsplash.selectedImages[imgid];
} else { } else {
this._unsplash.selectedImages[imgid] = {url: url, download_url: download_url}; this._unsplash.selectedImages[imgid] = {url: url, downloadUrl: downloadUrl};
} }
this._highlightSelectedImages(); this._highlightSelectedImages();
}, },
@@ -222,5 +244,61 @@ ImageWidget.include({
_onUnsplashImgDblClick: function (ev) { _onUnsplashImgDblClick: function (ev) {
this.trigger_up('save_request'); this.trigger_up('save_request');
}, },
/**
* @private
*/
_onLoadMore: function () {
this._unsplash.query = this.$('#icon-search').val().trim();
this._loadMoreImages();
},
/**
* @private
*/
_onSearchFromUnsplash: function () {
this.$('.o_dropdown_search').removeClass('show');
this._toggleAttachmentContaines(false);
this._onChangeUnsplashSearch();
},
/**
* @private
*/
_onSearchImage: function () {
var searchText = this.$('#icon-search').val().trim();
this._unsplash.query = false;
this.search(searchText);
this.$('.o_dropdown_search').removeClass('show');
this._toggleAttachmentContaines(true);
this._renderImages();
},
/**
* @private
*/
_onPressKeySearch: function (ev) {
var $searchAnImage = this.$('button.dropdown-item.o_search_an_image');
switch (ev.which) {
case $.ui.keyCode.ENTER:
$searchAnImage.focus();
break;
case $.ui.keyCode.UP:
$searchAnImage.focus();
break;
case $.ui.keyCode.DOWN:
$searchAnImage.next().focus();
break;
default: return;
}
ev.preventDefault();
},
/**
* @override
*/
_onSearchInput: function (ev) {
if (!this.options.document) {
this._toggleSearchDropdown(true);
} else {
this.search($(ev.currentTarget).val() || '');
}
},
}); });
}); });
@@ -2,14 +2,23 @@
<templates id="template" xml:space="preserve"> <templates id="template" xml:space="preserve">
<t t-extend="web_editor.dialog.image"> <t t-extend="web_editor.dialog.image">
<t t-jquery=".o_media_image_card .form-inline" t-operation="append">
<div class="ml-auto border-left pl-4">
<span class="d-block font-weight-bold">Photos by <a href="https://unsplash.com" target="_blank">Unsplash</a></span>
<input type="text" class="form-control unsplash_search mr8" placeholder="Search free high-resolution photos" style="width: 250px;"/>
</div>
</t>
<t t-jquery=".existing-attachments" t-operation="after"> <t t-jquery=".existing-attachments" t-operation="after">
<div class="unsplash_img_container container-fluid"></div> <div class="unsplash_img_container"></div>
</t>
</t>
<t t-extend="web_editor.dialog.files.submenu">
<t t-jquery=".o_search_div" t-operation="append">
<div class="dropdown-menu o_dropdown_search w-100" style="background-color:#efefef;">
<button class="dropdown-item o_search_an_image o_size_dropdown_item" type="button">
Search among my images for:
<div class="font-weight-bold o_search_value_input"></div>
</button>
<button class="dropdown-item o_search_from_unsplash o_size_dropdown_item" type="button">
Search from Unsplash for:
<div class="font-weight-bold o_search_value_input"></div>
</button>
</div>
</t> </t>
</t> </t>
@@ -17,7 +26,7 @@
<div class="row mt16" t-as="row" t-foreach="rows"> <div class="row mt16" t-as="row" t-foreach="rows">
<div class="col-sm-2 o_unsplash_img_cell text-center" t-as="img" t-foreach="row"> <div class="col-sm-2 o_unsplash_img_cell text-center" t-as="img" t-foreach="row">
<div class="o_image o_webimage" t-att-data-imgid="img.id" t-att-data-url="img.urls.regular" t-att-data-download-url="img.links.download_location"> <div class="o_image o_webimage" t-att-data-imgid="img.id" t-att-data-url="img.urls.regular" t-att-data-download-url="img.links.download_location">
<img class="img-fluid" t-att-src="img.urls.thumb" /> <img class="img-fluid" t-att-src="img.urls.thumb"/>
</div> </div>
<div class="author_name"><a t-att-href="img.user.links.html" target="_blank"><t t-esc="img.user.name"/></a></div> <div class="author_name"><a t-att-href="img.user.links.html" target="_blank"><t t-esc="img.user.name"/></a></div>
</div> </div>
@@ -41,8 +41,8 @@ odoo.define("website_sale.tour_shop", function (require) {
actions.dblclick(); actions.dblclick();
}, },
}, { }, {
trigger: ".o_select_media_dialog .o_upload_image_button", trigger: ".o_select_media_dialog .o_upload_media_button",
content: _t("Upload an image from your local library."), content: _t("Upload a file from your local library."),
position: "bottom", position: "bottom",
run: function (actions) { run: function (actions) {
actions.auto(".modal-footer .btn-secondary"); actions.auto(".modal-footer .btn-secondary");