[IMP] mail chatter: compose mail in js, less request

bzr revid: chm@openerp.com-20121005104654-t5lholex2gh11y15
This commit is contained in:
Christophe Matthieu 2012-10-05 12:46:54 +02:00
parent c5ac7217a8
commit df5071c896
10 changed files with 372 additions and 433 deletions

View File

@ -39,7 +39,7 @@
attrs="{'invisible':[('use_template','=',False)]}"
on_change="onchange_template_id(use_template, template_id, composition_mode, model, res_id, context)"/>
</xpath>
<xpath expr="//button[@class='oe_mail_compose_message_attachment']" position="before">
<xpath expr="//button[@name='dummy']" position="before">
<button icon="/email_template/static/src/img/email_template.png"
type="object" name="toggle_template" string=""
help="Use a message template"

View File

@ -151,6 +151,7 @@ class mail_message(osv.Model):
'date': lambda *a: fields.datetime.now(),
'author_id': lambda self, cr, uid, ctx={}: self._get_default_author(cr, uid, ctx),
'body': '',
'is_private': True,
}
#------------------------------------------------------
@ -495,13 +496,6 @@ class mail_message(osv.Model):
self.write(cr, SUPERUSER_ID, [newid], {'partner_ids': [(4, p_id) for p_id in missing_notified]}, context=context)
partners_to_notify |= extra_notified
# add myself if I wrote on my wall,
# unless remove myself author
if ((message.model=="res.partner" and message.res_id==message.author_id.id)):
self.write(cr, SUPERUSER_ID, [newid], {'partner_ids': [(4, message.author_id.id)]}, context=context)
else:
self.write(cr, SUPERUSER_ID, [newid], {'partner_ids': [(3, message.author_id.id)]}, context=context)
def _notify(self, cr, uid, newid, context=None):
""" Add the related record followers to the destination partner_ids if is not a private message.
Call mail_notification.notify to manage the email sending
@ -510,6 +504,13 @@ class mail_message(osv.Model):
if message and (message.is_private!=False and message.is_private!=None):
self._notify_followers(cr, uid, newid, message, context=context)
# add myself if I wrote on my wall,
# unless remove myself author
if ((message.model=="res.partner" and message.res_id==message.author_id.id)):
self.write(cr, SUPERUSER_ID, [newid], {'partner_ids': [(4, message.author_id.id)]}, context=context)
else:
self.write(cr, SUPERUSER_ID, [newid], {'partner_ids': [(3, message.author_id.id)]}, context=context)
self.pool.get('mail.notification')._notify(cr, uid, newid, context=context)
def copy(self, cr, uid, id, default=None, context=None):

View File

@ -87,29 +87,22 @@
<record id="action_mail_inbox_feeds" model="ir.actions.client">
<field name="name">Inbox</field>
<field name="tag">mail.wall</field>
<field name="params" eval="&quot;{'domain': [('is_private','=',True),('notification_ids.partner_id.user_ids', 'in', [uid]),('unread', '=', True)],
'context': {'default_model': 'res.partner', 'default_res_id': uid, 'default_is_private':True} }&quot;"/>
</record>
<record id="action_mail_wall_feeds" model="ir.actions.client">
<field name="name">Wall</field>
<field name="tag">mail.wall</field>
<field name="params" eval="&quot;{'domain': [('is_private','=',False),('notification_ids.partner_id.user_ids', 'in', [uid]),('unread', '=', True)],
'context': {'default_model': 'res.partner', 'default_res_id': uid, 'default_is_private':False} }&quot;"/>
<field name="params" eval="&quot;{'domain': [('notification_ids.partner_id.user_ids', 'in', [uid]),('unread', '=', True)],
'context': {'default_model': 'res.partner'} }&quot;"/>
</record>
<record id="action_mail_archives_feeds" model="ir.actions.client">
<field name="name">Archives</field>
<field name="tag">mail.wall</field>
<field name="params" eval="&quot;{'domain': [('notification_ids.partner_id.user_ids', 'in', [uid]),('unread', '=', False)],
'context': {'default_model': 'res.partner', 'default_res_id': uid} }&quot;"/>
'context': {'default_model': 'res.partner'} }&quot;"/>
</record>
<record id="action_mail_sent_feeds" model="ir.actions.client">
<field name="name">Sent</field>
<field name="tag">mail.wall</field>
<field name="params" eval="&quot;{'domain': [('author_id.user_ids', 'in', [uid])],
'context': {'default_model': 'res.partner', 'default_res_id': uid} }&quot;"/>
'context': {'default_model': 'res.partner'} }&quot;"/>
</record>
</data>
</openerp>

View File

@ -696,10 +696,14 @@ class mail_thread(osv.AbstractModel):
def message_post_api(self, cr, uid, thread_id, body='', subject=False, type='notification',
subtype=None, parent_id=False, attachments=None, context=None, **kwargs):
# if the user write on his wall
if self._name=='res.partner' and (not thread_id or not thread_id[0]):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
thread_id = user.partner_id.id
added_message_id = self.message_post(cr, uid, thread_id=thread_id, body=body, subject=subject, type=type,
subtype=subtype, parent_id=parent_id, attachments=attachments, context=context)
added_message = self.pool.get('mail.message').message_read(cr, uid, [added_message_id])
return added_message
def get_message_subtypes(self, cr, uid, ids, context=None):

View File

@ -18,12 +18,6 @@
<field name="action" ref="action_mail_inbox_feeds"/>
<field name="parent_id" ref="mail_feeds"/>
</record>
<record id="mail_wallfeeds" model="ir.ui.menu">
<field name="name">Wall</field>
<field name="sequence" eval="11"/>
<field name="action" ref="action_mail_wall_feeds"/>
<field name="parent_id" ref="mail_feeds"/>
</record>
<record id="mail_archivesfeeds" model="ir.ui.menu">
<field name="name">Archives</field>
<field name="sequence" eval="12"/>

View File

@ -173,41 +173,6 @@
clear: both;
}
.openerp .oe_mail .oe_mail_compose_textarea .oe_mail_post_header .oe_all_follower {
color: blue;
}
.openerp .oe_mail .oe_mail_compose_textarea .oe_mail_post_header .oe_partner_follower a {
color: red;
}
.openerp .oe_mail .oe_mail_compose_textarea .oe_mail_post_header .oe_hidden,
.openerp .oe_mail .oe_mail_compose_textarea .oe_mail_post_header .oe_more_hidden {
display: none;
}
.openerp .oe_mail .oe_mail_compose_textarea .oe_mail_post_bottom button.post {
float: left;
}
.openerp .oe_mail .oe_mail_compose_textarea .oe_mail_post_bottom span {
float: right;
}
/* default textarea (oe_mail_compose_textarea), and body textarea for compose form view */
.openerp .oe_mail.oe_semantic_html_override .oe_mail_compose_textarea textarea,
.openerp .oe_mail div.oe_mail_compose_message_body textarea {
width: 474px;
min-height: 120px;
height: auto;
padding: 4px;
font-size: 12px;
border: 1px solid #cccccc;
}
/* not top textarea */
.openerp .oe_mail.oe_semantic_html_override .oe_semantic_html_override .oe_mail_compose_textarea textarea {
height: 60px;
}
/* default textarea (oe_mail_compose_textarea), and body textarea for compose form view */
.openerp .oe_mail_msg_content textarea.oe_mail_compose_textarea:focus,
.openerp .oe_mail_msg_content div.oe_mail_compose_message_body textarea:focus {
@ -334,76 +299,6 @@
display: none;
}
/* ------------------------------------------------------------ */
/* mail.compose.message form view & OpenERP hacks
/* ------------------------------------------------------------ */
/* form_view: delete white background */
.openerp .oe_mail_msg_content div.oe_formview {
background-color: transparent;
}
.openerp .oe_mail_msg_content div.oe_form_nosheet {
margin: 0px;
}
.openerp .oe_mail_msg_content table.oe_form_group {
margin: 0px;
}
.openerp .oe_mail_msg_content table.oe_form_field,
.openerp .oe_mail_msg_content div.oe_form_field {
padding: 0px;
}
.openerp .oe_mail_msg_content td.oe_form_group_cell {
vertical-align: bottom;
}
/* subject: change width */
.openerp .oe_mail_msg_content .oe_form .oe_form_field input {
width: 472px;
}
/* body_html: cleditor */
.openerp .oe_mail_msg_content div.cleditorMain {
border: 1px solid #cccccc;
}
/* destination_partner_ids */
.openerp .oe_mail_msg_content div.text-core {
height: 22px !important;
width: 472px;
}
/* buttons */
.openerp .oe_mail_msg_content .oe_mail_compose_message_icons button.oe_form_button {
padding: 1px;
}
/* attachment button: override of openerp values */
.openerp .oe_mail_msg_content .oe_mail_compose_message_icons div.oe_hidden_input_file {
display: inline-block;
width: 24px;
height: 24px;
margin: 2px;
}
.openerp .oe_mail_msg_content .oe_mail_compose_message_icons div.oe_hidden_input_file button {
margin: 0px;
}
.openerp .oe_mail_msg_content .oe_mail_compose_message_icons input.oe_form_binary_file {
bottom: 0px;
top: auto;
left: auto;
right: 0;
height: 26px;
width: 26px;
min-width: 22px;
font-size: 0px;
margin: 0px;
padding: 0px;
}
/* ------------------------------------------------------------ */
/* Messages layout
/* ------------------------------------------------------------ */
@ -485,13 +380,14 @@
/* Attachments list */
.openerp .oe_mail_msg_content ul.oe_mail_msg_attachments {
display: none;
width: 100%;
border-top: 1px solid #CCC;
margin: .5em 0 0 0;
padding: .5em 0;
list-style-position: inside;
}
.openerp .oe_mail_msg_content ul.oe_mail_msg_attachments.oe_hidden {
display: none;
}
.openerp .oe_mail_msg_content ul.oe_mail_msg_attachments li {
float: none;
margin: 0;

View File

@ -1,12 +1,142 @@
/* ------------------------------ */
/* Compose Message Wizard Form */
/* Compose Message */
/* ------------------------------ */
.openerp .oe_mail_compose_message_icons {
text-align: right;
.openerp .oe_mail_msg_content .oe_mail_compose_message_footer {
height: 24px;
}
.openerp .oe_mail_compose_message_icons img {
width: 20px;
height: 20px;
.openerp .oe_mail_msg_content .oe_mail_compose_message_footer button.oe_mail_compose_message_button_send {
float: left;
}
.openerp .oe_mail .oe_mail_compose_textarea .oe_mail_post_header,
.openerp .oe_mail .oe_mail_compose_textarea .oe_mail_post_footer,
{
position: relative;
}
/* ------------------------------------------------------------ */
/* mail.compose.message : list_recipients
/* ------------------------------------------------------------ */
.openerp .oe_mail .oe_mail_list_recipients {
display: inline;
}
.openerp .oe_mail .oe_mail_list_recipients .oe_all_follower {
color: blue;
}
.openerp .oe_mail .oe_mail_list_recipients .oe_partner_follower a {
color: red;
}
.openerp .oe_mail .oe_mail_list_recipients .oe_hidden,
.openerp .oe_mail .oe_mail_list_recipients .oe_more_hidden {
display: none;
}
/* ------------------------------------------------------------ */
/* mail.compose.message : attachment
/* ------------------------------------------------------------ */
.openerp .oe_mail .oe_attachment_file {
display: inline-block;
}
.openerp .oe_mail .oe_attachment_file .oe_add {
float: left;
width: 24px;
height: 24px;
position: relative;
z-index: 10;
left: +2px;
top: +7px;
overflow: hidden;
}
/* attachment button: override of openerp values */
.openerp .oe_mail .oe_attachment_file .oe_add button,
.openerp .oe_mail .oe_attachment_file .oe_add input.oe_insert_file {
position: absolute;
bottom: +0px;
left: +0px;
height: 24px;
width: 24px;
margin: 0px;
padding: 0px;
}
.openerp .oe_mail .oe_attachment_file .oe_add input.oe_insert_file {
z-index:2;
width: 300px;
left: -100px;
background: transparent;
border: 0;
color: transparent;
}
.openerp .oe_mail .oe_attachment_file .oe_add button span {
position: relative;
bottom: +4px;
font-size: 30px;
}
.openerp .oe_mail .oe_mail_msg_attachments input {
visibility: hidden;
}
/* ------------------------------------------------------------ */
/* mail.compose.message
/* ------------------------------------------------------------ */
/* default textarea (oe_mail_compose_textarea), and body textarea for compose form view */
.openerp .oe_mail.oe_semantic_html_override .oe_mail_compose_textarea textarea.field_text,
.openerp .oe_mail div.oe_mail_compose_message_body textarea.field_text {
width: 474px;
min-height: 120px;
height: auto;
padding: 4px;
font-size: 12px;
border: 1px solid #cccccc;
}
/* not top textarea */
.openerp .oe_mail.oe_semantic_html_override .oe_semantic_html_override .oe_mail_compose_textarea textarea.field_text {
height: 60px;
}
/* form_view: delete white background */
.openerp .oe_mail_msg_content div.oe_formview {
background-color: transparent;
}
.openerp .oe_mail_msg_content div.oe_form_nosheet {
margin: 0px;
}
.openerp .oe_mail_msg_content table.oe_form_group {
margin: 0px;
}
.openerp .oe_mail_msg_content table.oe_form_field,
.openerp .oe_mail_msg_content div.oe_form_field {
padding: 0px;
}
.openerp .oe_mail_msg_content td.oe_form_group_cell {
vertical-align: bottom;
}
/* subject: change width */
.openerp .oe_mail_msg_content .oe_form .oe_form_field input[type='text'] {
width: 472px;
}
/* body_html: cleditor */
.openerp .oe_mail_msg_content div.cleditorMain {
border: 1px solid #cccccc;
}
/* destination_partner_ids */
.openerp .oe_mail_msg_content div.text-core {
height: 22px !important;
width: 472px;
}

View File

@ -84,16 +84,17 @@ openerp.mail = function(session) {
* This widget handles the display of a form to compose a new message.
* This form is a mail.compose.message form_view.
*/
mail.ComposeMessage = session.web.Widget.extend({
template: 'mail.compose_message',
/**
* @param {Object} parent parent
* @param {Object} [options]
* @param {Object} [options.context] context passed to the
* mail.compose.message DataSetSearch. Please refer to this model
* for more details about fields and default values.
* @param {Object} [context] context passed to the
* mail.compose.message DataSetSearch. Please refer to this model
* for more details about fields and default values.
* @param {Boolean} [show_attachment_delete]
*/
init: function (parent, options) {
var self = this;
@ -102,118 +103,43 @@ openerp.mail = function(session) {
// options
this.options = options || {};
this.options.context = options.context || {};
this.options.form_xml_id = options.form_xml_id || 'email_compose_message_wizard_form_chatter';
this.options.form_view_id = options.form_view_id || false;
this.options.show_attachment_delete = options.show_attachment_delete || false;
this.id = options.parameters.id;
this.model = options.parameters.model;
this.is_private = options.parameters.is_private;
this.partner_ids = options.parameters.partner_ids;
this.attachment_ids = [];
this.show_attachment_delete = true;
this.show_attachment_link = false;
},
start: function () {
this._super.apply(this, arguments);
// customize display: add avatar, clean previous content
start: function(){
var self = this;
this.display_attachments();
self.bind_events();
var user_avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid);
this.$('img.oe_mail_icon').attr('src', user_avatar);
this.$('div.oe_mail_msg_content').empty();
// create a context for the dataset and default_get of the wizard
var context = _.extend({}, this.options.context);
this.ds_compose = new session.web.DataSetSearch(this, 'mail.compose.message', context);
// find the id of the view to display in the chatter form
if (this.options.form_view_id) {
return this.create_form_view();
}
else {
var data_ds = new session.web.DataSetSearch(this, 'ir.model.data');
return data_ds.call('get_object_reference', ['mail', this.options.form_xml_id]).pipe(this.proxy('create_form_view'));
}
},
/** Create a FormView, then append it to the to widget DOM. */
create_form_view: function (new_form_view_id) {
display_attachments: function(){
var self = this;
this.options.form_view_id = (new_form_view_id && new_form_view_id[1]) || this.options.form_view_id;
// destroy previous form_view if any
if (this.form_view) { this.form_view.destroy(); }
// create the FormView
this.form_view = new session.web.FormView(this, this.ds_compose, this.options.form_view_id, {
action_buttons: false,
pager: false,
initial_mode: 'edit',
disable_autofocus: true,
});
// add the form, bind events, activate the form
var msg_node = this.$('div.oe_mail_msg_content');
return $.when(this.form_view.appendTo(msg_node)).pipe(this.proxy('postprocess_create_form_view'));
},
postprocess_create_form_view: function () {
// handle attachment button
this.fileupload_id = _.uniqueId('oe_fileupload');
var button_attach = this.$('button.oe_mail_compose_message_attachment');
var rendered = $( session.web.qweb.render('mail.compose_message.add_attachment', {'widget': this}) );
rendered.insertBefore(button_attach);
// move the button inside div.oe_hidden_input_file
var input_node = this.$('input[name=ufile]');
button_attach.detach().insertAfter(input_node);
// set the function called when attachments are added
this.$('input.oe_form_binary_file').change(this.on_attachment_change);
this.bind_events();
this.form_view.do_show();
},
on_attachment_change: function (event) {
var $target = $(event.target);
if ($target.val() !== '') {
this.$('form.oe_form_binary_form').submit();
session.web.blockUI();
var render = $(session.web.qweb.render('mail.thread.message.attachments', {'widget': self}));
if(!this.list_attachment){
this.$('.oe_mail_compose_attachment_list').replaceWith( render );
} else {
this.list_attachment.replaceWith( render );
}
this.list_attachment = this.$("ul.oe_mail_msg_attachments");
// event: delete an attachment
this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete);
},
on_attachment_delete: function (event) {
if (event.target.dataset && event.target.dataset.id) {
var attachment_id = parseInt(event.target.dataset.id);
var idx = _.pluck(this.attachment_ids, 'id').indexOf(attachment_id);
if (idx == -1) return false;
new session.web.DataSetSearch(this, 'ir.attachment').unlink(attachment_id);
this.attachment_ids.splice(idx, 1);
this.display_attachments();
}
},
display_attachments: function () {
var attach_node = this.$('div.oe_mail_compose_message_attachments');
var rendered = session.web.qweb.render('mail.thread.message.attachments', {'record': this});
attach_node.empty();
$(rendered).appendTo(attach_node);
this.$('.oe_mail_msg_attachments').show();
var composer_attachment_ids = _.pluck(this.attachment_ids, 'id');
var onchange_like = {'value': {'attachment_ids': composer_attachment_ids}}
this.form_view.on_processed_onchange(onchange_like, []);
},
/**
* Reinitialize the widget field values to the default values obtained
* using default_get on mail.compose.message. This allows to reinitialize
* the widget without having to rebuild a complete form view.
* @param {Object} new_context: context of the refresh */
refresh: function (new_context) {
if (! this.form_view) return;
var self = this;
this.attachments = [];
this.options.context = _.extend(this.options.context, new_context || {});
this.ds_compose.context = _.extend(this.ds_compose.context, this.options.context);
return this.ds_compose.call('default_get', [
['subject', 'body_text', 'body', 'partner_ids', 'composition_mode',
'use_template', 'template_id', 'model', 'res_id', 'parent_id', 'content_subtype'],
this.ds_compose.get_context(),
]).then( function (result) {
self.form_view.on_processed_onchange({'value': result}, []);
self.attachment_ids = [];
self.display_attachments();
});
},
/**
* Bind events in the widget. Each event is slightly described
* in the function. */
bind_events: function() {
var self = this;
// event: add a new attachment
@ -225,11 +151,54 @@ openerp.mail = function(session) {
self.display_attachments();
session.web.unblockUI();
});
// event: delete an attachment
this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete);
// set the function called when attachments are added
this.$el.on('change', 'input.oe_insert_file', self.on_attachment_change);
},
}),
on_attachment_change: function (event) {
event.stopPropagation();
var $target = $(event.target);
if ($target.val() !== '') {
//session.web.blockUI();
var id = _.uniqueId('oe_fileupload');
this.attachment_ids.push({
'url': $target.val(),
'filename' : $target.val().replace(/.*[\/\\]/,''),
'id': id
});
$newfield = $target.clone();
$newfield.insertAfter($target);
$target.hide();
$target.attr("id",id);
this.display_attachments();
}
},
on_attachment_delete: function (event) {
event.stopPropagation();
var id=$(event.target).data("id");
if (id) {
var attachments=[];
for(var i in this.attachment_ids){
if(id!=this.attachment_ids[i].id)
attachments.push(this.attachment_ids[i]);
}
this.attachment_ids = attachments;
this.$("input#"+id).remove();
/*
var attachment_id = parseInt(event.target.dataset.id);
var idx = _.pluck(this.attachment_ids, 'id').indexOf(attachment_id);
if (idx == -1) return false;
new session.web.DataSetSearch(this, 'ir.attachment').unlink(attachment_id);
this.attachment_ids.splice(idx, 1);
*/
this.display_attachments();
}
},
});
/**
* ------------------------------------------------------------
@ -263,7 +232,6 @@ openerp.mail = function(session) {
// record options and data
this.parent_thread= parent.messages!= undefined ? parent : options.options.thread._parents[0] ;
},
@ -285,7 +253,7 @@ openerp.mail = function(session) {
* @param {object} mouse envent
*/
on_expandable: function (event) {
event.stopPropagation();
if(event)event.stopPropagation();
this.parent_thread.message_fletch(false, this.domain, this.context);
this.destroy();
return false;
@ -361,7 +329,7 @@ openerp.mail = function(session) {
this._date = param.date;
this.author_id = param.author_id || [];
this.attachment_ids = param.attachment_ids || [];
// record domain and context
this.domain = options.domain || [];
this.context = _.extend({
@ -439,21 +407,13 @@ openerp.mail = function(session) {
// event: click on 'Reply' in msg
this.$el.on('click', 'a.oe_reply', this.on_message_reply);
// event: click on 'Reply by email' in msg side menu
this.$el.on('click', 'a.oe_reply_by_email', this.on_message_reply_by_mail);
// event: click on 'Vote' button
this.$el.on('click', 'button.oe_mail_msg_vote', this.on_vote);
},
on_message_reply:function(event){
event.stopPropagation();
this.thread.on_compose_message($(event.srcElement).hasClass("oe_full_reply"), false);
return false;
},
on_message_reply_by_mail:function(event){
event.stopPropagation();
this.thread.on_compose_message(true, true);
this.thread.on_compose_message();
return false;
},
@ -670,6 +630,7 @@ openerp.mail = function(session) {
this.model= param.model || false;
this.parent_id= param.parent_id || false;
this.is_private = param.is_private || false;
this.author_id = param.author_id || false;
this.partner_ids = [];
for(var i in param.partner_ids){
if(param.partner_ids[i][0]!=(param.author_id ? param.author_id[0] : -1)){
@ -694,7 +655,12 @@ openerp.mail = function(session) {
var display_done = compose_done = false;
// add message composition form view
compose_done = this.instantiate_composition_form();
this.ComposeMessage = new mail.ComposeMessage(this,{
'context': this.context,
'parameters': this,
'show_attachment_delete': true,
});
this.ComposeMessage.appendTo(this.$(".oe_mail_thread_action:first"));
this.bind_events();
@ -710,7 +676,6 @@ openerp.mail = function(session) {
* Normally it should be called only when clicking on 'Post/Send'
* in the composition form. */
do_action: function(action, on_close) {
this.instantiate_composition_form();
this.message_fletch(false, false, false, [action.id]);
return this._super(action, on_close);
},
@ -718,10 +683,40 @@ openerp.mail = function(session) {
/* this method is runing for first parent thread
*/
on_first_thread: function(){
var self=this;
// fetch and display message, using message_ids if set
display_done = this.message_fletch(true);
//show the first write message
this.$(">.oe_mail_thread_action").show();
self.$(">.oe_mail_thread_action").show();
$(document).scroll( self.on_scroll );
window.setTimeout( self.on_scroll, 500 );
},
/* When the expandable object is visible on screen (with scrolling)
* then the on_expandable function is launch
*/
on_scroll: function(event){
if(event)event.stopPropagation();
var last=this.messages[0];
if(last && last.type=="expandable"){
var pos = last.$el.position();
if(pos.top){
/* bottom of the screen */
var bottom = $(window).scrollTop()+$(window).height()+100;
if(bottom - pos.top > 0){
last.on_expandable();
}
}
}
},
on_attachment_change: function (event) {
var $target = $(event.target);
if ($target.val() !== '') {
this.$('form.oe_form_binary_form').submit();
session.web.blockUI();
}
},
/**
@ -794,43 +789,9 @@ openerp.mail = function(session) {
return this.options.thread._parents[0].messages[0].browse_message(options);
},
/** Instantiate the composition form, with every parameters in context
* or in the widget context.
* @param {object}
* @param {boolean} show_header_compose, force to instantiate form
*/
instantiate_composition_form: function(context) {
// add message composition form view
if ((!context || !context.show_header_compose) &&
(!this.options.thread.show_header_compose || !this.options.thread.use_composer ||
(this.options.thread.show_header_compose <= this.options.thread._parents.length && this.options.thread._parents[0]!=this))) {
this.$("textarea:first").val("");
return false;
}
if (this.compose_message_widget) {
this.compose_message_widget.refresh();
} else {
var context = _.extend(context || {}, this.context);
this.compose_message_widget = new mail.ComposeMessage(this, {'context': context});
var composition_node = this.$('div.oe_mail_thread_action');
composition_node.empty();
return this.compose_message_widget.appendTo(composition_node);
}
},
/* this function is launch when a user click on "Reply" button
*/
on_compose_message: function(full_reply, by_mail){
if(full_reply){
this.instantiate_composition_form({'show_header_compose':true});
}
if(by_mail){
if (!this.compose_message_widget) return true;
this.compose_message_widget.refresh({
'default_composition_mode': 'reply',
'default_parent_id': this.id,
'default_content_subtype': 'html'} );
}
on_compose_message: function(){
this.$('div.oe_mail_thread_action:first').toggle();
return false;
},
@ -953,19 +914,6 @@ openerp.mail = function(session) {
return message
},
/* Hide messages if they are more message that _expandable_max
* display "show more messages"
*/
display_expandable: function(){
if(this.messages.length>this.options._expandable_max){
this.list_ul.find('>li:gt('+(this.options._expandable_max-1)+')').hide();
this.more_msg.show();
} else {
this.list_ul.find('>li').show();
this.more_msg.hide();
}
},
display_user_avatar: function () {
var avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid);
return this.$('img.oe_mail_icon').attr('src', avatar);

View File

@ -1,11 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<!--
mail.compose_message template
This template holds the composition form to write a note or send
an e-mail. It contains by default a textarea, that will be replaced
by another composition form in the main wall composition form, or
for main thread composition form in document form view.
-->
<t t-name="mail.compose_message">
<div class="oe_mail_compose_textarea">
<img class="oe_mail_icon oe_mail_frame oe_left" alt="User img"/>
<div class="oe_mail_msg_content">
<!-- contains the composition form -->
<!-- default content: old basic textarea -->
<div class="oe_mail_post_header">
<t t-call="mail.thread.list_recipients"/>
</div>
<textarea class="field_text" placeholder="Add your comment here..."/>
<div class="oe_mail_post_footer">
<span class="oe_mail_compose_attachment_list"/>
<button class="post">Post message</button>
<t t-call="mail.compose_message.add_attachment"/>
</div>
</div>
<div class="oe_clear"/>
</div>
</t>
<!--
mail.compose_message.add_attachment template
Small template to be inserted in the composition for add attachments
-->
<t t-name="mail.compose_message.add_attachment">
<div class="oe_attachment_file">
<div class="oe_add">
<input type="file" class="oe_insert_file"/>
<button><span class="oe_e">p</span></button>
</div>
</div>
</t>
<!--
mail.thread.message.attachments template
Template used to display attachments in a mail.message
-->
<t t-name="mail.thread.message.attachments">
<ul t-attf-class="oe_mail_msg_attachments #{widget.attachment_ids[0]?'':'oe_hidden'}">
<t t-foreach="widget.attachment_ids" t-as="attachment">
<li>
<a t-if="widget.show_attachment_link" t-att-href="attachment.url"><t t-raw="attachment.name || attachment.filename"/></a>
<span t-if="!widget.show_attachment_link"><t t-raw="attachment.name || attachment.filename"/></span>
<t t-if="widget.show_attachment_delete">
<a class="oe_right oe_mail_attachment_delete" title="Delete this attachmentt" t-attf-data-id="{attachment.id}">x</a>
</t>
</li>
</t>
</ul>
</t>
<t t-name="mail.thread.message.private">
<div>
<span class="oe_placeholder_checkbox_private"/>
<span class="oe_send_private">This email is private and don't send to all my followers.</span>
<span class="oe_send_public">I wrote for contacts and all my followers.</span>
</div>
</t>
<!--
template to the recipients list
-->
<t t-name="mail.thread.list_recipients">
<div class="oe_mail_list_recipients">
Post to:
<span t-if="!widget.is_private" class="oe_all_follower">All Followers</span>
<t t-if="!widget.is_private and widget.partner_ids.length"> and </t>
<t t-set="inc" t-value="0"/>
<t t-if="widget.partner_ids.length" t-foreach="widget.partner_ids" t-as="partner"><span t-attf-class="oe_partner_follower #{inc>=3?'oe_hidden':''}"><t t-if="inc" t-raw="', '"/><a t-attf-href="#model=res.partner&amp;id=#{partner[0]}"><t t-raw="partner[1]"/></a></span><t t-set="inc" t-value="inc+1"/>
</t>
<t t-if="widget.partner_ids.length>=3">
<span class="oe_more">, <a><t t-raw="widget.partner_ids.length-3"/> others...</a></span>
<a class="oe_more_hidden">&lt;&lt;&lt;</a>
</t>
</div>
</t>
<!--
wall main template
Template used to display the communication history in the wall.
-->
<div t-name="mail.wall" class="oe_view_manager oe_mail_wall oe_view_manager_current">
<!--button string="Send Reminder Email" name="%(mail.action_email_compose_message_wizard)d" type="action"
states="waiting_answer"
context="{'default_body_text': 'Hello,\n\n',
'default_subject': '' }"/-->
<table class="oe_view_manager_header">
<colgroup>
<col width="33%"/>
@ -54,55 +146,6 @@
</ul>
</div>
<!--
mail.compose_message template
This template holds the composition form to write a note or send
an e-mail. It contains by default a textarea, that will be replaced
by another composition form in the main wall composition form, or
for main thread composition form in document form view.
-->
<t t-name="mail.compose_message">
<div class="oe_mail_compose_textarea">
<img class="oe_mail_icon oe_mail_frame oe_left" alt="User img"/>
<div class="oe_mail_msg_content">
<!-- contains the composition form -->
<!-- default content: old basic textarea -->
<div class="oe_mail_post_header">
Post a message to:
<span i-if="!widget.is_private" class="oe_all_follower">All Followers</span>
<t t-if="!widget.is_private and widget.partner_ids.length"> and </t>
<t t-set="inc" t-value="0"/>
<t t-if="widget.partner_ids.length" t-foreach="widget.partner_ids" t-as="partner"><span t-attf-class="oe_partner_follower #{inc>=3?'oe_hidden':''}"><t t-if="inc" t-raw="', '"/><a t-attf-href="#model=res.partner&amp;id=#{partner[0]}"><t t-raw="partner[1]"/></a></span><t t-set="inc" t-value="inc+1"/>
</t>
<t t-if="widget.partner_ids.length>=3">
<span class="oe_more">, <a><t t-raw="widget.partner_ids.length-3"/> others...</a></span>
<a class="oe_more_hidden">&lt;&lt;&lt;</a>
</t>
</div>
<textarea placeholder="Add your comment here..."/>
<div class="oe_mail_post_bottom">
<button class="post">Post</button>
<span><a>Compose a full message</a></span>
</div>
</div>
<div class="oe_clear"/>
</div>
</t>
<!--
mail.compose_message.add_attachment template
Small template to be inserted in the composition form to add attachments
-->
<t t-name="mail.compose_message.add_attachment">
<t t-call="HiddenInputFile">
<t t-set="fileupload_id" t-value="widget.fileupload_id"/>
<t t-set="fileupload_action">/web/binary/upload_attachment</t>
<input type="hidden" name="model" t-att-value="widget.form_view.model"/>
<input type="hidden" name="id" t-att-value="widget.form_view.datarecord.id || 0"/>
<input type="hidden" name="session_id" t-att-value="widget.session.session_id"/>
</t>
</t>
<!--
thread template
This template holds a thread of comments. It begins with an actions
@ -112,7 +155,6 @@
<div t-name="mail.thread" class="oe_mail oe_mail_thread oe_semantic_html_override">
<div class="oe_mail_thread_action">
<!-- contains the composition box (form + image) -->
<t t-call="mail.compose_message"/>
</div>
<ul class="oe_mail_thread_display">
<!-- contains the threads -->
@ -194,23 +236,6 @@
</div>
</li>
<!--
mail.thread.message.attachments template
Template used to display attachments in a mail.message
-->
<t t-name="mail.thread.message.attachments">
<ul class="oe_mail_msg_attachments">
<t t-foreach="record.attachment_ids" t-as="attachment">
<li>
<a t-att-href="attachment.url"><t t-raw="attachment.name || attachment.filename"/></a>
<t t-if="record.show_attachment_delete">
<a class="oe_right oe_mail_attachment_delete" title="Delete this attachmentt" t-attf-data-id="{attachment.id}">x</a>
</t>
</li>
</t>
</ul>
</t>
<!-- mail.thread.message.vote
Template used to display Like/Unlike in a mail.message
-->

View File

@ -32,67 +32,15 @@
<button string="Send" name="send_mail" type="object" class="oe_highlight" />
or
<button string="Cancel" class="oe_link" special="cancel" />
<div class="oe_right">
<!--div class="oe_right">
<button string="" name="toggle_content_subtype" type="object" icon="/mail/static/src/img/formatting.png"
help="Toggle advanced formatting mode"/>
</div>
</div-->
</footer>
</form>
</field>
</record>
<record model="ir.ui.view" id="email_compose_message_wizard_form_chatter">
<field name="name">mail.compose.message.form.chatter</field>
<field name="model">mail.compose.message</field>
<field name="priority">18</field>
<field name="arch" type="xml">
<form string="Compose Email" version="7.0" >
<group>
<!-- truly invisible fields for control and options -->
<field name="composition_mode" colspan="2" nolabel="1" invisible="1"/>
<field name="model" colspan="2" nolabel="1" invisible="1"/>
<field name="res_id" colspan="2" nolabel="1" invisible="1"/>
<field name="parent_id" colspan="2" nolabel="1" invisible="1"/>
<field name="content_subtype" colspan="2" nolabel="1" invisible="1"/>
<!-- visible wizard -->
<field name="subject" colspan="2" nolabel="1" placeholder="Subject..."
class="oe_mail_compose_message_subject"
attrs="{'invisible':[('content_subtype', '=', 'plain')]}"/>
<field name="body_text" colspan="2" nolabel="1" placeholder="What are you working on ?"
class="oe_mail_compose_message_body"
attrs="{'invisible':[('content_subtype', '=', 'html')]}"/>
<field name="body" colspan="2" nolabel="1" placeholder="What are you working on ?"
class="oe_mail_compose_message_body_html"
attrs="{'invisible':[('content_subtype', '=', 'plain')]}"/>
<field name="partner_ids" colspan="2" nolabel="1" widget="many2many_tags" placeholder="Add contacts to notify..."
context="{'force_email':True}"
on_change="onchange_partner_ids(partner_ids)"
class="oe_mail_compose_message_partner_ids"/>
<field name="attachment_ids" colspan="2" nolabel="1" widget="many2many_tags"
placeholder="Add attachments..." invisible="1"
class="oe_mail_compose_message_attachment_ids"/>
<!-- void div to display attachments, Chatter-controlled -->
<div colspan="2" class="oe_mail_compose_message_attachments"/>
<!-- buttons, with as few Chatter logic as possible -->
<div>
<button name="send_mail" string="Post message" type="object"
class="oe_mail_compose_message_button_send"/>
</div>
<div class='oe_mail_compose_message_icons'>
<button icon="/mail/static/src/img/attachment.png"
class="oe_mail_compose_message_attachment" string=""
name="dummy"
help="Add an attachment"/>
<button icon="/mail/static/src/img/formatting.png"
class="oe_mail_compose_message_formatting" string=""
type="object" name="toggle_content_subtype"
help="Toggle advanced formatting mode"/>
</div>
</group>
</form>
</field>
</record>
<record id="action_email_compose_message_wizard" model="ir.actions.act_window">
<field name="name">Compose Email</field>
<field name="res_model">mail.compose.message</field>