summaryrefslogtreecommitdiff
path: root/addons/web_unsplash/static
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2019-02-06 14:29:07 +0000
committerqsm-odoo <qsm@odoo.com>2019-02-26 17:09:22 +0000
commit27fca749af30d7dce448f6632132422df8d8a7c1 (patch)
treec644db5efbb12cde722d059d250a83ec0de8aed7 /addons/web_unsplash/static
parentc3da83b40a6431f607cf69b8c2a7a922a6e5b52c (diff)
[REF] *: use 'frontend' system in non-website apps
* account, auth_signup, payment, portal, project, sale, sale_management, web_unsplash, website, website_mail, website_rating, website_sale This commit does probably not do what is stated for all non-website apps but it is a first step. It also uses the system in apps which could have already used it but did not. Part of https://github.com/odoo/odoo/pull/29442 task-1932066
Diffstat (limited to 'addons/web_unsplash/static')
-rw-r--r--addons/web_unsplash/static/src/js/unsplash_beacon.js44
1 files changed, 27 insertions, 17 deletions
diff --git a/addons/web_unsplash/static/src/js/unsplash_beacon.js b/addons/web_unsplash/static/src/js/unsplash_beacon.js
index eb19383b93f..c15ff027faf 100644
--- a/addons/web_unsplash/static/src/js/unsplash_beacon.js
+++ b/addons/web_unsplash/static/src/js/unsplash_beacon.js
@@ -1,24 +1,34 @@
odoo.define('web_unsplash.beacon', function (require) {
'use strict';
-require('web.dom_ready');
-var ajax = require('web.ajax');
+var publicWidget = require('web.public.widget');
-var unsplash_images = [];
-_.each($('img[src*="/unsplash/"]'), function (img, index) {
- // 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) {
- if (appID) {
- var unsplash_view_url = 'https://views.unsplash.com/v';
- $.get(unsplash_view_url, {
- photo_id: unsplash_images.join(','),
- app_id: appID,
+publicWidget.registry.UnsplashBeacon = publicWidget.Widget.extend({
+ // /!\ To adapt the day the beacon makes sense for backend customizations
+ selector: '#wrapwrap',
+
+ /**
+ * @override
+ */
+ start: function () {
+ var unsplashImages = _.map(this.$('img[src*="/unsplash/"]'), function (img) {
+ // get image id from URL (`http://www.domain.com:1234/unsplash/xYdf5feoI/lion.jpg` -> `xYdf5feoI`)
+ return img.src.split('/unsplash/')[1].split('/')[0];
+ });
+ if (unsplashImages.length) {
+ this._rpc({
+ route: '/web_unsplash/get_app_id',
+ }).then(function (appID) {
+ if (!appID) {
+ return;
+ }
+ $.get('https://views.unsplash.com/v', {
+ 'photo_id': unsplashImages.join(','),
+ 'app_id': appID,
+ });
});
}
- });
-}
-
+ return this._super.apply(this, arguments);
+ },
+});
});