diff options
| author | Vincent Schippefilt <vsc@odoo.com> | 2019-03-06 14:02:33 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-03-06 20:07:17 +0100 |
| commit | c39033bc1cff578626b6925ed542cfc8f709e15c (patch) | |
| tree | 80bce527ff35e7e12dbd92713280815b8d107bd5 /addons | |
| parent | 61b59c031f574475a7c4ebbc7bd1c952306aeb7a (diff) | |
[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>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/web_unsplash/static/src/js/unsplash_image_widget.js | 14 | ||||
| -rw-r--r-- | addons/web_unsplash/static/src/js/unsplashapi.js | 9 |
2 files changed, 13 insertions, 10 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 61a698ed190..01785fc12d9 100644 --- a/addons/web_unsplash/static/src/js/unsplash_image_widget.js +++ b/addons/web_unsplash/static/src/js/unsplash_image_widget.js @@ -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); }, //-------------------------------------------------------------------------- diff --git a/addons/web_unsplash/static/src/js/unsplashapi.js b/addons/web_unsplash/static/src/js/unsplashapi.js index 3055ec306e8..8156be6c4bc 100644 --- a/addons/web_unsplash/static/src/js/unsplashapi.js +++ b/addons/web_unsplash/static/src/js/unsplashapi.js @@ -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); |
