[IMP] Improve tour registration
authorddm <ddm@openerp.com>
Tue, 19 Nov 2013 09:43:53 +0000 (10:43 +0100)
committerddm <ddm@openerp.com>
Tue, 19 Nov 2013 09:43:53 +0000 (10:43 +0100)
bzr revid: ddm@openerp.com-20131119094353-kg04ijualwtsz1lo

addons/website/static/src/js/website.tour.banner.js
addons/website/static/src/js/website.tour.install-app.js
addons/website/static/src/js/website.tour.js
addons/website/static/src/js/website.tour.menu-editor.js
addons/website_sale/static/src/js/website.tour.shop.js

index f6cbfa4..0b47700 100644 (file)
@@ -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);
             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('<li><a href="#">'+bannerTour.name+'</a></li>'));
-            $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();
         },
     });
index 4917b6a..b4be242 100644 (file)
 
     website.EditorBar.include({
         start: function () {
-            var menu = $('#help-menu');
-            var installAppTour = new website.InstallAppTour(this);
-            var $menuItem = $($.parseHTML('<li><a href="#">'+installAppTour.name+'</a></li>'));
-            $menuItem.click(function () {
-                installAppTour.reset();
-                installAppTour.start();
-            });
-            menu.append($menuItem);
+            this.registerTour(new website.InstallAppTour(this));
             return this._super();
         },
     });
index f9a931b..9181029 100644 (file)
         stop: function () {
             this.tour.end();
         },
+        continueTour: function () {
+            // Override if necessary
+            return true;
+        },
+        redirect: function () {
+            // Override if necessary
+        },
     });
 
     website.UrlParser = openerp.Class.extend({
     });
 
     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('<li><a href="#">'+tour.name+'</a></li>'));
+                $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);
+        },
     });
 
 }());
index 3736fcf..b82b21f 100644 (file)
 
     website.EditorBar.include({
         start: function () {
-            var menu = $('#help-menu');
-            var builderTour = new website.EditorBuilderTour(this);
-            var $menuItem = $($.parseHTML('<li><a href="#">'+builderTour.name+'</a></li>'));
-            $menuItem.click(function () {
-                builderTour.reset();
-                builderTour.start();
-            });
-            menu.append($menuItem);
+            this.registerTour(new website.EditorBuilderTour(this));
             return this._super();
         },
     });
index d18d914..a665327 100644 (file)
@@ -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);
                     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('<li><a href="#">'+shopTour.name+'</a></li>'));
-            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();
         },
     });