From 8d61316486798be226def49bb093ec3b3178a51f Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 20 Jun 2016 08:32:13 +0200 Subject: [PATCH] [FIX] web_tour: load consumed tours in the frontend Also deactivate unnecessary magic fields for the web_tour model. --- addons/web_tour/models/ir_http.py | 3 +-- addons/web_tour/models/tour.py | 6 ++++++ addons/web_tour/static/src/js/tour_manager.js | 2 +- addons/web_tour/static/src/js/tour_service.js | 14 +++++++++----- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/addons/web_tour/models/ir_http.py b/addons/web_tour/models/ir_http.py index 5718ce84858..fbd70d5b247 100644 --- a/addons/web_tour/models/ir_http.py +++ b/addons/web_tour/models/ir_http.py @@ -8,6 +8,5 @@ class Http(models.Model): def session_info(self): result = super(Http, self).session_info() if result['is_admin']: - consumed_tours = request.env['web_tour.tour'].search([('user_id', '=', request.env.uid)]) - result['web_tours'] = [t.name for t in consumed_tours] + result['web_tours'] = request.env['web_tour.tour'].get_consumed_tours() return result diff --git a/addons/web_tour/models/tour.py b/addons/web_tour/models/tour.py index 4741ea45d95..546bf020451 100644 --- a/addons/web_tour/models/tour.py +++ b/addons/web_tour/models/tour.py @@ -8,6 +8,7 @@ class Tour(models.Model): _name = "web_tour.tour" _description = "Tours" + _log_access = False name = fields.Char(string="Tour name", required=True) user_id = fields.Many2one('res.users', string='Consumed by') @@ -17,3 +18,8 @@ class Tour(models.Model): """ Sets tour 'name' as consumed for the current user, meaning that this tour won't be active anymore for that user """ self.create({'name': name, 'user_id': self.env.uid}) + + @api.model + def get_consumed_tours(self): + """ Returns the list of consumed tours for the current user """ + return [t.name for t in self.search([('user_id', '=', self.env.uid)])] diff --git a/addons/web_tour/static/src/js/tour_manager.js b/addons/web_tour/static/src/js/tour_manager.js index d19b27b4888..e08b293e4c7 100644 --- a/addons/web_tour/static/src/js/tour_manager.js +++ b/addons/web_tour/static/src/js/tour_manager.js @@ -22,7 +22,7 @@ return core.Class.extend({ this.$body = $('body'); this.active_tooltips = {}; this.tours = {}; - this.consumed_tours = consumed_tours; + this.consumed_tours = consumed_tours || []; this.running_tour = local_storage.getItem(getRunningKey()); this.TourModel = new Model('web_tour.tour'); }, diff --git a/addons/web_tour/static/src/js/tour_service.js b/addons/web_tour/static/src/js/tour_service.js index 608e63527fe..88498498e3c 100644 --- a/addons/web_tour/static/src/js/tour_service.js +++ b/addons/web_tour/static/src/js/tour_service.js @@ -4,6 +4,7 @@ odoo.define('web_tour.tour', function(require) { var ajax = require('web.ajax'); var config = require('web.config'); var core = require('web.core'); +var Model = require('web.Model'); var session = require('web.session'); var TourManager = require('web_tour.TourManager'); @@ -12,13 +13,16 @@ var QWeb = core.qweb; if (config.device.size_class <= config.device.SIZES.XS) { return; } return session.is_bound.then(function () { - var template_def; + var defs = []; + // Load the list of consumed tours and the tip template only if we are admin, in the frontend, + // tours being only available for the admin. For the backend, the list of consumed is directly + // in the page source. if (session.is_frontend && session.is_admin) { - // Manually load tip template if we are in the frontend, as admin - template_def = ajax.loadXML('/web_tour/static/src/xml/tip.xml', QWeb); + defs.push(new Model('web_tour.tour').call('get_consumed_tours')); + defs.push(ajax.loadXML('/web_tour/static/src/xml/tip.xml', QWeb)); } - return $.when(template_def).then(function () { - var tour = new TourManager(session.web_tours); + return $.when.apply($, defs).then(function (consumed_tours) { + var tour = new TourManager(session.is_frontend ? consumed_tours : session.web_tours); // Use a MutationObserver to detect DOM changes var untracked_classnames = ["o_tooltip", "o_tooltip_content", "o_tooltip_overlay"];