summaryrefslogtreecommitdiff
path: root/addons/web_unsplash/static/src
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-11-29 20:06:16 +0100
committerChristophe Simonis <chs@odoo.com>2018-11-29 20:06:16 +0100
commitce4cc24621bf6430d7d3a2d469b375b59120c200 (patch)
tree3837b5fe41ff88b24136ab53c871bc01f965cab1 /addons/web_unsplash/static/src
parent4d7aa97da38e497fef31a06543bfa5d2c8785708 (diff)
parent82a1e1dcc33d7c123e50d3e1aacb5e127f57c521 (diff)
[MERGE] forward port branch 12.0 up to 82a1e1dcc33
Diffstat (limited to 'addons/web_unsplash/static/src')
-rw-r--r--addons/web_unsplash/static/src/js/unsplash_beacon.js4
-rw-r--r--addons/web_unsplash/static/src/js/unsplash_image_widget.js7
-rw-r--r--addons/web_unsplash/static/src/js/unsplashapi.js43
-rw-r--r--addons/web_unsplash/static/src/xml/unsplash_image_widget.xml2
4 files changed, 14 insertions, 42 deletions
diff --git a/addons/web_unsplash/static/src/js/unsplash_beacon.js b/addons/web_unsplash/static/src/js/unsplash_beacon.js
index f8e74a3b759..179d566cee3 100644
--- a/addons/web_unsplash/static/src/js/unsplash_beacon.js
+++ b/addons/web_unsplash/static/src/js/unsplash_beacon.js
@@ -7,8 +7,8 @@ var ajax = require('web.ajax');
base.ready().then(function () {
var unsplash_images = [];
_.each($('img[src*="/unsplash/"]'), function (img, index) {
- // get image id from URL (`/unsplash/xYdf5feoI.jpg` -> `xYdf5feoI`)
- unsplash_images.push(img.src.split('/unsplash/')[1].split('.')[0]);
+ // get image id from URL (`http://www.domain.com:1234/unsplash/xYdf5feoI/lion.jpg` -> `xYdf5feoI`)
+ unsplash_images.push(img.src.split('/unsplash/')[1].split('/')[0]);
});
if (unsplash_images.length) {
ajax.jsonRpc('/web_unsplash/get_app_id', 'call').then(function (appID) {
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 d353694ddea..6eb393d3798 100644
--- a/addons/web_unsplash/static/src/js/unsplash_image_widget.js
+++ b/addons/web_unsplash/static/src/js/unsplash_image_widget.js
@@ -86,12 +86,9 @@ ImageWidget.include({
unsplashurls: self._unsplash.selectedImages,
res_model : self.options.res_model,
res_id: self.options.res_id,
+ query: self._unsplash.query,
}
}).then(function (images) {
- for (var img in self._unsplash.selectedImages) {
- self.unsplashAPI.notifyDownload(self._unsplash.selectedImages[img].download_url);
- }
-
_.each(images, function (image) {
image.src = image.url;
image.isDocument = !(/gif|jpe|jpg|png/.test(image.mimetype));
@@ -140,7 +137,7 @@ ImageWidget.include({
self.$('.unsplash_img_container').html(QWeb.render('web_unsplash.dialog.image.content', { rows: rows }));
self._highlightSelectedImages();
}).fail(function (err) {
- self.$('.unsplash_img_container').html(QWeb.render('web_unsplash.dialog.error.content', err));
+ self.$('.unsplash_img_container').html(QWeb.render('web_unsplash.dialog.error.content', { status: err }));
}).always(function () {
self._toggleAttachmentContaines(false);
});
diff --git a/addons/web_unsplash/static/src/js/unsplashapi.js b/addons/web_unsplash/static/src/js/unsplashapi.js
index 0ceb2b8f8a7..a6ec5b75324 100644
--- a/addons/web_unsplash/static/src/js/unsplashapi.js
+++ b/addons/web_unsplash/static/src/js/unsplashapi.js
@@ -38,46 +38,16 @@ var UnsplashCore = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
if (cachedData && (cachedData.images.length >= to || (cachedData.totalImages !== 0 && cachedData.totalImages < to))) {
return $.when({ images: cachedData.images.slice(from, to), isMaxed: to > cachedData.totalImages });
}
- return this._getAPIKey().then(function (clientID) {
- if (!clientID) {
- return $.Deferred().reject({ key_not_found: true });
- }
- return self._fetchImages(query).then(function (cachedData) {
- return { images: cachedData.images.slice(from, to), isMaxed: to > cachedData.totalImages };
- });
+ return self._fetchImages(query).then(function (cachedData) {
+ return { images: cachedData.images.slice(from, to), isMaxed: to > cachedData.totalImages };
});
},
- /**
- * Notifies Unsplash from an image download. (API requirement)
- *
- * @param {String} url url of the image to notify
- */
- notifyDownload: function (url) {
- $.get(url, { client_id: this.clientId });
- },
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
- * Checks and retrieves the unsplash API key
- *
- * @private
- */
- _getAPIKey: function () {
- var self = this;
- if (this.clientId) {
- return $.Deferred().resolve(self.clientId);
- }
- return this._rpc({
- route: '/web_unsplash/get_client_id',
- }).then(function (res) {
- self.clientId = res;
- return res;
- });
- },
- /**
* Fetches images from unsplash and stores it in cache
*
* @param {String} query search terms
@@ -96,10 +66,15 @@ var UnsplashCore = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
var payload = {
query: query,
page: cachedData.pageCached + 1,
- client_id: this.clientId,
per_page: 30, // max size from unsplash API
};
- return $.get('https://api.unsplash.com/search/photos/', payload).then(function (result) {
+ return this._rpc({
+ route: '/web_unsplash/fetch_images',
+ params: payload,
+ }).then(function (result) {
+ if (result.error) {
+ return $.Deferred().reject(result.error);
+ }
cachedData.pageCached++;
cachedData.images.push.apply(cachedData.images, result.results);
cachedData.maxPages = result.total_pages;
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 409c435884b..05202e073b2 100644
--- a/addons/web_unsplash/static/src/xml/unsplash_image_widget.xml
+++ b/addons/web_unsplash/static/src/xml/unsplash_image_widget.xml
@@ -50,7 +50,7 @@
<t t-name="web_unsplash.dialog.error.content">
<div class="row mt16 text-muted unsplash_error">
<div class="m-auto text-center">
- <t t-if="key_not_found">
+ <t t-if="status == 'key_not_found'">
<t t-call="web_unsplash.dialog.error.credentials">
<t t-set="title">
Unsplash requires an access key and an application ID