[IMP] mail: add email_from like partner before opening wizard composer

bzr revid: chm@openerp.com-20121231142250-ykdxaqoqfvush1ah
This commit is contained in:
Christophe Matthieu 2012-12-31 15:22:50 +01:00
parent f1fcb4a994
commit 876e53dfcf
1 changed files with 43 additions and 41 deletions

View File

@ -370,6 +370,7 @@ openerp.mail = function (session) {
this.show_compact_message = false; this.show_compact_message = false;
this.show_delete_attachment = true; this.show_delete_attachment = true;
this.emails_from = []; this.emails_from = [];
this.partners_from = [];
}, },
start: function () { start: function () {
@ -494,43 +495,41 @@ openerp.mail = function (session) {
this.$(".oe_msg_attachment_list").on('click', '.oe_delete', this.on_attachment_delete); this.$(".oe_msg_attachment_list").on('click', '.oe_delete', this.on_attachment_delete);
this.$(".oe_emails_from").on('change', 'input', this.on_checked_email_from); this.$(".oe_emails_from").on('change', 'input', this.on_checked_email_from);
this.$(".oe_partners_from").on('change', 'input', this.on_checked_partner_from);
}, },
on_compose_fullmail: function (default_composition_mode) { on_compose_fullmail: function (default_composition_mode) {
var self = this;
if(!this.do_check_attachment_upload()) { if(!this.do_check_attachment_upload()) {
return false; return false;
} }
if (default_composition_mode == 'reply') { // create list of new partners
var extra_email = _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]});
this.check_recipient_partners(extra_email).done(function () {
var context = { var context = {
'default_model': default_composition_mode == 'reply' ? undefined : self.context.default_model,
'default_res_id': default_composition_mode == 'reply' ? undefined : self.context.default_res_id,
'default_composition_mode': default_composition_mode, 'default_composition_mode': default_composition_mode,
'default_parent_id': this.id, 'default_parent_id': self.id,
'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''), 'default_body': mail.ChatterUtils.get_text2html(self.$el ? (self.$el.find('textarea:not(.oe_compact)').val() || '') : ''),
'default_attachment_ids': this.attachment_ids, 'default_attachment_ids': self.attachment_ids,
'default_partner_ids': _.map(_.filter(self.partners_from, function (f) {return f[1]}), function (f) {return f[0]}),
}; };
} else { var action = {
var context = { type: 'ir.actions.act_window',
'default_model': this.context.default_model, res_model: 'mail.compose.message',
'default_res_id': this.context.default_res_id, view_mode: 'form',
'default_composition_mode': default_composition_mode, view_type: 'form',
'default_parent_id': this.id, views: [[false, 'form']],
'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''), target: 'new',
'default_attachment_ids': this.attachment_ids, context: context,
}; };
}
var action = {
type: 'ir.actions.act_window',
res_model: 'mail.compose.message',
view_mode: 'form',
view_type: 'form',
views: [[false, 'form']],
target: 'new',
context: context,
};
this.do_action(action); self.do_action(action);
this.on_cancel(); self.on_cancel();
});
}, },
reinit: function() { reinit: function() {
@ -564,14 +563,13 @@ openerp.mail = function (session) {
check_recipient_partners: function (emails) { check_recipient_partners: function (emails) {
var self = this; var self = this;
self.partners_from = [];
var deferreds = []; var deferreds = [];
for (var i = 0; i < emails.length; i++) {
deferreds.push($.Deferred());
}
var ds_partner = new session.web.DataSetSearch(this, 'res.partner'); var ds_partner = new session.web.DataSetSearch(this, 'res.partner');
_.each(emails, function (email) { _.each(emails, function (email) {
ds_partner.call('search', [[['email', 'ilike', email]]]).then(function (partner_ids) { var deferred = $.Deferred();
var deferred = deferreds[_.indexOf(emails, email)]; deferreds.push(deferred);
ds_partner.call('search', [[['email', 'like', email]]]).then(function (partner_ids) {
if (!partner_ids.length) { if (!partner_ids.length) {
var pop = new session.web.form.FormOpenPopup(this); var pop = new session.web.form.FormOpenPopup(this);
pop.show_element( pop.show_element(
@ -586,17 +584,22 @@ openerp.mail = function (session) {
title: _t("Please complete partner's informations"), title: _t("Please complete partner's informations"),
} }
); );
pop.on('write_completed, closed', self, function () { pop.on('closed', self, function () {
deferred.resolve();
});
pop.on('saved', self, function (id) {
self.partners_from.push([id, true]);
deferred.resolve(); deferred.resolve();
}); });
} }
else { else {
self.partners_from.push([partner_ids[0], true]);
deferred.resolve(); deferred.resolve();
} }
return deferred; return deferred;
}); });
}); });
return $.when.apply( $, deferreds ).done(); return $.when.apply( $, deferreds );
}, },
on_message_post: function (event) { on_message_post: function (event) {
@ -639,7 +642,7 @@ openerp.mail = function (session) {
/* convert the compact mode into the compose message /* convert the compact mode into the compose message
*/ */
on_compose_expandable: function (event) { on_compose_expandable: function (event) {
this.get_emails_from(); this.get_from();
if ((!this.stay_open || (event && event.type == 'click')) && (!this.show_composer || !this.$('textarea:not(.oe_compact)').val().match(/\S+/) && !this.attachment_ids.length)) { if ((!this.stay_open || (event && event.type == 'click')) && (!this.show_composer || !this.$('textarea:not(.oe_compact)').val().match(/\S+/) && !this.attachment_ids.length)) {
this.show_composer = !this.show_composer || this.stay_open; this.show_composer = !this.show_composer || this.stay_open;
this.reinit(); this.reinit();
@ -664,7 +667,7 @@ openerp.mail = function (session) {
} }
}, },
get_emails_from: function () { get_from: function () {
var self = this; var self = this;
var messages = []; var messages = [];
@ -678,13 +681,12 @@ openerp.mail = function (session) {
_.each(this.options.root_thread.messages, function (msg) {messages.push(msg); messages.concat(msg.get_childs());}); _.each(this.options.root_thread.messages, function (msg) {messages.push(msg); messages.concat(msg.get_childs());});
} }
var emails_from = _.map(_.filter(messages, _.each(messages, function (thread) {
function (thread) {return thread.author_id && !thread.author_id[0];}), if (thread.author_id && !thread.author_id[0] &&
function (thread) {return thread.author_id[1];}); !_.find(self.emails_from, function (from) {return from[0] == thread.author_id[1];})) {
self.emails_from.push([thread.author_id[1], true]);
return _.each(emails_from, function (email_from) {
if (!_.find(self.emails_from, function (from) {return from[0] == email_from;})) {
self.emails_from.push([email_from, true]);
} }
}); });
}, },
@ -697,7 +699,7 @@ openerp.mail = function (session) {
email_from[1] = $input.is(":checked"); email_from[1] = $input.is(":checked");
} }
}); });
} },
}); });
/** /**