diff options
| author | Thibault Delavallée <tde@openerp.com> | 2013-10-08 10:40:23 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2013-10-08 10:40:23 +0200 |
| commit | 567765166882f5d28031aec4e75b231d30553e35 (patch) | |
| tree | 1b4680a2ed42b84442532af2269b344650f3677e /addons | |
| parent | b87ddc1bf47cf86e5fd9b4f594e80e7f73988b4a (diff) | |
| parent | e535a152e5195f82d7d3337b707f362477dea935 (diff) | |
[MERGE] Sync with website-al branch
bzr revid: tde@openerp.com-20131008084023-utmkc3cfhyzw5c0p
Diffstat (limited to 'addons')
| -rwxr-xr-x | addons/website/static/lib/bootstrap-tour/bootstrap-tour.css | 43 | ||||
| -rwxr-xr-x | addons/website/static/lib/bootstrap-tour/bootstrap-tour.js | 559 | ||||
| -rw-r--r-- | addons/website/static/src/css/editor.css | 5 | ||||
| -rw-r--r-- | addons/website/static/src/css/editor.sass | 7 | ||||
| -rw-r--r-- | addons/website/static/src/js/website.snippets.js | 183 | ||||
| -rw-r--r-- | addons/website/static/src/js/website.tour.js | 224 | ||||
| -rw-r--r-- | addons/website/static/src/xml/website.tour.xml | 44 | ||||
| -rw-r--r-- | addons/website/static/src/xml/website.xml | 6 | ||||
| -rw-r--r-- | addons/website/views/snippets.xml | 10 | ||||
| -rw-r--r-- | addons/website/views/views.xml | 3 |
10 files changed, 1012 insertions, 72 deletions
diff --git a/addons/website/static/lib/bootstrap-tour/bootstrap-tour.css b/addons/website/static/lib/bootstrap-tour/bootstrap-tour.css new file mode 100755 index 00000000000..72c6e8cbab7 --- /dev/null +++ b/addons/website/static/lib/bootstrap-tour/bootstrap-tour.css @@ -0,0 +1,43 @@ +.tour-backdrop { + position: fixed; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 1009; + background-color: #000; + opacity: 0.8; +} +.tour-step-backdrop { + position: relative; + z-index: 1011; +} +.tour-step-background { + position: absolute; + z-index: 1010; + background: #fff; + border-radius: 6px; +} +.popover[class*="tour-"] .popover-navigation { + padding: 9px 14px; +} +.popover[class*="tour-"] .popover-navigation *[data-role=end] { + float: right; +} +.popover[class*="tour-"] .popover-navigation *[data-role=prev], +.popover[class*="tour-"] .popover-navigation *[data-role=next], +.popover[class*="tour-"] .popover-navigation *[data-role=end] { + cursor: pointer; +} +.popover[class*="tour-"] .popover-navigation *[data-role=prev].disabled, +.popover[class*="tour-"] .popover-navigation *[data-role=next].disabled, +.popover[class*="tour-"] .popover-navigation *[data-role=end].disabled { + cursor: default; +} +.popover[class*="tour-"].orphan { + position: fixed; + margin-top: 0; +} +.popover[class*="tour-"].orphan .arrow { + display: none; +} diff --git a/addons/website/static/lib/bootstrap-tour/bootstrap-tour.js b/addons/website/static/lib/bootstrap-tour/bootstrap-tour.js new file mode 100755 index 00000000000..8b45d6da9ee --- /dev/null +++ b/addons/website/static/lib/bootstrap-tour/bootstrap-tour.js @@ -0,0 +1,559 @@ +/* =========================================================== +# bootstrap-tour - v0.6.1 +# http://bootstraptour.com +# ============================================================== +# Copyright 2012-2013 Ulrich Sossou +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ +(function() { + (function($, window) { + var Tour, document; + document = window.document; + Tour = (function() { + function Tour(options) { + this._options = $.extend({ + name: "tour", + container: "body", + keyboard: true, + storage: window.localStorage, + debug: false, + backdrop: false, + redirect: true, + orphan: false, + basePath: "", + template: "<div class='popover'> <div class='arrow'></div> <h3 class='popover-title'></h3> <div class='popover-content'></div> <nav class='popover-navigation'> <div class='btn-group'> <button class='btn btn-sm btn-default' data-role='prev'>« Prev</button> <button class='btn btn-sm btn-default' data-role='next'>Next »</button> </div> <button class='btn btn-sm btn-default' data-role='end'>End tour</button> </nav> </div>", + afterSetState: function(key, value) {}, + afterGetState: function(key, value) {}, + afterRemoveState: function(key) {}, + onStart: function(tour) {}, + onEnd: function(tour) {}, + onShow: function(tour) {}, + onShown: function(tour) {}, + onHide: function(tour) {}, + onHidden: function(tour) {}, + onNext: function(tour) {}, + onPrev: function(tour) {} + }, options); + this._steps = []; + this.setCurrentStep(); + this.backdrop = { + overlay: null, + $element: null, + $background: null + }; + } + + Tour.prototype.setState = function(key, value) { + var keyName; + if (this._options.storage) { + keyName = "" + this._options.name + "_" + key; + this._options.storage.setItem(keyName, value); + return this._options.afterSetState(keyName, value); + } else { + if (this._state == null) { + this._state = {}; + } + return this._state[key] = value; + } + }; + + Tour.prototype.removeState = function(key) { + var keyName; + if (this._options.storage) { + keyName = "" + this._options.name + "_" + key; + this._options.storage.removeItem(keyName); + return this._options.afterRemoveState(keyName); + } else { + if (this._state != null) { + return delete this._state[key]; + } + } + }; + + Tour.prototype.getState = function(key) { + var keyName, value; + if (this._options.storage) { + keyName = "" + this._options.name + "_" + key; + value = this._options.storage.getItem(keyName); + } else { + if (this._state != null) { + value = this._state[key]; + } + } + if (value === void 0 || value === "null") { + value = null; + } + this._options.afterGetState(key, value); + return value; + }; + + Tour.prototype.addSteps = function(steps) { + var step, _i, _len, _results; + _results = []; + for (_i = 0, _len = steps.length; _i < _len; _i++) { + step = steps[_i]; + _results.push(this.addStep(step)); + } + return _results; + }; + + Tour.prototype.addStep = function(step) { + return this._steps.push(step); + }; + + Tour.prototype.getStep = function(i) { + if (this._steps[i] != null) { + return $.extend({ + id: "step-" + i, + path: "", + placement: "right", + title: "", + content: "<p></p>", + next: i === this._steps.length - 1 ? -1 : i + 1, + prev: i - 1, + animation: true, + container: this._options.container, + backdrop: this._options.backdrop, + redirect: this._options.redirect, + orphan: this._options.orphan, + template: this._options.template, + onShow: this._options.onShow, + onShown: this._options.onShown, + onHide: this._options.onHide, + onHidden: this._options.onHidden, + onNext: this._options.onNext, + onPrev: this._options.onPrev + }, this._steps[i]); + } + }; + + Tour.prototype.start = function(force) { + var promise, + _this = this; + if (force == null) { + force = false; + } + if (this.ended() && !force) { + return this._debug("Tour ended, start prevented."); + } + $(document).off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=next]").on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=next]:not(.disabled)", function(e) { + e.preventDefault(); + return _this.next(); + }); + $(document).off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=prev]").on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=prev]:not(.disabled)", function(e) { + e.preventDefault(); + return _this.prev(); + }); + $(document).off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=end]").on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=end]", function(e) { + e.preventDefault(); + return _this.end(); + }); + this._onResize(function() { + return _this.showStep(_this._current); + }); + this._setupKeyboardNavigation(); + promise = this._makePromise(this._options.onStart != null ? this._options.onStart(this) : void 0); + return this._callOnPromiseDone(promise, this.showStep, this._current); + }; + + Tour.prototype.next = function() { + var promise; + if (this.ended()) { + return this._debug("Tour ended, next prevented."); + } + promise = this.hideStep(this._current); + return this._callOnPromiseDone(promise, this._showNextStep); + }; + + Tour.prototype.prev = function() { + var promise; + if (this.ended()) { + return this._debug("Tour ended, prev prevented."); + } + promise = this.hideStep(this._current); + return this._callOnPromiseDone(promise, this._showPrevStep); + }; + + Tour.prototype.goto = function(i) { + var promise; + if (this.ended()) { + return this._debug("Tour ended, goto prevented."); + } + promise = this.hideStep(this._current); + return this._callOnPromiseDone(promise, this.showStep, i); + }; + + Tour.prototype.end = function() { + var endHelper, hidePromise, + _this = this; + endHelper = function(e) { + $(document).off("click.tour-" + _this._options.name); + $(document).off("keyup.tour-" + _this._options.name); + $(window).off("resize.tour-" + _this._options.name); + _this.setState("end", "yes"); + if (_this._options.onEnd != null) { + return _this._options.onEnd(_this); + } + }; + hidePromise = this.hideStep(this._current); + return this._callOnPromiseDone(hidePromise, endHelper); + }; + + Tour.prototype.ended = function() { + return !!this.getState("end"); + }; + + Tour.prototype.restart = function() { + this.removeState("current_step"); + this.removeState("end"); + this.setCurrentStep(0); + return this.start(); + }; + + Tour.prototype.hideStep = function(i) { + var hideStepHelper, promise, step, + _this = this; + step = this.getStep(i); + promise = this._makePromise(step.onHide != null ? step.onHide(this, i) : void 0); + hideStepHelper = function(e) { + var $element; + $element = _this._isOrphan(step) ? $("body") : $(step.element); + $element.popover("destroy"); + if (step.reflex) { + $element.css("cursor", "").off("click.tour-" + _this._options.name); + } + if (step.backdrop) { + _this._hideBackdrop(); + } + if (step.onHidden != null) { + return step.onHidden(_this); + } + }; + this._callOnPromiseDone(promise, hideStepHelper); + return promise; + }; + + Tour.prototype.showStep = function(i) { + var promise, showStepHelper, skipToPrevious, step, + _this = this; + step = this.getStep(i); + if (!step) { + return; + } + skipToPrevious = i < this._current; + promise = this._makePromise(step.onShow != null ? step.onShow(this, i) : void 0); + showStepHelper = function(e) { + var current_path, path; + _this.setCurrentStep(i); + path = $.isFunction(step.path) ? step.path.call() : _this._options.basePath + step.path; + current_path = [document.location.pathname, document.location.hash].join(""); + if (_this._isRedirect(path, current_path)) { + _this._redirect(step, path); + return; + } + if (_this._isOrphan(step)) { + if (!step.orphan) { + _this._debug("Skip the orphan step " + (_this._current + 1) + ". Orphan option is false and the element doesn't exist or is hidden."); + if (skipToPrevious) { + _this._showPrevStep(); + } else { + _this._showNextStep(); + } + return; + } + _this._debug("Show the orphan step " + (_this._current + 1) + ". Orphans option is true."); + } + if (step.backdrop) { + _this._showBackdrop(!_this._isOrphan(step) ? step.element : void 0); + } + _this._showPopover(step, i); + if (step.onShown != null) { + step.onShown(_this); + } + return _this._debug("Step " + (_this._current + 1) + " of " + _this._steps.length); + }; + return this._callOnPromiseDone(promise, showStepHelper); + }; + + Tour.prototype.setCurrentStep = function(value) { + if (value != null) { + this._current = value; + return this.setState("current_step", value); + } else { + this._current = this.getState("current_step"); + return this._current = this._current === null ? 0 : parseInt(this._current, 10); + } + }; + + Tour.prototype._showNextStep = function() { + var promise, showNextStepHelper, step, + _this = this; + step = this.getStep(this._current); + showNextStepHelper = function(e) { + return _this.showStep(step.next); + }; + promise = this._makePromise((step.onNext != null ? step.onNext(this) : void 0)); + return this._callOnPromiseDone(promise, showNextStepHelper); + }; + + Tour.prototype._showPrevStep = function() { + var promise, showPrevStepHelper, step, + _this = this; + step = this.getStep(this._current); + showPrevStepHelper = function(e) { + return _this.showStep(step.prev); + }; + promise = this._makePromise((step.onPrev != null ? step.onPrev(this) : void 0)); + return this._callOnPromiseDone(promise, showPrevStepHelper); + }; + + Tour.prototype._debug = function(text) { + if (this._options.debug) { + return window.console.log("Bootstrap Tour '" + this._options.name + "' | " + text); + } + }; + + Tour.prototype._isRedirect = function(path, currentPath) { + return (path != null) && path !== "" && path.replace(/\?.*$/, "").replace(/\/?$/, "") !== currentPath.replace(/\/?$/, ""); + }; + + Tour.prototype._redirect = function(step, path) { + if ($.isFunction(step.redirect)) { + return step.redirect.call(this, path); + } else if (step.redirect === true) { + this._debug("Redirect to " + path); + return document.location.href = path; + } + }; + + Tour.prototype._isOrphan = function(step) { + return (step.element == null) || !$(step.element).length || $(step.element).is(":hidden"); + }; + + Tour.prototype._showPopover = function(step, i) { + var $element, $navigation, $template, $tip, isOrphan, options, + _this = this; + options = $.extend({}, this._options); + $template = $.isFunction(step.template) ? $(step.template(i, step)) : $(step.template); + $navigation = $template.find(".popover-navigation"); + isOrphan = this._isOrphan(step); + if (isOrphan) { + step.element = "body"; + step.placement = "top"; + $template = $template.addClass("orphan"); + } + $element = $(step.element); + $template.addClass("tour-" + this._options.name); + if (step.options) { + $.extend(options, step.options); + } + if (step.reflex) { + $element.css("cursor", "pointer").on("click.tour-" + this._options.name, function(e) { + if (_this._current < _this._steps.length - 1) { + return _this.next(); + } else { + return _this.end(); + } + }); + } + if (step.prev < 0) { + $navigation.find("*[data-role=prev]").addClass("disabled"); + } + if (step.next < 0) { + $navigation.find("*[data-role=next]").addClass("disabled"); + } + step.template = $template.clone().wrap("<div>").parent().html(); + $element.popover({ + placement: step.placement, + trigger: "manual", + title: step.title, + content: step.content, + html: true, + animation: step.animation, + container: step.container, + template: step.template, + selector: step.element + }).popover("show"); + $tip = $element.data("bs.popover") ? $element.data("bs.popover").tip() : $element.data("popover").tip(); + $tip.attr("id", step.id); + this._scrollIntoView($tip); + this._reposition($tip, step); + if (isOrphan) { + return this._center($tip); + } + }; + + Tour.prototype._reposition = function($tip, step) { + var offsetBottom, offsetHeight, offsetRight, offsetWidth, originalLeft, originalTop, tipOffset; + offsetWidth = $tip[0].offsetWidth; + offsetHeight = $tip[0].offsetHeight; + tipOffset = $tip.offset(); + originalLeft = tipOffset.left; + originalTop = tipOffset.top; + offsetBottom = $(document).outerHeight() - tipOffset.top - $tip.outerHeight(); + if (offsetBottom < 0) { + tipOffset.top = tipOffset.top + offsetBottom; + } + offsetRight = $("html").outerWidth() - tipOffset.left - $tip.outerWidth(); + if (offsetRight < 0) { + tipOffset.left = tipOffset.left + offsetRight; + } + if (tipOffset.top < 0) { + tipOffset.top = 0; + } + if (tipOffset.left < 0) { + tipOffset.left = 0; + } + $tip.offset(tipOffset); + if (step.placement === "bottom" || step.placement === "top") { + if (originalLeft !== tipOffset.left) { + return this._replaceArrow($tip, (tipOffset.left - originalLeft) * 2, offsetWidth, "left"); + } + } else { + if (originalTop !== tipOffset.top) { + return this._replaceArrow($tip, (tipOffset.top - originalTop) * 2, offsetHeight, "top"); + } + } + }; + + Tour.prototype._center = function($tip) { + return $tip.css("top", $(window).outerHeight() / 2 - $tip.outerHeight() / 2); + }; + + Tour.prototype._replaceArrow = function($tip, delta, dimension, position) { + return $tip.find(".arrow").css(position, delta ? 50 * (1 - delta / dimension) + "%" : ""); + }; + + Tour.prototype._scrollIntoView = function(tip) { + return $("html, body").stop().animate({ + scrollTop: Math.ceil(tip.offset().top - ($(window).height() / 2)) + }); + }; + + Tour.prototype._onResize = function(callback, timeout) { + return $(window).on("resize.tour-" + this._options.name, function() { + clearTimeout(timeout); + return timeout = setTimeout(callback, 100); + }); + }; + + Tour.prototype._setupKeyboardNavigation = function() { + var _this = this; + if (this._options.keyboard) { + return $(document).on("keyup.tour-" + this._options.name, function(e) { + if (!e.which) { + return; + } + switch (e.which) { + case 39: + e.preventDefault(); + if (_this._current < _this._steps.length - 1) { + return _this.next(); + } else { + return _this.end(); + } + break; + case 37: + e.preventDefault(); + if (_this._current > 0) { + return _this.prev(); + } + break; + case 27: + e.preventDefault(); + return _this.end(); + } + }); + } + }; + + Tour.prototype._makePromise = function(result) { + if (result && $.isFunction(result.then)) { + return result; + } else { + return null; + } + }; + + Tour.prototype._callOnPromiseDone = function(promise, cb, arg) { + var _this = this; + if (promise) { + return promise.then(function(e) { + return cb.call(_this, arg); + }); + } else { + return cb.call(this, arg); + } + }; + + Tour.prototype._showBackdrop = function(element) { + if (this.backdrop.overlay !== null) { + return; + } + this._showOverlay(); + if (element != null) { + return this._showOverlayElement(element); + } + }; + + Tour.prototype._hideBackdrop = function() { + if (this.backdrop.overlay === null) { + return; + } + if (this.backdrop.$element) { + this._hideOverlayElement(); + } + return this._hideOverlay(); + }; + + Tour.prototype._showOverlay = function() { + this.backdrop = $("<div/>", { + "class": "tour-backdrop" + }); + return $("body").append(this.backdrop); + }; + + Tour.prototype._hideOverlay = function() { + this.backdrop.remove(); + return this.backdrop.overlay = null; + }; + + Tour.prototype._showOverlayElement = function(element) { + var $background, $element, offset; + $element = $(element); + $background = $("<div/>"); + offset = $element.offset(); + offset.top = offset.top; + offset.left = offset.left; + $background.width($element.innerWidth()).height($element.innerHeight()).addClass("tour-step-background").offset(offset); + $element.addClass("tour-step-backdrop"); + $("body").append($background); + this.backdrop.$element = $element; + return this.backdrop.$background = $background; + }; + + Tour.prototype._hideOverlayElement = function() { + this.backdrop.$element.removeClass("tour-step-backdrop"); + this.backdrop.$background.remove(); + this.backdrop.$element = null; + return this.backdrop.$background = null; + }; + + return Tour; + + })(); + return window.Tour = Tour; + })(jQuery, window); + +}).call(this); diff --git a/addons/website/static/src/css/editor.css b/addons/website/static/src/css/editor.css index bc8f566793b..9e363448103 100644 --- a/addons/website/static/src/css/editor.css +++ b/addons/website/static/src/css/editor.css @@ -632,3 +632,8 @@ table.editorbar-panel td.selected { filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0); opacity: 0; } + +/* ---- EDITOR TOUR ---- */ +.popover.tour { + z-index: 2010; +} diff --git a/addons/website/static/src/css/editor.sass b/addons/website/static/src/css/editor.sass index 5e4a095e8c4..6eab4f6fb32 100644 --- a/addons/website/static/src/css/editor.sass +++ b/addons/website/static/src/css/editor.sass @@ -175,7 +175,7 @@ table.editorbar-panel div width: 100px text-align: center - @include transform( translate(-39px, 44px) , rotate(-90deg) ) + @include transform( translate(-39px, 44px) , rotate(-90deg) ) @include transform-origin(50% 50%) .oe_snippet @@ -477,4 +477,9 @@ $navbar_height: 51px &.oe_ace_closed width: 0 +opacity(0) + +/* ---- EDITOR TOUR ---- */ + +.popover.tour + z-index: 2010 // vim:tabstop=4:shiftwidth=4:softtabstop=4:fdm=marker: diff --git a/addons/website/static/src/js/website.snippets.js b/addons/website/static/src/js/website.snippets.js index d85b2a814eb..3877635a84d 100644 --- a/addons/website/static/src/js/website.snippets.js +++ b/addons/website/static/src/js/website.snippets.js @@ -243,12 +243,10 @@ // activate drag and drop for the snippets in the snippet toolbar make_snippet_draggable: function($snippets){ var self = this; - var $toInsert = false; var $tumb = $snippets.find(".oe_snippet_thumbnail:first"); var left = $tumb.outerWidth()/2; var top = $tumb.outerHeight()/2; - var dropped = false; - var $snippet = false; + var $toInsert, dropped, $snippet, action, snipped_id; $snippets.draggable({ greedy: true, @@ -265,8 +263,8 @@ self.hide(); dropped = false; $snippet = $(this); - var snipped_id = $snippet.data('snippet-id'); - var action = $snippet.find('.oe_snippet_body').size() ? 'insert' : 'mutate'; + snipped_id = $snippet.data('snippet-id'); + action = $snippet.find('.oe_snippet_body').size() ? 'insert' : 'mutate'; if( action === 'insert'){ if (!$snippet.data('selector-siblings') && !$snippet.data('selector-children') && !$snippet.data('selector-vertical-children')) { console.debug($snippet.data("snippet-id") + " have oe_snippet_body class and have not for insert action"+ @@ -312,38 +310,38 @@ }, drop: function(){ dropped = true; - - var $target = false; - if(action === 'insert'){ - $target = $toInsert; - - if (website.snippet.animationRegistry[snipped_id]) { - new website.snippet.animationRegistry[snipped_id]($target); - } - - self.create_overlay($target); - $target.data("snippet-editor").build_snippet($target); - - } else { - $target = $(this).data('target'); - - self.create_overlay($target); - if (website.snippet.editorRegistry[snipped_id]) { - var snippet = new website.snippet.editorRegistry[snipped_id](self, $target); - snippet.build_snippet($target); - } - } - - $('.oe_drop_zone').remove(); - - setTimeout(function () {self.make_active($target);},0); }, }); }, stop: function(){ $('.oe_drop_zone').droppable('destroy').remove(); - if (!dropped && self.$modal.find('input:not(:checked)').length) { - self.$modal.modal('toggle'); + if (dropped) { + var $target = false; + if(action === 'insert'){ + $target = $toInsert; + + if (website.snippet.animationRegistry[snipped_id]) { + new website.snippet.animationRegistry[snipped_id]($target); + } + + self.create_overlay($target); + $target.data("snippet-editor").build_snippet($target); + + } else { + $target = $(this).data('target'); + + self.create_overlay($target); + if (website.snippet.editorRegistry[snipped_id]) { + var snippet = new website.snippet.editorRegistry[snipped_id](self, $target); + snippet.build_snippet($target); + } + } + setTimeout(function () {self.make_active($target);},0); + } else { + $toInsert.remove(); + if (self.$modal.find('input:not(:checked)').length) { + self.$modal.modal('toggle'); + } } }, }); @@ -488,7 +486,6 @@ $zone.appendTo('#oe_manipulators'); $zone.data('target',$target); $target.data('overlay',$zone); - console.log($target[0], $zone); $target.on("DOMNodeInserted DOMNodeRemoved DOMSubtreeModified", function () { self.cover_target($zone, $target); @@ -746,16 +743,8 @@ change_background: function (bg, ul_options) { var self = this; + this.set_options_background(bg, ul_options); var $ul = this.$editor.find(ul_options); - var bg_value = (typeof bg === 'string' ? self.$target.find(bg) : $(bg)).css("background-image").replace(/url\(['"]*|['"]*\)/g, ""); - - // select in ul options - $ul.find("li").removeClass("active"); - var selected = $ul.find('[data-value="' + bg_value + '"], [data-value="' + bg_value.replace(/.*:\/\/[^\/]+/, '') + '"]'); - selected.addClass('active'); - if (!selected.length) { - $ul.find('.oe_custom_bg b').html(bg_value); - } // bind envent on options var $li = $ul.find("li"); @@ -787,6 +776,19 @@ $bg.css("background-image", "url(" + src + ")"); }); }, + + set_options_background: function (bg, ul_options) { + var $ul = this.$editor.find(ul_options); + var bg_value = (typeof bg === 'string' ? this.$target.find(bg) : $(bg)).css("background-image").replace(/url\(['"]*|['"]*\)/g, ""); + + // select in ul options + $ul.find("li").removeClass("active"); + var selected = $ul.find('[data-value="' + bg_value + '"], [data-value="' + bg_value.replace(/.*:\/\/[^\/]+/, '') + '"]'); + selected.addClass('active'); + if (!selected.length) { + $ul.find('.oe_custom_bg b').html(bg_value); + } + }, }); @@ -974,50 +976,95 @@ }); website.snippet.editorRegistry.carousel = website.snippet.editorRegistry.resize.extend({ - build_snippet: function($target) { - var id = "myCarousel" + $("body .carousel").length; - $target.attr("id", id); - $target.find(".carousel-control").attr("href", "#"+id); + build_snippet: function() { + var id = 0; + $("body .carousel").each(function () { + var _id = +$(this).attr("id").replace(/^myCarousel/, ''); + if (id <= _id) { + id = _id + 1; + } + }); + this.$target.attr("id", "myCarousel" + id); + this.$target.find(".carousel-control").attr("href", "#myCarousel" + id); + this.$target.find("[data-target='#myCarousel']").attr("data-target", "#myCarousel" + id); + this.rebind_event(); + }, + onFocus: function () { + this._super(); + this.$target.carousel('pause'); + }, + onBlur: function () { + this._super(); + this.$target.carousel('cycle'); }, start : function () { this._super(); + this.id = this.$target.attr("id"); + + this.$inner = this.$target.find('.carousel-inner'); + this.$indicators = this.$target.find('.carousel-indicators'); + this.$editor.find(".js_add").on('click', _.bind(this.on_add, this)); this.$editor.find(".js_remove").on('click', _.bind(this.on_remove, this)); this.change_background(".item.active", 'ul[name="carousel-background"]'); this.change_style(); - this.set_options_style(); this.change_size(); + this.set_options_style(); + this.$target.carousel(); + + var self = this; + this.$target.on('slide.bs.carousel', function () { + self.set_options_style(); + self.set_options_background(".item.active", 'ul[name="carousel-background"]'); + self.$target.carousel(); + }); + + this.rebind_event(); + }, + // rebind event to active carousel on edit mode + rebind_event: function () { + var self = this; + this.$target.on('click', '.carousel-control', function () { + self.$target.carousel($(this).data('slide')); }); + this.$target.on('click', '.carousel-indicators [data-target]', function () { + self.$target.carousel(+$(this).data('slide-to')); }); }, on_add: function (e) { e.preventDefault(); - this.$target.find('.carousel-control').removeClass("hidden"); - var $inner = this.$target.find('.carousel-inner'); - var cycle = $inner.find('.item').length; - $inner.find('.item.active').clone().removeClass('active').appendTo($inner); - this.$target.carousel(cycle); - this.set_options_background(); - this.set_options_style(); + var cycle = this.$inner.find('.item').length; + var $active = this.$inner.find('.item.active'); + var index = $active.index(); + this.$target.find('.carousel-control, .carousel-indicators').removeClass("hidden"); + this.$indicators.append('<li data-target="#' + this.id + '" data-slide-to="' + cycle + '"></li>'); + $active.clone().removeClass('active').insertAfter($active); + this.$target.carousel().carousel(++index); }, on_remove: function (e) { e.preventDefault(); - var $inner = this.$target.find('.carousel-inner'); - var nb = $inner.find('.item').length; - if (nb > 1) { - $inner - .find('.item.active').remove().end() - .find('.item:first').addClass('active'); - this.$target.carousel(0); - this.set_options_style(); - } - if (nb <= 1) { - this.$target.find('.carousel-control').addClass("hidden"); + var self = this; + var new_index = 0; + var cycle = this.$inner.find('.item').length - 1; + var index = this.$inner.find('.item.active').index(); + if (cycle > 0) { + this.$inner.find('.item.active').fadeOut(1000, function () { + $(this).remove(); + self.$indicators.find('[data-target]:last').remove(); + self.$indicators.find("[data-slide-to]").removeClass("active"); + self.$indicators.find("[data-slide-to='" + new_index + "']").addClass("active"); + }); + setTimeout(function () { + new_index = index % cycle; + self.$target.carousel( new_index + 1 ); + }, 500); + } else { + this.$target.find('.carousel-control, .carousel-indicators').addClass("hidden"); } }, set_options_style: function () { var style = false; - var $el = this.$target.find('.carousel-inner .item.active'); + var $el = this.$inner.find('.item.active'); var $ul = this.$editor.find('ul[name="carousel-style"]'); var $li = $ul.find("li"); @@ -1040,12 +1087,12 @@ $(this).addClass("active"); }) .on('mouseover', function (event) { - var $el = self.$target.find('.carousel-inner .item.active'); + var $el = self.$inner.find('.item.active'); $el.removeClass('image_text text_image text_only'); $el.addClass($(event.currentTarget).data("value")); }) .on('mouseout', function (event) { - var $el = self.$target.find('.carousel-inner .item.active'); + var $el = self.$inner.find('.item.active'); $el.removeClass('image_text text_image text_only'); $el.addClass($ul.find('li.active').data("value")); }); diff --git a/addons/website/static/src/js/website.tour.js b/addons/website/static/src/js/website.tour.js new file mode 100644 index 00000000000..c19b24d4b49 --- /dev/null +++ b/addons/website/static/src/js/website.tour.js @@ -0,0 +1,224 @@ +(function () { + 'use strict'; + + var website = openerp.website; + website.templates.push('/website/static/src/xml/website.tour.xml'); + + function render (template, dict) { + return openerp.qweb.render(template, dict); + } + + website.EditorTour = openerp.Class.extend({ + tour: undefined, + steps: [], + tourStorage: window.localStorage, + init: function () { + this.tour = new Tour({ + name: this.id, + storage: this.tourStorage, + keyboard: false, + }); + this.tour.addSteps(_.map(this.steps, function (step) { + step.title = render('website.tour_title', { title: step.title }); + return step; + })); + }, + reset: function () { + this.tourStorage.removeItem(this.id+'_current_step'); + this.tourStorage.removeItem(this.id+'_end'); + $('.popover.tour').remove(); + }, + start: function () { + if (this.canResume()) { + this.tour.start(); + } + }, + canResume: function () { + return this.currentStepIndex() === 0 && !this.tour.ended(); + }, + currentStepIndex: function () { + var index = this.tourStorage.getItem(this.id+'_current_step') || 0; + return parseInt(index, 10); + }, + indexOfStep: function (stepId) { + var index = -1; + _.each(this.steps, function (step, i) { + if (step.stepId === stepId) { + index = i; + } + }); + return index; + }, + movetoStep: function (stepId) { + $('.popover.tour').remove(); + var index = this.indexOfStep(stepId); + if (index > -1) { + this.tour.goto(index); + } + }, + saveStep: function (stepId) { + var index = this.indexOfStep(stepId); + this.tourStorage.setItem(this.id+'_current_step', index); + }, + stop: function () { + this.tour.end(); + }, + }); + + website.EditorBasicTour = website.EditorTour.extend({ + id: 'add_banner_tour', + name: "How to add a banner", + init: function () { + var self = this; + self.steps = [ + { + stepId: 'welcome', + orphan: true, + backdrop: true, + title: "Welcome to your website!", + content: "This tutorial will guide you through the firsts steps to build your enterprise class website.", + template: render('website.tour_full', { next: "OK", end: "Close" }), + }, + { + stepId: 'edit-page', + element: 'button[data-action=edit]', + placement: 'right', + reflex: true, + title: "Edit this page", + content: "Every page of your website can be edited. Click the <b>Edit</b> button to modify your homepage.", + template: render('website.tour_simple'), + }, + { + stepId: 'show-bar', + element: '#website-top-navbar', + placement: 'bottom', + title: "Editor bar", + content: "This is the <b>Editor Bar</b>, use it to modify your website's pages.", + template: render('website.tour_confirm', { next: "OK" }), + }, + { + stepId: 'add-block', + element: 'button[data-action=snippet]', + placement: 'right', + reflex: true, + title: "Add a block to your page", + content: "Click on the <b>Insert Blocks</b> button to open the block collection.", + template: render('website.tour_simple'), + }, + { + stepId: 'drag-banner', + element: '#website-top-navbar [data-snippet-id=carousel]', + placement: 'bottom', + title: "Add a banner to your page", + content: "Drag the <b>Banner</b> block to the body of the page and drop it on a purple zone.", + template: render('website.tour_simple'), + onShown: function () { + function beginDrag () { + $('.popover.tour').remove(); + $('body').off('mousedown', beginDrag); + function goToNextStep () { + $('#oe_snippets').hide(); + self.movetoStep('edit-title'); + $('body').off('mouseup', goToNextStep); + } + $('body').on('mouseup', goToNextStep); + } + $('body').on('mousedown', beginDrag); + }, + }, + { + stepId: 'edit-title', + element: '#wrap [data-snippet-id=carousel]:first .carousel-caption', + placement: 'top', + title: "Change the title", + content: "Click on the title and modify it to fit your needs then click <b>Done</b>.", + template: render('website.tour_confirm', { next: "Done" }), + onHide: function () { + var $banner = $("#wrap [data-snippet-id=carousel]:first"); + if ($banner.length) { + $banner.click(); + } + }, + }, + { + stepId: 'customize-banner', + element: '.oe_overlay_options .oe_options', + placement: 'left', + title: "Customize the banner", + content: "Click on <b>Customize</b> and change the background of your banner.", + template: render('website.tour_confirm', { next: "Not now" }), + onShow: function () { + $('.dropdown-menu [name=carousel-background]').click(function () { + self.movetoStep('save-changes'); + }); + }, + }, + { + stepId: 'save-changes', + element: 'button[data-action=save]', + placement: 'right', + reflex: true, + title: "Save your modifications", + content: "Click the <b>Save</b> button to apply modifications on your website.", + template: render('website.tour_simple'), + onHide: function () { + self.saveStep('part-2'); + }, + + }, + { + stepId: 'part-2', + orphan: true, + title: "Congratutaltions!", + content: "Congratulations on your first modifications.", + template: render('website.tour_confirm', { next: "OK" }), + }, + { + stepId: 'show-tutorials', + element: '#help-menu-button', + placement: 'left', + title: "Help is always available", + content: "You can find more tutorials in the <b>Help</b> menu.", + template: render('website.tour_end', { end: "Close" }), + }, + ]; + return this._super(); + }, + startOfPart2: function () { + var currentStepIndex = this.currentStepIndex(); + var secondPartIndex = this.indexOfStep('part-2'); + return currentStepIndex === secondPartIndex && !this.tour.ended(); + }, + canResume: function () { + return this.startOfPart2() || this._super(); + }, + }); + + function refererPath () { + var anchor = document.createElement('a'); + anchor.href = document.referrer; + return anchor.pathname; + } + + website.EditorBar.include({ + start: function () { + website.tutorials = { + basic: new website.EditorBasicTour(), + }; + var menu = $('#help-menu'); + _.each(website.tutorials, function (tutorial) { + var $menuItem = $($.parseHTML('<li><a href="#">'+tutorial.name+'</a></li>')); + $menuItem.click(function () { + tutorial.reset(); + tutorial.start(); + }) + menu.append($menuItem); + }); + if (refererPath() === '/web' || website.tutorials.basic.startOfPart2()) { + website.tutorials.basic.start(); + } + return this._super(); + }, + }); + +}());
\ No newline at end of file diff --git a/addons/website/static/src/xml/website.tour.xml b/addons/website/static/src/xml/website.tour.xml new file mode 100644 index 00000000000..6d2ef140610 --- /dev/null +++ b/addons/website/static/src/xml/website.tour.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="utf-8"?> +<templates id="template" xml:space="preserve"> + <t t-name="website.tour_simple"> + <div class="popover tour"> + <div class="arrow"></div> + <h3 class="popover-title"></h3> + <div class="popover-content"></div> + </div> + </t> + <t t-name="website.tour_confirm"> + <div class="popover tour"> + <div class="arrow"></div> + <h3 class="popover-title"></h3> + <div class="popover-content"></div> + <nav class="popover-navigation"> + <button class="btn btn-sm btn-default" data-role="next"><t t-esc="next"/></button> + </nav> + </div> + </t> + <t t-name="website.tour_end"> + <div class="popover tour"> + <div class="arrow"></div> + <h3 class="popover-title"></h3> + <div class="popover-content"></div> + <nav class="popover-navigation"> + <button class="btn btn-sm btn-default" data-role="end"><t t-esc="end"/></button> + </nav> + </div> + </t> + <t t-name="website.tour_full"> + <div class="popover tour"> + <div class="arrow"></div> + <h3 class="popover-title"></h3> + <div class="popover-content"></div> + <nav class="popover-navigation"> + <button class="btn btn-sm btn-default" data-role="next"><t t-esc="next"/></button> + <button class="btn btn-sm btn-default" data-role="end"><t t-esc="end"/></button> + </nav> + </div> + </t> + <t t-name="website.tour_title"> + <t t-esc="title"/><button title="Close" type="button" class="close" data-role="end">×</button> + </t> +</templates>
\ No newline at end of file diff --git a/addons/website/static/src/xml/website.xml b/addons/website/static/src/xml/website.xml index c2f7abe6ed2..b3e4cacd32a 100644 --- a/addons/website/static/src/xml/website.xml +++ b/addons/website/static/src/xml/website.xml @@ -28,6 +28,12 @@ <!-- filled in JS --> </ul> </li> + <li class="dropdown"> + <a id="help-menu-button" class="dropdown-toggle" data-toggle="dropdown" href="#">Help <span class="caret"></span></a> + <ul class="dropdown-menu" role="menu" id="help-menu"> + <!-- filled in JS --> + </ul> + </li> <li> <a href="/admin#action=website.action_module_website">Apps</a> </li> diff --git a/addons/website/views/snippets.xml b/addons/website/views/snippets.xml index 1a79d52d5cc..5e9bb5e623d 100644 --- a/addons/website/views/snippets.xml +++ b/addons/website/views/snippets.xml @@ -63,7 +63,11 @@ <img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_banner.png"/> <span class="oe_snippet_thumbnail_title">Banner</span> </div> - <div id="myCarousel" class="oe_snippet_body carousel slide oe_medium mb32" data-interval="10000" contenteditable="false"> + <div id="myCarousel" class="oe_snippet_body carousel slide oe_medium mb32" contenteditable="false"> + <!-- Indicators --> + <ol class="carousel-indicators hidden"> + <li data-target="#myCarousel" data-slide-to="0" class="active"></li> + </ol> <div class="carousel-inner"> <div class="item image_text active" style="background-image: url('/website/static/src/img/banner/color_splash.jpg')"> <div class="container" contenteditable="true"> @@ -80,8 +84,8 @@ </div> </div> </div> - <a class="carousel-control left hidden" href="#myCarousel" data-slide="prev" style="width: 10%"><span class="glyphicon glyphicon-circle-arrow-left"><span class="hidden">.</span></span></a> - <a class="carousel-control right hidden" href="#myCarousel" data-slide="next" style="width: 10%"><span class="glyphicon glyphicon-circle-arrow-right"><span class="hidden">.</span></span></a> + <a class="carousel-control left hidden" href="#myCarousel" data-slide="prev" style="width: 10%"><span class="glyphicon glyphicon-chevron-left"><span class="hidden">.</span></span></a> + <a class="carousel-control right hidden" href="#myCarousel" data-slide="next" style="width: 10%"><span class="glyphicon glyphicon-chevron-right"><span class="hidden">.</span></span></a> </div> </div> diff --git a/addons/website/views/views.xml b/addons/website/views/views.xml index 0e8dbf422d9..40445daa6da 100644 --- a/addons/website/views/views.xml +++ b/addons/website/views/views.xml @@ -28,6 +28,7 @@ <t t-if="editable"> <link rel='stylesheet' href='/website/static/src/css/snippets.css'/> <link rel='stylesheet' href='/website/static/src/css/editor.css'/> + <link rel='stylesheet' href='/website/static/lib/bootstrap-tour/bootstrap-tour.css'/> </t> <t t-call="website.theme"/> @@ -45,6 +46,7 @@ <t t-if="editable"> <script type="text/javascript" src="/website/static/lib/ckeditor/ckeditor.js"></script> <script type="text/javascript" src="/website/static/lib/ckeditor.sharedspace/plugin.js"></script> + <script type="text/javascript" src="/website/static/lib/bootstrap-tour/bootstrap-tour.js"></script> <script t-if="not translatable" type="text/javascript" src="/website/static/lib/ace/ace.js"></script> <script type="text/javascript" src="/website/static/lib/vkbeautify/vkbeautify.0.99.00.beta.js"></script> <script type="text/javascript" src="/web/static/lib/jquery.ui/js/jquery-ui-1.9.1.custom.js"></script> @@ -55,6 +57,7 @@ <script type="text/javascript" src="/website/static/src/js/website.editor.js"></script> <script type="text/javascript" src="/website/static/src/js/website.mobile.js"></script> <script type="text/javascript" src="/website/static/src/js/website.seo.js"></script> + <script type="text/javascript" src="/website/static/src/js/website.tour.js"></script> <script t-if="not translatable" type="text/javascript" src="/website/static/src/js/website.snippets.js"></script> <script t-if="not translatable" type="text/javascript" src="/website/static/src/js/website.ace.js"></script> <script t-if="translatable" type="text/javascript" src="/website/static/src/js/website.translator.js"></script> |
