diff options
| author | Dharmraj Jhala (OpenERP) <dizzy.zala@gmail.com> | 2014-02-25 11:02:04 +0530 |
|---|---|---|
| committer | Dharmraj Jhala (OpenERP) <dizzy.zala@gmail.com> | 2014-02-25 11:02:04 +0530 |
| commit | c6917b9c074f3f2c19cac1dc3e05c8a3d2cadbed (patch) | |
| tree | 6a17e259f27e029458207671d10fec50b5c425be /addons/website/static/src/js/website.tour.js | |
| parent | b2688a37f84a505d8e334f8b0325b4747d440170 (diff) | |
| parent | 9eb2db4465cefa5dc331123c1b0a4df035545015 (diff) | |
[MERGE] with trunk-survey2-rim addons branch
bzr revid: dizzy.zala@gmail.com-20140225053204-mra08nfvumkxyixa
Diffstat (limited to 'addons/website/static/src/js/website.tour.js')
| -rw-r--r-- | addons/website/static/src/js/website.tour.js | 145 |
1 files changed, 87 insertions, 58 deletions
diff --git a/addons/website/static/src/js/website.tour.js b/addons/website/static/src/js/website.tour.js index 1db813e4cd4..8b1284f0a07 100644 --- a/addons/website/static/src/js/website.tour.js +++ b/addons/website/static/src/js/website.tour.js @@ -2,8 +2,11 @@ 'use strict'; var website = openerp.website; + +if (typeof QWeb2 !== "undefined") website.add_template_file('/website/static/src/xml/website.tour.xml'); +if (website.EditorBar) website.EditorBar.include({ tours: [], start: function () { @@ -17,31 +20,11 @@ website.EditorBar.include({ }); menu.append($menuItem); }); - - this.waitRTEReady = false; - this.on('rte:called', this, function () {self.waitRTEReady = true; }); - this.on('rte:ready', this, function () {self.waitRTEReady = false;}); - - var res = this._super(); - website.Tour.waitReady.call(this, this.testRunning); - return res; + return this._super(); }, registerTour: function (tour) { website.Tour.add(tour); this.tours.push(tour); - }, - testRunning: function () { - if (this.waitRTEReady) { - this.on('rte:ready', this, function () { - website.Tour.each(function () { - this.running(); - }); - }); - } else { - website.Tour.each(function () { - this.running(); - }); - } } }); @@ -78,23 +61,12 @@ $.ajaxSetup({ } }); - website.Tour = openerp.Class.extend({ steps: [], defaultDelay: 50, //ms + defaultOverLaps: 5000, //ms localStorage: window.localStorage, - init: function (url) { - this.tour = new Tour({ - name: this.id, - storage: this.tourStorage, - keyboard: false, - template: this.popover(), - onHide: function () { - window.scrollTo(0, 0); - } - }); - this.registerSteps(); - }, + init: function () {}, run: function (automatic) { this.reset(); @@ -107,7 +79,10 @@ website.Tour = openerp.Class.extend({ if (automatic) { this.localStorage.setItem("tour-"+this.id+"-test-automatic", true); + } else { + this.localStorage.removeItem("tour-"+this.id+"-test-automatic"); } + this.automatic = automatic; if (this.path) { // redirect to begin of the tour in function of the language @@ -123,12 +98,13 @@ website.Tour = openerp.Class.extend({ website.Tour.waitReady.call(this, function () {self._running();}); }, running: function () { + var self = this; if (+this.localStorage.getItem("tour-"+this.id+"-test") >= this.steps.length-1) { this.endTour(); return; } - if (website.Tour.is_busy() || !this.testPathUrl()) return; + if (website.Tour.is_busy()) return; // launch tour with url this.checkRunningUrl(); @@ -136,6 +112,21 @@ website.Tour = openerp.Class.extend({ // mark tour as busy (only one test running) if (this.localStorage.getItem("tour-"+this.id+"-test") != null) { website.Tour.busy = true; + this.automatic = !!this.localStorage.getItem("tour-"+this.id+"-test-automatic"); + } + + if (!this.testPathUrl()) { + if (this.automatic) { + this.timer = setTimeout(function () { + self.reset(); + throw new Error("Wrong url for running " + self.id + + '\ntestPath: ' + self.testPath + + '\nhref: ' + window.location.href + + "\nreferrer: " + document.referrer + ); + },this.defaultOverLaps); + } + return; } var self = this; @@ -143,14 +134,10 @@ website.Tour = openerp.Class.extend({ }, _running: function () { var stepId = this.localStorage.getItem("tour-"+this.id+"-test"); - var automatic = !!this.localStorage.getItem("tour-"+this.id+"-test-automatic"); - + if (stepId != null) { - if (!this.check(this.step(stepId))) { - var step = this.next(stepId); - stepId = step ? step.stepId : stepId; - } - this.nextStep(stepId, automatic ? this.autoNextStep : null, automatic ? 5000 : null); + this.registerTour(); + this.nextStep(stepId, this.automatic ? this.autoNextStep : null, this.automatic ? this.defaultOverLaps : null); } }, @@ -187,20 +174,35 @@ website.Tour = openerp.Class.extend({ } }, + registerTour: function () { + this.tour = new Tour({ + name: this.id, + storage: this.tourStorage, + keyboard: false, + template: this.popover(), + onHide: function () { + window.scrollTo(0, 0); + } + }); + this.registerSteps(); + }, registerSteps: function () { for (var index=0, len=this.steps.length; index<len; index++) { var step = this.steps[index]; step.stepId = step.stepId || ""+index; - if (!step.waitNot && index > 0 && $(this.steps[index-1].template).has("button[data-role='next']").size()) { - step.waitNot = '.popover.tour'; + if (!step.waitNot && index > 0 && this.steps[index-1] && + this.steps[index-1].popover && this.steps[index-1].popover.next) { + step.waitNot = '.popover.tour:visible'; } if (!step.waitFor && index > 0 && this.steps[index-1].snippet) { step.waitFor = '.oe_overlay_options .oe_options:visible'; } - step._title = step.title; - step.title = openerp.qweb.render('website.tour_popover_title', { title: step.title }); + step._title = step._title || step.title; + step.title = this.popoverTitle({ title: step._title }); + step.template = step.template || this.popover( step.popover ); + if (!step.element) step.orphan = true; if (step.snippet) { step.element = '#oe_snippets div.oe_snippet[data-snippet-id="'+step.snippet+'"] .oe_snippet_thumbnail'; @@ -208,9 +210,10 @@ website.Tour = openerp.Class.extend({ } - if ($(this.steps[index-1].template).has("button[data-role='next']").size()) { + if (this.steps[index-1] && + this.steps[index-1].popover && this.steps[index-1].popover.next) { var step = { - stepId: index, + stepId: ""+index, waitNot: '.popover.tour:visible' }; this.steps.push(step); @@ -219,8 +222,21 @@ website.Tour = openerp.Class.extend({ this.tour.addSteps(this.steps); }, + popoverTitle: function (options) { + try { + return openerp.qweb.render('website.tour_popover_title', options); + } catch (e) { + if (!this.automatic) throw e; + return options.title; + } + }, popover: function (options) { - return openerp.qweb.render('website.tour_popover', options); + try { + return openerp.qweb.render('website.tour_popover', options); + } catch (e) { + if (!this.automatic) throw e; + return ""; + } }, timer: null, @@ -268,7 +284,12 @@ website.Tour = openerp.Class.extend({ self.timer = setTimeout(checkNext, self.defaultDelay); } else { self.reset(); - throw new Error("Time overlaps to arrive to step " + step.stepId + ": '" + step._title + "'"); + throw new Error("Time overlaps to arrive to step " + step.stepId + ": '" + step._title + "'" + + '\nelement: ' + Boolean(!step.element || ($(step.element).size() && $(step.element).is(":visible") && !$(step.element).is(":hidden"))) + + '\nwaitNot: ' + Boolean(!step.waitNot || !$(step.waitNot).size()) + + '\nwaitFor: ' + Boolean(!step.waitFor || $(step.waitFor).size()) + + '\n\n' + $("body").html() + ); } } checkNext(); @@ -291,7 +312,7 @@ website.Tour = openerp.Class.extend({ $(".popover.tour").remove(); // go to step in bootstrap tour this.tour.goto(index); - if (step.callback) step.callback(); + if (step.onload) step.onload(); next = steps.shift(); break; } @@ -358,7 +379,10 @@ website.Tour = openerp.Class.extend({ } else if (step.sampleText) { $element.trigger($.Event("keydown", { srcElement: $element })); - if ($element.is("select") || $element.is("input") ) { + if ($element.is("input") ) { + $element.val(step.sampleText); + } if ($element.is("select")) { + $element.find("[value='"+step.sampleText+"'], option:contains('"+step.sampleText+"')").attr("selected", true); $element.val(step.sampleText); } else { $element.html(step.sampleText); @@ -404,7 +428,10 @@ website.Tour.busy = false; website.Tour.add = function (tour) { website.Tour.waitReady(function () { tour = tour.id ? tour : new tour(); - website.Tour.tours[tour.id] = tour; + if (!website.Tour.tours[tour.id]) { + website.Tour.tours[tour.id] = tour; + tour.running(); + } }); }; website.Tour.get = function (id) { @@ -420,7 +447,7 @@ website.Tour.each = function (callback) { website.Tour.waitReady = function (callback) { var self = this; $(document).ready(function () { - if ($.ajaxBusy == null || $.ajaxBusy) { + if ($.ajaxBusy) { $(document).ajaxStop(function() { setTimeout(function () { callback.call(self); @@ -435,18 +462,20 @@ website.Tour.waitReady = function (callback) { }); }; website.Tour.run_test = function (id) { - website.Tour.get(id).run(true); + website.Tour.waitReady(function () { + if (!website.Tour.is_busy()) { + website.Tour.tours[id].run(true); + } + }); }; website.Tour.is_busy = function () { for (var k in this.localStorage) { if (!k.indexOf("tour-")) { - return true; + return k; } } return website.Tour.busy; }; - - }()); |
