2012-02-01 16:22:13 +00:00
|
|
|
openerp.mail = function(session) {
|
2012-03-29 09:18:08 +00:00
|
|
|
var _t = session.web._t,
|
|
|
|
_lt = session.web._lt;
|
2012-06-21 21:55:27 +00:00
|
|
|
|
2012-02-02 14:18:43 +00:00
|
|
|
var mail = session.mail = {};
|
2012-02-08 16:42:29 +00:00
|
|
|
|
2012-08-10 13:05:42 +00:00
|
|
|
openerp_mail_followers(session, mail); // import mail_followers.js
|
|
|
|
|
2012-04-05 09:48:42 +00:00
|
|
|
/**
|
2012-07-17 15:57:02 +00:00
|
|
|
* ------------------------------------------------------------
|
|
|
|
* FormView
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Override of formview do_action method, to catch all return action about
|
2012-10-18 15:23:22 +00:00
|
|
|
* mail.compose.message. The purpose is to bind 'Send by e-mail' buttons.
|
2012-06-20 15:54:34 +00:00
|
|
|
*/
|
2012-07-17 15:57:02 +00:00
|
|
|
|
|
|
|
session.web.FormView = session.web.FormView.extend({
|
2012-10-17 14:56:39 +00:00
|
|
|
do_action: function(action) {
|
2012-10-08 14:26:54 +00:00
|
|
|
if (action.res_model == 'mail.compose.message') {
|
2012-10-10 11:02:03 +00:00
|
|
|
/* hack for stop context propagation of wrong value
|
|
|
|
* delete this hack when a global method to clean context is create
|
2012-10-18 15:23:22 +00:00
|
|
|
*/
|
|
|
|
var context_keys = ['default_template_id', 'default_composition_mode',
|
|
|
|
'default_use_template', 'default_partner_ids', 'default_model',
|
2012-10-19 11:34:08 +00:00
|
|
|
'default_res_id', 'default_content_subtype', 'active_id', 'lang',
|
2012-10-18 15:23:22 +00:00
|
|
|
'bin_raw', 'tz', 'active_model', 'edi_web_url_view', 'active_ids']
|
|
|
|
for (var key in action.context) {
|
|
|
|
if (_.indexOf(context_keys, key) == -1) {
|
|
|
|
action.context[key] = null;
|
|
|
|
}
|
|
|
|
}
|
2012-10-10 11:02:03 +00:00
|
|
|
/* end hack */
|
2012-07-17 15:57:02 +00:00
|
|
|
}
|
2012-10-17 14:56:39 +00:00
|
|
|
return this._super.apply(this, arguments);
|
2012-07-17 15:57:02 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-10-18 15:23:22 +00:00
|
|
|
|
2012-06-18 16:03:57 +00:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------
|
2012-06-21 15:24:28 +00:00
|
|
|
* ChatterUtils
|
2012-06-18 16:03:57 +00:00
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
2012-09-11 13:37:06 +00:00
|
|
|
* This class holds a few tools method for Chatter.
|
2012-08-20 16:15:47 +00:00
|
|
|
* Some regular expressions not used anymore, kept because I want to
|
2012-09-03 15:20:25 +00:00
|
|
|
* - (^|\s)@((\w|@|\.)*): @login@log.log
|
2012-08-20 16:15:47 +00:00
|
|
|
* - (^|\s)\[(\w+).(\w+),(\d)\|*((\w|[@ .,])*)\]: [ir.attachment,3|My Label],
|
2012-09-03 15:20:25 +00:00
|
|
|
* for internal links
|
2012-06-18 16:03:57 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-21 15:24:28 +00:00
|
|
|
mail.ChatterUtils = {
|
2012-06-18 16:03:57 +00:00
|
|
|
|
2012-09-06 11:14:44 +00:00
|
|
|
/** Get an image in /web/binary/image?... */
|
|
|
|
get_image: function(session, model, field, id) {
|
|
|
|
return session.prefix + '/web/binary/image?session_id=' + session.session_id + '&model=' + model + '&field=' + field + '&id=' + (id || '');
|
2012-06-18 16:03:57 +00:00
|
|
|
},
|
2012-06-19 12:12:11 +00:00
|
|
|
|
2012-09-06 11:14:44 +00:00
|
|
|
/** Get the url of an attachment {'id': id} */
|
|
|
|
get_attachment_url: function (session, attachment) {
|
|
|
|
return session.origin + '/web/binary/saveas?session_id=' + session.session_id + '&model=ir.attachment&field=datas&filename_field=datas_fname&id=' + attachment['id'];
|
|
|
|
},
|
|
|
|
|
2012-08-20 16:15:47 +00:00
|
|
|
/** Replaces some expressions
|
2012-06-21 15:24:28 +00:00
|
|
|
* - :name - shortcut to an image
|
|
|
|
*/
|
|
|
|
do_replace_expressions: function (string) {
|
|
|
|
var icon_list = ['al', 'pinky']
|
|
|
|
/* special shortcut: :name, try to find an icon if in list */
|
|
|
|
var regex_login = new RegExp(/(^|\s):((\w)*)/g);
|
|
|
|
var regex_res = regex_login.exec(string);
|
|
|
|
while (regex_res != null) {
|
|
|
|
var icon_name = regex_res[2];
|
|
|
|
if (_.include(icon_list, icon_name))
|
|
|
|
string = string.replace(regex_res[0], regex_res[1] + '<img src="/mail/static/src/img/_' + icon_name + '.png" width="22px" height="22px" alt="' + icon_name + '"/>');
|
|
|
|
regex_res = regex_login.exec(string);
|
|
|
|
}
|
|
|
|
return string;
|
|
|
|
},
|
2012-10-09 14:36:45 +00:00
|
|
|
|
|
|
|
/* replace textarea text into html text
|
|
|
|
* (add <p>, <a>)
|
2012-10-18 15:23:22 +00:00
|
|
|
* TDE note : should not be here, but server-side I think ...
|
2012-10-09 14:36:45 +00:00
|
|
|
*/
|
|
|
|
get_text2html: function(text){
|
|
|
|
return text
|
|
|
|
.replace(/[\n\r]/g,'<br/>')
|
|
|
|
.replace(/((?:https?|ftp):\/\/[\S]+)/g,'<a href="$1">$1</a> ')
|
|
|
|
}
|
2012-06-18 16:03:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-06-14 08:40:33 +00:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* ComposeMessage widget
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* This widget handles the display of a form to compose a new message.
|
2012-09-03 15:20:25 +00:00
|
|
|
* This form is a mail.compose.message form_view.
|
2012-10-18 08:04:11 +00:00
|
|
|
* On first time : display a compact textarea but is not the compose form.
|
|
|
|
* When the user focus this box, the compose message is intantiate and
|
|
|
|
* with focus on the textarea.
|
|
|
|
*/
|
2012-10-05 10:46:54 +00:00
|
|
|
|
2012-10-10 10:15:32 +00:00
|
|
|
mail.ThreadComposeMessage = session.web.Widget.extend({
|
2012-10-18 08:04:11 +00:00
|
|
|
template: 'mail.compose_message.compact',
|
|
|
|
// expandable view : 'mail.compose_message'
|
2012-10-05 10:46:54 +00:00
|
|
|
|
2012-07-06 15:52:26 +00:00
|
|
|
/**
|
|
|
|
* @param {Object} parent parent
|
2012-09-03 15:20:25 +00:00
|
|
|
* @param {Object} [options]
|
2012-10-05 10:46:54 +00:00
|
|
|
* @param {Object} [context] context passed to the
|
|
|
|
* mail.compose.message DataSetSearch. Please refer to this model
|
|
|
|
* for more details about fields and default values.
|
2012-07-06 15:52:26 +00:00
|
|
|
*/
|
2012-10-19 11:39:51 +00:00
|
|
|
|
2012-10-18 16:39:23 +00:00
|
|
|
init: function (parent, datasets, options) {
|
2012-07-16 15:39:47 +00:00
|
|
|
var self = this;
|
2012-06-14 08:40:33 +00:00
|
|
|
this._super(parent);
|
2012-10-05 12:27:41 +00:00
|
|
|
this.context = options.context || {};
|
2012-10-05 10:46:54 +00:00
|
|
|
|
2012-10-15 14:17:31 +00:00
|
|
|
this.datasets = {
|
|
|
|
'attachment_ids' : [],
|
2012-10-18 16:39:23 +00:00
|
|
|
'id': datasets.id,
|
|
|
|
'model': datasets.model,
|
|
|
|
'res_model': datasets.res_model,
|
|
|
|
'is_private': datasets.is_private || false,
|
|
|
|
'partner_ids': datasets.partner_ids || [],
|
2012-10-18 08:04:11 +00:00
|
|
|
'avatar': mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid),
|
2012-10-15 14:17:31 +00:00
|
|
|
};
|
2012-10-19 13:53:56 +00:00
|
|
|
this.options = options.options;
|
2012-10-05 12:27:41 +00:00
|
|
|
|
|
|
|
this.parent_thread= parent.messages!= undefined ? parent : false;
|
2012-10-08 14:26:54 +00:00
|
|
|
|
2012-10-09 13:28:24 +00:00
|
|
|
this.ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment');
|
2012-10-15 14:17:31 +00:00
|
|
|
|
2012-10-08 14:26:54 +00:00
|
|
|
this.fileupload_id = _.uniqueId('oe_fileupload_temp');
|
|
|
|
$(window).on(self.fileupload_id, self.on_attachment_loaded);
|
2012-10-19 11:39:51 +00:00
|
|
|
|
|
|
|
this.$render_expandable = false;
|
|
|
|
this.$render_compact = false;
|
2012-06-14 08:40:33 +00:00
|
|
|
},
|
2012-07-10 13:06:31 +00:00
|
|
|
|
2012-10-05 10:46:54 +00:00
|
|
|
start: function(){
|
2012-10-19 11:39:51 +00:00
|
|
|
this.$render_compact = this.$el;
|
|
|
|
|
2012-10-08 14:26:54 +00:00
|
|
|
this.bind_events();
|
2012-10-05 10:46:54 +00:00
|
|
|
},
|
|
|
|
|
2012-10-08 14:26:54 +00:00
|
|
|
/* upload the file on the server, add in the attachments list and reload display
|
|
|
|
*/
|
2012-10-05 10:46:54 +00:00
|
|
|
display_attachments: function(){
|
|
|
|
var self = this;
|
|
|
|
var render = $(session.web.qweb.render('mail.thread.message.attachments', {'widget': self}));
|
|
|
|
if(!this.list_attachment){
|
2012-10-19 11:39:51 +00:00
|
|
|
this.$render_expandable.find('.oe_msg_attachment_list').replaceWith( render );
|
2012-10-05 10:46:54 +00:00
|
|
|
} else {
|
|
|
|
this.list_attachment.replaceWith( render );
|
2012-08-22 16:21:51 +00:00
|
|
|
}
|
2012-10-19 11:39:51 +00:00
|
|
|
this.list_attachment = this.$render_expandable.find(".oe_msg_attachments");
|
2012-10-05 10:46:54 +00:00
|
|
|
|
|
|
|
// event: delete an attachment
|
2012-10-19 11:39:51 +00:00
|
|
|
this.$render_expandable.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete);
|
2012-08-22 16:21:51 +00:00
|
|
|
},
|
2012-10-18 08:04:11 +00:00
|
|
|
|
|
|
|
/* when a user click on the upload button, send file read on_attachment_loaded
|
|
|
|
*/
|
2012-10-08 14:26:54 +00:00
|
|
|
on_attachment_change: function (event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
var self = this;
|
|
|
|
var $target = $(event.target);
|
|
|
|
if ($target.val() !== '') {
|
|
|
|
|
2012-10-09 13:28:24 +00:00
|
|
|
var filename = $target.val().replace(/.*[\\\/]/,'');
|
|
|
|
|
2012-10-09 08:08:58 +00:00
|
|
|
// if the files exits for this answer, delete the file before upload
|
|
|
|
var attachments=[];
|
2012-10-15 14:17:31 +00:00
|
|
|
for(var i in this.datasets.attachment_ids){
|
|
|
|
if((this.datasets.attachment_ids[i].filename || this.datasets.attachment_ids[i].name) == filename){
|
|
|
|
if(this.datasets.attachment_ids[i].upload){
|
2012-10-09 13:28:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-15 14:17:31 +00:00
|
|
|
this.ds_attachment.unlink([this.datasets.attachment_ids[i].id]);
|
2012-10-09 08:08:58 +00:00
|
|
|
} else {
|
2012-10-15 14:17:31 +00:00
|
|
|
attachments.push(this.datasets.attachment_ids[i]);
|
2012-10-08 14:26:54 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-15 14:17:31 +00:00
|
|
|
this.datasets.attachment_ids = attachments;
|
2012-10-08 14:26:54 +00:00
|
|
|
|
|
|
|
// submit file
|
2012-10-19 11:39:51 +00:00
|
|
|
this.$render_expandable.find('form.oe_form_binary_form').submit();
|
2012-10-09 13:28:24 +00:00
|
|
|
|
2012-10-19 11:39:51 +00:00
|
|
|
this.$render_expandable.find(".oe_attachment_file").hide();
|
2012-10-09 13:28:24 +00:00
|
|
|
|
2012-10-15 14:17:31 +00:00
|
|
|
this.datasets.attachment_ids.push({
|
2012-10-09 13:28:24 +00:00
|
|
|
'id': 0,
|
|
|
|
'name': filename,
|
|
|
|
'filename': filename,
|
|
|
|
'url': '',
|
|
|
|
'upload': true
|
|
|
|
});
|
|
|
|
this.display_attachments();
|
2012-10-08 14:26:54 +00:00
|
|
|
}
|
|
|
|
},
|
2012-10-09 13:28:24 +00:00
|
|
|
|
2012-10-18 08:04:11 +00:00
|
|
|
/* when the file is uploaded
|
|
|
|
*/
|
2012-10-09 13:28:24 +00:00
|
|
|
on_attachment_loaded: function (event, result) {
|
2012-10-15 14:17:31 +00:00
|
|
|
for(var i in this.datasets.attachment_ids){
|
2012-10-17 09:35:59 +00:00
|
|
|
if(this.datasets.attachment_ids[i].filename == result.filename && this.datasets.attachment_ids[i].upload) {
|
2012-10-15 14:17:31 +00:00
|
|
|
this.datasets.attachment_ids[i]={
|
2012-10-09 13:28:24 +00:00
|
|
|
'id': result.id,
|
|
|
|
'name': result.name,
|
|
|
|
'filename': result.filename,
|
|
|
|
'url': mail.ChatterUtils.get_attachment_url(this.session, result)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2012-10-08 14:26:54 +00:00
|
|
|
this.display_attachments();
|
2012-10-09 13:28:24 +00:00
|
|
|
|
2012-10-19 11:39:51 +00:00
|
|
|
var $input = this.$render_expandable.find('input.oe_form_binary_file');
|
2012-10-09 13:28:24 +00:00
|
|
|
$input.after($input.clone(true)).remove();
|
2012-10-19 11:39:51 +00:00
|
|
|
this.$render_expandable.find(".oe_attachment_file").show();
|
2012-10-08 14:26:54 +00:00
|
|
|
},
|
2012-10-18 08:04:11 +00:00
|
|
|
|
2012-10-08 14:26:54 +00:00
|
|
|
/* unlink the file on the server and reload display
|
|
|
|
*/
|
|
|
|
on_attachment_delete: function (event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
var attachment_id=$(event.target).data("id");
|
|
|
|
if (attachment_id) {
|
|
|
|
var attachments=[];
|
2012-10-15 14:17:31 +00:00
|
|
|
for(var i in this.datasets.attachment_ids){
|
|
|
|
if(attachment_id!=this.datasets.attachment_ids[i].id){
|
|
|
|
attachments.push(this.datasets.attachment_ids[i]);
|
2012-10-09 08:44:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-10-09 13:28:24 +00:00
|
|
|
this.ds_attachment.unlink([attachment_id]);
|
2012-10-09 08:44:36 +00:00
|
|
|
}
|
2012-10-08 14:26:54 +00:00
|
|
|
}
|
2012-10-15 14:17:31 +00:00
|
|
|
this.datasets.attachment_ids = attachments;
|
2012-10-08 14:26:54 +00:00
|
|
|
this.display_attachments();
|
|
|
|
}
|
|
|
|
},
|
2012-08-22 16:21:51 +00:00
|
|
|
|
2012-10-09 13:28:24 +00:00
|
|
|
/* to avoid having unsorted file on the server.
|
|
|
|
we will show the users files of the first message post
|
2012-10-17 09:28:07 +00:00
|
|
|
TDE note: unnecessary call to server I think
|
2012-10-09 13:28:24 +00:00
|
|
|
*/
|
2012-10-17 09:28:07 +00:00
|
|
|
// set_free_attachments: function(){
|
|
|
|
// var self=this;
|
|
|
|
// this.parent_thread.ds_message.call('user_free_attachment').then(function(attachments){
|
|
|
|
// this.attachment_ids=[];
|
|
|
|
// for(var i in attachments){
|
|
|
|
// self.attachment_ids[i]={
|
|
|
|
// 'id': attachments[i].id,
|
|
|
|
// 'name': attachments[i].name,
|
|
|
|
// 'filename': attachments[i].filename,
|
|
|
|
// 'url': mail.ChatterUtils.get_attachment_url(self.session, attachments[i])
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// self.display_attachments();
|
|
|
|
// });
|
|
|
|
// },
|
2012-10-09 08:44:36 +00:00
|
|
|
|
2012-10-05 10:46:54 +00:00
|
|
|
bind_events: function() {
|
2012-07-16 15:39:47 +00:00
|
|
|
var self = this;
|
2012-10-05 10:46:54 +00:00
|
|
|
|
2012-10-19 11:39:51 +00:00
|
|
|
this.$render_compact.find('textarea').unbind().on('focus', self.on_compose_expandable);
|
|
|
|
|
|
|
|
if(this.$render_expandable){
|
|
|
|
// set the function called when attachments are added
|
|
|
|
this.$render_expandable.on('change', 'input.oe_form_binary_file', self.on_attachment_change );
|
|
|
|
|
|
|
|
this.$render_expandable.on('click', 'a.oe_cancel', self.on_cancel );
|
|
|
|
this.$render_expandable.on('click', 'button.oe_post', function(){self.on_message_post()} );
|
|
|
|
this.$render_expandable.on('click', 'button.oe_full', function(){self.on_compose_fullmail()} );
|
|
|
|
|
|
|
|
// auto close
|
|
|
|
this.$render_expandable.on('blur', 'textarea', this.on_compose_expandable);
|
|
|
|
|
|
|
|
/* stack for don't close the compose form if the user click on a button */
|
|
|
|
this.$render_expandable.on('focus', 'textarea', function () { self.stay_open = false; });
|
|
|
|
this.$render_expandable.on('mousedown', function () { self.stay_open = true; });
|
|
|
|
}
|
2012-09-06 11:14:44 +00:00
|
|
|
},
|
|
|
|
|
2012-10-05 13:10:13 +00:00
|
|
|
on_compose_fullmail: function(){
|
2012-10-08 14:26:54 +00:00
|
|
|
var attachments=[];
|
2012-10-15 14:17:31 +00:00
|
|
|
for(var i in this.datasets.attachment_ids){
|
|
|
|
attachments.push(this.datasets.attachment_ids[i].id);
|
2012-10-08 14:26:54 +00:00
|
|
|
}
|
2012-10-19 12:06:57 +00:00
|
|
|
/* TDE note: I think this is not necessary, because
|
|
|
|
* 1/ post on a document: followers added server-side in _notify
|
|
|
|
* 2/ reply to a message: mail.compose.message should add the previous partners
|
|
|
|
*/
|
2012-10-12 12:40:03 +00:00
|
|
|
var partner_ids=[];
|
2012-10-15 14:17:31 +00:00
|
|
|
for(var i in this.datasets.partner_ids){
|
|
|
|
partner_ids.push(this.datasets.partner_ids[i][0]);
|
2012-10-12 12:40:03 +00:00
|
|
|
}
|
2012-10-05 12:27:41 +00:00
|
|
|
var action = {
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
res_model: 'mail.compose.message',
|
|
|
|
view_mode: 'form',
|
|
|
|
view_type: 'form',
|
2012-10-10 10:15:32 +00:00
|
|
|
action_from: 'mail.ThreadComposeMessage',
|
2012-10-05 12:27:41 +00:00
|
|
|
views: [[false, 'form']],
|
|
|
|
target: 'new',
|
|
|
|
context: {
|
2012-10-19 11:39:51 +00:00
|
|
|
'default_model': this.context.default_model,
|
|
|
|
'default_res_id': this.context.default_res_id,
|
2012-10-05 12:27:41 +00:00
|
|
|
'default_content_subtype': 'html',
|
2012-10-15 14:17:31 +00:00
|
|
|
'default_parent_id': this.datasets.id,
|
2012-10-19 13:16:22 +00:00
|
|
|
'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''),
|
2012-10-12 12:40:03 +00:00
|
|
|
'default_attachment_ids': attachments,
|
|
|
|
'default_partner_ids': partner_ids
|
2012-10-05 12:27:41 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
this.do_action(action);
|
|
|
|
},
|
|
|
|
|
2012-10-12 12:40:03 +00:00
|
|
|
on_cancel: function(event){
|
|
|
|
if(event) event.stopPropagation();
|
2012-10-19 11:39:51 +00:00
|
|
|
this.$render_expandable.find('textarea').val("");
|
|
|
|
this.$render_expandable.find('input[data-id]').remove();
|
|
|
|
|
|
|
|
this.datasets.attachment_ids=[];
|
2012-10-05 12:27:41 +00:00
|
|
|
this.display_attachments();
|
2012-10-19 11:39:51 +00:00
|
|
|
|
2012-10-19 11:53:34 +00:00
|
|
|
this.stay_open = false;
|
2012-10-19 11:39:51 +00:00
|
|
|
this.on_compose_expandable();
|
2012-10-05 12:27:41 +00:00
|
|
|
},
|
|
|
|
|
2012-10-10 11:02:03 +00:00
|
|
|
/*post a message and fetch the message*/
|
2012-10-05 12:27:41 +00:00
|
|
|
on_message_post: function (body) {
|
2012-10-12 12:40:03 +00:00
|
|
|
var self = this;
|
2012-10-08 14:26:54 +00:00
|
|
|
|
2012-10-05 12:27:41 +00:00
|
|
|
if (! body) {
|
2012-10-19 11:39:51 +00:00
|
|
|
var comment_node = this.$render_expandable.find('textarea');
|
2012-10-05 12:27:41 +00:00
|
|
|
var body = comment_node.val();
|
|
|
|
comment_node.val('');
|
|
|
|
}
|
2012-10-08 14:26:54 +00:00
|
|
|
|
2012-10-09 13:28:24 +00:00
|
|
|
var attachments=[];
|
2012-10-15 14:17:31 +00:00
|
|
|
for(var i in this.datasets.attachment_ids){
|
|
|
|
if(this.datasets.attachment_ids[i].upload){
|
2012-10-09 13:28:24 +00:00
|
|
|
session.web.dialog($('<div>' + session.web.qweb.render('CrashManager.warning', {message: 'Please, wait while the file is uploading.'}) + '</div>'));
|
|
|
|
return false;
|
2012-10-08 14:26:54 +00:00
|
|
|
}
|
2012-10-15 14:17:31 +00:00
|
|
|
attachments.push(this.datasets.attachment_ids[i].id);
|
2012-10-09 13:28:24 +00:00
|
|
|
}
|
2012-10-08 14:26:54 +00:00
|
|
|
|
2012-10-09 13:28:24 +00:00
|
|
|
if(body.match(/\S+/)) {
|
2012-10-19 11:53:34 +00:00
|
|
|
//session.web.blockUI();
|
2012-10-05 12:27:41 +00:00
|
|
|
this.parent_thread.ds_thread.call('message_post_api', [
|
2012-10-09 14:36:45 +00:00
|
|
|
this.context.default_res_id,
|
|
|
|
mail.ChatterUtils.get_text2html(body),
|
|
|
|
false,
|
|
|
|
'comment',
|
2012-10-19 07:33:38 +00:00
|
|
|
'mail.mt_comment',
|
2012-10-09 14:36:45 +00:00
|
|
|
this.context.default_parent_id,
|
2012-10-15 16:03:24 +00:00
|
|
|
attachments,
|
2012-10-19 07:36:10 +00:00
|
|
|
this.parent_thread.context
|
|
|
|
]).then(function(records){
|
2012-10-12 12:40:03 +00:00
|
|
|
self.parent_thread.switch_new_message(records);
|
|
|
|
self.on_cancel();
|
2012-10-19 11:53:34 +00:00
|
|
|
//session.web.unblockUI();
|
2012-10-12 12:40:03 +00:00
|
|
|
});
|
2012-10-09 13:28:24 +00:00
|
|
|
return true;
|
2012-10-05 12:27:41 +00:00
|
|
|
}
|
|
|
|
},
|
2012-10-17 15:17:15 +00:00
|
|
|
|
2012-10-18 08:04:11 +00:00
|
|
|
/* convert the compact mode into the compose message
|
|
|
|
*/
|
2012-10-19 11:39:51 +00:00
|
|
|
on_compose_expandable: function(event){
|
|
|
|
if(event) event.stopPropagation();
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if(!this.$render_expandable) {
|
|
|
|
this.$render_expandable = $(session.web.qweb.render('mail.compose_message', {'widget': this}));
|
|
|
|
this.$render_expandable.hide();
|
|
|
|
|
|
|
|
this.$render_expandable.insertAfter( this.$render_compact );
|
|
|
|
this.display_attachments();
|
|
|
|
|
|
|
|
this.bind_events();
|
|
|
|
}
|
2012-10-19 11:53:34 +00:00
|
|
|
|
2012-10-19 11:39:51 +00:00
|
|
|
if(this.$render_expandable.is(':hidden')){
|
|
|
|
|
|
|
|
this.$render_expandable.show();
|
|
|
|
this.$render_compact.hide();
|
|
|
|
this.$render_expandable.find('textarea').focus();
|
|
|
|
|
|
|
|
} else if(!this.stay_open){
|
|
|
|
|
2012-10-19 11:45:13 +00:00
|
|
|
// do not close the box if there are some text
|
|
|
|
if(!this.$render_expandable.find('textarea').val().match(/\S+/)){
|
|
|
|
this.$render_expandable.hide();
|
2012-10-19 14:32:28 +00:00
|
|
|
if(this.options.show_compact_message) {
|
2012-10-19 11:45:13 +00:00
|
|
|
this.$render_compact.show();
|
|
|
|
} else {
|
|
|
|
this.$render_compact.hide();
|
|
|
|
}
|
2012-10-19 11:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
2012-10-18 08:04:11 +00:00
|
|
|
},
|
|
|
|
|
2012-10-19 11:39:51 +00:00
|
|
|
do_hide_compact: function() {
|
|
|
|
this.$render_compact.hide();
|
2012-10-19 14:32:28 +00:00
|
|
|
this.options.show_compact_message = false;
|
2012-10-17 15:17:15 +00:00
|
|
|
},
|
2012-10-19 11:39:51 +00:00
|
|
|
|
|
|
|
do_show_compact: function() {
|
2012-10-19 11:53:34 +00:00
|
|
|
if(!this.$render_expandable || this.$render_expandable.is(':hidden')){
|
|
|
|
this.$render_compact.show();
|
|
|
|
}
|
2012-10-19 14:32:28 +00:00
|
|
|
this.options.show_compact_message = true;
|
2012-10-19 11:39:51 +00:00
|
|
|
}
|
2012-10-05 10:46:54 +00:00
|
|
|
});
|
2012-04-05 09:48:42 +00:00
|
|
|
|
2012-03-02 17:07:49 +00:00
|
|
|
/**
|
2012-06-15 08:36:56 +00:00
|
|
|
* ------------------------------------------------------------
|
2012-10-02 13:48:43 +00:00
|
|
|
* Thread Message Expandable Widget
|
2012-06-15 08:36:56 +00:00
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
2012-10-10 18:16:11 +00:00
|
|
|
* This widget handles the display the expandable message in a thread.
|
2012-10-02 13:48:43 +00:00
|
|
|
* - thread
|
|
|
|
* - - visible message
|
|
|
|
* - - expandable
|
|
|
|
* - - visible message
|
|
|
|
* - - visible message
|
|
|
|
* - - expandable
|
2012-03-02 17:07:49 +00:00
|
|
|
*/
|
2012-10-02 13:48:43 +00:00
|
|
|
mail.ThreadExpandable = session.web.Widget.extend({
|
|
|
|
template: 'mail.thread.expandable',
|
2012-10-02 10:52:35 +00:00
|
|
|
|
2012-10-18 16:39:23 +00:00
|
|
|
init: function(parent, datasets, options) {
|
2012-10-02 13:48:43 +00:00
|
|
|
this._super(parent);
|
|
|
|
this.domain = options.domain || [];
|
|
|
|
this.context = _.extend({
|
|
|
|
default_model: 'mail.thread',
|
2012-10-15 14:17:31 +00:00
|
|
|
default_res_id: 0,
|
2012-10-02 13:48:43 +00:00
|
|
|
default_parent_id: false }, options.context || {});
|
|
|
|
|
2012-10-16 12:41:05 +00:00
|
|
|
this.datasets = {
|
2012-10-18 16:39:23 +00:00
|
|
|
'id' : datasets.id || -1,
|
|
|
|
'model' : datasets.model || false,
|
|
|
|
'parent_id' : datasets.parent_id || false,
|
|
|
|
'nb_messages' : datasets.nb_messages || 0,
|
2012-10-19 12:38:16 +00:00
|
|
|
'thread_level' : datasets.thread_level || 0,
|
2012-10-16 12:41:05 +00:00
|
|
|
'type' : 'expandable',
|
2012-10-18 16:39:23 +00:00
|
|
|
'max_limit' : datasets.max_limit || false,
|
2012-10-17 00:13:20 +00:00
|
|
|
'flag_used' : false,
|
2012-10-16 12:41:05 +00:00
|
|
|
};
|
2012-10-02 13:48:43 +00:00
|
|
|
|
|
|
|
// record options and data
|
2012-10-18 16:39:23 +00:00
|
|
|
this.parent_thread= parent.messages!= undefined ? parent : options.options._parents[0] ;
|
2012-10-02 13:48:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
start: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.bind_events();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind events in the widget. Each event is slightly described
|
|
|
|
* in the function. */
|
|
|
|
bind_events: function() {
|
|
|
|
var self = this;
|
2012-10-17 13:37:50 +00:00
|
|
|
this.$el.on('click', 'a.oe_msg_fetch_more', self.on_expandable);
|
2012-10-02 13:48:43 +00:00
|
|
|
},
|
|
|
|
|
2012-10-17 00:13:20 +00:00
|
|
|
animated_destroy: function(options) {
|
|
|
|
var self=this;
|
|
|
|
//graphic effects
|
|
|
|
if(options && options.fadeTime) {
|
|
|
|
self.$el.fadeOut(options.fadeTime, function(){
|
|
|
|
self.destroy();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.destroy();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-02 13:48:43 +00:00
|
|
|
/*The selected thread and all childs (messages/thread) became read
|
|
|
|
* @param {object} mouse envent
|
|
|
|
*/
|
|
|
|
on_expandable: function (event) {
|
2012-10-05 10:46:54 +00:00
|
|
|
if(event)event.stopPropagation();
|
2012-10-17 00:13:20 +00:00
|
|
|
if(this.datasets.flag_used) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
this.datasets.flag_used = true;
|
|
|
|
|
|
|
|
this.animated_destroy({'fadeTime':300});
|
2012-10-10 11:02:03 +00:00
|
|
|
this.parent_thread.message_fetch(false, this.domain, this.context);
|
2012-10-02 13:48:43 +00:00
|
|
|
return false;
|
|
|
|
},
|
2012-10-02 10:52:35 +00:00
|
|
|
});
|
2012-05-10 12:10:58 +00:00
|
|
|
|
2012-10-02 10:52:35 +00:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* Thread Message Widget
|
|
|
|
* ------------------------------------------------------------
|
2012-10-02 13:48:43 +00:00
|
|
|
* This widget handles the display of a messages in a thread.
|
|
|
|
* Displays a record and performs some formatting on the record :
|
|
|
|
* - record.date: formatting according to the user timezone
|
|
|
|
* - record.timerelative: relative time givein by timeago lib
|
|
|
|
* - record.avatar: image url
|
|
|
|
* - record.attachment_ids[].url: url of each attachmentThe
|
2012-10-10 18:16:11 +00:00
|
|
|
* thread view :
|
2012-10-02 10:52:35 +00:00
|
|
|
* - root thread
|
|
|
|
* - - sub message (parent_id = root message)
|
|
|
|
* - - - sub thread
|
|
|
|
* - - - - sub sub message (parent id = sub thread)
|
|
|
|
* - - sub message (parent_id = root message)
|
|
|
|
* - - - sub thread
|
|
|
|
*/
|
2012-09-29 21:19:24 +00:00
|
|
|
mail.ThreadMessage = session.web.Widget.extend({
|
|
|
|
template: 'mail.thread.message',
|
2012-02-27 16:04:42 +00:00
|
|
|
|
2012-10-01 09:36:33 +00:00
|
|
|
/**
|
|
|
|
* @param {Object} parent parent
|
|
|
|
* @param {Array} [domain]
|
|
|
|
* @param {Object} [context] context of the thread. It should
|
|
|
|
contain at least default_model, default_res_id. Please refer to
|
|
|
|
the ComposeMessage widget for more information about it.
|
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {Object} [thread] read obout mail.Thread object
|
|
|
|
* @param {Object} [message]
|
|
|
|
* @param {Number} [truncate_limit=250] 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
|
|
|
|
* @param {Boolean} [show_record_name]
|
2012-10-18 16:39:23 +00:00
|
|
|
*... @param {int} [show_reply_button] number thread level to display the reply button
|
|
|
|
*... @param {int} [show_read_unread_button] number thread level to display the read/unread button
|
2012-10-01 09:36:33 +00:00
|
|
|
*/
|
2012-10-18 16:39:23 +00:00
|
|
|
init: function(parent, datasets, options) {
|
2012-02-23 16:32:36 +00:00
|
|
|
this._super(parent);
|
2012-09-29 21:19:24 +00:00
|
|
|
|
2012-10-17 00:13:20 +00:00
|
|
|
// record datasets
|
2012-10-15 16:03:24 +00:00
|
|
|
this.datasets = _.extend({
|
|
|
|
'id' : -1,
|
|
|
|
'model' : false,
|
|
|
|
'parent_id': false,
|
|
|
|
'res_id' : false,
|
|
|
|
'type' : false,
|
|
|
|
'is_author' : false,
|
|
|
|
'is_private' : false,
|
|
|
|
'subject' : false,
|
|
|
|
'name' : false,
|
|
|
|
'record_name' : false,
|
|
|
|
'body' : false,
|
2012-10-19 11:39:51 +00:00
|
|
|
'vote_nb' :0,
|
2012-10-15 16:03:24 +00:00
|
|
|
'has_voted' : false,
|
2012-10-18 15:23:22 +00:00
|
|
|
'is_favorite' : false,
|
2012-10-15 16:03:24 +00:00
|
|
|
'thread_level' : 0,
|
2012-10-17 09:35:59 +00:00
|
|
|
'to_read' : true,
|
2012-10-15 16:03:24 +00:00
|
|
|
'author_id' : [],
|
|
|
|
'attachment_ids' : [],
|
2012-10-18 16:39:23 +00:00
|
|
|
}, datasets || {});
|
|
|
|
this.datasets._date = datasets.date;
|
2012-10-05 10:46:54 +00:00
|
|
|
|
2012-10-04 09:09:02 +00:00
|
|
|
// record domain and context
|
|
|
|
this.domain = options.domain || [];
|
|
|
|
this.context = _.extend({
|
|
|
|
default_model: 'mail.thread',
|
2012-10-15 14:17:31 +00:00
|
|
|
default_res_id: 0,
|
2012-10-04 09:09:02 +00:00
|
|
|
default_parent_id: false }, options.context || {});
|
2012-09-29 21:19:24 +00:00
|
|
|
|
2012-10-04 09:09:02 +00:00
|
|
|
// record options
|
2012-10-19 13:53:56 +00:00
|
|
|
this.options = options.options;
|
2012-10-16 12:41:05 +00:00
|
|
|
|
2012-10-19 13:53:56 +00:00
|
|
|
this.datasets.show_reply_button = this.options.show_compose_message && this.options.show_reply_button > this.datasets.thread_level;
|
|
|
|
this.datasets.show_read_unread_button = this.options.show_read_unread_button > this.datasets.thread_level;
|
2012-10-16 12:41:05 +00:00
|
|
|
|
2012-10-04 09:09:02 +00:00
|
|
|
// record options and data
|
2012-10-18 16:39:23 +00:00
|
|
|
this.parent_thread= parent.messages!= undefined ? parent : options.options._parents[0];
|
2012-09-29 21:19:24 +00:00
|
|
|
this.thread = false;
|
|
|
|
|
2012-10-17 00:13:20 +00:00
|
|
|
if( this.datasets.id > 0 ) {
|
2012-09-29 21:19:24 +00:00
|
|
|
this.formating_data();
|
2012-09-03 15:20:25 +00:00
|
|
|
}
|
2012-09-27 08:30:56 +00:00
|
|
|
|
2012-09-12 10:22:17 +00:00
|
|
|
this.ds_notification = new session.web.DataSetSearch(this, 'mail.notification');
|
|
|
|
this.ds_message = new session.web.DataSetSearch(this, 'mail.message');
|
2012-10-15 14:17:31 +00:00
|
|
|
this.ds_follow = new session.web.DataSetSearch(this, 'mail.followers');
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
2012-09-29 21:19:24 +00:00
|
|
|
|
|
|
|
formating_data: function(){
|
|
|
|
|
|
|
|
//formating and add some fields for render
|
2012-10-15 14:17:31 +00:00
|
|
|
this.datasets.date = session.web.format_value(this.datasets._date, {type:"datetime"});
|
|
|
|
this.datasets.timerelative = $.timeago(this.datasets.date);
|
|
|
|
if (this.datasets.type == 'email') {
|
|
|
|
this.datasets.avatar = ('/mail/static/src/img/email_icon.png');
|
2012-09-29 21:19:24 +00:00
|
|
|
} else {
|
2012-10-15 14:17:31 +00:00
|
|
|
this.datasets.avatar = mail.ChatterUtils.get_image(this.session, 'res.partner', 'image_small', this.datasets.author_id[0]);
|
2012-09-29 21:19:24 +00:00
|
|
|
}
|
2012-10-15 14:17:31 +00:00
|
|
|
for (var l in this.datasets.attachment_ids) {
|
|
|
|
var attach = this.datasets.attachment_ids[l];
|
2012-09-29 21:19:24 +00:00
|
|
|
attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach);
|
|
|
|
}
|
|
|
|
},
|
2012-02-23 16:32:36 +00:00
|
|
|
|
|
|
|
start: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-09-29 21:19:24 +00:00
|
|
|
this.expender();
|
|
|
|
this.$el.hide().fadeIn(750);
|
2012-10-01 09:36:33 +00:00
|
|
|
this.bind_events();
|
2012-09-29 21:19:24 +00:00
|
|
|
this.create_thread();
|
2012-05-14 12:32:31 +00:00
|
|
|
},
|
2012-07-11 11:17:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind events in the widget. Each event is slightly described
|
|
|
|
* in the function. */
|
|
|
|
bind_events: function() {
|
2012-03-13 17:41:05 +00:00
|
|
|
var self = this;
|
2012-10-09 08:08:58 +00:00
|
|
|
|
2012-09-11 16:38:53 +00:00
|
|
|
// event: click on 'Attachment(s)' in msg
|
2012-10-17 00:13:20 +00:00
|
|
|
this.$('a.oe_msg_view_attachments:first').on('click', function (event) {
|
|
|
|
self.$('.oe_msg_attachments:first').toggle();
|
2012-07-11 11:17:22 +00:00
|
|
|
});
|
2012-09-27 08:30:56 +00:00
|
|
|
// event: click on icone 'Read' in header
|
2012-09-28 13:27:23 +00:00
|
|
|
this.$el.on('click', 'a.oe_read', this.on_message_read_unread);
|
|
|
|
// event: click on icone 'UnRead' in header
|
|
|
|
this.$el.on('click', 'a.oe_unread', this.on_message_read_unread);
|
2012-07-11 09:55:45 +00:00
|
|
|
// event: click on 'Delete' in msg side menu
|
2012-10-17 00:13:20 +00:00
|
|
|
this.$el.on('click', 'a.oe_msg_delete', this.on_message_delete);
|
2012-10-01 16:44:14 +00:00
|
|
|
|
|
|
|
// event: click on 'Reply' in msg
|
|
|
|
this.$el.on('click', 'a.oe_reply', this.on_message_reply);
|
2012-09-18 12:23:15 +00:00
|
|
|
// event: click on 'Vote' button
|
2012-10-17 00:13:20 +00:00
|
|
|
this.$el.on('click', 'button.oe_msg_vote', this.on_vote);
|
2012-10-19 11:39:51 +00:00
|
|
|
// event: click on 'starred/favorite' button
|
|
|
|
this.$el.on('click', 'a.oe_mail_starbox', this.on_star);
|
2012-03-13 17:41:05 +00:00
|
|
|
},
|
2012-08-20 16:49:24 +00:00
|
|
|
|
2012-10-01 16:44:14 +00:00
|
|
|
on_message_reply:function(event){
|
|
|
|
event.stopPropagation();
|
2012-10-05 10:46:54 +00:00
|
|
|
this.thread.on_compose_message();
|
2012-10-02 13:48:43 +00:00
|
|
|
return false;
|
2012-10-01 16:44:14 +00:00
|
|
|
},
|
|
|
|
|
2012-09-29 21:19:24 +00:00
|
|
|
expender: function(){
|
2012-10-17 15:09:41 +00:00
|
|
|
this.$('.oe_msg_body:first').expander({
|
2012-09-29 21:19:24 +00:00
|
|
|
slicePoint: this.options.truncate_limit,
|
|
|
|
expandText: 'read more',
|
|
|
|
userCollapseText: '[^]',
|
2012-10-17 00:13:20 +00:00
|
|
|
detailClass: 'oe_msg_tail',
|
2012-09-29 21:19:24 +00:00
|
|
|
moreClass: 'oe_mail_expand',
|
|
|
|
lessClass: 'oe_mail_reduce',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
create_thread: function(){
|
2012-10-01 09:36:33 +00:00
|
|
|
if(this.thread){
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-29 21:19:24 +00:00
|
|
|
/*create thread*/
|
2012-10-19 11:39:51 +00:00
|
|
|
this.thread = new mail.Thread(this, this.datasets, {
|
|
|
|
'domain': this.domain,
|
2012-09-29 21:19:24 +00:00
|
|
|
'context':{
|
2012-10-19 11:39:51 +00:00
|
|
|
'default_model': this.datasets.model,
|
|
|
|
'default_res_id': this.datasets.res_id,
|
|
|
|
'default_parent_id': this.datasets.id
|
2012-09-29 21:19:24 +00:00
|
|
|
},
|
2012-10-19 11:39:51 +00:00
|
|
|
'options': this.options
|
2012-09-29 21:19:24 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
/*insert thread in parent message*/
|
2012-10-19 11:39:51 +00:00
|
|
|
this.thread.insertAfter(this.$el);
|
2012-09-29 21:19:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
animated_destroy: function(options) {
|
|
|
|
var self=this;
|
|
|
|
//graphic effects
|
2012-10-02 15:12:45 +00:00
|
|
|
if(options && options.fadeTime) {
|
2012-09-29 21:19:24 +00:00
|
|
|
self.$el.fadeOut(options.fadeTime, function(){
|
|
|
|
self.destroy();
|
|
|
|
});
|
2012-10-22 07:50:58 +00:00
|
|
|
self.thread.$el.fadeOut(options.fadeTime);
|
2012-09-29 21:19:24 +00:00
|
|
|
} else {
|
|
|
|
self.destroy();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-09-11 16:38:53 +00:00
|
|
|
on_message_delete: function (event) {
|
2012-10-01 16:44:14 +00:00
|
|
|
event.stopPropagation();
|
2012-09-11 16:38:53 +00:00
|
|
|
if (! confirm(_t("Do you really want to delete this message?"))) { return false; }
|
2012-10-02 13:48:43 +00:00
|
|
|
|
|
|
|
this.animated_destroy({fadeTime:250});
|
|
|
|
// delete this message and his childs
|
2012-10-15 14:17:31 +00:00
|
|
|
var ids = [this.datasets.id].concat( this.get_child_ids() );
|
2012-10-02 13:48:43 +00:00
|
|
|
this.ds_message.unlink(ids);
|
|
|
|
return false;
|
2012-09-11 16:38:53 +00:00
|
|
|
},
|
|
|
|
|
2012-09-27 08:30:56 +00:00
|
|
|
/*The selected thread and all childs (messages/thread) became read
|
|
|
|
* @param {object} mouse envent
|
|
|
|
*/
|
2012-09-28 13:27:23 +00:00
|
|
|
on_message_read_unread: function (event) {
|
2012-10-19 12:06:57 +00:00
|
|
|
// TDE note: code here seems complicated... just check that current message is read (value coming from server)
|
|
|
|
// and send its opposite to set_message_read
|
2012-10-01 16:44:14 +00:00
|
|
|
event.stopPropagation();
|
2012-10-02 13:48:43 +00:00
|
|
|
// if this message is read, all childs message display is read
|
2012-10-15 14:17:31 +00:00
|
|
|
var ids = [this.datasets.id].concat( this.get_child_ids() );
|
2012-10-16 11:38:41 +00:00
|
|
|
var read = $(event.srcElement).hasClass("oe_read");
|
2012-10-18 13:50:50 +00:00
|
|
|
this.$el.removeClass(read ? 'oe_msg_unread':'oe_msg_read').addClass(read ? 'oe_msg_read':'oe_msg_unread');
|
2012-10-16 11:45:38 +00:00
|
|
|
|
2012-10-18 16:39:23 +00:00
|
|
|
if( (read && this.options.typeof_thread == 'inbox') ||
|
|
|
|
(!read && this.options.typeof_thread == 'archives')) {
|
2012-10-16 11:38:41 +00:00
|
|
|
this.animated_destroy({fadeTime:250});
|
2012-10-08 14:26:54 +00:00
|
|
|
}
|
2012-10-19 08:36:12 +00:00
|
|
|
// TDE note: should have a context here
|
2012-10-18 13:06:01 +00:00
|
|
|
this.ds_notification.call('set_message_read', [ids, read]);
|
2012-10-02 13:48:43 +00:00
|
|
|
return false;
|
2012-09-27 08:30:56 +00:00
|
|
|
},
|
|
|
|
|
2012-09-29 21:19:24 +00:00
|
|
|
/** browse message
|
|
|
|
* @param {object}{int} option.id
|
|
|
|
* @param {object}{string} option.model
|
|
|
|
* @param {object}{boolean} option._go_thread_wall
|
|
|
|
* private for check the top thread
|
|
|
|
* @return thread object
|
|
|
|
*/
|
|
|
|
browse_message: function(options){
|
|
|
|
// goto the wall thread for launch browse
|
|
|
|
if(!options._go_thread_wall) {
|
|
|
|
options._go_thread_wall = true;
|
2012-10-18 16:39:23 +00:00
|
|
|
for(var i in this.options._parents[0].messages){
|
|
|
|
var res=this.options._parents[0].messages[i].browse_message(options);
|
2012-09-29 21:19:24 +00:00
|
|
|
if(res) return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-15 14:17:31 +00:00
|
|
|
if(this.datasets.id==options.id)
|
2012-10-02 13:48:43 +00:00
|
|
|
return this;
|
2012-09-29 21:19:24 +00:00
|
|
|
|
2012-10-02 13:48:43 +00:00
|
|
|
for(var i in this.thread.messages){
|
|
|
|
if(this.thread.messages[i].thread){
|
2012-09-29 21:19:24 +00:00
|
|
|
var res=this.thread.messages[i].browse_message(options);
|
|
|
|
if(res) return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* get all child message/thread id linked
|
2012-09-27 08:30:56 +00:00
|
|
|
*/
|
2012-09-29 21:19:24 +00:00
|
|
|
get_child_ids: function(){
|
|
|
|
var res=[]
|
2012-10-15 14:17:31 +00:00
|
|
|
if(arguments[0]) res.push(this.datasets.id);
|
2012-09-29 21:19:24 +00:00
|
|
|
if(this.thread){
|
|
|
|
res = res.concat( this.thread.get_child_ids(true) );
|
2012-09-27 08:30:56 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
},
|
2012-10-01 09:36:33 +00:00
|
|
|
|
|
|
|
on_vote: function (event) {
|
2012-10-01 16:44:14 +00:00
|
|
|
event.stopPropagation();
|
2012-10-01 09:36:33 +00:00
|
|
|
var self=this;
|
2012-10-15 14:17:31 +00:00
|
|
|
return this.ds_message.call('vote_toggle', [[self.datasets.id]]).pipe(function(vote){
|
2012-10-19 12:06:57 +00:00
|
|
|
// TDE note: to update, because vote_user_ids is about to disappear to be replaced by vote_nb (number of votes)
|
2012-10-15 14:17:31 +00:00
|
|
|
self.datasets.has_voted=vote;
|
2012-10-19 11:39:51 +00:00
|
|
|
self.datasets.vote_nb += self.datasets.has_voted ? 1 : -1;
|
2012-10-01 16:44:14 +00:00
|
|
|
self.display_vote();
|
|
|
|
});
|
2012-10-02 13:48:43 +00:00
|
|
|
return false;
|
2012-10-01 09:36:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Render vote Display template.
|
|
|
|
display_vote: function () {
|
|
|
|
var self = this;
|
|
|
|
var vote_element = session.web.qweb.render('mail.thread.message.vote', {'widget': self});
|
2012-10-19 11:39:51 +00:00
|
|
|
self.$(".oe_msg_vote:first").remove();
|
|
|
|
self.$(".oe_mail_vote_count:first").replaceWith(vote_element);
|
2012-10-01 09:36:33 +00:00
|
|
|
},
|
2012-10-12 15:25:05 +00:00
|
|
|
|
|
|
|
// Stared/unstared + Render star.
|
|
|
|
on_star: function (event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
var self=this;
|
2012-10-16 11:45:38 +00:00
|
|
|
var button = self.$('button.oe_mail_starbox:first');
|
2012-10-18 15:23:22 +00:00
|
|
|
return this.ds_message.call('favorite_toggle', [[self.datasets.id]]).pipe(function(star){
|
|
|
|
self.datasets.is_favorite=star;
|
|
|
|
if(self.datasets.is_favorite){
|
2012-10-16 11:45:38 +00:00
|
|
|
button.addClass('oe_stared');
|
2012-10-12 15:25:05 +00:00
|
|
|
} else {
|
2012-10-16 11:45:38 +00:00
|
|
|
button.removeClass('oe_stared');
|
2012-10-18 16:39:23 +00:00
|
|
|
if( self.options.typeof_thread == 'stared' ) {
|
2012-10-16 11:45:38 +00:00
|
|
|
self.animated_destroy({fadeTime:250});
|
|
|
|
}
|
2012-10-12 15:25:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2012-09-29 21:19:24 +00:00
|
|
|
});
|
2012-09-27 08:30:56 +00:00
|
|
|
|
2012-09-29 21:19:24 +00:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* Thread Widget
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* This widget handles the display of a thread of messages. The
|
2012-10-10 18:16:11 +00:00
|
|
|
* thread view:
|
|
|
|
* - root thread
|
2012-09-29 21:19:24 +00:00
|
|
|
* - - sub message (parent_id = root message)
|
2012-10-10 18:16:11 +00:00
|
|
|
* - - - sub thread
|
|
|
|
* - - - - sub sub message (parent id = sub thread)
|
2012-09-29 21:19:24 +00:00
|
|
|
* - - sub message (parent_id = root message)
|
2012-10-10 18:16:11 +00:00
|
|
|
* - - - sub thread
|
2012-09-29 21:19:24 +00:00
|
|
|
*/
|
|
|
|
mail.Thread = session.web.Widget.extend({
|
|
|
|
template: 'mail.thread',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object} parent parent
|
|
|
|
* @param {Array} [domain]
|
|
|
|
* @param {Object} [context] context of the thread. It should
|
|
|
|
contain at least default_model, default_res_id. Please refer to
|
|
|
|
the ComposeMessage widget for more information about it.
|
|
|
|
* @param {Object} [options]
|
2012-10-01 09:36:33 +00:00
|
|
|
* @param {Object} [message] read about mail.ThreadMessage object
|
|
|
|
* @param {Object} [thread]
|
2012-10-18 16:39:23 +00:00
|
|
|
* @param {int} [display_indented_thread] number thread level to indented threads.
|
|
|
|
* other are on flat mode
|
2012-10-16 11:38:41 +00:00
|
|
|
* @param {Select} [typeof_thread] inbox/archives/stared/sent
|
|
|
|
* type of thread and option for user application like animate
|
|
|
|
* destroy for read/unread
|
2012-10-01 09:36:33 +00:00
|
|
|
* @param {Array} [parents] liked with the parents thread
|
2012-10-10 11:02:03 +00:00
|
|
|
* use with browse, fetch... [O]= top parent
|
2012-09-29 21:19:24 +00:00
|
|
|
*/
|
2012-10-18 16:39:23 +00:00
|
|
|
init: function(parent, datasets, options) {
|
2012-09-29 21:19:24 +00:00
|
|
|
this._super(parent);
|
|
|
|
this.domain = options.domain || [];
|
|
|
|
this.context = _.extend({
|
|
|
|
default_model: 'mail.thread',
|
2012-10-15 14:17:31 +00:00
|
|
|
default_res_id: 0,
|
2012-09-29 21:19:24 +00:00
|
|
|
default_parent_id: false }, options.context || {});
|
|
|
|
|
2012-10-19 13:53:56 +00:00
|
|
|
this.options = options.options;
|
|
|
|
this.options._parents = (options.options._parents != undefined ? options.options._parents : []).concat( [this] );
|
2012-10-01 09:36:33 +00:00
|
|
|
|
2012-09-29 21:19:24 +00:00
|
|
|
// record options and data
|
2012-10-16 11:38:41 +00:00
|
|
|
this.parent_message= parent.thread!= undefined ? parent : false ;
|
2012-09-29 21:19:24 +00:00
|
|
|
|
2012-10-16 12:41:05 +00:00
|
|
|
// datasets and internal vars
|
|
|
|
this.datasets = {
|
2012-10-18 16:39:23 +00:00
|
|
|
'id' : datasets.id || false,
|
|
|
|
'model' : datasets.model || false,
|
|
|
|
'parent_id' : datasets.parent_id || false,
|
|
|
|
'is_private' : datasets.is_private || false,
|
|
|
|
'author_id' : datasets.author_id || false,
|
|
|
|
'thread_level' : (datasets.thread_level+1) || 0,
|
2012-10-19 14:32:28 +00:00
|
|
|
'partner_ids' : _.filter(datasets.partner_ids, function(partner){ return partner[0]!=datasets.author_id[0]; } )
|
2012-10-16 12:41:05 +00:00
|
|
|
};
|
|
|
|
|
2012-10-22 07:50:58 +00:00
|
|
|
this.datasets.show_compose_message = this.options.show_compose_message && this.options.show_reply_button > this.datasets.thread_level;
|
2012-10-18 16:39:23 +00:00
|
|
|
|
2012-09-29 21:19:24 +00:00
|
|
|
this.messages = [];
|
2012-10-17 00:13:20 +00:00
|
|
|
this.ComposeMessage = false;
|
2012-09-29 21:19:24 +00:00
|
|
|
|
2012-10-12 12:40:03 +00:00
|
|
|
this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model || 'mail.thread');
|
2012-09-29 21:19:24 +00:00
|
|
|
this.ds_message = new session.web.DataSetSearch(this, 'mail.message');
|
|
|
|
},
|
|
|
|
|
|
|
|
start: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-10-19 13:53:56 +00:00
|
|
|
if(this.datasets.show_compose_message){
|
2012-10-18 16:39:23 +00:00
|
|
|
this.instantiate_ComposeMessage();
|
|
|
|
}
|
2012-10-01 09:36:33 +00:00
|
|
|
this.bind_events();
|
2012-09-29 21:19:24 +00:00
|
|
|
},
|
|
|
|
|
2012-10-05 12:27:41 +00:00
|
|
|
instantiate_ComposeMessage: function(){
|
|
|
|
// add message composition form view
|
2012-10-18 16:39:23 +00:00
|
|
|
this.ComposeMessage = new mail.ThreadComposeMessage(this, this.datasets, {
|
2012-10-05 12:27:41 +00:00
|
|
|
'context': this.context,
|
2012-10-15 14:17:31 +00:00
|
|
|
'options': this.options,
|
2012-10-05 12:27:41 +00:00
|
|
|
});
|
2012-10-08 14:26:54 +00:00
|
|
|
|
2012-10-17 13:37:50 +00:00
|
|
|
if(this.datasets.thread_level){
|
|
|
|
this.ComposeMessage.appendTo(this.$el);
|
2012-10-17 15:03:27 +00:00
|
|
|
} else {
|
2012-10-18 08:04:11 +00:00
|
|
|
// root view
|
2012-10-17 15:03:27 +00:00
|
|
|
this.ComposeMessage.prependTo(this.$el);
|
2012-10-08 15:20:45 +00:00
|
|
|
}
|
2012-10-19 11:39:51 +00:00
|
|
|
this.ComposeMessage.do_hide_compact();
|
2012-10-05 10:46:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* 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();
|
2012-10-19 13:13:58 +00:00
|
|
|
this.$('.oe_msg_expandable:last');
|
|
|
|
|
2012-10-19 12:38:16 +00:00
|
|
|
var message = this.messages[this.messages.length-1];
|
2012-10-17 00:13:20 +00:00
|
|
|
if(message && message.datasets.type=="expandable" && message.datasets.max_limit){
|
|
|
|
var pos = message.$el.position();
|
|
|
|
if(pos.top){
|
|
|
|
/* bottom of the screen */
|
|
|
|
var bottom = $(window).scrollTop()+$(window).height()+200;
|
2012-10-19 12:38:16 +00:00
|
|
|
if(bottom > pos.top){
|
2012-10-17 00:13:20 +00:00
|
|
|
message.on_expandable();
|
2012-10-05 10:46:54 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-17 00:13:20 +00:00
|
|
|
}
|
2012-10-05 10:46:54 +00:00
|
|
|
},
|
|
|
|
|
2012-09-29 21:19:24 +00:00
|
|
|
/**
|
|
|
|
* Bind events in the widget. Each event is slightly described
|
|
|
|
* in the function. */
|
|
|
|
bind_events: function() {
|
|
|
|
var self = this;
|
2012-10-18 08:04:11 +00:00
|
|
|
self.$el.on('click', '.oe_mail_list_recipients .oe_more', self.on_show_recipients);
|
|
|
|
self.$el.on('click', '.oe_mail_compose_textarea .oe_more_hidden', self.on_hide_recipients);
|
|
|
|
},
|
|
|
|
|
|
|
|
on_show_recipients: function(){
|
|
|
|
var p=$(this).parent();
|
|
|
|
p.find('.oe_more_hidden, .oe_hidden').show();
|
|
|
|
p.find('.oe_more').hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
on_hide_recipients: function(){
|
|
|
|
var p=$(this).parent();
|
|
|
|
p.find('.oe_more_hidden, .oe_hidden').hide();
|
|
|
|
p.find('.oe_more').show();
|
2012-09-29 21:19:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* get all child message/thread id linked
|
|
|
|
*/
|
|
|
|
get_child_ids: function(){
|
|
|
|
var res=[];
|
2012-10-16 11:38:41 +00:00
|
|
|
_(this.get_childs()).each(function (val, key) { res.push(val.datasets.id); });
|
|
|
|
return res;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* get all child message/thread linked
|
|
|
|
*/
|
|
|
|
get_childs: function(nb_thread_level){
|
|
|
|
var res=[];
|
|
|
|
if(arguments[1]) res.push(this);
|
|
|
|
if(isNaN(nb_thread_level) || nb_thread_level>0){
|
|
|
|
_(this.messages).each(function (val, key) {
|
|
|
|
if(val.thread){
|
|
|
|
res = res.concat( val.thread.get_childs((isNaN(nb_thread_level) ? null : nb_thread_level-1), true) )
|
|
|
|
}
|
|
|
|
});
|
2012-09-29 21:19:24 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** browse thread
|
2012-09-27 08:30:56 +00:00
|
|
|
* @param {object}{int} option.id
|
|
|
|
* @param {object}{string} option.model
|
|
|
|
* @param {object}{boolean} option._go_thread_wall
|
|
|
|
* private for check the top thread
|
2012-10-02 10:52:35 +00:00
|
|
|
* @param {object}{boolean} option.default_return_top_thread
|
2012-09-27 16:15:58 +00:00
|
|
|
* return the top thread (wall) if no thread found
|
2012-09-27 08:30:56 +00:00
|
|
|
* @return thread object
|
|
|
|
*/
|
|
|
|
browse_thread: function(options){
|
|
|
|
// goto the wall thread for launch browse
|
|
|
|
if(!options._go_thread_wall) {
|
|
|
|
options._go_thread_wall = true;
|
2012-10-18 16:39:23 +00:00
|
|
|
return this.options._parents[0].browse_thread(options);
|
2012-09-27 08:30:56 +00:00
|
|
|
}
|
|
|
|
|
2012-10-15 14:17:31 +00:00
|
|
|
if(this.datasets.id==options.id){
|
2012-10-02 13:48:43 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(options.id)
|
|
|
|
for(var i in this.messages){
|
|
|
|
if(this.messages[i].thread){
|
|
|
|
var res=this.messages[i].thread.browse_thread({'id':options.id, '_go_thread_wall':true});
|
2012-09-27 16:15:58 +00:00
|
|
|
if(res) return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-02 10:52:35 +00:00
|
|
|
//if option default_return_top_thread, return the top if no found thread
|
|
|
|
if(options.default_return_top_thread){
|
2012-10-02 13:48:43 +00:00
|
|
|
return this;
|
2012-09-27 08:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2012-09-29 21:19:24 +00:00
|
|
|
/** browse message
|
|
|
|
* @param {object}{int} option.id
|
|
|
|
* @param {object}{string} option.model
|
|
|
|
* @param {object}{boolean} option._go_thread_wall
|
|
|
|
* private for check the top thread
|
|
|
|
* @return thread object
|
|
|
|
*/
|
|
|
|
browse_message: function(options){
|
2012-10-18 16:39:23 +00:00
|
|
|
if(this.options._parents[0].messages[0])
|
|
|
|
return this.options._parents[0].messages[0].browse_message(options);
|
2012-08-21 10:43:45 +00:00
|
|
|
},
|
|
|
|
|
2012-10-01 17:52:25 +00:00
|
|
|
/* this function is launch when a user click on "Reply" button
|
|
|
|
*/
|
2012-10-05 10:46:54 +00:00
|
|
|
on_compose_message: function(){
|
2012-10-19 14:32:28 +00:00
|
|
|
if(!this.ComposeMessage){
|
|
|
|
this.instantiate_ComposeMessage();
|
|
|
|
this.ComposeMessage.do_hide_compact();
|
|
|
|
}
|
|
|
|
|
2012-10-18 08:04:11 +00:00
|
|
|
this.ComposeMessage.on_compose_expandable();
|
2012-10-01 17:52:25 +00:00
|
|
|
},
|
|
|
|
|
2012-10-17 13:37:50 +00:00
|
|
|
/* display the no message on the thread
|
|
|
|
*/
|
|
|
|
no_message: function(){
|
|
|
|
$(session.web.qweb.render('mail.wall_no_message', {})).appendTo(this.$el);
|
|
|
|
},
|
|
|
|
|
2012-08-21 09:20:15 +00:00
|
|
|
/** Fetch messages
|
2012-10-02 13:48:43 +00:00
|
|
|
* @param {Array} replace_domain: added to this.domain
|
|
|
|
* @param {Object} replace_context: added to this.context
|
2012-08-21 09:20:15 +00:00
|
|
|
*/
|
2012-10-12 12:40:03 +00:00
|
|
|
message_fetch: function (initial_mode, replace_domain, replace_context, ids, callback) {
|
2012-02-29 08:59:53 +00:00
|
|
|
var self = this;
|
2012-09-29 21:19:24 +00:00
|
|
|
|
2012-09-03 15:20:25 +00:00
|
|
|
// domain and context: options + additional
|
2012-10-02 13:48:43 +00:00
|
|
|
fetch_domain = replace_domain ? replace_domain : this.domain;
|
|
|
|
fetch_context = replace_context ? replace_context : this.context;
|
2012-10-19 09:02:52 +00:00
|
|
|
var message_loaded = [this.datasets.id||0].concat( self.options._parents[0].get_child_ids() );
|
2012-10-03 08:40:29 +00:00
|
|
|
|
2012-10-18 13:06:01 +00:00
|
|
|
return this.ds_message.call('message_read', [ids, fetch_domain, message_loaded, fetch_context, this.context.default_parent_id || undefined]
|
2012-10-01 11:03:35 +00:00
|
|
|
).then(this.proxy('switch_new_message'));
|
2012-04-04 12:00:53 +00:00
|
|
|
},
|
2012-08-21 09:20:15 +00:00
|
|
|
|
2012-10-01 09:36:33 +00:00
|
|
|
/* create record object and linked him
|
2012-09-03 15:20:25 +00:00
|
|
|
*/
|
2012-10-17 00:13:20 +00:00
|
|
|
create_message_object: function (data) {
|
2012-03-05 16:59:10 +00:00
|
|
|
var self = this;
|
2012-09-28 13:27:23 +00:00
|
|
|
|
2012-10-17 00:13:20 +00:00
|
|
|
if(data.type=='expandable'){
|
2012-10-18 16:39:23 +00:00
|
|
|
var message = new mail.ThreadExpandable(self, data, {
|
2012-10-17 00:13:20 +00:00
|
|
|
'domain': data.domain,
|
2012-10-02 13:48:43 +00:00
|
|
|
'context': {
|
2012-10-17 00:13:20 +00:00
|
|
|
'default_model': data.model || self.context.default_model,
|
|
|
|
'default_res_id': data.res_id || self.context.default_res_id,
|
2012-10-15 16:03:24 +00:00
|
|
|
'default_parent_id': self.datasets.id },
|
2012-10-02 13:48:43 +00:00
|
|
|
});
|
|
|
|
} else {
|
2012-10-18 16:39:23 +00:00
|
|
|
var message = new mail.ThreadMessage(self, _.extend(data, {'thread_level': self.datasets.thread_level}), {
|
2012-10-17 00:13:20 +00:00
|
|
|
'domain': data.domain,
|
2012-10-02 13:48:43 +00:00
|
|
|
'context': {
|
2012-10-17 00:13:20 +00:00
|
|
|
'default_model': data.model,
|
|
|
|
'default_res_id': data.res_id,
|
|
|
|
'default_parent_id': data.id },
|
2012-10-18 16:39:23 +00:00
|
|
|
'options': self.options
|
2012-10-02 13:48:43 +00:00
|
|
|
});
|
2012-10-17 00:13:20 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 13:13:58 +00:00
|
|
|
// insert the message on dom
|
|
|
|
self.insert_message( message );
|
|
|
|
|
2012-10-17 00:13:20 +00:00
|
|
|
// check if the message is already create
|
|
|
|
for(var i in self.messages){
|
2012-10-17 13:37:50 +00:00
|
|
|
if(self.messages[i].datasets.id == message.datasets.id){
|
2012-10-17 00:13:20 +00:00
|
|
|
self.messages[i].destroy();
|
2012-10-19 13:13:58 +00:00
|
|
|
if(message.datasets.id>0){
|
|
|
|
self.messages[i] = message;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
delete self.messages[i];
|
|
|
|
}
|
2012-10-17 00:13:20 +00:00
|
|
|
}
|
2012-10-02 13:48:43 +00:00
|
|
|
}
|
2012-10-19 13:13:58 +00:00
|
|
|
self.messages.push( message );
|
2012-10-17 00:13:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/** Displays a message or an expandable message */
|
|
|
|
insert_message: function (message) {
|
|
|
|
var self=this;
|
|
|
|
|
2012-10-22 07:50:58 +00:00
|
|
|
if(this.datasets.show_compose_message &&
|
|
|
|
this.options.display_indented_thread > self.datasets.thread_level){
|
2012-10-19 11:39:51 +00:00
|
|
|
this.ComposeMessage.do_show_compact();
|
2012-10-19 09:02:52 +00:00
|
|
|
}
|
2012-10-18 16:39:23 +00:00
|
|
|
|
2012-10-17 13:37:50 +00:00
|
|
|
this.$('.oe_wall_no_message').remove();
|
2012-10-02 10:52:35 +00:00
|
|
|
|
2012-10-16 11:38:41 +00:00
|
|
|
// insert on hierarchy display => insert in self child
|
|
|
|
var thread_messages = self.messages;
|
|
|
|
var thread = self;
|
2012-10-18 16:39:23 +00:00
|
|
|
if( self.options.display_indented_thread < self.datasets.thread_level ) {
|
|
|
|
var thread = self.options._parents[self.options.display_indented_thread] || self.options._parents[0];
|
2012-10-16 11:38:41 +00:00
|
|
|
var thread_messages = [];
|
2012-10-18 16:39:23 +00:00
|
|
|
_(thread.get_childs()).each(function (val, key) { thread_messages.push(val.parent_message); });
|
2012-10-16 11:38:41 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 07:50:58 +00:00
|
|
|
// check older and newer message for insertion
|
2012-09-27 08:30:56 +00:00
|
|
|
var parent_newer = false;
|
|
|
|
var parent_older = false;
|
2012-10-19 12:38:16 +00:00
|
|
|
if(message.datasets.id > 0){
|
|
|
|
for(var i in thread_messages){
|
|
|
|
if(thread_messages[i].datasets.id > message.datasets.id){
|
|
|
|
if(!parent_newer ||
|
|
|
|
parent_newer.datasets.id > thread_messages[i].datasets.id) {
|
|
|
|
parent_newer = thread_messages[i];
|
|
|
|
}
|
|
|
|
} else if(thread_messages[i].datasets.id > 0 && thread_messages[i].datasets.id < message.datasets.id) {
|
|
|
|
if(!parent_older ||
|
|
|
|
parent_older.datasets.id < thread_messages[i].datasets.id) {
|
|
|
|
parent_older = thread_messages[i];
|
|
|
|
}
|
2012-10-12 12:40:03 +00:00
|
|
|
}
|
2012-09-27 13:48:23 +00:00
|
|
|
}
|
2012-10-01 09:36:33 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 07:50:58 +00:00
|
|
|
var sort = (!!self.datasets.thread_level || message.datasets.id<0);
|
2012-10-10 18:16:11 +00:00
|
|
|
|
2012-10-08 15:20:45 +00:00
|
|
|
if(parent_older){
|
2012-10-10 18:16:11 +00:00
|
|
|
if(sort){
|
2012-10-17 15:03:27 +00:00
|
|
|
message.insertAfter(parent_older.thread ? parent_older.thread.$el : parent_older.$el);
|
2012-10-18 16:39:23 +00:00
|
|
|
} else {
|
|
|
|
message.insertBefore(parent_older.$el);
|
2012-10-10 18:16:11 +00:00
|
|
|
}
|
2012-10-16 11:38:41 +00:00
|
|
|
} else if(parent_newer){
|
2012-10-18 16:39:23 +00:00
|
|
|
if(sort || parent_newer.datasets.id<0){
|
2012-10-10 18:16:11 +00:00
|
|
|
message.insertBefore(parent_newer.$el);
|
2012-10-18 16:39:23 +00:00
|
|
|
} else {
|
|
|
|
message.insertAfter(parent_newer.thread ? parent_newer.thread.$el : parent_newer.$el);
|
2012-10-10 18:16:11 +00:00
|
|
|
}
|
2012-10-16 11:38:41 +00:00
|
|
|
} else {
|
2012-10-19 12:38:16 +00:00
|
|
|
if(sort && message.datasets.id>0) {
|
2012-10-17 13:37:50 +00:00
|
|
|
message.prependTo(thread.$el);
|
2012-10-10 18:16:11 +00:00
|
|
|
} else {
|
2012-10-17 13:37:50 +00:00
|
|
|
message.appendTo(thread.$el);
|
2012-10-10 18:16:11 +00:00
|
|
|
}
|
2012-10-08 15:20:45 +00:00
|
|
|
}
|
2012-10-12 12:40:03 +00:00
|
|
|
|
2012-10-19 08:19:26 +00:00
|
|
|
self.$('.oe_msg_first:first').removeClass("oe_msg_first");
|
|
|
|
self.$('.oe_msg_last:last').removeClass("oe_msg_last");
|
|
|
|
self.$('.oe_msg_comment:first, .oe_msg_comment:first-child').addClass("oe_msg_first");
|
|
|
|
self.$('.oe_msg_comment:last, .oe_msg_comment:last-child').addClass("oe_msg_last");
|
|
|
|
|
2012-10-02 10:52:35 +00:00
|
|
|
return message
|
2012-09-29 21:19:24 +00:00
|
|
|
},
|
2012-02-23 16:32:36 +00:00
|
|
|
|
2012-10-02 10:52:35 +00:00
|
|
|
/* Send the records to his parent thread */
|
2012-10-01 11:03:35 +00:00
|
|
|
switch_new_message: function(records) {
|
2012-09-26 07:17:09 +00:00
|
|
|
var self=this;
|
2012-10-02 10:52:35 +00:00
|
|
|
_(records).each(function(record){
|
2012-10-02 13:48:43 +00:00
|
|
|
self.browse_thread({
|
2012-10-02 15:12:45 +00:00
|
|
|
'id': record.parent_id,
|
2012-10-02 13:48:43 +00:00
|
|
|
'default_return_top_thread':true
|
|
|
|
}).create_message_object( record );
|
2012-09-28 14:51:47 +00:00
|
|
|
});
|
|
|
|
},
|
2012-02-23 16:32:36 +00:00
|
|
|
});
|
|
|
|
|
2012-10-17 13:37:50 +00:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------
|
2012-10-17 14:20:05 +00:00
|
|
|
* mail : root Widget
|
2012-10-17 13:37:50 +00:00
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
2012-10-17 14:20:05 +00:00
|
|
|
* This widget handles the display of messages with thread options. Its main
|
2012-10-17 13:37:50 +00:00
|
|
|
* use is to receive a context and a domain, and to delegate the message
|
|
|
|
* fetching and displaying to the Thread widget.
|
|
|
|
*/
|
|
|
|
session.web.client_actions.add('mail.Widget', 'session.mail.Widget');
|
|
|
|
mail.Widget = session.web.Widget.extend({
|
|
|
|
template: 'mail.Widget',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object} parent parent
|
2012-10-17 14:20:05 +00:00
|
|
|
* @param {Array} [domain]
|
|
|
|
* @param {Object} [context] context of the thread. It should
|
|
|
|
* contain at least default_model, default_res_id. Please refer to
|
|
|
|
* the ComposeMessage widget for more information about it.
|
|
|
|
* ... @param {Select} [typeof_thread=(mail|stared|archives|send|other)]
|
|
|
|
* options for destroy message when the user click on a button
|
2012-10-17 13:37:50 +00:00
|
|
|
* @param {Object} [options]
|
2012-10-17 14:20:05 +00:00
|
|
|
*... @param {Number} [truncate_limit=250] 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
|
|
|
|
*... @param {Boolean} [show_record_name] display the name and link for do action
|
2012-10-18 16:39:23 +00:00
|
|
|
*... @param {int} [show_reply_button] number thread level to display the reply button
|
|
|
|
*... @param {int} [show_read_unread_button] number thread level to display the read/unread button
|
|
|
|
*... @param {int} [display_indented_thread] number thread level to indented threads.
|
|
|
|
* other are on flat mode
|
2012-10-19 14:32:28 +00:00
|
|
|
*... @param {Boolean} [show_compose_message] allow to display the composer
|
|
|
|
*... @param {Boolean} [show_compact_message] display the compact message on the thread
|
|
|
|
* when the user clic on this compact mode, the composer is open
|
2012-10-17 13:37:50 +00:00
|
|
|
*/
|
|
|
|
init: function (parent, options) {
|
|
|
|
this._super(parent);
|
2012-10-19 13:53:56 +00:00
|
|
|
this.domain = options.domain || [];
|
|
|
|
this.context = options.context || {};
|
2012-10-17 13:37:50 +00:00
|
|
|
this.search_results = {'domain': [], 'context': {}, 'groupby': {}};
|
2012-10-19 13:53:56 +00:00
|
|
|
|
2012-10-19 14:32:28 +00:00
|
|
|
this.options = _.extend({
|
|
|
|
'typeof_thread' : 'inbox',
|
|
|
|
'display_indented_thread' : -1,
|
|
|
|
'show_reply_button' : -1,
|
|
|
|
'show_read_unread_button' : -1,
|
|
|
|
'truncate_limit' : 250,
|
|
|
|
'show_record_name' : false,
|
|
|
|
'show_compose_message' : false,
|
|
|
|
'show_compact_message' : false
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
if(this.display_indented_thread === false) {
|
|
|
|
this.display_indented_thread = -1;
|
|
|
|
}
|
|
|
|
if(this.show_reply_button === false) {
|
|
|
|
this.show_reply_button = -1;
|
|
|
|
}
|
|
|
|
if(this.show_read_unread_button === false) {
|
|
|
|
this.show_read_unread_button = -1;
|
|
|
|
}
|
|
|
|
|
2012-10-17 13:37:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
start: function (options) {
|
|
|
|
this._super.apply(this, arguments);
|
2012-10-17 14:20:05 +00:00
|
|
|
this.message_render();
|
|
|
|
this.bind_events();
|
2012-10-17 13:37:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the threads
|
|
|
|
*/
|
|
|
|
message_render: function (search) {
|
2012-10-19 13:53:56 +00:00
|
|
|
|
2012-10-18 16:39:23 +00:00
|
|
|
this.thread = new mail.Thread(this, {}, {
|
2012-10-19 13:53:56 +00:00
|
|
|
'domain' : this.domain,
|
|
|
|
'context' : this.context,
|
|
|
|
'options': this.options,
|
2012-10-18 16:39:23 +00:00
|
|
|
});
|
2012-10-17 13:37:50 +00:00
|
|
|
|
|
|
|
this.thread.appendTo( this.$el );
|
|
|
|
this.thread.no_message();
|
|
|
|
this.thread.message_fetch();
|
2012-10-19 11:39:51 +00:00
|
|
|
|
|
|
|
if(this.options.show_compose_message){
|
|
|
|
this.thread.ComposeMessage.do_show_compact();
|
|
|
|
}
|
2012-10-17 13:37:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
bind_events: function(){
|
2012-10-19 13:53:56 +00:00
|
|
|
if(this.context['typeof_thread']!='other'){
|
2012-10-17 14:20:05 +00:00
|
|
|
$(document).scroll( this.thread.on_scroll );
|
|
|
|
$(window).resize( this.thread.on_scroll );
|
|
|
|
window.setTimeout( this.thread.on_scroll, 500 );
|
|
|
|
}
|
2012-10-17 13:37:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-02-23 16:32:36 +00:00
|
|
|
|
2012-06-15 08:36:56 +00:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------
|
2012-06-20 09:18:22 +00:00
|
|
|
* mail_thread Widget
|
2012-06-15 08:36:56 +00:00
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
2012-09-11 13:37:06 +00:00
|
|
|
* This widget handles the display of messages on a document. Its main
|
|
|
|
* use is to receive a context and a domain, and to delegate the message
|
|
|
|
* fetching and displaying to the Thread widget.
|
2012-06-15 08:36:56 +00:00
|
|
|
*/
|
2012-06-20 09:18:22 +00:00
|
|
|
session.web.form.widgets.add('mail_thread', 'openerp.mail.RecordThread');
|
2012-04-16 10:29:54 +00:00
|
|
|
mail.RecordThread = session.web.form.AbstractField.extend({
|
2012-06-15 08:36:56 +00:00
|
|
|
template: 'mail.record_thread',
|
2012-02-23 16:32:36 +00:00
|
|
|
|
2012-08-21 09:20:15 +00:00
|
|
|
init: function() {
|
2012-02-06 09:06:18 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-08-21 11:41:28 +00:00
|
|
|
this.options.domain = this.options.domain || [];
|
2012-09-03 15:20:25 +00:00
|
|
|
this.options.context = {'default_model': 'mail.thread', 'default_res_id': false};
|
2012-02-02 14:18:43 +00:00
|
|
|
},
|
2012-08-18 20:18:59 +00:00
|
|
|
|
2012-02-06 11:26:23 +00:00
|
|
|
start: function() {
|
2012-09-03 15:20:25 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-09-11 13:37:06 +00:00
|
|
|
// NB: check the actual_mode property on view to know if the view is in create mode anymore
|
2012-07-26 12:15:50 +00:00
|
|
|
this.view.on("change:actual_mode", this, this._check_visibility);
|
|
|
|
this._check_visibility();
|
2012-02-06 15:10:09 +00:00
|
|
|
},
|
2012-08-21 11:41:28 +00:00
|
|
|
|
2012-07-26 12:15:50 +00:00
|
|
|
_check_visibility: function() {
|
2012-08-24 18:27:43 +00:00
|
|
|
this.$el.toggle(this.view.get("actual_mode") !== "create");
|
2012-07-26 12:15:50 +00:00
|
|
|
},
|
2012-10-12 11:09:43 +00:00
|
|
|
render_value: function() {
|
2012-10-19 11:27:00 +00:00
|
|
|
var self = this;
|
2012-10-16 12:41:05 +00:00
|
|
|
if (! this.view.datarecord.id || session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) {
|
2012-09-26 07:17:09 +00:00
|
|
|
this.$('oe_mail_thread').hide();
|
2012-07-10 09:42:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-21 11:41:28 +00:00
|
|
|
// update context
|
2012-09-03 15:20:25 +00:00
|
|
|
_.extend(this.options.context, {
|
|
|
|
default_res_id: this.view.datarecord.id,
|
2012-10-12 13:02:32 +00:00
|
|
|
default_model: this.view.model,
|
|
|
|
default_is_private: false });
|
2012-09-11 14:17:40 +00:00
|
|
|
// update domain
|
|
|
|
var domain = this.options.domain.concat([['model', '=', this.view.model], ['res_id', '=', this.view.datarecord.id]]);
|
2012-10-19 09:02:52 +00:00
|
|
|
|
2012-10-16 11:17:53 +00:00
|
|
|
// TDE note: replace message_is_follower by a check in message_follower_ids, as message_is_follower is not used in views anymore
|
2012-10-19 11:39:51 +00:00
|
|
|
var show_compose_message = this.view.is_action_enabled('edit') ||
|
2012-09-18 09:44:23 +00:00
|
|
|
(this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value());
|
2012-09-27 13:48:23 +00:00
|
|
|
|
2012-10-19 09:02:52 +00:00
|
|
|
if(this.root){
|
|
|
|
this.root.destroy();
|
2012-10-10 11:02:03 +00:00
|
|
|
}
|
2012-10-19 09:02:52 +00:00
|
|
|
// create and render Thread widget
|
|
|
|
this.root = new mail.Widget(this, {
|
|
|
|
'domain' : domain,
|
|
|
|
'context' : this.options.context,
|
|
|
|
'typeof_thread': this.options.context['typeof_thread'] || 'other',
|
2012-10-19 13:53:56 +00:00
|
|
|
'display_indented_thread': -1,
|
|
|
|
'show_reply_button': 10,
|
|
|
|
'show_read_unread_button': -1,
|
2012-10-19 11:39:51 +00:00
|
|
|
'show_compose_message': show_compose_message
|
2012-09-27 13:48:23 +00:00
|
|
|
}
|
|
|
|
);
|
2012-10-17 14:20:05 +00:00
|
|
|
|
2012-10-19 09:02:52 +00:00
|
|
|
return this.root.appendTo( this.$('.oe_mail_wall_threads:first') );
|
2012-02-10 12:43:48 +00:00
|
|
|
},
|
2012-02-02 14:18:43 +00:00
|
|
|
});
|
2012-06-21 21:55:27 +00:00
|
|
|
|
2012-06-19 13:58:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------
|
2012-08-21 11:41:28 +00:00
|
|
|
* Wall Widget
|
2012-06-19 13:58:27 +00:00
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
2012-09-11 13:37:06 +00:00
|
|
|
* This widget handles the display of messages on a Wall. Its main
|
|
|
|
* use is to receive a context and a domain, and to delegate the message
|
|
|
|
* fetching and displaying to the Thread widget.
|
2012-06-19 13:58:27 +00:00
|
|
|
*/
|
2012-06-20 09:18:22 +00:00
|
|
|
session.web.client_actions.add('mail.wall', 'session.mail.Wall');
|
2012-06-21 15:24:28 +00:00
|
|
|
mail.Wall = session.web.Widget.extend({
|
2012-06-19 12:12:11 +00:00
|
|
|
template: 'mail.wall',
|
2012-02-08 16:42:29 +00:00
|
|
|
|
2012-02-28 08:51:11 +00:00
|
|
|
/**
|
|
|
|
* @param {Object} parent parent
|
2012-08-21 11:41:28 +00:00
|
|
|
* @param {Object} [options]
|
2012-09-12 09:21:43 +00:00
|
|
|
* @param {Array} [options.domain] domain on the Wall
|
|
|
|
* @param {Object} [options.context] context, is an object. It should
|
2012-09-03 15:20:25 +00:00
|
|
|
* contain default_model, default_res_id, to give it to the threads.
|
2012-09-12 09:21:43 +00:00
|
|
|
* @param {Number} [options.thread_level] number of thread levels to display
|
|
|
|
* 0 being flat.
|
2012-02-28 08:51:11 +00:00
|
|
|
*/
|
2012-08-20 13:07:30 +00:00
|
|
|
init: function (parent, options) {
|
2012-02-09 10:04:47 +00:00
|
|
|
this._super(parent);
|
2012-08-20 13:07:30 +00:00
|
|
|
this.options = options || {};
|
|
|
|
this.options.domain = options.domain || [];
|
|
|
|
this.options.context = options.context || {};
|
2012-04-05 11:34:19 +00:00
|
|
|
this.search_results = {'domain': [], 'context': {}, 'groupby': {}}
|
2012-09-11 13:21:22 +00:00
|
|
|
this.ds_msg = new session.web.DataSetSearch(this, 'mail.message');
|
2012-02-08 17:08:08 +00:00
|
|
|
},
|
|
|
|
|
2012-03-30 15:11:47 +00:00
|
|
|
start: function () {
|
2012-02-08 17:08:08 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-09-12 09:21:43 +00:00
|
|
|
var searchview_ready = this.load_searchview({}, false);
|
|
|
|
var thread_displayed = this.message_render();
|
2012-10-03 10:22:20 +00:00
|
|
|
this.options.domain = this.options.domain.concat(this.search_results['domain']);
|
2012-10-05 13:10:13 +00:00
|
|
|
this.bind_events();
|
2012-10-17 10:40:26 +00:00
|
|
|
return $.when(searchview_ready, thread_displayed);
|
2012-02-08 17:08:08 +00:00
|
|
|
},
|
2012-07-11 13:14:30 +00:00
|
|
|
|
2012-02-28 08:51:11 +00:00
|
|
|
/**
|
2012-08-20 15:52:02 +00:00
|
|
|
* Load the mail.message search view
|
2012-02-29 14:23:31 +00:00
|
|
|
* @param {Object} defaults ??
|
2012-03-30 15:11:47 +00:00
|
|
|
* @param {Boolean} hidden some kind of trick we do not care here
|
2012-02-28 08:51:11 +00:00
|
|
|
*/
|
2012-09-12 09:21:43 +00:00
|
|
|
load_searchview: function (defaults, hidden) {
|
2012-03-30 15:11:47 +00:00
|
|
|
var self = this;
|
2012-08-19 17:53:09 +00:00
|
|
|
this.searchview = new session.web.SearchView(this, this.ds_msg, false, defaults || {}, hidden || false);
|
2012-09-26 07:17:09 +00:00
|
|
|
return this.searchview.appendTo(this.$('.oe_view_manager_view_search')).then(function () {
|
2012-10-19 07:44:49 +00:00
|
|
|
self.searchview.on('search_data', self, self.do_searchview_search);
|
2012-03-30 15:11:47 +00:00
|
|
|
});
|
2012-02-24 15:21:59 +00:00
|
|
|
},
|
2012-02-28 08:56:07 +00:00
|
|
|
|
|
|
|
/**
|
2012-09-12 09:21:43 +00:00
|
|
|
* Get the domains, contexts and groupbys in parameter from search
|
|
|
|
* view, then render the filtered threads.
|
2012-02-28 08:56:07 +00:00
|
|
|
* @param {Array} domains
|
|
|
|
* @param {Array} contexts
|
|
|
|
* @param {Array} groupbys
|
|
|
|
*/
|
2012-02-24 15:21:59 +00:00
|
|
|
do_searchview_search: function(domains, contexts, groupbys) {
|
|
|
|
var self = this;
|
|
|
|
this.rpc('/web/session/eval_domain_and_context', {
|
|
|
|
domains: domains || [],
|
|
|
|
contexts: contexts || [],
|
|
|
|
group_by_seq: groupbys || []
|
2012-10-03 12:34:12 +00:00
|
|
|
}).then(function (results) {
|
2012-04-05 11:34:19 +00:00
|
|
|
self.search_results['context'] = results.context;
|
|
|
|
self.search_results['domain'] = results.domain;
|
2012-10-19 07:44:49 +00:00
|
|
|
self.root.destroy();
|
2012-09-12 09:21:43 +00:00
|
|
|
return self.message_render();
|
2012-02-28 11:07:40 +00:00
|
|
|
});
|
|
|
|
},
|
2012-09-26 07:17:09 +00:00
|
|
|
|
2012-10-10 11:02:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the threads
|
|
|
|
*/
|
2012-10-01 16:44:14 +00:00
|
|
|
message_render: function (search) {
|
2012-10-16 11:38:41 +00:00
|
|
|
var domain = this.options.domain.concat(this.search_results['domain']);
|
|
|
|
var context = _.extend(this.options.context, search&&search.search_results['context'] ? search.search_results['context'] : {});
|
2012-10-17 13:37:50 +00:00
|
|
|
this.root = new mail.Widget(this, {
|
|
|
|
'domain' : domain,
|
|
|
|
'context' : context,
|
2012-10-19 09:02:52 +00:00
|
|
|
'typeof_thread': context['typeof_thread'] || 'other',
|
2012-10-18 16:39:23 +00:00
|
|
|
'display_indented_thread': 2,
|
2012-10-19 14:32:28 +00:00
|
|
|
'show_reply_button': 10,
|
|
|
|
'show_read_unread_button': 11,
|
2012-10-22 07:50:58 +00:00
|
|
|
'show_compose_message': true,
|
|
|
|
'show_compact_message': true
|
2012-08-20 15:52:02 +00:00
|
|
|
}
|
2012-08-21 09:20:15 +00:00
|
|
|
);
|
2012-10-19 13:53:56 +00:00
|
|
|
|
2012-10-17 13:37:50 +00:00
|
|
|
return this.root.appendTo( this.$('.oe_mail_wall_threads:first') );
|
2012-08-21 09:20:15 +00:00
|
|
|
},
|
2012-10-05 13:10:13 +00:00
|
|
|
|
|
|
|
bind_events: function(){
|
|
|
|
var self=this;
|
2012-10-17 13:37:50 +00:00
|
|
|
this.$("button.oe_write_full:first").click(function(){ self.root.thread.ComposeMessage.on_compose_fullmail(); });
|
|
|
|
this.$("button.oe_write_onwall:first").click(function(){ self.root.thread.on_compose_message(); });
|
2012-10-05 13:10:13 +00:00
|
|
|
}
|
2012-02-08 16:42:29 +00:00
|
|
|
});
|
2012-10-12 14:53:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* UserMenu
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
2012-10-18 16:45:33 +00:00
|
|
|
* Add a link on the top user bar for write a full mail
|
2012-10-12 14:53:20 +00:00
|
|
|
*/
|
|
|
|
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 = {
|
2012-10-18 16:45:33 +00:00
|
|
|
'default_model': false,
|
2012-10-12 14:53:20 +00:00
|
|
|
'default_res_id': 0,
|
|
|
|
'default_content_subtype': 'html',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
start: function(parent, params) {
|
|
|
|
var self = this;
|
|
|
|
this.$el.on('click', 'button', self.on_compose_message );
|
|
|
|
this._super(parent, params);
|
|
|
|
},
|
|
|
|
|
|
|
|
on_compose_message: 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: this.options.context,
|
|
|
|
};
|
|
|
|
session.client.action_manager.do_action(action);
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
session.web.UserMenu = session.web.UserMenu.extend({
|
|
|
|
start: function(parent, params) {
|
|
|
|
var render = new session.web.ComposeMessageTopButton();
|
|
|
|
render.insertAfter(this.$el);
|
|
|
|
this._super(parent, params);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-02-01 16:22:13 +00:00
|
|
|
};
|