[MERGE] Introducing the Many2Many Email Widget, based on Many2Many Tags. This widget designed for many2many fields on partners checks that partners added in the widget have an email address defined; if not, a popup is opened to enter an email.
Also featuring in a 'by the way' fashion: - the 'Compose' button now opens a mail.compose.message wizard, without using further Chatter values. bzr revid: tde@openerp.com-20121106161549-qzmvmu96c5ony0zr
This commit is contained in:
@@ -89,6 +89,7 @@ Main Features
|
||||
'static/lib/jquery.expander/jquery.expander.js',
|
||||
'static/src/js/mail.js',
|
||||
'static/src/js/mail_followers.js',
|
||||
'static/src/js/many2many_tags_email.js',
|
||||
],
|
||||
'qweb': [
|
||||
'static/src/xml/mail.xml',
|
||||
|
||||
@@ -5,6 +5,7 @@ openerp.mail = function (session) {
|
||||
var mail = session.mail = {};
|
||||
|
||||
openerp_mail_followers(session, mail); // import mail_followers.js
|
||||
openerp_FieldMany2ManyTagsEmail(session); // import manyy2many_tags_email.js
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------
|
||||
@@ -1630,7 +1631,22 @@ openerp.mail = function (session) {
|
||||
|
||||
bind_events: function () {
|
||||
var self=this;
|
||||
this.$(".oe_write_full").click(function(){ self.root.thread.compose_message.on_compose_fullmail(); });
|
||||
this.$(".oe_write_full").click(function (event) {
|
||||
event.stopPropagation();
|
||||
var action = {
|
||||
type: 'ir.actions.act_window',
|
||||
res_model: 'mail.compose.message',
|
||||
view_mode: 'form',
|
||||
view_type: 'form',
|
||||
action_from: 'mail.ThreadComposeMessage',
|
||||
views: [[false, 'form']],
|
||||
target: 'new',
|
||||
context: {
|
||||
'default_content_subtype': 'html',
|
||||
},
|
||||
};
|
||||
session.client.action_manager.do_action(action);
|
||||
});
|
||||
this.$(".oe_write_onwall").click(function(){ self.root.thread.on_compose_message(); });
|
||||
}
|
||||
});
|
||||
@@ -1646,17 +1662,6 @@ openerp.mail = function (session) {
|
||||
session.web.ComposeMessageTopButton = session.web.Widget.extend({
|
||||
template:'mail.compose_message.button_top_bar',
|
||||
|
||||
init: function (parent, options) {
|
||||
this._super.apply(this, options);
|
||||
this.options = this.options || {};
|
||||
this.options.domain = this.options.domain || [];
|
||||
this.options.context = {
|
||||
'default_model': false,
|
||||
'default_res_id': 0,
|
||||
'default_content_subtype': 'html',
|
||||
};
|
||||
},
|
||||
|
||||
start: function (parent, params) {
|
||||
var self = this;
|
||||
this.$el.on('click', 'button', self.on_compose_message );
|
||||
@@ -1673,11 +1678,11 @@ openerp.mail = function (session) {
|
||||
action_from: 'mail.ThreadComposeMessage',
|
||||
views: [[false, 'form']],
|
||||
target: 'new',
|
||||
context: _.extend(this.options.context, {
|
||||
'default_model': this.context.default_model,
|
||||
'default_res_id': this.context.default_res_id,
|
||||
context: {
|
||||
'default_model': '',
|
||||
'default_res_id': false,
|
||||
'default_content_subtype': 'html',
|
||||
}),
|
||||
},
|
||||
};
|
||||
session.client.action_manager.do_action(action);
|
||||
},
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
openerp_FieldMany2ManyTagsEmail = function(instance) {
|
||||
var _t = instance.web._t;
|
||||
|
||||
/**
|
||||
* Extend of FieldMany2ManyTags widget method.
|
||||
* When the user add a partner and the partner don't have an email, open a popup to purpose to add an email.
|
||||
* The user can choose to add an email or cancel and close the popup.
|
||||
*/
|
||||
instance.web.form.FieldMany2ManyTagsEmail = instance.web.form.FieldMany2ManyTags.extend({
|
||||
|
||||
start: function() {
|
||||
this.values = [];
|
||||
this.values_checking = [];
|
||||
|
||||
this.on("change:value", this, this.on_change_value_check);
|
||||
this.trigger("change:value");
|
||||
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
on_change_value_check : function () {
|
||||
this.values = _.uniq(this.values);
|
||||
|
||||
// filter for removed values
|
||||
var values_removed = _.difference(this.values, this.get('value'));
|
||||
if (values_removed.length) {
|
||||
this.values = _.difference(this.values, values_removed);
|
||||
this.set({'value': this.values});
|
||||
return false;
|
||||
}
|
||||
|
||||
// find not checked values that are not currently on checking
|
||||
var not_checked = _.difference(this.get('value'), this.values, this.values_checking);
|
||||
if (not_checked.length) {
|
||||
// remember values on checking for cheked only one time
|
||||
this.values_checking = this.values_checking.concat(not_checked);
|
||||
// check values
|
||||
this._check_email_popup(not_checked);
|
||||
}
|
||||
},
|
||||
|
||||
_check_email_popup: function (ids) {
|
||||
var self = this;
|
||||
new instance.web.Model('res.partner').call("search", [[
|
||||
["id", "in", ids],
|
||||
["email", "=", false],
|
||||
["notification_email_send", "in", ['all', 'comment']] ]],
|
||||
{context: this.build_context()})
|
||||
.pipe(function (record_ids) {
|
||||
// valid partner
|
||||
var valid_partner = _.difference(ids, record_ids);
|
||||
self.values = self.values.concat(valid_partner);
|
||||
self.values_checking = _.difference(self.values_checking, valid_partner);
|
||||
|
||||
// unvalid partner
|
||||
_.each(record_ids, function (id) {
|
||||
var pop = new instance.web.form.FormOpenPopup(self);
|
||||
pop.show_element(
|
||||
'res.partner',
|
||||
id,
|
||||
self.build_context(),
|
||||
{
|
||||
title: _t("Please complete partner's informations and Email"),
|
||||
}
|
||||
);
|
||||
pop.on('write_completed', self, function () {
|
||||
this.values.push(id);
|
||||
this.values_checking = _.without(this.values_checking, id);
|
||||
this.set({'value': this.values});
|
||||
});
|
||||
pop.on('closed', self, function () {
|
||||
this.values_checking = _.without(this.values_checking, id);
|
||||
this.set({'value': this.values});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Registry of form fields
|
||||
*/
|
||||
instance.web.form.widgets = instance.web.form.widgets.extend({
|
||||
'many2many_tags_email' : 'instance.web.form.FieldMany2ManyTagsEmail',
|
||||
});
|
||||
|
||||
};
|
||||
@@ -186,17 +186,6 @@ class mail_compose_message(osv.TransientModel):
|
||||
"""
|
||||
return {'value': {'content_subtype': value}}
|
||||
|
||||
def onchange_partner_ids(self, cr, uid, ids, value, context=None):
|
||||
""" The basic purpose of this method is to check that destination partners
|
||||
effectively have email addresses. Otherwise a warning is thrown.
|
||||
:param value: value format: [[6, 0, [3, 4]]]
|
||||
"""
|
||||
res = {'value': {}}
|
||||
if not value or not value[0] or not value[0][0] == 6:
|
||||
return
|
||||
res.update(self.check_partners_email(cr, uid, value[0][2], context=context))
|
||||
return res
|
||||
|
||||
def dummy(self, cr, uid, ids, context=None):
|
||||
""" TDE: defined to have buttons that do basically nothing. It is
|
||||
currently impossible to have buttons that do nothing special
|
||||
|
||||
@@ -14,9 +14,8 @@
|
||||
<field name="parent_id" invisible="1"/>
|
||||
<field name="content_subtype" invisible="1"/>
|
||||
<!-- visible wizard -->
|
||||
<field name="partner_ids" widget="many2many_tags" placeholder="Add contacts to notify..."
|
||||
context="{'force_email':True}"
|
||||
on_change="onchange_partner_ids(partner_ids)" required="1"/>
|
||||
<field name="partner_ids" widget="many2many_tags_email" placeholder="Add contacts to notify..."
|
||||
context="{'force_email':True}" required="1"/>
|
||||
<field name="subject" placeholder="Subject..."
|
||||
attrs="{'invisible':[('content_subtype', '=', 'plain')]}"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user