[IMP] [ADD] website: added base for template designer.

[ADD] website: email_template: added website_link field, a link to edit the template
directly in the website
[ADD] website_mail: added controller and page to edit templates. They are still jinja
templates editable in the website. Not qweb templates.
[ADD] website_mail: JS file and editor override to enable only certain snippets. Those
are still to add, but will be base templates for email.
[IMP] website: improved the addition of editor JS in the template header to be able
to add JS file that override the editor without having to hack everything in the
template.

bzr revid: tde@openerp.com-20140113125534-djy48pi7lf42f9ms
This commit is contained in:
Thibault Delavallée 2014-01-13 13:55:34 +01:00
parent 778de23d6f
commit b97727701c
11 changed files with 276 additions and 3 deletions

View File

@ -148,10 +148,13 @@
});
self.$el.css('top', this.parent.get('height'));
},
_get_snippet_url: function () {
return '/website/snippets';
},
fetch_snippet_templates: function () {
var self = this;
openerp.jsonRpc("/website/snippets", 'call', {})
openerp.jsonRpc(this._get_snippet_url(), 'call', {})
.then(function (html) {
var $html = $(html);

View File

@ -75,7 +75,7 @@
<script type="text/javascript" src="/website/static/src/js/website.js"></script>
<script t-if="not translatable" type="text/javascript" src="/website/static/src/js/website.snippets.animation.js"></script>
<t t-raw="head or ''"/>
<t t-raw="head or ''" name='layout_head'/>
</head>
<body>
<div id="wrapwrap">
@ -195,7 +195,7 @@
</template>
<template id="editor_head" inherit_id="website.layout" name="Editor" groups="base.group_website_publisher">
<xpath expr="//head" position="inside">
<xpath expr='//t[@name="layout_head"]' position="before">
<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'/>

View File

@ -28,7 +28,10 @@
'author': 'OpenERP SA',
'depends': ['website', 'mail'],
'data': [
'views/snippets.xml',
'views/website_mail.xml',
'views/website_email_designer.xml',
'views/email_template_view.xml',
'security/website_mail.xml',
],
'css': [

View File

@ -1 +1,2 @@
import email_designer
import main

View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# from openerp import SUPERUSER_ID
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website.models import website
class WebsiteEmailDesigner(http.Controller):
@website.route('/website_mail/email_designer/<model("email.template"):template>/', type='http', auth="public", multilang=True)
def index(self, template, **kw):
values = {
'template': template,
}
print template
return request.website.render("website_mail.designer_index", values)
@website.route(['/website_mail/snippets'], type='json', auth="public")
def snippets(self):
return request.website._render('website_mail.email_designer_snippets')

View File

@ -1,2 +1,3 @@
import mail_message
import mail_thread
import email_template

View File

@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014-Today OpenERP SA (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import lxml
import urlparse
from openerp.osv import osv, fields
from openerp.tools.translate import _
class EmailTemplate(osv.Model):
_inherit = 'email.template'
def _get_website_link(self, cr, uid, ids, name, args, context=None):
return dict((id, _('<a href="website_mail/email_designer/%s">Edit in Website</a>') % id) for id in ids)
_columns = {
'website_link': fields.function(
_get_website_link, type='text',
string='Website Link',
help='Link to the website',
),
}
def _postprocess_html_replace_links(self, cr, uid, body_html, context=None):
""" Post-processing of body_html. Indeed the content generated by the
website builder contains references to local addresses, for example
for images. This method changes those addresses to absolute addresses. """
html = body_html
if not body_html:
return html
# form a tree
root = lxml.html.fromstring(html)
if not len(root) and root.text is None and root.tail is None:
html = '<div>%s</div>' % html
root = lxml.html.fromstring(html)
base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url')
(base_scheme, base_netloc, bpath, bparams, bquery, bfragment) = urlparse.urlparse(base_url)
def _process_link(url):
new_url = url
(scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url)
if not scheme and not netloc:
new_url = urlparse.urlunparse((base_scheme, base_netloc, path, params, query, fragment))
return new_url
# check all nodes, replace :
# - img src -> check URL
# - a href -> check URL
for node in root.iter():
if node.tag == 'a':
node.set('href', _process_link(node.get('href')))
elif node.tag == 'img' and not node.get('src', 'data').startswith('data'):
node.set('src', _process_link(node.get('src')))
html = lxml.etree.tostring(root, pretty_print=False)
return html
def create(self, cr, uid, values, context=None):
if 'body_html' in values:
values['body_html'] = self._postprocess_html_replace_links(cr, uid, values['body_html'], context=context)
return super(EmailTemplate, self).create(cr, uid, values, context=context)
def write(self, cr, uid, ids, values, context=None):
if 'body_html' in values:
values['body_html'] = self._postprocess_html_replace_links(cr, uid, values['body_html'], context=context)
return super(EmailTemplate, self).write(cr, uid, ids, values, context=context)

View File

@ -0,0 +1,17 @@
(function () {
'use strict';
var website = openerp.website;
website.snippet.BuildingBlock.include({
// init: function (parent) {
// this._super.apply(this, arguments);
// },
_get_snippet_url: function () {
return '/website_mail/snippets';
}
});
})();

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="email_template_form_inherit_website_link">
<field name="name">email.template.form</field>
<field name="model">email.template</field>
<field name="inherit_id" ref="email_template.email_template_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@string='Mailing Template']/group" position="before">
<field name="website_link" widget='html' radonly='1'/>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="email_designer_snippets">
<div class="scroll" t-ignore="1">
<ul class="nav navbar-nav nav-tabs">
<li class="active"><a href="#snippet_structure" data-toggle="tab">Structure</a></li>
<li><a href="#snippet_content" data-toggle="tab">Content</a></li>
<li><a href="#snippet_feature" data-toggle="tab">Features</a></li>
<li><a href="#snippet_effect" data-toggle="tab">Effects</a></li>
</ul>
<div class="tab-content">
<div id="snippet_structure" class="tab-pane fade in active">
<div data-snippet-id="text-image" data-selector-children=".oe_structure, [data-oe-type=html]">
<div class="oe_snippet_thumbnail">
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_text_image.png"/>
<span class="oe_snippet_thumbnail_title">Text-Image</span>
</div>
<section class="oe_snippet_body">
<div class="container">
<div class="row">
<div class="col-md-6 mt16">
<h3>A Section Subtitle</h3>
<p>
Write one or two paragraphs describing your product or
services. To be successful your content needs to be
useful to your readers.
</p><p>
Start with the customer find out what they want
and give it to them.
</p>
</div>
<div class="col-md-6 mt16 mb16">
<img class="img img-responsive shadow" src="/website/static/src/img/text_image.png"/>
</div>
</div>
</div>
</section>
</div>
</div>
<div id="snippet_feature" class="tab-pane fade">
</div>
<div id="snippet_effect" class="tab-pane fade">
</div>
<div id="snippet_styles" class="hidden">
</div>
</div>
</div>
</template>
</data>
</openerp>

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Email Designer main page -->
<template id="designer_index" name="Email Designer">
<t t-call="website.layout">
<t t-set="head">
<script type="text/javascript" src="/website_mail/static/src/js/website_email_designer.js"></script>
</t>
<div id="wrap">
<div class="oe_structure container">
<div class="row">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="email_from" class="col-sm-2 control-label">Email From</label>
<div class="col-sm-10">
<input type="char" class="form-control" id="email_from"
placeholder="my.email@example.com" t-att-value="template.email_from"/>
</div>
</div>
<div class="form-group">
<label for="email_to" class="col-sm-2 control-label">To (Email)</label>
<div class="col-sm-10">
<input type="char" class="form-control" id="email_to"
placeholder="my.email@example.com" t-att-value="template.email_to"/>
</div>
</div>
<div class="form-group">
<label for="partner_to" class="col-sm-2 control-label">To (Partners)</label>
<div class="col-sm-10">
<input type="char" class="form-control" id="partner_to"
placeholder="1,2,3" t-att-value="template.partner_to"/>
</div>
</div>
<div class="form-group">
<label for="reply_to" class="col-sm-2 control-label">Reply-To</label>
<div class="col-sm-10">
<input type="char" class="form-control" id="reply_to"
placeholder="my.email@example.com" t-att-value="template.reply_to"/>
</div>
</div>
<div class="form-group">
<label for="subject" class="col-sm-2 control-label">Subject</label>
<div class="col-sm-10">
<input type="char" class="form-control" id="subject"
placeholder="Subject" t-att-value="template.subject"/>
</div>
</div>
</form>
<div t-field="template.body_html"/>
</div>
</div>
</div>
</t>
<t t-set="website.footer"></t>
</template>
</data>
</openerp>