diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index ba3a1154e54..6b11c065552 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -112,7 +112,7 @@ class Website(openerp.addons.web.controllers.main.Home): @website.route(['/website/snippets'], type='json', auth="public") def snippets(self): - return request.website.render('website.snippets') + return request.website._render('website.snippets') @website.route('/page/', type='http', auth="public", multilang=True) def page(self, page, **opt): @@ -261,8 +261,9 @@ class Website(openerp.addons.web.controllers.main.Home): @website.route(['/robots.txt'], type='http', auth="public") def robots(self): - body = request.website.render('website.robots', {'url_root': request.httprequest.url_root}) - return request.make_response(body, headers=[('Content-Type', 'text/plain')]) + response = request.website.render('website.robots', {'url_root': request.httprequest.url_root}) + response.mimetype = 'text/plain' + return response @website.route('/sitemap', type='http', auth='public', multilang=True) def sitemap(self): @@ -270,14 +271,11 @@ class Website(openerp.addons.web.controllers.main.Home): @website.route('/sitemap.xml', type='http', auth="public") def sitemap_xml(self): - body = request.website.render('website.sitemap_xml', { + response = request.website.render('website.sitemap_xml', { 'pages': request.website.enumerate_pages() }) - - return request.make_response(body, [ - ('Content-Type', 'application/xml;charset=utf-8') - ]) - + response.headers['Content-Type'] = 'application/xml;charset=utf-8' + return response class Images(http.Controller): def placeholder(self, response): diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 60e680aaefc..478b6a97ec9 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -20,8 +20,7 @@ from openerp.osv import orm, osv, fields from openerp.tools.safe_eval import safe_eval from openerp.addons.web import http -from openerp.addons.web.http import request - +from openerp.addons.web.http import request, LazyResponse logger = logging.getLogger(__name__) @@ -157,7 +156,7 @@ class website(osv.osv): 'translatable': not is_public_user and not is_master_lang and request.multilang, }) - def render(self, cr, uid, ids, template, values=None, context=None): + def _render(self, cr, uid, ids, template, values=None, context=None): view = self.pool.get("ir.ui.view") IMD = self.pool.get("ir.model.data") user = self.pool.get("res.users") @@ -221,6 +220,13 @@ class website(osv.osv): return self.error(cr, uid, 500 if qweb_context['editable'] else 404, qweb_context, context=context) + def render(self, cr, uid, ids, template, values=None, context=None): + def callback(template, values, context): + return self._render(cr, uid, ids, template, values, context) + if values is None: + values = {} + return LazyResponse(callback, template=template, values=values, context=context) + def error(self, cr, uid, code, qweb_context, context=None): View = request.registry['ir.ui.view'] return werkzeug.wrappers.Response( @@ -478,7 +484,7 @@ class website(osv.osv): object_ids = model_obj.search(cr, uid, domain, limit=step, offset=offset, order=orderby) object_ids = model_obj.browse(cr, uid, object_ids) for object_id in object_ids: - html += request.website.render(template, {'object_id': object_id}) + html += request.website._render(template, {'object_id': object_id}) return html def get_menu(self, cr, uid, ids, context=None): diff --git a/addons/website/static/src/js/website.menu.js b/addons/website/static/src/js/website.menu.js index 40551b2dd75..b3554b9e7c5 100644 --- a/addons/website/static/src/js/website.menu.js +++ b/addons/website/static/src/js/website.menu.js @@ -5,15 +5,12 @@ website.menu = {}; website.add_template_file('/website/static/src/xml/website.menu.xml'); - var globalEditor; - website.EditorBar.include({ events: _.extend({}, website.EditorBar.prototype.events, { 'click a[data-action="edit-structure"]': 'editStructure', }), editStructure: function () { var self = this; - globalEditor = self; var context = website.get_context(); openerp.jsonRpc('/web/dataset/call_kw', 'call', { model: 'website.menu', @@ -24,7 +21,6 @@ }, }).then(function (menu) { var result = new website.menu.EditMenuDialog(menu).appendTo(document.body); - self.trigger('tour:menu_editor_dialog_ready'); return result; }); }, @@ -171,7 +167,6 @@ $link_text.focus(); }); }); - globalEditor.trigger('tour:new_menu_entry_dialog_ready'); return result; }, save: function () { @@ -192,7 +187,6 @@ } }, destroy: function () { - globalEditor.trigger('tour:new_menu_entry_dialog_closed'); this._super.apply(this, arguments); }, }); diff --git a/addons/website/static/src/js/website.tour.install-app.js b/addons/website/static/src/js/website.tour.app.js similarity index 77% rename from addons/website/static/src/js/website.tour.install-app.js rename to addons/website/static/src/js/website.tour.app.js index d7d98fb5430..b4fab2db620 100644 --- a/addons/website/static/src/js/website.tour.install-app.js +++ b/addons/website/static/src/js/website.tour.app.js @@ -3,18 +3,16 @@ var website = openerp.website; - var render = website.tour.render; - website.EditorBar.include({ start: function () { - this.registerTour(new website.InstallAppTour(this)); + this.registerTour(new website.AppTour(this)); return this._super(); }, }); - website.InstallAppTour = website.Tour.extend({ - id: 'install-app', - name: "Install a new App", + website.AppTour = website.Tour.extend({ + id: 'app-tutorial', + name: "Install a new application", init: function (editor) { var self = this; self.steps = [ @@ -24,7 +22,7 @@ backdrop: true, title: "Install an App", content: "You can intall some apps to manage your website content.", - template: render('website.tour_popover', { next: "Start Tutorial", end: "Skip It" }), + template: self.popover({ next: "Start Tutorial", end: "Skip It" }), }, { stepId: 'customize', @@ -32,7 +30,6 @@ placement: 'left', title: "Install an app", content: "Add new apps by customizing your website.", - template: render('website.tour_popover'), onShow: function () { editor.on('rte:customize_menu_ready', editor, function () { self.movetoStep('install-app'); @@ -46,7 +43,6 @@ orphan: true, title: "Install an app", content: "Click 'Install Apps' to select and install the application you would like to manage from your website.", - template: render('website.tour_popover'), }, ]; return this._super(); diff --git a/addons/website/static/src/js/website.tour.banner.js b/addons/website/static/src/js/website.tour.banner.js index bb4b576ba24..5e826116fe3 100644 --- a/addons/website/static/src/js/website.tour.banner.js +++ b/addons/website/static/src/js/website.tour.banner.js @@ -3,16 +3,14 @@ var website = openerp.website; - var render = website.tour.render; - website.EditorBar.include({ start: function () { - this.registerTour(new website.AddBannerTour(this)); + this.registerTour(new website.BannerTour(this)); return this._super(); }, }); - website.AddBannerTour = website.Tour.extend({ + website.BannerTour = website.Tour.extend({ id: 'banner-tutorial', name: "Insert a banner", startPath: '/page/website.homepage', @@ -25,7 +23,7 @@ backdrop: true, title: "Welcome to your website!", content: "This tutorial will guide you to build your home page. We will start by adding a banner.", - template: render('website.tour_popover', { next: "Start Tutorial", end: "Skip It" }), + template: self.popover({ next: "Start Tutorial", end: "Skip It" }), }, { stepId: 'edit-page', @@ -33,7 +31,6 @@ placement: 'bottom', title: "Edit this page", content: "Every page of your website can be modified through the Edit button.", - template: render('website.tour_popover'), onShow: function () { editor.on('tour:editor_bar_loaded', editor, function () { self.movetoStep('add-block'); @@ -46,7 +43,6 @@ placement: 'bottom', title: "Insert building blocks", content: "To add content in a page, you can insert building blocks.", - template: render('website.tour_popover'), onShow: function () { $('button[data-action=snippet]').click(function () { self.movetoStep('drag-banner'); @@ -59,13 +55,12 @@ placement: 'bottom', title: "Drag & Drop a Banner", content: "Drag the Banner block and drop it in your page.", - template: render('website.tour_popover'), onShow: function () { var $body = $(document.body); function beginDrag () { $('.popover.tour').remove(); function goToNextStep () { - $('#oe_snippets').hide(); + $('#snippets').toggle(); self.movetoStep('edit-title'); $body.off('mouseup', goToNextStep); } @@ -81,7 +76,7 @@ placement: 'top', title: "Customize banner's text", content: "Click in the text and start editing it. Click continue once it's done.", - template: render('website.tour_popover', { next: "Continue" }), + template: self.popover({ next: "Continue" }), onHide: function () { var $banner = $("#wrap [data-snippet-id=carousel]:first"); if ($banner.length) { @@ -95,7 +90,7 @@ placement: 'left', title: "Customize the banner", content: "You can customize characteristic of any blocks through the Customize menu. For instance, change the background of the banner.", - template: render('website.tour_popover', { next: "Continue" }), + template: self.popover({ next: "Continue" }), onShow: function () { $('.dropdown-menu [name=carousel-background]').click(function () { self.movetoStep('save-changes'); @@ -109,7 +104,6 @@ reflex: true, title: "Save your modifications", content: "Once you click on save, your website page is updated.", - template: render('website.tour_popover'), onHide: function () { self.saveStep('part-2'); }, @@ -119,7 +113,7 @@ orphan: true, title: "Congratulation!", content: "Your homepage have been updated. Now, we suggest you insert another snippet to overview possible customization.", - template: render('website.tour_popover', { next: "Continue" }), + template: self.popover({ next: "Continue" }), }, { stepId: 'show-tutorials', @@ -128,12 +122,12 @@ reflex: true, title: "Help is always available", content: "You can always click here if you want more helps or continue to build and get more tips about your website contents like page menu, ...", - template: render('website.tour_popover', { end: "Close" }), + template: self.popover({ end: "Close" }), } ]; return this._super(); }, - continueTour: function () { + resume: function () { return (this.isCurrentStep('part-2') || this.isCurrentStep('show-tutorials')) && !this.tour.ended(); }, }); diff --git a/addons/website/static/src/js/website.tour.js b/addons/website/static/src/js/website.tour.js index 25317f06aac..8cefecba466 100644 --- a/addons/website/static/src/js/website.tour.js +++ b/addons/website/static/src/js/website.tour.js @@ -4,12 +4,6 @@ var website = openerp.website; website.add_template_file('/website/static/src/xml/website.tour.xml'); - website.tour = { - render: function render (template, dict) { - return openerp.qweb.render(template, dict); - } - }; - website.Tour = openerp.Class.extend({ tour: undefined, steps: [], @@ -19,9 +13,10 @@ name: this.id, storage: this.tourStorage, keyboard: false, + template: this.popover(), }); this.tour.addSteps(_.map(this.steps, function (step) { - step.title = website.tour.render('website.tour_popover_title', { title: step.title }); + step.title = openerp.qweb.render('website.tour_popover_title', { title: step.title }); return step; })); }, @@ -32,7 +27,7 @@ $('.popover.tour').remove(); }, start: function () { - if (this.continueTour() || ((this.currentStepIndex() === 0) && !this.tour.ended())) { + if (this.resume() || ((this.currentStepIndex() === 0) && !this.tour.ended())) { this.tour.start(); } }, @@ -73,11 +68,11 @@ window.location.replace(newUrl); } }, - continueTour: function () { + resume: function () { // Override if necessary return this.currentStepIndex() === 0; }, - isTriggerUrl: function (url) { + trigger: function (url) { // Override if necessary url = url || new website.UrlParser(window.location.href); var urlTrigger = this.id + "=true"; @@ -87,6 +82,9 @@ var url = new website.UrlParser(window.location.href); return pattern.test(url.pathname+url.search); }, + popover: function (options) { + return openerp.qweb.render('website.tour_popover', options); + }, }); website.UrlParser = openerp.Class.extend({ @@ -122,7 +120,7 @@ tour.start(); }); menu.append($menuItem); - if (tour.isTriggerUrl()) { + if (tour.trigger()) { tour.start(); } }); diff --git a/addons/website/static/src/js/website.tour.menu-editor.js b/addons/website/static/src/js/website.tour.page.js similarity index 75% rename from addons/website/static/src/js/website.tour.menu-editor.js rename to addons/website/static/src/js/website.tour.page.js index b37d3c3813e..b52c11efa28 100644 --- a/addons/website/static/src/js/website.tour.menu-editor.js +++ b/addons/website/static/src/js/website.tour.page.js @@ -3,17 +3,15 @@ var website = openerp.website; - var render = website.tour.render; - website.EditorBar.include({ start: function () { - this.registerTour(new website.EditorBuilderTour(this)); + this.registerTour(new website.PageTour(this)); return this._super(); }, }); - website.EditorBuilderTour = website.Tour.extend({ - id: 'menu-editor', + website.PageTour = website.Tour.extend({ + id: 'page-tutorial', name: "Add a new page", init: function (editor) { var self = this; @@ -24,7 +22,7 @@ backdrop: true, title: "Menu editor", content: "We will show how to edit your website's menu.", - template: render('website.tour_popover', { next: "Start Tutorial", end: "Skip It" }), + template: self.popover({ next: "Start Tutorial", end: "Skip It" }), }, { stepId: 'content-menu', @@ -33,7 +31,6 @@ reflex: true, title: "Edit the content", content: "Click here to edit the menu.", - template: render('website.tour_popover'), }, { stepId: 'edit-entry', @@ -41,9 +38,8 @@ placement: 'left', title: "Edit menu", content: "Click here to create a new menu entry and manage options.", - template: render('website.tour_popover'), onShow: function () { - editor.on('tour:menu_editor_dialog_ready', editor, function () { + $(document).one('shown.bs.modal', function () { self.movetoStep('add-menu-entry'); }); }, @@ -54,9 +50,8 @@ placement: 'left', title: "Add menu entry", content: "Click here to create a new menu entry.", - template: render('website.tour_popover'), onShow: function () { - editor.on('tour:new_menu_entry_dialog_ready', editor, function () { + $(document).one('shown.bs.modal', function () { self.movetoStep('enter-entry-name'); }); }, @@ -67,15 +62,15 @@ placement: 'left', title: "Choose a label", content: "This label will appear in the top menu and will be visible by all your audience.\nGive a meaningful name to help your visitors. For instance, 'Photos Gallery'.", - template: render('website.tour_popover', { next: "Continue" }), + template: self.popover({ next: "Continue" }), }, { stepId: 'enter-page-name', - element: '#link-new', + element: '.modal .select2-container', placement: 'left', title: "Link your menu to a 'gallery' page", content: "This page does not exist. Create it by filling the name here. For instance, 'gallery'.", - template: render('website.tour_popover', { next: "Continue" }), + template: self.popover({ next: "Continue" }), }, { stepId: 'save-page', @@ -83,9 +78,8 @@ placement: 'right', title: "Save the page", content: "Save your new page.", - template: render('website.tour_popover'), onShow: function () { - editor.on('tour:new_menu_entry_dialog_closed', editor, function () { + $(document).one('hidden.bs.modal', function () { self.movetoStep('save-menu'); }); }, @@ -97,7 +91,6 @@ reflex: true, title: "Save the menu", content: "Save the menu to edit the Gallery content directly from the interface.", - template: render('website.tour_popover'), }, ]; return this._super(); diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index dfd9b47756a..efb9176db12 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -102,8 +102,8 @@ - - + + 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 02c69530ce5..e524758819f 100644 --- a/addons/website_blog/static/src/js/website.tour.blog.js +++ b/addons/website_blog/static/src/js/website.tour.blog.js @@ -3,8 +3,6 @@ var website = openerp.website; - var render = website.tour.render; - website.EditorBar.include({ start: function () { this.registerTour(new website.BlogTour(this)); @@ -25,7 +23,7 @@ backdrop: true, title: "Blog", content: "We will show how to create a new blog post.", - template: render('website.tour_popover', { next: "Start Tutorial", end: "Skip It" }), + template: self.popover({ next: "Start Tutorial", end: "Skip It" }), }, { stepId: 'content-menu', @@ -34,7 +32,6 @@ reflex: true, title: "Edit the content", content: "Click here to add content to your site.", - template: render('website.tour_popover'), }, { stepId: 'new-post-entry', @@ -42,7 +39,6 @@ placement: 'left', title: "New blog post", content: "Click here to create a blog post.", - template: render('website.tour_popover'), onShow: function () { $(document).one('shown.bs.modal', function () { $('.modal button.btn-primary').click(function () { @@ -58,7 +54,6 @@ placement: 'right', title: "Choose the post category", content: "Select the 'News' category and click 'Continue'.", - template: render('website.tour_popover'), }, { stepId: 'post-page', @@ -66,25 +61,57 @@ backdrop: true, title: "New blog post created", content: "You just created a new blog post. We are now going to edit it.", - template: render('website.tour_popover', { next: "OK" }), + template: self.popover({ next: "OK" }), + }, + { + stepId: 'post-title', + element: 'h1[data-oe-expression="blog_post.name"]', + placement: 'top', + title: "Pick a title", + content: "Choose a catchy title for your blog post.", + template: self.popover({ next: "OK" }), }, { stepId: 'add-block', element: 'button[data-action=snippet]', placement: 'bottom', - reflex: true, title: "Layout your blog post", content: "Insert blocks like text-image to layout the body of your blog post.", - template: render('website.tour_popover'), + onShow: function () { + $('button[data-action=snippet]').click(function () { + self.movetoStep('drag-image-text'); + }); + } + }, + { + stepId: 'drag-image-text', + element: '#website-top-navbar [data-snippet-id=image-text].ui-draggable', + placement: 'bottom', + title: "Drag & Drop a block", + content: "Drag the 'Image Text' block and drop it in your page.", + onShow: function () { + var $body = $(document.body); + function beginDrag () { + $('.popover.tour').remove(); + function goToNextStep () { + $('#snippets').toggle(); + self.stop(); + $body.off('mouseup', goToNextStep); + } + $body.off('mousedown', beginDrag); + $body.on('mouseup', goToNextStep); + } + $body.on('mousedown', beginDrag); + }, }, ]; return this._super(); }, - continueTour: function () { + resume: function () { return this.isCurrentStep('post-page') && !this.tour.ended(); }, - isTriggerUrl: function () { - return (this.continueTour() && this.testUrl(/^\/blog\/[0-9]+\/\?enable_editor=1/)) || this._super(); + trigger: function () { + return (this.resume() && this.testUrl(/^\/blog\/[0-9]+\/\?enable_editor=1/)) || this._super(); }, }); 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 8bbd470d1e6..5d97c320b23 100644 --- a/addons/website_event/static/src/js/website.tour.event.js +++ b/addons/website_event/static/src/js/website.tour.event.js @@ -3,8 +3,6 @@ var website = openerp.website; - var render = website.tour.render; - website.EditorBar.include({ start: function () { this.registerTour(new website.EventTour(this)); @@ -25,7 +23,7 @@ backdrop: true, title: "Event", content: "We will show how to create a new event.", - template: render('website.tour_popover', { next: "Start Tutorial", end: "Skip It" }), + template: self.popover({ next: "Start Tutorial", end: "Skip It" }), }, { stepId: 'content-menu', @@ -34,7 +32,6 @@ reflex: true, title: "Edit the content", content: "Click here to add content to your site.", - template: render('website.tour_popover'), }, { stepId: 'new-post-entry', @@ -42,7 +39,6 @@ placement: 'left', title: "New event", content: "Click here to create an event.", - template: render('website.tour_popover'), onShow: function () { $(document).one('shown.bs.modal', function () { $('.modal button.btn-primary').click(function () { @@ -58,7 +54,6 @@ placement: 'right', title: "Choose the event name", content: "Choose a name for the new event and click 'Continue'.", - template: render('website.tour_popover'), }, { stepId: 'event-page', @@ -66,7 +61,7 @@ backdrop: true, title: "New event created", content: "You just created a new event. We are now going to edit it.", - template: render('website.tour_popover', { next: "OK" }), + template: self.popover({ next: "OK" }), }, { stepId: 'add-block', @@ -75,16 +70,15 @@ reflex: true, title: "Layout your event", content: "Insert blocks like text-image to layout the body of your event.", - template: render('website.tour_popover'), }, ]; return this._super(); }, - continueTour: function () { + resume: function () { return this.isCurrentStep('event-page') && !this.tour.ended(); }, - isTriggerUrl: function () { - return (this.continueTour() && this.testUrl(/^\/event\/[0-9]+\/\?enable_editor=1/)) || this._super(); + trigger: function () { + return (this.resume() && this.testUrl(/^\/event\/[0-9]+\/\?enable_editor=1/)) || this._super(); }, }); 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 6b67836ac84..835ccd9d44a 100644 --- a/addons/website_sale/static/src/js/website.tour.shop.js +++ b/addons/website_sale/static/src/js/website.tour.shop.js @@ -3,8 +3,6 @@ var website = openerp.website; - var render = website.tour.render; - website.EditorBar.include({ start: function () { this.registerTour(new website.EditorShopTour(this)); @@ -25,7 +23,7 @@ backdrop: true, 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" }), + template: self.popover({ next: "Start Tutorial", end: "Skip It" }), }, { stepId: 'content-menu', @@ -34,7 +32,6 @@ reflex: true, title: "Create your first product", content: "Click here to add a new product.", - template: render('website.tour_popover'), }, { stepId: 'edit-entry', @@ -42,7 +39,6 @@ placement: 'left', title: "Create a new product", content: "Select 'New Product' to create it and manage its properties to boost your sales.", - template: render('website.tour_popover'), onShow: function () { $(document).one('shown.bs.modal', function () { $('.modal button.btn-primary').click(function () { @@ -58,7 +54,6 @@ placement: 'right', title: "Choose name", content: "Enter a name for your new product.", - template: render('website.tour_popover'), }, { @@ -67,7 +62,7 @@ backdrop: true, title: "New product created", content: "This page contains all the information related to the new product.", - template: render('website.tour_popover', { next: "OK" }), + template: self.popover({ next: "OK" }), }, { stepId: 'edit-price', @@ -75,7 +70,7 @@ placement: 'left', title: "Change the public price", content: "Edit the sale price of this product by clicking on the amount. The price is the sale price used in all sale order when selling this product.", - template: render('website.tour_popover', { next: "OK" }), + template: self.popover({ next: "OK" }), }, { stepId: 'add-block', @@ -84,16 +79,15 @@ reflex: true, title: "Describe the product for your audience", content: "Insert blocks like text-image, or gallery to fully describe the product and make your visitors want to buy this product.", - template: render('website.tour_popover'), }, ]; return this._super(); }, - continueTour: function () { + resume: function () { return this.isCurrentStep('product-page') && !this.tour.ended(); }, - isTriggerUrl: function (url) { - return (this.continueTour() && this.testUrl(/^\/shop\/product\/[0-9]+\/\?enable_editor=1/)) || this._super(); + trigger: function (url) { + return (this.resume() && this.testUrl(/^\/shop\/product\/[0-9]+\/\?enable_editor=1/)) || this._super(); }, });