From 0980546f4115ff7d072371d1b57d30000d07ce2c Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 15 Jun 2016 09:40:09 +0200 Subject: [PATCH] [IMP] web_tour,website: enable web_tour in the frontend --- addons/web_tour/static/src/js/tour_service.js | 83 +++++++++++-------- addons/website/views/website_templates.xml | 4 + 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/addons/web_tour/static/src/js/tour_service.js b/addons/web_tour/static/src/js/tour_service.js index 9417f4da9e1..4856e920076 100644 --- a/addons/web_tour/static/src/js/tour_service.js +++ b/addons/web_tour/static/src/js/tour_service.js @@ -1,53 +1,64 @@ odoo.define('web_tour.tour', function(require) { "use strict"; +var ajax = require('web.ajax'); var config = require('web.config'); +var core = require('web.core'); var session = require('web.session'); var TourManager = require('web_tour.TourManager'); +var QWeb = core.qweb; + if (config.device.size_class <= config.device.SIZES.XS) { return; } return session.is_bound.then(function () { - var tour = new TourManager(session.web_tours); + var template_def; + 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); + } + return $.when(template_def).then(function () { + var tour = new TourManager(session.web_tours); - // Use a MutationObserver to detect DOM changes - var untracked_classnames = ["o_tooltip", "o_tooltip_content", "o_tooltip_overlay"]; - var check_tooltip = _.throttle(function (records) { - var update = _.find(records, function (record) { - var record_class = record.target.className; - return !_.isString(record_class) || - _.intersection(record_class.split(' '), untracked_classnames).length === 0; + // Use a MutationObserver to detect DOM changes + var untracked_classnames = ["o_tooltip", "o_tooltip_content", "o_tooltip_overlay"]; + var check_tooltip = _.throttle(function (records) { + var update = _.find(records, function (record) { + var record_class = record.target.className; + return !_.isString(record_class) || + _.intersection(record_class.split(' '), untracked_classnames).length === 0; + }); + if (update) { // ignore mutations in the tooltip itself + tour.update(); + } + }, 500, {leading: false}); + var observer = new MutationObserver(check_tooltip); + var observe = observer.observe.bind(observer, document.body, { + attributes: true, + childList: true, + subtree: true, }); - if (update) { // ignore mutations in the tooltip itself - tour.update(); + + // Enable the MutationObserver for the admin or if a tour is running, when the DOM is ready + if (session.is_admin || tour.running_tour) { + $(observe); } - }, 500, {leading: false}); - var observer = new MutationObserver(check_tooltip); - var observe = observer.observe.bind(observer, document.body, { - attributes: true, - childList: true, - subtree: true, + // Override the TourManager so that it enables/disables the observer when necessary + if (!session.is_admin) { + var run = tour.run; + tour.run = function () { + run.apply(this, arguments); + if (this.running_tour) { observe(); } + }; + var _consume_tour = tour._consume_tour; + tour._consume_tour = function () { + _consume_tour.apply(this, arguments); + observer.disconnect(); + }; + } + + return tour; }); - - // Enable the MutationObserver for the admin or if a tour is running, when the DOM is ready - if (session.is_admin || tour.running_tour) { - $(observe); - } - // Override the TourManager so that it enables/disables the observer when necessary - if (!session.is_admin) { - var run = tour.run; - tour.run = function () { - run.apply(this, arguments); - if (this.running_tour) { observe(); } - }; - var _consume_tour = tour._consume_tour; - tour._consume_tour = function () { - _consume_tour.apply(this, arguments); - observer.disconnect(); - }; - } - - return tour; }); }); diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index 12fc1bca33e..af36b1083f1 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -126,6 +126,10 @@