diff options
Diffstat (limited to 'addons/web_unsplash/static/src')
3 files changed, 32 insertions, 30 deletions
diff --git a/addons/web_unsplash/static/src/js/unsplash_image_widget.js b/addons/web_unsplash/static/src/js/unsplash_image_widget.js index 229283b00c4..e638806dc1c 100644 --- a/addons/web_unsplash/static/src/js/unsplash_image_widget.js +++ b/addons/web_unsplash/static/src/js/unsplash_image_widget.js @@ -27,8 +27,6 @@ widgetsMedia.ImageWidget.include({ 'click .o_unsplash_attachment_cell[data-imgid]': '_onUnsplashImgClick', 'click button.save_unsplash': '_onSaveUnsplashCredentials', }), - // Max number of database attachments to show when searching. - maxDbAttachments: 5, /** * @override @@ -103,10 +101,11 @@ widgetsMedia.ImageWidget.include({ */ search: async function (needle) { var self = this; - await this._super(needle, true); + await this._super(...arguments); this._unsplash.query = needle; if (!needle) { + this._unsplash.records = []; return; } @@ -118,6 +117,17 @@ widgetsMedia.ImageWidget.include({ self._unsplash.error = err; }); }, + /** + * @override + */ + hasContent() { + if (this.searchService === 'all') { + return this._super(...arguments) || (this.unsplashRecords && this.unsplashRecords.length); + } else if (this.searchService === 'unsplash') { + return (this.unsplashRecords && this.unsplashRecords.length); + } + return this._super(...arguments); + }, //-------------------------------------------------------------------------- // Private @@ -149,6 +159,10 @@ widgetsMedia.ImageWidget.include({ */ _renderThumbnails: function () { this._super(...arguments); + this.$('.unsplash_error').empty(); + if (!['all', 'unsplash'].includes(this.searchService)) { + return; + } if (this._unsplash.query && this._unsplash.error) { this.$('.unsplash_error').html( core.qweb.render('web_unsplash.dialog.error.content', { @@ -157,9 +171,8 @@ widgetsMedia.ImageWidget.include({ ); return; } - this.$('.unsplash_error').empty(); - if (this._unsplash.query && !this._unsplash.isMaxed) { + if (['all', 'unsplash'].includes(this.searchService) && this._unsplash.query && !this._unsplash.isMaxed) { this.$('.o_load_more').removeClass('d-none'); this.$('.o_load_done_msg').addClass('d-none'); } @@ -168,10 +181,7 @@ widgetsMedia.ImageWidget.include({ * @override */ _renderExisting: function (attachments) { - if (this._unsplash.records.length) { - attachments.splice(this.maxDbAttachments); - } - return this._super(attachments.concat(this._unsplash.records.map(record => { + this.unsplashRecords = this._unsplash.records.map(record => { const url = new URL(record.urls.regular); // In small windows, row height could get quite a bit larger than the min, so we keep some leeway. url.searchParams.set('h', 2 * this.MIN_ROW_HEIGHT); @@ -179,7 +189,8 @@ widgetsMedia.ImageWidget.include({ return Object.assign({}, record, { url: url.toString(), }); - }))); + }); + return this._super(...arguments); }, /** * @override diff --git a/addons/web_unsplash/static/src/scss/unsplash.scss b/addons/web_unsplash/static/src/scss/unsplash.scss index 340b21581ec..9e0267c214d 100644 --- a/addons/web_unsplash/static/src/scss/unsplash.scss +++ b/addons/web_unsplash/static/src/scss/unsplash.scss @@ -1,14 +1,3 @@ -.o_we_unplash_author { - font-size: 11px; - bottom: 0; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - width: 100%; - position: absolute; - text-align: center; - background-color: #FFFB; -} .unsplash_error { padding: 30px 0; .access_key_box { diff --git a/addons/web_unsplash/static/src/xml/unsplash_image_widget.xml b/addons/web_unsplash/static/src/xml/unsplash_image_widget.xml index b27a098c303..092f12038bd 100644 --- a/addons/web_unsplash/static/src/xml/unsplash_image_widget.xml +++ b/addons/web_unsplash/static/src/xml/unsplash_image_widget.xml @@ -2,25 +2,27 @@ <templates id="template" xml:space="preserve"> <t t-extend="wysiwyg.widgets.file"> - <t t-jquery=".o_we_existing_attachments" t-operation="after"> + <t t-jquery=".o_we_load_more" t-operation="after"> <div class="unsplash_error"></div> </t> </t> +<t t-extend="wysiwyg.widgets.image"> + <t t-jquery="option[value='media-library']" t-operation="after"> + <option value="unsplash">Photos (via Unsplash)</option> + </t> +</t> <t t-extend="wysiwyg.widgets.image.existing.attachments"> - <t t-jquery="t[t-call]" t-operation="replace"> - <t t-if="typeof(attachment.id) === 'number'"> - <t t-call="wysiwyg.widgets.image.existing.attachment"/> - </t> - <t t-else=""> + <t t-jquery="t[t-foreach='libraryMedia']" t-operation="after"> + <t t-if="['all', 'unsplash'].includes(widget.searchService)" t-foreach="widget.unsplashRecords" t-as="record"> <t t-call="web_unsplash.dialog.image.content"/> </t> </t> </t> <t t-name="web_unsplash.dialog.image.content"> - <div class="o_existing_attachment_cell o_unsplash_attachment_cell position-relative align-items-center justify-content-center bg-light" t-att-data-imgid="attachment.id" t-att-data-id="attachment.id" t-att-data-url="attachment.urls.regular" t-att-data-download-url="attachment.links.download_location" t-att-data-description="attachment.alt_description"> - <img class="img img-fluid o_we_attachment_highlight" t-att-src="attachment.url" t-att-alt="attachment.alt_description" style="max-height: 100%;"/> - <a class="o_we_unplash_author" t-att-href="attachment.user.links.html" target="_blank" t-esc="attachment.user.name" t-att-title="attachment.user.name"/> + <div class="o_existing_attachment_cell o_unsplash_attachment_cell position-relative align-items-center justify-content-center bg-light" t-att-data-imgid="record.id" t-att-data-id="record.id" t-att-data-url="record.urls.regular" t-att-data-download-url="record.links.download_location" t-att-data-description="record.alt_description"> + <img class="img img-fluid o_we_attachment_highlight" t-att-src="record.url" t-att-alt="record.alt_description" style="max-height: 100%;"/> + <a class="o_we_media_author" t-att-href="record.user.links.html" target="_blank" t-esc="record.user.name" t-att-title="record.user.name"/> </div> </t> |
