From 09a54b25dece70f7f8b378819eefffa16f088845 Mon Sep 17 00:00:00 2001 From: ddm Date: Tue, 26 Nov 2013 15:13:24 +0100 Subject: [PATCH] [IMP] Tour: simplify modal handling bzr revid: ddm@openerp.com-20131126141324-3aynn0r5sqpttc90 --- addons/website/static/src/js/website.tour.js | 30 +++++++++++++++---- .../static/src/js/website.tour.blog.js | 18 +++-------- .../static/src/js/website.tour.event.js | 18 +++-------- .../static/src/js/website.tour.shop.js | 20 ++++--------- 4 files changed, 38 insertions(+), 48 deletions(-) diff --git a/addons/website/static/src/js/website.tour.js b/addons/website/static/src/js/website.tour.js index ad0280b0b35..71fd1eb095d 100644 --- a/addons/website/static/src/js/website.tour.js +++ b/addons/website/static/src/js/website.tour.js @@ -15,11 +15,6 @@ keyboard: false, template: this.popover(), }); - this.tour.addSteps(_.map(this.steps, function (step) { - step.title = openerp.qweb.render('website.tour_popover_title', { title: step.title }); - step.onShow = step.triggers; - return step; - })); }, reset: function () { this.tourStorage.removeItem(this.id+'_current_step'); @@ -28,6 +23,31 @@ $('.popover.tour').remove(); }, start: function () { + var self = this; + this.tour.addSteps(_.map(this.steps, function (step) { + step.title = openerp.qweb.render('website.tour_popover_title', { title: step.title }); + if (step.modal) { + step.onShow = function () { + var $doc = $(document); + function onStop () { + if (step.modal.stopOnClose) { + self.stop(); + } + } + $doc.on('hide.bs.modal', onStop); + $doc.one('shown.bs.modal', function () { + $('.modal button.btn-primary').one('click', function () { + $doc.off('hide.bs.modal', onStop); + self.moveToStep(step.modal.afterSubmit); + }); + self.moveToNextStep(); + }); + }; + } else { + step.onShow = step.triggers; + } + return step; + })); if (this.resume() || ((this.currentStepIndex() === 0) && !this.tour.ended())) { this.tour.start(); } diff --git a/addons/website_blog/static/src/js/website.tour.blog.js b/addons/website_blog/static/src/js/website.tour.blog.js index 2da68a89819..4b21a9608c4 100644 --- a/addons/website_blog/static/src/js/website.tour.blog.js +++ b/addons/website_blog/static/src/js/website.tour.blog.js @@ -38,19 +38,9 @@ placement: 'left', title: "New Blog Post", content: "Select this entry to create a new blog post.", - triggers: function () { - var $doc = $(document); - function stopNewBlog () { - self.stop(); - } - $doc.on('hide.bs.modal', stopNewBlog); - $doc.one('shown.bs.modal', function () { - $('.modal button.btn-primary').one('click', function () { - $doc.off('hide.bs.modal', stopNewBlog); - self.moveToStep('post-page'); - }); - self.moveToNextStep(); - }); + modal: { + stopOnClose: true, + afterSubmit: 'post-page', }, }, { @@ -167,7 +157,7 @@ { stepId: 'publish-post', element: 'button.js_publish_btn', - placement: 'right', + placement: 'top', reflex: true, title: "Publish Your Post", content: "Your blog post is not yet published. You can update this draft version and publish it once you are ready.", diff --git a/addons/website_event/static/src/js/website.tour.event.js b/addons/website_event/static/src/js/website.tour.event.js index f2617df3c80..2c16b7f49ed 100644 --- a/addons/website_event/static/src/js/website.tour.event.js +++ b/addons/website_event/static/src/js/website.tour.event.js @@ -38,19 +38,9 @@ placement: 'left', title: "New Event", content: "Click here to create a new event.", - triggers: function () { - var $doc = $(document); - function stopNewEvent () { - self.stop(); - } - $doc.on('hide.bs.modal', stopNewEvent); - $doc.one('shown.bs.modal', function () { - $('.modal button.btn-primary').one('click', function () { - $doc.off('hide.bs.modal', stopNewEvent); - self.moveToStep('event-page'); - }); - self.moveToNextStep(); - }); + modal: { + stopOnClose: true, + afterSubmit: 'event-page', }, }, { @@ -100,7 +90,7 @@ { stepId: 'publish-post', element: 'button.js_publish_btn', - placement: 'right', + placement: 'top', reflex: true, title: "Publish your event", content: "Click to publish your event.", 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 98add0d8bd8..a8d74eb3be9 100644 --- a/addons/website_sale/static/src/js/website.tour.shop.js +++ b/addons/website_sale/static/src/js/website.tour.shop.js @@ -38,19 +38,9 @@ placement: 'left', title: "Create a new product", content: "Select 'New Product' to create it and manage its properties to boost your sales.", - triggers: function () { - var $doc = $(document); - function stopProductTour () { - self.stop(); - } - $doc.on('hide.bs.modal', stopProductTour); - $doc.one('shown.bs.modal', function () { - $('.modal button.btn-primary').one('click', function () { - $doc.off('hide.bs.modal', stopProductTour); - self.moveToStep('product-page'); - }); - self.moveToNextStep(); - }); + modal: { + stopOnClose: true, + afterSubmit: 'product-page', }, }, { @@ -147,7 +137,7 @@ { stepId: 'publish-product', element: 'button.js_publish_btn', - placement: 'right', + placement: 'top', reflex: true, title: "Publish your product", content: "Click to publish your product so your customers can see it.", @@ -158,7 +148,7 @@ resume: function () { return (this.isCurrentStep('product-page') || this.isCurrentStep('publish-product')) && this._super(); }, - trigger: function (url) { + trigger: function () { return (this.resume() && this.testUrl(/^\/shop\/product\/[0-9]+\//)) || this._super(); }, });