From 4ba5cad0e3a7e24ab404aaa08014c42e8d8973d8 Mon Sep 17 00:00:00 2001 From: ddm Date: Tue, 19 Nov 2013 10:43:53 +0100 Subject: [PATCH] [IMP] Improve tour registration bzr revid: ddm@openerp.com-20131119094353-kg04ijualwtsz1lo --- .../static/src/js/website.tour.banner.js | 26 ++++++-------- .../static/src/js/website.tour.install-app.js | 9 +---- addons/website/static/src/js/website.tour.js | 25 +++++++++++++ .../static/src/js/website.tour.menu-editor.js | 9 +---- .../static/src/js/website.tour.shop.js | 36 ++++++++++--------- 5 files changed, 57 insertions(+), 48 deletions(-) diff --git a/addons/website/static/src/js/website.tour.banner.js b/addons/website/static/src/js/website.tour.banner.js index f6cbfa490d6..0b47700169e 100644 --- a/addons/website/static/src/js/website.tour.banner.js +++ b/addons/website/static/src/js/website.tour.banner.js @@ -8,6 +8,7 @@ website.EditorBannerTour = website.EditorTour.extend({ id: 'add_banner_tour', name: "Insert a banner", + urlTrigger: '?banner-tutorial=true', init: function (editor) { var self = this; var $body = $(document.body); @@ -132,28 +133,23 @@ var showTutorialsIndex = this.indexOfStep('show-tutorials'); return (currentStepIndex === secondPartIndex || currentStepIndex === showTutorialsIndex) && !this.tour.ended(); }, + continueTour: function () { + return this.startOfPart2(); + }, canResume: function () { return this.startOfPart2() || this._super(); }, + redirect: function (url) { + url = url || new website.UrlParser(window.location.href); + if (url.pathname !== '/' && url.pathname !== '/page/website.homepage') { + window.location.replace('/page/website.homepage?banner-tutorial=true'); + } + }, }); website.EditorBar.include({ start: function () { - var menu = $('#help-menu'); - var bannerTour = new website.EditorBannerTour(this); - var $menuItem = $($.parseHTML('
  • '+bannerTour.name+'
  • ')); - $menuItem.click(function () { - if (url.pathname !== '/' && url.pathname !== '/page/website.homepage') { - window.location.replace('/page/website.homepage?banner-tutorial=true'); - } - bannerTour.reset(); - bannerTour.start(); - }); - menu.append($menuItem); - var url = new website.UrlParser(window.location.href); - if (url.search.indexOf('?banner-tutorial=true') === 0 || bannerTour.startOfPart2()) { - bannerTour.start(); - } + this.registerTour(new website.EditorBannerTour(this)); return this._super(); }, }); diff --git a/addons/website/static/src/js/website.tour.install-app.js b/addons/website/static/src/js/website.tour.install-app.js index 4917b6a4460..b4be2420c35 100644 --- a/addons/website/static/src/js/website.tour.install-app.js +++ b/addons/website/static/src/js/website.tour.install-app.js @@ -49,14 +49,7 @@ website.EditorBar.include({ start: function () { - var menu = $('#help-menu'); - var installAppTour = new website.InstallAppTour(this); - var $menuItem = $($.parseHTML('
  • '+installAppTour.name+'
  • ')); - $menuItem.click(function () { - installAppTour.reset(); - installAppTour.start(); - }); - menu.append($menuItem); + this.registerTour(new website.InstallAppTour(this)); return this._super(); }, }); diff --git a/addons/website/static/src/js/website.tour.js b/addons/website/static/src/js/website.tour.js index f9a931bfaaa..9181029c7a2 100644 --- a/addons/website/static/src/js/website.tour.js +++ b/addons/website/static/src/js/website.tour.js @@ -82,6 +82,13 @@ stop: function () { this.tour.end(); }, + continueTour: function () { + // Override if necessary + return true; + }, + redirect: function () { + // Override if necessary + }, }); website.UrlParser = openerp.Class.extend({ @@ -100,13 +107,31 @@ }); website.EditorBar.include({ + tours: [], start: function () { $('.tour-backdrop').click(function (e) { e.stopImmediatePropagation(); e.preventDefault(); }); + var url = new website.UrlParser(window.location.href); + var menu = $('#help-menu'); + _.each(this.tours, function (tour) { + var $menuItem = $($.parseHTML('
  • '+tour.name+'
  • ')); + $menuItem.click(function () { + tour.redirect(url); + tour.reset(); + tour.start(); + }); + menu.append($menuItem); + if (tour.urlTrigger && (url.search.indexOf(tour.urlTrigger) === 0 || tour.continueTour())) { + tour.start(); + } + }); return this._super(); }, + registerTour: function (tour) { + this.tours.push(tour); + }, }); }()); diff --git a/addons/website/static/src/js/website.tour.menu-editor.js b/addons/website/static/src/js/website.tour.menu-editor.js index 3736fcf8707..b82b21f4b85 100644 --- a/addons/website/static/src/js/website.tour.menu-editor.js +++ b/addons/website/static/src/js/website.tour.menu-editor.js @@ -100,14 +100,7 @@ website.EditorBar.include({ start: function () { - var menu = $('#help-menu'); - var builderTour = new website.EditorBuilderTour(this); - var $menuItem = $($.parseHTML('
  • '+builderTour.name+'
  • ')); - $menuItem.click(function () { - builderTour.reset(); - builderTour.start(); - }); - menu.append($menuItem); + this.registerTour(new website.EditorBuilderTour(this)); return this._super(); }, }); diff --git a/addons/website_sale/static/src/js/website.tour.shop.js b/addons/website_sale/static/src/js/website.tour.shop.js index d18d9146c91..a665327c563 100644 --- a/addons/website_sale/static/src/js/website.tour.shop.js +++ b/addons/website_sale/static/src/js/website.tour.shop.js @@ -8,6 +8,7 @@ website.EditorShopTour = website.EditorTour.extend({ id: 'shop_tour', name: "Create a product", + urlTrigger: '?shop-tutorial=true', init: function (editor) { var self = this; var $body = $(document.body); @@ -16,32 +17,33 @@ stepId: 'welcome-shop', orphan: true, backdrop: true, - title: "e-commerce", - content: "Welcome to the e-commerce. This tutorial will help you to create a product.", + title: "Welcome to your shop", + content: "You successfully installed the e-commerce. This guide will help you to create your product and promote your sales.", template: render('website.tour_popover', { next: "Start Tutorial", end: "Skip It" }), }, + { + stepId: 'content-menu', + element: '#content-menu-button', + placement: 'left', + reflex: true, + title: "Create your first product", + content: "Click here to add a new product.", + template: render('website.tour_popover'), + }, ]; return this._super(); }, + redirect: function (url) { + url = url || new website.UrlParser(window.location.href); + if (url.pathname !== '/shop') { + window.location.replace('/shop?shop-tutorial=true'); + } + }, }); website.EditorBar.include({ start: function () { - var menu = $('#help-menu'); - var shopTour = new website.EditorShopTour(this); - var $menuItem = $($.parseHTML('
  • '+shopTour.name+'
  • ')); - var url = new website.UrlParser(window.location.href); - $menuItem.click(function () { - shopTour.reset(); - shopTour.start(); - if (url.pathname !== '/shop') { - window.location.replace('/shop?shop-tutorial=true'); - } - }); - if (url.search.indexOf('?shop-tutorial=true') === 0) { - shopTour.start(); - } - menu.append($menuItem); + this.registerTour(new website.EditorShopTour(this)); return this._super(); }, });