4 var website = openerp.website;
5 website.add_template_file('/website/static/src/xml/website.tour.xml');
7 website.Tour = openerp.Class.extend({
10 tourStorage: window.localStorage,
12 this.tour = new Tour({
14 storage: this.tourStorage,
16 template: this.popover(),
18 this.tour.addSteps(_.map(this.steps, function (step) {
19 step.title = openerp.qweb.render('website.tour_popover_title', { title: step.title });
24 this.tourStorage.removeItem(this.id+'_current_step');
25 this.tourStorage.removeItem(this.id+'_end');
26 this.tour._current = 0;
27 $('.popover.tour').remove();
30 if (this.resume() || ((this.currentStepIndex() === 0) && !this.tour.ended())) {
34 currentStepIndex: function () {
35 var index = this.tourStorage.getItem(this.id+'_current_step') || 0;
36 return parseInt(index, 10);
38 indexOfStep: function (stepId) {
40 _.each(this.steps, function (step, i) {
41 if (step.stepId === stepId) {
47 isCurrentStep: function (stepId) {
48 return this.currentStepIndex() === this.indexOfStep(stepId);
50 movetoStep: function (stepId) {
51 $('.popover.tour').remove();
52 var index = this.indexOfStep(stepId);
54 this.tour.goto(index);
57 saveStep: function (stepId) {
58 var index = this.indexOfStep(stepId);
59 this.tourStorage.setItem(this.id+'_current_step', index);
64 redirect: function (url) {
65 url = url || new website.UrlParser(window.location.href);
66 if (this.startPath && url.pathname !== this.startPath) {
67 var newUrl = this.startPath + (url.search ? (url.search + "&") : "?") + this.id + "=true"
68 window.location.replace(newUrl);
72 // Override if necessary
73 return this.currentStepIndex() === 0;
75 trigger: function (url) {
76 // Override if necessary
77 url = url || new website.UrlParser(window.location.href);
78 var urlTrigger = this.id + "=true";
79 return url.search.indexOf(urlTrigger) >= 0;
81 testUrl: function (pattern) {
82 var url = new website.UrlParser(window.location.href);
83 return pattern.test(url.pathname+url.search);
85 popover: function (options) {
86 return openerp.qweb.render('website.tour_popover', options);
90 website.UrlParser = openerp.Class.extend({
91 init: function (url) {
92 var a = document.createElement('a');
96 this.protocol = a.protocol;
98 this.hostname = a.hostname;
99 this.pathname = a.pathname;
100 this.origin = a.origin;
101 this.search = a.search;
106 website.EditorBar.include({
109 $('.tour-backdrop').click(function (e) {
110 e.stopImmediatePropagation();
113 var url = new website.UrlParser(window.location.href);
114 var menu = $('#help-menu');
115 _.each(this.tours, function (tour) {
116 var $menuItem = $($.parseHTML('<li><a href="#">'+tour.name+'</a></li>'));
117 $menuItem.click(function () {
122 menu.append($menuItem);
123 if (tour.trigger()) {
127 return this._super();
129 registerTour: function (tour) {
130 this.tours.push(tour);