[REF] web_unsplash: adapt code after jQuery update

Part of task 1896658

Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Christophe Matthieu <chm@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
Co-authored-by: svs-odoo <svs@odoo.com>
Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
This commit is contained in:
Vincent Schippefilt
2019-03-06 20:07:17 +01:00
committed by Aaron Bohy
co-authored by Aaron Bohy Christophe Matthieu Mathieu Duckerts-Antoine David Monjoie Martin Geubelle svs-odoo
parent 61b59c031f
commit c39033bc1c
2 changed files with 13 additions and 10 deletions
@@ -112,18 +112,20 @@ widgetsMedia.ImageWidget.include({
}
this._unsplash.query = needle;
var always = function () {
if (!noRender) {
self._renderImages();
self._adaptLoadMore();
}
};
return this.unsplashAPI.getImages(needle, this.IMAGES_DISPLAYED_TOTAL).then(function (res) {
self._unsplash.isMaxed = res.isMaxed;
self._unsplash.records = res.images;
self._unsplash.error = false;
}, function (err) {
self._unsplash.error = err;
}).always(function () {
if (!noRender) {
self._renderImages();
self._adaptLoadMore();
}
});
}).then(always).guardedCatch(always);
},
//--------------------------------------------------------------------------
@@ -27,17 +27,17 @@ var UnsplashCore = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
*
* @param {String} query search terms
* @param {Integer} pageSize number of image to display per page
* @returns {Promise}
*/
getImages: function (query, pageSize) {
var self = this;
var from = 0;
var to = pageSize;
var cachedData = this._cache[query];
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 Promise.resolve({ images: cachedData.images.slice(from, to), isMaxed: to > cachedData.totalImages });
}
return self._fetchImages(query).then(function (cachedData) {
return this._fetchImages(query).then(function (cachedData) {
return { images: cachedData.images.slice(from, to), isMaxed: to > cachedData.totalImages };
});
},
@@ -50,6 +50,7 @@ var UnsplashCore = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
* Fetches images from unsplash and stores it in cache
*
* @param {String} query search terms
* @returns {Promise}
* @private
*/
_fetchImages: function (query) {
@@ -72,7 +73,7 @@ var UnsplashCore = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
params: payload,
}).then(function (result) {
if (result.error) {
return $.Deferred().reject(result.error);
return Promise.reject(result.error);
}
cachedData.pageCached++;
cachedData.images.push.apply(cachedData.images, result.results);