diff --git a/addons/mail/__openerp__.py b/addons/mail/__openerp__.py index 0c32ba27d6f..9ad3232d396 100644 --- a/addons/mail/__openerp__.py +++ b/addons/mail/__openerp__.py @@ -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', diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index bfda31119f2..1eb3c29e556 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -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); }, diff --git a/addons/mail/static/src/js/many2many_tags_email.js b/addons/mail/static/src/js/many2many_tags_email.js new file mode 100644 index 00000000000..52dcbf7aeb5 --- /dev/null +++ b/addons/mail/static/src/js/many2many_tags_email.js @@ -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', +}); + +}; diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 1bcbb0c2efc..33712847534 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -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 diff --git a/addons/mail/wizard/mail_compose_message_view.xml b/addons/mail/wizard/mail_compose_message_view.xml index 5e571eb4338..b9c3d237e78 100644 --- a/addons/mail/wizard/mail_compose_message_view.xml +++ b/addons/mail/wizard/mail_compose_message_view.xml @@ -14,9 +14,8 @@ - +