summaryrefslogtreecommitdiff
path: root/addons/mail/static/src
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2013-01-10 13:51:29 +0100
committerThibault Delavallée <tde@openerp.com>2013-01-10 13:51:29 +0100
commitfb3dd0ebc2ae4db6a19d6c781d0b243281c8dfaf (patch)
tree28be4e39a3992cb508ec37978020d6cac997f83e /addons/mail/static/src
parentf51c31bbfdb0b396628b29880276f26cbb43f818 (diff)
parentd9faa7c095718e405e0cf043090526a259d527b8 (diff)
[MERGE] Forward porting of the 7.0 addons branch inside trunk until rev 8561.
bzr revid: tde@openerp.com-20130110125129-9g99h3heldcnspfh
Diffstat (limited to 'addons/mail/static/src')
-rw-r--r--addons/mail/static/src/js/mail.js151
-rw-r--r--addons/mail/static/src/js/mail_followers.js3
-rw-r--r--addons/mail/static/src/xml/mail.xml8
3 files changed, 86 insertions, 76 deletions
diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js
index f8643e94bb3..e08afdad217 100644
--- a/addons/mail/static/src/js/mail.js
+++ b/addons/mail/static/src/js/mail.js
@@ -253,7 +253,14 @@ openerp.mail = function (session) {
} else {
this.avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid);
}
-
+ if (this.author_id) {
+ var email = this.author_id[1].match(/(.*)<(.*@.*)>/);
+ if (!email) {
+ this.author_id.push(_.str.escapeHTML(this.author_id[1]), '', this.author_id[1]);
+ } else {
+ this.author_id.push(_.str.escapeHTML(email[0]), _.str.trim(email[1]), email[2]);
+ }
+ }
},
@@ -370,6 +377,7 @@ openerp.mail = function (session) {
this.show_compact_message = false;
this.show_delete_attachment = true;
this.emails_from = [];
+ this.partners_from = [];
},
start: function () {
@@ -494,43 +502,43 @@ openerp.mail = function (session) {
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_partners_from").on('change', 'input', this.on_checked_partner_from);
},
on_compose_fullmail: function (default_composition_mode) {
-
+ var self = this;
if(!this.do_check_attachment_upload()) {
return false;
}
- if (default_composition_mode == 'reply') {
+ // create list of new partners
+ this.check_recipient_partners().done(function (partner_ids) {
var context = {
'default_composition_mode': default_composition_mode,
- 'default_parent_id': this.id,
- 'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''),
- 'default_attachment_ids': this.attachment_ids,
+ 'default_parent_id': self.id,
+ 'default_body': mail.ChatterUtils.get_text2html(self.$el ? (self.$el.find('textarea:not(.oe_compact)').val() || '') : ''),
+ 'default_attachment_ids': self.attachment_ids,
+ 'default_partner_ids': partner_ids,
};
- } else {
- var context = {
- 'default_model': this.context.default_model,
- 'default_res_id': this.context.default_res_id,
- 'default_composition_mode': default_composition_mode,
- 'default_parent_id': this.id,
- 'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''),
- 'default_attachment_ids': this.attachment_ids,
+ if (default_composition_mode != 'reply' && self.context.default_model && self.context.default_res_id) {
+ context.default_model = self.context.default_model;
+ context.default_res_id = self.context.default_res_id;
+ }
+
+ 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,
};
- }
- 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);
- this.on_cancel();
+ self.do_action(action);
+ self.on_cancel();
+ });
+
},
reinit: function() {
@@ -562,63 +570,65 @@ openerp.mail = function (session) {
}
},
- check_recipient_partners: function (emails) {
+ check_recipient_partners: function () {
var self = this;
- var deferreds = [];
- for (var i = 0; i < emails.length; i++) {
- deferreds.push($.Deferred());
- }
- var ds_partner = new session.web.DataSetSearch(this, 'res.partner');
- _.each(emails, function (email) {
- ds_partner.call('search', [[['email', 'ilike', email]]]).then(function (partner_ids) {
- var deferred = deferreds[_.indexOf(emails, email)];
- if (!partner_ids.length) {
- var pop = new session.web.form.FormOpenPopup(this);
- pop.show_element(
- 'res.partner',
- 0,
- {
- 'default_email': email,
- 'force_email': true,
- 'ref': "compound_context",
- },
- {
- title: _t("Please complete partner's informations"),
- }
- );
- pop.on('write_completed, closed', self, function () {
- deferred.resolve();
- });
- }
- else {
+ var partners_from = [];
+ var emails = [];
+ _.each(this.emails_from, function (email_from) {
+ if (email_from[1] && !_.find(emails, function (email) {return email == email_from[0][4];})) {
+ emails.push(email_from[0][1]);
+ }
+ });
+ var deferred_check = $.Deferred();
+ self.parent_thread.ds_thread._model.call('message_create_partners_from_emails', [emails]).then(function (partners) {
+ partners_from = _.clone(partners.partner_ids);
+ var deferreds = [];
+ _.each(partners.new_partner_ids, function (id) {
+ var deferred = $.Deferred()
+ deferreds.push(deferred);
+ var pop = new session.web.form.FormOpenPopup(this);
+ pop.show_element(
+ 'res.partner',
+ id,
+ {
+ 'force_email': true,
+ 'ref': "compound_context",
+ },
+ {
+ title: _t("Please complete partner's informations"),
+ }
+ );
+ pop.on('closed', self, function () {
deferred.resolve();
- }
- return deferred;
+ });
+ partners_from.push(id);
+ });
+ $.when.apply( $, deferreds ).then(function () {
+ deferred_check.resolve(partners_from);
});
});
- return $.when.apply( $, deferreds ).done();
+ return deferred_check;
},
on_message_post: function (event) {
var self = this;
if (this.do_check_attachment_upload() && (this.attachment_ids.length || this.$('textarea').val().match(/\S+/))) {
// 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 () {
- self.do_send_message_post();
+ this.check_recipient_partners().done(function (partner_ids) {
+ self.do_send_message_post(partner_ids);
});
}
},
/*do post a message and fetch the message*/
- do_send_message_post: function () {
+ do_send_message_post: function (partner_ids) {
var self = this;
this.parent_thread.ds_thread._model.call('message_post_user_api', [this.context.default_res_id], {
'body': this.$('textarea').val(),
'subject': false,
'parent_id': this.context.default_parent_id,
'attachment_ids': _.map(this.attachment_ids, function (file) {return file.id;}),
- 'extra_emails': _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}),
+ 'partner_ids': partner_ids,
'context': this.parent_thread.context,
}).done(function (message_id) {
var thread = self.parent_thread;
@@ -678,26 +688,24 @@ openerp.mail = function (session) {
_.each(this.options.root_thread.messages, function (msg) {messages.push(msg); messages.concat(msg.get_childs());});
}
- var emails_from = _.map(_.filter(messages,
- function (thread) {return thread.author_id && !thread.author_id[0];}),
- function (thread) {return thread.author_id[1];});
-
- 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]);
+ _.each(messages, function (thread) {
+ if (thread.author_id && !thread.author_id[0] &&
+ !_.find(self.emails_from, function (from) {return from[0][4] == thread.author_id[4];})) {
+ self.emails_from.push([thread.author_id, true]);
}
});
+ return self.emails_from;
},
on_checked_email_from: function (event) {
var $input = $(event.target);
var email = $input.attr("data");
_.each(this.emails_from, function (email_from) {
- if (email_from[0] == email) {
+ if (email_from[0][4] == email) {
email_from[1] = $input.is(":checked");
}
});
- }
+ },
});
/**
@@ -1690,7 +1698,6 @@ openerp.mail = function (session) {
this.defaults[key.replace(/^search_default_/, '')] = this.context[key];
}
}
-
this.action.params = _.extend({
'display_indented_thread': 1,
'show_reply_button': true,
diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js
index 1fc93781039..9f88116acc7 100644
--- a/addons/mail/static/src/js/mail_followers.js
+++ b/addons/mail/static/src/js/mail_followers.js
@@ -221,11 +221,14 @@ openerp_mail_followers = function(session, mail) {
var nb_subtype = 0;
_(records).each(function (record) {nb_subtype++;});
if (nb_subtype > 1) {
+ this.$('hr').show();
_(records).each(function (record, record_name) {
record.name = record_name;
record.followed = record.followed || undefined;
$(session.web.qweb.render('mail.followers.subtype', {'record': record})).appendTo( self.$('.oe_subtype_list') );
});
+ } else {
+ this.$('hr').hide();
}
},
diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml
index c1a32a2fe89..63f8a10658f 100644
--- a/addons/mail/static/src/xml/mail.xml
+++ b/addons/mail/static/src/xml/mail.xml
@@ -132,8 +132,8 @@
<div class="oe_emails_from">
<t t-foreach='widget.emails_from' t-as='email_from'>
<label title="Add them into recipients and followers">
- <input type="checkbox" t-att-checked="email_from[1] ? 'checked' : undefind" t-att-data="email_from[0]"/>
- <t t-raw="email_from[0]"/>
+ <input type="checkbox" t-att-checked="email_from[1] ? 'checked' : undefind" t-att-data="email_from[0][4]"/>
+ <t t-raw="email_from[0][2]"/>
</label>
</t>
</div>
@@ -243,8 +243,8 @@
<t t-if="widget.attachment_ids.length > 0">
<div class="oe_msg_attachment_list"></div>
</t>
- <a t-if="widget.author_id and widget.options.show_link and widget.author_id[0]" t-attf-href="#model=res.partner&amp;id=#{widget.author_id[0]}"><t t-raw="widget.author_id[1]"/></a>
- <span t-if="widget.author_id and (!widget.options.show_link or !widget.author_id[0])"><t t-raw="widget.author_id[1]"/></span>
+ <a t-if="widget.author_id and widget.options.show_link and widget.author_id[0]" t-attf-href="#model=res.partner&amp;id=#{widget.author_id[0]}"><t t-raw="widget.author_id[2]"/></a>
+ <span t-if="widget.author_id and (!widget.options.show_link or !widget.author_id[0])"><t t-raw="widget.author_id[2]"/></span>
<span class='oe_subtle'>•</span>
<span t-att-title="widget.date"><t t-raw="widget.timerelative"/></span>
<span t-if="!widget.options.readonly" class='oe_subtle'>•</span>