[IMP] Thread widget: cleaned links, added reply by e-mail links. Added in mail.compose.message wizard support for a 'message_id' in context have a document with reply behavior. Also cleaned a bit the mail;js code. Updated a detail in a default temporary data in hr_recruitment.

bzr revid: tde@openerp.com-20120510121058-a2emjtvm227603ou
This commit is contained in:
Thibault Delavallée 2012-05-10 14:10:58 +02:00
parent 82dcce2c1d
commit 931302eca0
5 changed files with 98 additions and 56 deletions

View File

@ -9,6 +9,7 @@
<field name="smtp_encryption">starttls</field>
<field name="smtp_port">2525</field>
<field name="smtp_user">tde</field>
<field name="sequence">9</field>
</record>

View File

@ -120,6 +120,10 @@
padding: 5px;
}
.openerp .oe_mail_compose img{
max-height: 25px;
}
/* ------------------------------ */
/* ThreadDisplay */
/* ------------------------------ */
@ -236,10 +240,7 @@
}
.openerp ul.oe_mail_msg_menu {
/*
display: none;
*/
display: block;
position: absolute;
top: 1em;
right: 1em;

View File

@ -4,12 +4,8 @@ openerp.mail = function(session) {
var mail = session.mail = {};
/* Add ThreadDisplay widget to registry */
session.web.form.widgets.add( 'Thread', 'openerp.mail.Thread');
// session.web.page.readonly.add( 'Thread', 'openerp.mail.Thread');
/**
* ThreadDisplay widget: this widget handles the display of a thread of
* Thread widget: this widget handles the display of a thread of
* messages. The [thread_level] parameter sets the thread level number:
* - root message
* - - sub message (parent_id = root message)
@ -18,22 +14,28 @@ openerp.mail = function(session) {
* This widget has 2 ways of initialization, either you give records to be rendered,
* either it will fetch [limit] messages related to [res_model]:[res_id].
*/
/* Add ThreadDisplay widget to registry */
session.web.form.widgets.add( 'Thread', 'openerp.mail.Thread');
/* Thread is an extension of a Widget */
mail.Thread = session.web.Widget.extend({
template: 'Thread',
/**
* @param {Object} parent parent
* @param {Object} [params]
* @param {String} [params.res_model] res_model of mail.thread object
* @param {Number} [params.res_id] res_id of record
* @param {Number} [params.parent_id=false] parent_id of message
* @param {Number} [params.uid] user id
* @param {String} [params.res_model] res_model of document [REQUIRED]
* @param {Number} [params.res_id] res_id of record [REQUIRED]
* @param {Number} [params.uid] user id [REQUIRED]
* @param {Bool} [params.parent_id=false] parent_id of message
* @param {Number} [params.thread_level=0] number of levels in the thread (only 0 or 1 currently)
* @param {Number} [params.msg_more_limit=100] number of character to display before having a "show more" link;
* @param {Bool} [params.wall=false] thread is displayed in the wall
* @param {Number} [params.msg_more_limit=150] number of character to display before having a "show more" link;
* note that the text will not be truncated if it does not have 110% of
* the parameter (ex: 110 characters needed to be truncated and be displayed
* as a 100-characters message)
* @param {Number} [params.limit=10] maximum number of messages to fetch
* @param {Number} [params.limit=100] maximum number of messages to fetch
* @param {Number} [params.offset=0] offset for fetching messages
* @param {Number} [params.records=null] records to show instead of fetching messages
*/
@ -42,7 +44,8 @@ openerp.mail = function(session) {
this.params = params;
this.params.parent_id = this.params.parent_id || false;
this.params.thread_level = this.params.thread_level || 0;
this.params.msg_more_limit = this.params.msg_more_limit || 100;
this.params.wall = this.params.wall || this.params.records || false;
this.params.msg_more_limit = this.params.msg_more_limit || 150;
this.params.limit = this.params.limit || 100;
this.params.offset = this.params.offset || 0;
this.params.records = this.params.records || null;
@ -55,11 +58,13 @@ openerp.mail = function(session) {
// display customization vars
this.display = {};
this.display.show_post_comment = this.params.show_post_comment || false;
this.display.show_msg_menu = this.params.wall;
this.display.show_reply = (this.params.thread_level > 0);
this.display.show_delete = true;
this.display.show_hide = this.params.show_hide || false;
this.display.show_delete = ! this.params.wall;
this.display.show_hide = this.params.wall;
this.display.show_reply_by_email = ! this.params.wall;
this.display.show_more = (this.params.thread_level == 0);
// not used currently
// internal links mapping
this.intlinks_mapping = {};
},
@ -96,7 +101,6 @@ openerp.mail = function(session) {
});
// event: click on 'delete' in msg
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_delete', 'click', function (event) {
//console.log('deleting');
if (! confirm(_t("Do you really want to delete this message?"))) { return false; }
var msg_id = event.srcElement.dataset.id;
if (! msg_id) return false;
@ -109,11 +113,9 @@ openerp.mail = function(session) {
});
// event: click on 'hide' in msg
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_hide', 'click', function (event) {
//console.log('hiding');
if (! confirm(_t("Do you really want to hide this thread ?"))) { return false; }
var msg_id = event.srcElement.dataset.id;
if (! msg_id) return false;
//console.log(msg_id);
var call_defer = self.ds.call('message_remove_pushed_notifications', [[self.params.res_id], [parseInt(msg_id)], true]);
$(event.srcElement).parents('li.oe_mail_thread_msg').eq(0).hide();
if (self.params.thread_level > 0) {
@ -121,14 +123,33 @@ openerp.mail = function(session) {
}
return false;
});
// event: click on 'hide notification' in wheel_menu
// event: click on "reply by email" in msg
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_reply_by_email', 'click', function (event) {
console.log('reply by e-mail');
var msg_id = event.srcElement.dataset.id;
if (! msg_id) return false;
self.do_action({
type: 'ir.actions.act_window',
res_model: 'mail.compose.message',
views: [[false, 'form']],
view_type: 'form',
view_mode: 'form',
target: 'new',
context: {'active_model': self.params.res_model, 'active_id': self.params.res_id, 'message_id': msg_id, 'mail.compose.message.mode': 'reply'},
key2: 'client_action_multi',
});
return false;
});
// event: click on the wheel menu in messages
this.$element.find('div.oe_mail_thread_display').delegate('img.oe_mail_msg_menu_icon', 'click', function (event) {
self.$element.find('ul.oe_mail_msg_menu').toggle();
});
// event: click on 'hide' in wheel_menu
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_hide_thread', 'click', function (event) {
console.log('hiding notification');
if (! confirm(_t("Do you really want to hide this thread ?"))) { return false; }
var msg_id = event.srcElement.dataset.id;
if (! msg_id) return false;
console.log(msg_id);
//var call_defer = self.ds.call('message_remove_pushed_notifications', [[self.params.res_id], [parseInt(msg_id)], true]);
var call_defer = self.ds.call('message_remove_pushed_notifications', [[self.params.res_id], [parseInt(msg_id)], true]);
$(event.srcElement).parents('li.oe_mail_thread_msg').eq(0).hide();
if (self.params.thread_level > 0) {
$(event.srcElement).parents('ul.oe_mail_thread').eq(0).hide();
@ -137,11 +158,11 @@ openerp.mail = function(session) {
});
// event: click on 'hide this type' in wheel_menu
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_hide_type', 'click', function (event) {
//console.log('hiding type');
if (! confirm(_t("Do you really want to hide this thread ?"))) { return false; }
console.log('hiding type');
if (! confirm(_t("Do you really want to hide this type of thread ?"))) { return false; }
var subtype = event.srcElement.dataset.subtype;
if (! subtype) return false;
//console.log(subtype);
console.log(subtype);
var call_defer = self.ds.call('message_subscription_hide', [[self.params.res_id], subtype]);
$(event.srcElement).parents('li.oe_mail_thread_msg').eq(0).hide();
if (self.params.thread_level > 0) {
@ -168,13 +189,8 @@ openerp.mail = function(session) {
}
else self.do_action({ type: 'ir.actions.act_window', res_model: res_model, res_id: parseInt(res_id), views: [[false, 'form']]});
});
// event: click on the wheel menu in messages
this.$element.find('div.oe_mail_thread_display').delegate('img.oe_mail_msg_menu_icon', 'click', function (event) {
self.$element.find('ul.oe_mail_msg_menu').toggle();
});
// event: click on "send an email"
this.$element.find('div.oe_mail_thread_act').delegate('a.oe_mail_compose', 'click', function (event) {
console.log('cacaprout');
self.do_action({
type: 'ir.actions.act_window',
res_model: 'mail.compose.message',
@ -182,12 +198,11 @@ openerp.mail = function(session) {
view_type: 'form',
view_mode: 'form',
target: 'new',
context: {'active_model': self.params.res_model, 'active_id': self.params.res_id, 'mail.compose.message.mode': 'new'},
context: {'active_model': self.params.res_model, 'active_id': self.params.res_id, 'mail.compose.message.mode': 'document'},
key2: 'client_action_multi',
});
return false;
});
},
destroy: function () {
@ -271,6 +286,8 @@ openerp.mail = function(session) {
record.body = this.do_clean_text(record.body);
record.tr_body = this.do_truncate_string(record.body, this.params.msg_more_limit);
record.body = this.do_replace_internal_links(record.body);
console.log(record.body);
console.log(record.tr_body);
if (record.tr_body) record.tr_body = this.do_replace_internal_links(record.tr_body);
// format date according to the user timezone
record.date = session.web.format_value(record.date, {type:"datetime"});
@ -781,7 +798,11 @@ openerp.mail = function(session) {
},
});
/**
* TOOLS
*/
/**
* Add records to sorted_comments array
* @param {Array} records records from mail.message sorted by date desc

View File

@ -45,11 +45,14 @@
<ul t-name="Thread" class="oe_mail oe_mail_thread">
<div class="oe_mail_thread_act">
<a href="#" class="oe_mail_compose">Repley by e-mail</a><br />
<img class="oe_mail_msg_image oe_mail_oe_left" alt="User img"/>
<div class="oe_mail_msg_content">
<textarea class="oe_mail oe_mail_action_textarea" placeholder="Add your comment here..." onfocus="this.value = '';"/><br />
</div>
<p><a href="#" class="oe_mail_compose oe_mail_oe_right">
Send an e-mail
<img src='/mail/static/src/img/email_icon.png' alt='Send an e-mail'/>
</a></p>
</div>
<div class="oe_mail_thread_display"></div>
<div class="oe_mail_thread_more">
@ -67,8 +70,10 @@
</ul>
<img class="oe_mail_msg_image oe_mail_oe_left" t-att-src="record.mini_url"/>
<div class="oe_mail_msg_content">
<t t-if="record.type == 'email'"><t t-call="EmailDisplay" /></t>
<t t-if="record.type == 'notification' || record.type == 'comment'"><t t-call="NoteDisplay" /></t>
<t t-if="record.type == 'email'"><t t-call="EmailDisplay"/></t>
<t t-if="record.type == 'notification' || record.type == 'comment'"><t t-call="NoteDisplay"/></t>
<br />Message-id: <t t-esc="record.message_id"/>
<br />References: <t t-esc="record.references"/>
</div>
<t t-if="record.type == 'tmp'"><t t-call="ThreadDisplay" /></t>
</div>
@ -86,13 +91,9 @@
<a href="#" class="intlink oe_mail_oe_intlink" data-res-model='res.users' t-attf-data-res-id='{record.user_id[0]}'><t t-raw="record.user_id[1]"/></a>
on <t t-raw="record.date"/>
</span>
<t t-if="display['show_reply']"><a href="#" class="oe_mail_oe_space oe_mail_msg_reply oe_mail_oe_intlink"> Reply</a> </t>
<t t-if="display['show_delete']">
<t t-if="thread._is_author(record.user_id[0])"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_oe_space oe_mail_msg_delete oe_mail_oe_intlink"> Delete </a></t>
</t>
<t t-if="display['show_hide']">
<t t-if="!(thread._is_author(record.user_id[0]))"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_oe_space oe_mail_msg_hide oe_mail_oe_intlink">Hide</a></t>
</t>
<span class="oe_mail_oe_right">
<t t-call="MessageDisplayManageLinks"/>
</span>
</p>
</t>
@ -101,7 +102,6 @@
<t t-if="params.thread_level > 0">
<a href="#" class="intlink oe_mail_oe_intlink" t-attf-data-res-model='{params.res_model}' t-attf-data-res-id='{params.res_id}'><t t-raw="record.record_name"/></a>
</t>
<br />
<span class="oe_mail_oe_bold">From:</span> <t t-esc="record.email_from"/> on <span class="oe_mail_oe_fade"><t t-raw="record.date"/></span><br />
<span class="oe_mail_oe_bold">To:</span> <t t-esc="record.email_to"/><br />
<span class="oe_mail_oe_bold">Subject:</span> <t t-esc="record.subject"/><br />
@ -110,13 +110,25 @@
<span class="oe_mail_msg_body"><t t-raw="record.body"/></span>
<t t-if="record.tr_body"><span class="oe_mail_msg_body_short"><t t-raw="record.tr_body"/></span></t>
<br />
<t t-if="display['show_delete']">
<t t-if="thread._is_author(record.user_id[0])"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_delete oe_mail_oe_intlink"> Delete </a></t>
</t>
<t t-if="display['show_hide']">
<t t-if="!(thread._is_author(record.user_id[0]))"><span class="oe_mail_oe_space"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_hide oe_mail_oe_intlink">Hide</a></span></t>
</t>
<span class="oe_mail_oe_right">
<t t-call="MessageDisplayManageLinks"/>
</span>
</p>
</t>
<t t-name="MessageDisplayManageLinks">
<t t-if="display['show_reply']">
<a href="#" class="oe_mail_oe_space oe_mail_oe_intlink oe_mail_msg_reply">Reply</a>
</t>
<t t-if="display['show_delete']"><t t-if="thread._is_author(record.user_id[0])">
<a href="#" t-attf-data-id='{record.id}' class="oe_mail_oe_space oe_mail_oe_intlink oe_mail_msg_delete">Delete</a>
</t></t>
<t t-if="display['show_hide']">
<a href="#" t-attf-data-id='{record.id}' class="oe_mail_oe_space oe_mail_oe_intlink oe_mail_msg_hide">Remove from Wall</a>
</t>
<t t-if="display['show_reply_by_email']"><t t-if="record.type == 'email'">
<a href="#" t-attf-data-id='{record.id}' class="oe_mail_oe_space oe_mail_oe_intlink oe_mail_msg_reply_by_email">Reply by e-mail</a>
</t></t>
</t>
</template>

View File

@ -67,7 +67,6 @@ class mail_compose_message(osv.osv_memory):
:param dict context: several context values will modify the behavior
of the wizard, cfr. the class description.
"""
print context
if context is None:
context = {}
result = super(mail_compose_message, self).default_get(cr, uid, fields, context=context)
@ -76,14 +75,22 @@ class mail_compose_message(osv.osv_memory):
if (not reply_mode) and context.get('active_model') and context.get('active_id'):
# normal mode when sending an email related to any document, as specified by
# active_model and active_id in context
vals = self.get_value(cr, uid, context.get('active_model'), context.get('active_id'), context)
# if a message_id is specified in context, this means we send an e-mail related
# to a document, but based on a previous e-mail
if context.get('message_id'):
vals = self.get_message_data(cr, uid, int(context['message_id']), context=context)
vals.update(self.get_value(cr, uid, context.get('active_model'), context.get('active_id'), context))
elif reply_mode and context.get('active_id'):
# reply mode, consider active_id is the ID of a mail.message to which we're
# replying
vals = self.get_message_data(cr, uid, int(context['active_id']), context)
if context.get('message_id'):
vals = self.get_message_data(cr, uid, int(context['message_id']), context=context)
else:
vals = self.get_message_data(cr, uid, int(context['active_id']), context)
else:
# default mode
result['model'] = context.get('active_model', False)
for field in vals:
if field in fields:
result.update({field : vals[field]})