'js': [
'static/src/js/mass_mailing.js',
],
- 'qweb': [],
+ 'qweb' : [
+ 'static/src/xml/*.xml',
+ ],
'css': [
'static/src/css/mass_mailing.css',
'static/src/css/email_template.css'
}
def action_edit_html(self, cr, uid, ids, context=None):
- url = '/website_mail/email_designer?model=mail.mass_mailing&res_id=%d' % ids[0]
+ assert len(ids)==1, "One and only one ID allowed for this action"
+ mail = self.browse(cr, uid, ids[0], context=context)
+ url = '/website_mail/email_designer?model=mail.mass_mailing&res_id=%d&field_body=body_html&field_from=email_form&field_subject=name&template_model=%s' % (ids[0], mail.mailing_model)
return {
'name': _('Open with Visual Editor'),
'type': 'ir.actions.act_url',
-openerp.mass_mailing = function(openerp) {
+openerp.mass_mailing = function (instance) {
+ var _t = instance.web._t;
+ debugger;
- openerp.web_kanban.KanbanRecord.include({
- on_card_clicked: function (event) {
- if (this.view.dataset.model === 'mail.mass_mailing.campaign') {
- this.$('.oe_mailings').click();
+ openerp.mass_mailing = function(openerp) {
+ openerp.web_kanban.KanbanRecord.include({
+ on_card_clicked: function (event) {
+ if (this.view.dataset.model === 'mail.mass_mailing.campaign') {
+ this.$('.oe_mailings').click();
+ } else {
+ this._super.apply(this, arguments);
+ }
+ },
+ });
+ };
+
+ instance.web.form.CharDomainButton = instance.web.form.AbstractField.extend({
+ template: 'CharDomainButton',
+ init: function(field_manager, node) {
+ this._super.apply(this, arguments);
+ },
+ start: function() {
+ var self=this;
+ this._super.apply(this, arguments);
+ $('button', this.$el).on('click', self.on_click);
+ this.set_button();
+ },
+ set_button: function() {
+ if (this.get('value')) {
+ // TODO: rpc to copute X
+ $('.oe_domain_count', this.$el).text('X records selected');
+ $('button span', this.$el).text(' Change selection');
} else {
- this._super.apply(this, arguments);
- }
+ $('.oe_domain_count', this.$el).text('0 record selected');
+ $('button span', this.$el).text(' Select records');
+ };
},
+ on_click: function(ev) {
+ var self = this;
+ var model = this.options.model || this.field_manager.get_field_value(this.options.model_field);
+ this.pop = new instance.web.form.SelectCreatePopup(this);
+ this.pop.select_element(
+ model, {title: 'Select records...'},
+ [], this.build_context());
+ this.pop.on("elements_selected", self, function() {
+ var self2 = this;
+ var search_data = this.pop.searchview.build_search_data()
+ instance.web.pyeval.eval_domains_and_contexts({
+ domains: search_data.domains,
+ contexts: search_data.contexts,
+ group_by_seq: search_data.groupbys || []
+ }).then(function (results) {
+ var domain = self2.pop.dataset.domain.concat(results.domain || []);
+ self.set_value(JSON.stringify(domain))
+ });
+ });
+ event.preventDefault();
+ },
+ set_value: function(value_) {
+ var self = this;
+ this.set('value', value_ || false);
+ this.set_button();
+ },
});
+ instance.web.form.widgets = instance.web.form.widgets.extend(
+ {'char_domain': 'instance.web.form.CharDomainButton'}
+ );
+
};
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<template>
+ <t t-name="CharDomainButton">
+ <div class="oe_form_field">
+ <span class="oe_domain_count"/>
+ <button class="oe_button oe_link" type="button"
+ t-att-style="widget.node.attrs.style"
+ t-att-accesskey="widget.node.attrs.accesskey">
+ <span class="fa fa-arrow-right"/>
+ </button>
+ </div>
+ </t>
+</template>
<field name="name"/>
<label for="mailing_model" string="Recipients"/>
<div>
- <field name="mailing_domain" invisible="1"/>
<field name="mailing_model" widget="radio" style="margin-bottom: 8px"
on_change="on_change_model(mailing_model, contact_list_ids)"/>
- <div attrs="{'invisible': [('mailing_model', '=', 'mail.mass_mailing.contact')]}">
- <button class="oe_link" type='object' name='action_domain_select' attrs="{'invisible': [('contact_nbr', '>', '0')]}">
- <span class="fa fa-arrow-right"> Select Recipients</span>
- </button>
- </div>
+ <field name="mailing_domain" widget="char_domain"
+ attrs="{'invisible': [('mailing_model', '=', 'mail.mass_mailing.contact')]}"
+ placeholder="Select recipients"
+ options="{'model_field': 'mailing_model'}"/>
+
<div attrs="{'invisible': [('mailing_model', '<>', 'mail.mass_mailing.contact')]}">
<label for="contact_list_ids" string="Select mailing lists:" class="oe_edit_only"/>
<field name="contact_list_ids" widget="many2many_tags"
<notebook>
<page string="Mail Body">
<button name="action_edit_html" type="object" string="Design Email" class="oe_highlight"/>
- <div attrs="{'invisible' : ['|', ('body_html','!=',False), ('contact_nbr', '<', 1)]}" class="oe_view_nocontent oe_clear">
+ <div attrs="{'invisible' : ['|', ('body_html','!=',False), ('mailing_domain', '!=', False)]}" class="oe_view_nocontent oe_clear">
<p class="oe_view_nocontent_create oe_edit_only">
Click to design your email.
</p>
class WebsiteEmailDesigner(http.Controller):
@http.route('/website_mail/email_designer', type='http', auth="user", website=True, multilang=True)
- def index(self, model=None, res_id=None, **kw):
- if not model or not model in request.registry or not res_id:
- return request.redirect('/')
- if not 'body' in request.registry[model]._all_columns and not 'body_html' in request.registry[model]._all_columns:
- return request.redirect('/')
- obj_ids = request.registry[model].exists(request.cr, request.uid, [res_id], context=request.context)
- if not obj_ids:
- return request.redirect('/')
+ def index(self, model, res_id, template_model, field_body='body', field_from='email_from', field_subject='name', **kw):
+ cr, uid, context = request.cr, request.uid, request.context
+ tmpl_obj = request.registry['email.template']
+ res_id = int(res_id)
+
+ tids = tmpl_obj.search(cr, uid, [('model','=',template_model)], context=context)
+ templates = tmpl_obj.browse(cr, uid, tids, context=context)
+
values = {
- 'object': request.registry[model].browse(request.cr, request.uid, obj_ids[0], context=request.context),
- 'model': request.registry[model],
- 'model_name': model,
+ 'object': request.registry[model].browse(cr, uid, res_id, context=context),
+ 'templates': templates,
+ 'model': model,
'res_id': res_id,
+ 'field_body': field_body,
+ 'field_from': field_from,
+ 'field_subject': field_subject,
}
+ print '*', values
return request.website.render("website_mail.designer_index", values)
@http.route(['/website_mail/snippets'], type='json', auth="user", website=True)
.js_follow[data-follow='on'] .js_follow_btn ,
.js_follow[data-follow='off'] .js_unfollow_btn {
display: none;
-}
\ No newline at end of file
+}
+
+.email_preview_border {
+ overflow: hidden !important;
+ border: 2px solid grey;
+ height: 300px;
+}
+.email_preview {
+ -webkit-transform: scale(.50);
+ -ms-transform: scale(.50);
+ transform: scale(.50);
+ -webkit-transform-origin: 0 0;
+ -ms-transform-origin: 0 0;
+ transform-origin: 0 0;
+ margin: 0 0px -300px 0;
+}
(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';
}
+ });
+
+ // Copy the template to the body of the email
+ $(document).ready(function () {
+ $('.js_template_set').click(function(ev) {
+ $('#email_designer').show();
+ $('#email_template').hide();
+ $(".js_content", $(this).parent()).children().clone().appendTo('#email_body');
+ // Todo: switch to edit mode
+ event.preventDefault();
+ });
});
+
})();
<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="container">
+ <div id="wrap" class="container">
+ <div id="email_template" t-att-style="(object.body_html and len(templates>0)) and 'display: none'" class="mb32">
+ <a class="mt16 btn btn-default pull-right"
+ t-att-href="'/web#return_label=Website&model=%s&id=%s&view_type=form' % (model_name, res_id)">
+ Back
+ </a>
+ <h1 class="page-header mt16">
+ Choose an Email Template
+ </h1>
<div class="row">
- <div class="col-md-8">
- <a class="pull-right mt32"
- t-att-href="'/web#return_label=Website&model=%s&id=%s&view_type=form' % (model_name, res_id)">
- <button class="btn btn-primary">Back to Form</button>
- </a>
- <h1 t-field="object.name"/>
- <div class="row" style="width: 600px;">
- <div t-if="'email_from' in model._all_columns" class="row">
- <div class="col-lg-3"><b>Email From</b></div>
- <div class="col-lg-9"><span t-field="object.email_from"/></div>
- </div>
-
- <div t-if="'email_to' in model._all_columns" class="row">
- <div class="col-lg-3"><b>To (Email)</b></div>
- <div class="col-lg-9"><span t-field="object.email_to"/></div>
- </div>
-
- <div t-if="'partner_to' in model._all_columns" class="row">
- <div class="col-lg-3"><b>To (Partners)</b></div>
- <div class="col-lg-9"><span t-field="object.partner_to"/></div>
- </div>
-
- <div t-if="'reply_to' in model._all_columns" class="row">
- <div class="col-lg-3"><b>Reply To</b></div>
- <div class="col-lg-9"><span t-field="object.reply_to"/></div>
- </div>
-
- <div t-if="'subject' in model._all_columns" class="row">
- <div class="col-lg-3"><b>Subject</b></div>
- <div class="col-lg-9"><span t-field="object.subject"/></div>
- </div>
-
- <div class="row well">
- <div t-field="object.body_html" style="position: relative;"/>
- </div>
+ <div class="col-md-3 col-sm-4 text-center img-border">
+ <div class="email_preview_border">
+ <div class="email_preview js_content"/>
+ </div>
+ <h4>New Template</h4>
+ <button class="btn btn-primary">Select</button>
+ </div>
+ <div t-foreach="templates" t-as="template" class="col-md-3 col-sm-4 text-center">
+ <div class="email_preview_border">
+ <div t-field="template.body_html" class="email_preview js_content"/>
+ </div>
+ <h4 t-field="template.name"/>
+ <button class="btn btn-primary js_template_set">Select</button>
+ </div>
+ </div>
+ </div><div id="email_designer" t-att-style="not (object.body_html and len(templates)> 0) and 'display: none'" class="mb32">
+ <a class="mt16 btn btn-primary pull-right"
+ t-att-href="'/web#return_label=Website&model=%s&id=%s&view_type=form' % (model_name, res_id)">
+ Save and Continue
+ </a>
+ <h1 class="page-header mt16">
+ Design Your Email
+ </h1>
+ <div class="form-horizontal">
+ <div class="form-group">
+ <label class="col-sm-2 control-label">From:</label>
+ <div class="col-sm-7">
+ <span t-field="object.email_from" class="form-control"/>
+ </div>
+ </div>
+ <div class="form-group">
+ <label class="col-sm-2 control-label">Subject:</label>
+ <div class="col-sm-7">
+ <span t-field="object.name" class="form-control"/>
</div>
</div>
</div>
+ <hr/>
+ <div t-field="object.body_html" id="email_body"/>
</div>
</div>
</t>