From 62aafc07b1b7cfd83108bd854ea87997bbad1876 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 6 Sep 2013 18:00:06 +0200 Subject: [PATCH] [WIP] website: snippets, use template qweb js for snippets bzr revid: chm@openerp.com-20130906160006-5gdgsv2jq8lz1voz --- .../website/static/src/js/website.snippets.js | 132 ++++++++++-------- .../static/src/xml/website.snippets.xml | 107 +++++++++++++- addons/website/views/views.xml | 89 ------------ 3 files changed, 181 insertions(+), 147 deletions(-) diff --git a/addons/website/static/src/js/website.snippets.js b/addons/website/static/src/js/website.snippets.js index 8662bc1522d..c558da530bc 100644 --- a/addons/website/static/src/js/website.snippets.js +++ b/addons/website/static/src/js/website.snippets.js @@ -55,8 +55,7 @@ $snipped_id = $(event.currentTarget); - if (typeof $snipped_id.data("snippet-editor") === 'undefined' && - website.snippet.editorRegistry[$snipped_id.data("snippet-id")]) { + if (typeof $snipped_id.data("snippet-editor") === 'undefined') { $snipped_id.data("snippet-editor", new website.snippet.editorRegistry[$snipped_id.data("snippet-id")](self, $snipped_id)); } self.snippetFocus($snipped_id); @@ -106,18 +105,14 @@ start: function() { var self = this; - $.ajax({ - type: "GET", - url: "/page/website.snippets", - dataType: "text", - success: function(snippets){ - self.$el.html(snippets); - self.$('.oe_snippet').each(function(index,snippet){ - self.make_snippet_draggable($(snippet)); - }); - }, + var snippets_template = []; + _.each(openerp.qweb.compiled_templates, function (val, key) { + if (key.indexOf('website.snippets.Builder.') === 0) { + var $snippet = $(openerp.qweb.render(key)).addClass("oe_snippet"); + self.$el.append($snippet); + self.make_snippet_draggable($snippet); + } }); - }, path_eval: function(path){ var obj = window; @@ -455,6 +450,17 @@ }); + $(document).ready(function () { + $("[data-snippet-id]").each(function() { + var $snipped_id = $(this); + if (typeof $snipped_id.data("snippet-view") === 'undefined' && + website.snippet.viewRegistry[$snipped_id.data("snippet-id")]) { + $snipped_id.data("snippet-view", new website.snippet.viewRegistry[$snipped_id.data("snippet-id")]($snipped_id)); + } + }); + }); + + website.snippet.editorRegistry = {}; website.snippet.Editor = openerp.Widget.extend({ init: function (parent, dom) { @@ -506,61 +512,75 @@ }, }); + + + website.snippet.editorRegistry.carousel = website.snippet.Editor.extend({ template : "website.snippets.EditorBar.carousel", start : function () { - var self = this; - - self.$(".js_add").on('click', function (e) { - e.preventDefault(); - var $inner = self.$target.find('.carousel-inner'); - var cycle = $inner.find('.item').size(); - $inner.append(openerp.qweb.render('website.carousel')); - self.$target.carousel(cycle); - }); - - - self.$(".js_remove").on('click', function (e) { - e.preventDefault(); - var $inner = self.$target.find('.carousel-inner'); - if ($inner.find('.item').size() > 1) { - $inner - .find('.item.active').remove().end() - .find('.item:first').addClass('active'); - self.$target.carousel(0); - } - }); + this.$(".js_add").on('click', this.on_add); + this.$(".js_remove").on('click', this.on_remove); var bg = this.$target.find('.carousel-inner .item.active').css('background-image').replace(/url\((.*)\)/g, '\$1'); - this.$( 'select[name="carousel-background"] option[value="'+bg+'"], select[name="carousel-background"] option[value="'+bg.replace(window.location.protocol+'//'+window.location.host, '')+'"]') + this.$('select[name="carousel-background"] option[value="'+bg+'"], select[name="carousel-background"] option[value="'+bg.replace(window.location.protocol+'//'+window.location.host, '')+'"]') .prop('selected', true); - self.$('select[name="carousel-background"]').on('change', function () { - self.$target.find('.carousel-inner .item.active').css('background-image', 'url(' + $(this).val() + ')'); - $(this).val(""); + + this.$('select[name="carousel-background"]').on('change', function () { + this.$target.find('.carousel-inner .item.active').css('background-image', 'url(' + $(this).val() + ')'); }); + var style = false; + if (this.$target.find('.carousel-inner .item.active .container .content_image.col-lg-offset-1')) + style = 'image_right'; + if (this.$target.find('.carousel-inner .item.active .container .content_image')) + style = 'image_left'; + this.$('select[name="carousel-style"] option[value="'+style+'"]').prop('selected', true); - self.$('select[name="carousel-style"]').on('change', function () { - var $container = self.$target.find('.carousel-inner .item.active .container'); - $('.content_image', $container).remove(); - switch ($(this).val()) { - case 'no_image': - $('.content', $container).attr("class", "content"); - break; - case 'image_left': - $('.content', $container).attr("class", "content col-md-6") - .before('
'); + this.$('select[name="carousel-style"]').on('change', this.on_bg_change); + }, + on_add: function (e) { + e.preventDefault(); + var $inner = this.$target.find('.carousel-inner'); + var cycle = $inner.find('.item').size(); + $inner.append(openerp.qweb.render('website.carousel')); + this.$target.carousel(cycle); + }, + on_remove: function (e) { + e.preventDefault(); + var $inner = this.$target.find('.carousel-inner'); + if ($inner.find('.item').size() > 1) { + $inner + .find('.item.active').remove().end() + .find('.item:first').addClass('active'); + this.$target.carousel(0); + } + }, + on_bg_change: function (e) { + var $container = this.$target.find('.carousel-inner .item.active .container'); + var img_url = $('.content_image img', $container).attr("src"); + if (!img_url) { + img_url = this.img_url || "/website/static/src/img/china.jpg"; + } else { + this.img_url = img_url; + } + + $('.content_image', $container).remove(); + switch ($(e.currentTarget).val()) { + case 'no_image': + $('.content', $container).attr("class", "content"); break; - case 'image_right': - $('.content', $container).attr("class", "content col-md-6") - .after('
'); - break; - } - $(this).val(""); - }); - } + case 'image_left': + $('.content', $container).attr("class", "content col-md-6") + .before('
'); + break; + case 'image_right': + $('.content', $container).attr("class", "content col-md-6") + .after('
'); + break; + } + }, }); })(); diff --git a/addons/website/static/src/xml/website.snippets.xml b/addons/website/static/src/xml/website.snippets.xml index 8665a1ce06e..a32b2dc5191 100644 --- a/addons/website/static/src/xml/website.snippets.xml +++ b/addons/website/static/src/xml/website.snippets.xml @@ -5,17 +5,120 @@ +
+
carousel
+ +
+ +
+
Darken
+
+ +
+
Surprise!
+
+ +
+
Spacer
+
+
+ +
+
+ Main Title +
+
+
+
+

Welcome To Your New Homepage,

+

where everything can be customized

+
+
+
+
+ +
+
+
+
+

Ut enim ad minim veniam

+
+
+
+
+ +

Cillum Dolore

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod + tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, + quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo + consequat.

+
+
+ +

Mollit Anim

+

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum + dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non + proident, sunt in culpa qui officia deserunt mollit anim id est laborum

+
+
+ +

Nemo Enim Ipsam

+

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium + doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore + veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim + ipsam voluptatem quia voluptas

+
+
+
+
+ +
+
+
+
+ +
+
+

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod + tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, + quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo + consequat.

+

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum + dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non + proident, sunt in culpa qui officia deserunt mollit anim id est laborum

+ +
+
+
+
+ diff --git a/addons/website/views/views.xml b/addons/website/views/views.xml index a48068b82ed..a116ee6a157 100644 --- a/addons/website/views/views.xml +++ b/addons/website/views/views.xml @@ -156,7 +156,6 @@ - - -