[FIX] web_tour: load consumed tours in the frontend
Also deactivate unnecessary magic fields for the web_tour model.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)])]
|
||||
|
||||
@@ -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');
|
||||
},
|
||||
|
||||
@@ -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"];
|
||||
|
||||
Reference in New Issue
Block a user