[IMP] website.snippet: snippets can be splitted into separate template and be called into the lits of the snippet

This commit is contained in:
Christophe Matthieu
2014-12-18 22:50:12 +01:00
committed by Antony Lesuisse
parent 790312dbf9
commit 4734cbab4d
2 changed files with 41 additions and 0 deletions
+17
View File
@@ -69,6 +69,23 @@ class QWeb(orm.AbstractModel):
return super(QWeb, self).render_attribute(element, name, value, qwebcontext)
def render_tag_snippet(self, element, template_attributes, generated_attributes, qwebcontext):
d = qwebcontext.copy()
d[0] = self.render_element(element, template_attributes, generated_attributes, d)
cr = d.get('request') and d['request'].cr or None
uid = d.get('request') and d['request'].uid or None
template = self.eval_format(template_attributes["snippet"], d)
elements = html.fragments_fromstring(self.render(cr, uid, template, d))
id = int(elements[0].get('data-oe-id', None))
elements[0].set('data-oe-name', self.pool['ir.ui.view'].browse(cr, uid, id, context=qwebcontext.context).name)
elements[0].set('data-oe-type', "snippet")
elements[0].set('data-oe-thumbnail', template_attributes.get('thumbnail', "oe-thumbnail"))
return "".join(map(html.tostring, elements))
def render_tag_call_assets(self, element, template_attributes, generated_attributes, qwebcontext):
if request and request.website and request.website.cdn_activated:
if qwebcontext.context is None:
@@ -182,6 +182,12 @@
.then(function (html) {
var $html = $(html);
// t-snippet
$html.find('> .tab-content > div > [data-oe-type="snippet"]').each(function () {
var $div = $('<div/>').insertAfter(this).append(this).attr('name', $(this).data('oe-name'));
});
// end
var selector = [];
var $styles = $html.find("[data-js], [data-selector]");
$styles.each(function () {
@@ -214,10 +220,28 @@
'</div>');
$div.find('span').text($(this).attr("name"));
$(this).prepend($div);
// from t-snippet
var thumbnail = $("[data-oe-thumbnail]", this).data("oe-thumbnail");
if (thumbnail) {
$div.find('.oe_snippet_thumbnail_img').css('background-image', 'url(' + thumbnail + ')');
}
// end
}
$("> *:not(.oe_snippet_thumbnail)", this).addClass('oe_snippet_body');
});
// clean t-oe
$html.find('[data-oe-model]').each(function () {
for (var k=0; k<this.attributes.length; k++) {
if (this.attributes[k].name.indexOf('data-oe-') === 0) {
$(this).removeAttr(this.attributes[k].name);
k--;
}
}
});
// end
self.$el.append($html);
self.make_snippet_draggable(self.$snippets);