Permalink
Browse files

m

  • Loading branch information...
kea14 committed Nov 7, 2018
1 parent fc3088d commit 979fc9babfd5dda10fcf321a68301b552f0d6e3b
@@ -194,10 +194,14 @@ var ImageWidget = MediaWidget.extend({
'click .existing-attachments [data-src]': '_onImageClick',
'dblclick .existing-attachments [data-src]': '_onImageDblClick',
'click .o_existing_attachment_remove': '_onRemoveClick',
'click .o_load_more_images': '_onLoadMore',
'keyup #imageurl': '_onImageURL',
'keyup #documenturl': '_onDocumentURL',
'click .o_search_an_image': '_onSearchImage',
},
IMAGES_PER_ROW: 6,
IMAGES_ROWS: 2,
IMAGES_ROWS: 6,
/**
* @constructor
@@ -243,6 +247,8 @@ var ImageWidget = MediaWidget.extend({
var self = this;
this._renderImages();
this._displayLoadMoreBtn();
this.$('.o_load_more_unsplash').hide();
var o = {
url: null,
@@ -453,7 +459,14 @@ var ImageWidget = MediaWidget.extend({
this.$('.form-text').empty();
this.$('.existing-attachments').replaceWith(QWeb.render('web_editor.dialog.image.existing.content', {rows: rows}));
//Rendering menu & content for 'Image' tab or 'Document' tab
if (this.options.document) {
this.$('.o_submenu').replaceWith(QWeb.render('web_editor.dialog.document.submenu', {accept: this.accept}));
this.$('.existing-attachments').replaceWith(QWeb.render('web_editor.dialog.document.existing.content', {rows: rows}));
} else {
this.$('.o_submenu').replaceWith(QWeb.render('web_editor.dialog.image.submenu', {accept: this.accept}));
this.$('.existing-attachments').replaceWith(QWeb.render('web_editor.dialog.image.existing.content', {rows: rows}));
}
var $divs = this.$('.o_image');
var imageDefs = _.map($divs, function (el) {
@@ -475,6 +488,7 @@ var ImageWidget = MediaWidget.extend({
}, 400);
});
this._highlightSelectedImages();
this._hideUnsplash();
},
/**
* @private
@@ -550,6 +564,96 @@ var ImageWidget = MediaWidget.extend({
});
this.$el.submit();
},
/**
* @private
*/
_loadMoreImages: function () {
this.IMAGES_ROWS = this.IMAGES_ROWS + 2;
this.IMAGES_PER_PAGE = this.IMAGES_ROWS * this.IMAGES_PER_ROW;
this._renderImages();
this._displayLoadMoreBtn();
},
/**
* @private
*/
_displayLoadMoreBtn: function () {
var records = this.records.length;
var $loadMoreBtn = this.$el.find('.o_load_more_images');
var $parentDiv = this.$el.find('.o_load_elements');
if (this.IMAGES_PER_PAGE >= records) {
$loadMoreBtn.hide();
$parentDiv.append(QWeb.render('web_editor.dialog.image.loaded.content'));
}
},
/**
* @private
*/
_checkImageUrl: function () {
var format = ['.gif','.jpe','.jpg','.png'];
var url = this.$('#imageurl').val();
var acceptedURL = false;
var $warning = this.$('.warning-url-image');
var $success = this.$('.success-url-image');
var regex = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/;
if (url.match(regex)) {
for (var i in format) {
var endsWith = url.endsWith(format[i]);
if (endsWith) {
acceptedURL = true;
$warning.toggleClass('d-none', true);
$success.toggleClass('d-none', false);
_nameButton('image');
}
}
}
if (!acceptedURL) {
$warning.toggleClass('d-none', false);
$success.toggleClass('d-none', true);
_nameButton('document');
}
if (url.length < 1) {
$warning.toggleClass('d-none', true);
$success.toggleClass('d-none', true);
_nameButton('image');
}
function _nameButton(name) {
if (name === 'document') {
name = _t("Add a document URL");
} else {
name = _t("Add an image URL");
}
$('.o_upload_image_url_button').html(name);
}
},
/**
* @private
*/
_checkDocumentUrl: function () {
var url = this.$('#documenturl').val();
var $error = this.$('.error-url-document');
var $success = this.$('.success-url-document');
var regex = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/;
var success = (url.match(regex) !== null);
$success.toggleClass('d-none', !success);
$error.toggleClass('d-none', success);
if (url.length < 1) {
$success.toggleClass('d-none', !success);
$error.toggleClass('d-none', !success);
}
},
/**
* @private
*/
_hideUnsplash: function () {
this.$('.o_load_more_unsplash').hide();
$('.o_search_unsplash').addClass('o_hidden');
$('.unsplash_img_container').addClass('o_hidden');
$('.o_search_image_dir').removeClass('o_hidden');
$('.existing-attachments').removeClass('o_hidden');
},
//--------------------------------------------------------------------------
// Handlers
@@ -587,27 +691,29 @@ var ImageWidget = MediaWidget.extend({
* @private
*/
_onRemoveClick: function (ev) {
var self = this;
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({
route: '/web_editor/attachment/remove',
params: {
ids: [id],
},
}).then(function (prevented) {
if (_.isEmpty(prevented)) {
self.records = _.without(self.records, attachment);
self._renderImages();
return;
}
$helpBlock.replaceWith(QWeb.render('web_editor.dialog.image.existing.error', {
views: prevented[id]
}));
});
if (confirm(_t('Are you sure to delete this component ?'))) {
var self = this;
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({
route: '/web_editor/attachment/remove',
params: {
ids: [id],
},
}).then(function (prevented) {
if (_.isEmpty(prevented)) {
self.records = _.without(self.records, attachment);
self._renderImages();
return;
}
$helpBlock.replaceWith(QWeb.render('web_editor.dialog.image.existing.error', {
views: prevented[id]
}));
});
}
},
/**
* @private
@@ -638,6 +744,33 @@ var ImageWidget = MediaWidget.extend({
_onUploadURLButtonClick: function () {
this._uploadImage();
},
/**
* @private
*/
_onLoadMore: function () {
this._loadMoreImages();
},
/**
* @private
*/
_onImageURL: function () {
this._checkImageUrl();
},
/**
* @private
*/
_onDocumentURL: function () {
this._checkDocumentUrl();
},
/**
* Hide Unsplash searching bar + Unsplash content & reveal Image
* @private
*/
_onSearchImage: function () {
this._displayLoadMoreBtn();
this._hideUnsplash();
this._renderImages();
},
});
/**
@@ -812,7 +945,7 @@ var VideoWidget = MediaWidget.extend({
events : {
'change .o_video_dialog_options input': '_onUpdateVideoOption',
'input textarea#o_video_text': '_onVideoCodeInput',
'change textarea#o_video_text': '_onVideoCodeChange',
'keyup textarea#o_video_text': '_onVideoCodeChange',
},
/**
@@ -994,7 +1127,7 @@ var VideoWidget = MediaWidget.extend({
// Reset the feedback
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_dialog_options li').addClass('d-none');
this.$('.o_video_dialog_options div').addClass('d-none');
// Check video code
var $textarea = this.$('textarea#o_video_text');
@@ -1031,29 +1164,30 @@ var VideoWidget = MediaWidget.extend({
.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
$opt_box.find('li.o_' + query.type + '_option').removeClass('d-none');
$opt_box.find('div.o_' + query.type + '_option').removeClass('d-none');
// Hide the entire options box if no options are available
$opt_box.toggleClass('d-none', $opt_box.find('li:not(.d-none)').length === 0);
$opt_box.toggleClass('d-none', $opt_box.find('div:not(.d-none)').length === 0);
$('.option_title').toggleClass('d-none');
if (query.type === 'yt') {
// Youtube only: If 'hide controls' is checked, hide 'fullscreen'
// 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;
if (!$content) {
switch (query.errorCode) {
case 0:
$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"),
});
break;
case 1:
$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"),
});
break;
@@ -1302,11 +1436,8 @@ var MediaDialog = Dialog.extend({
* @private
*/
_onSearchInput: function (ev) {
var self = this;
this.active.goToPage(0);
this.active.search($(ev.currentTarget).val() || '').then(function () {
self._updateControlPanel();
});
this.active.search($(ev.currentTarget).val() || '');
},
/**
* @private
@@ -1452,6 +1452,35 @@ body .modal {
}
}
}
// Align label on the left
.o_label_left {
justify-content:left !important;
}
// Adding border-color
.is-valid {
border-color: #28a745 !important;
}
// Search bar in the right corner
.o_search_bar {
position: absolute !important;
right: 0 !important;
}
// Width search bar
.o_width_search_bar {
width: 40em;
}
// Custom confirm delete button
.o_confirm_delete {
cursor: pointer;
position: absolute;
left: 6%;
top: 0.5%;
}
}
}
Oops, something went wrong.

0 comments on commit 979fc9b

Please sign in to comment.