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
|
|
|
|
* mail.compose.message. The purpose is to bind 'Send by e-mail' buttons
|
|
|
|
* and redirect them to the Chatter.
|
2012-06-20 15:54:34 +00:00
|
|
|
*/
|
2012-07-17 15:57:02 +00:00
|
|
|
|
|
|
|
session.web.FormView = session.web.FormView.extend({
|
|
|
|
do_action: function(action, on_close) {
|
2012-09-03 15:20:25 +00:00
|
|
|
if (action.res_model == 'mail.compose.message' &&
|
2012-09-11 09:40:07 +00:00
|
|
|
action.context && action.context.redirect == true &&
|
2012-09-11 13:37:06 +00:00
|
|
|
this.fields && this.fields.message_ids && this.fields.message_ids.view.get("actual_mode") != 'create') {
|
|
|
|
var thread = this.fields.message_ids.thread;
|
2012-09-11 09:40:07 +00:00
|
|
|
thread.refresh_composition_form(action.context);
|
|
|
|
return true;
|
2012-07-17 15:57:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this._super(action, on_close);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-09-06 11:14:44 +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-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-06-14 08:40:33 +00:00
|
|
|
*/
|
2012-06-21 15:24:28 +00:00
|
|
|
|
|
|
|
mail.ComposeMessage = session.web.Widget.extend({
|
2012-06-14 08:40:33 +00:00
|
|
|
template: 'mail.compose_message',
|
|
|
|
|
2012-07-06 15:52:26 +00:00
|
|
|
/**
|
|
|
|
* @param {Object} parent parent
|
2012-09-03 15:20:25 +00:00
|
|
|
* @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.
|
2012-07-06 15:52:26 +00:00
|
|
|
*/
|
2012-08-22 16:21:51 +00:00
|
|
|
init: function (parent, options) {
|
2012-07-16 15:39:47 +00:00
|
|
|
var self = this;
|
2012-06-14 08:40:33 +00:00
|
|
|
this._super(parent);
|
2012-09-06 11:14:44 +00:00
|
|
|
this.attachment_ids = [];
|
2012-06-19 09:57:30 +00:00
|
|
|
// options
|
2012-08-20 13:59:58 +00:00
|
|
|
this.options = options || {};
|
2012-08-22 17:23:46 +00:00
|
|
|
this.options.context = options.context || {};
|
2012-08-20 13:59:58 +00:00
|
|
|
this.options.form_xml_id = options.form_xml_id || 'email_compose_message_wizard_form_chatter';
|
2012-08-22 16:21:51 +00:00
|
|
|
this.options.form_view_id = options.form_view_id || false;
|
2012-09-11 16:17:00 +00:00
|
|
|
this.show_attachment_delete = true;
|
2012-06-14 08:40:33 +00:00
|
|
|
},
|
2012-07-10 13:06:31 +00:00
|
|
|
|
2012-08-22 16:21:51 +00:00
|
|
|
start: function () {
|
2012-06-14 08:40:33 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-07-04 13:29:58 +00:00
|
|
|
// customize display: add avatar, clean previous content
|
2012-09-06 11:14:44 +00:00
|
|
|
var user_avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid);
|
2012-09-26 07:17:09 +00:00
|
|
|
this.$('img.oe_mail_icon').attr('src', user_avatar);
|
|
|
|
this.$('div.oe_mail_msg_content').empty();
|
2012-08-22 16:21:51 +00:00
|
|
|
// create a context for the dataset and default_get of the wizard
|
2012-09-03 15:20:25 +00:00
|
|
|
var context = _.extend({}, this.options.context);
|
2012-07-16 15:39:47 +00:00
|
|
|
this.ds_compose = new session.web.DataSetSearch(this, 'mail.compose.message', context);
|
|
|
|
// find the id of the view to display in the chatter form
|
2012-09-03 15:20:25 +00:00
|
|
|
if (this.options.form_view_id) {
|
|
|
|
return this.create_form_view();
|
2012-08-22 16:21:51 +00:00
|
|
|
}
|
2012-09-03 15:20:25 +00:00
|
|
|
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'));
|
2012-08-22 16:21:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Create a FormView, then append it to the to widget DOM. */
|
2012-09-03 15:20:25 +00:00
|
|
|
create_form_view: function (new_form_view_id) {
|
2012-07-16 15:39:47 +00:00
|
|
|
var self = this;
|
2012-09-03 15:20:25 +00:00
|
|
|
this.options.form_view_id = (new_form_view_id && new_form_view_id[1]) || this.options.form_view_id;
|
2012-07-16 15:39:47 +00:00
|
|
|
// destroy previous form_view if any
|
|
|
|
if (this.form_view) { this.form_view.destroy(); }
|
|
|
|
// create the FormView
|
2012-08-20 13:59:58 +00:00
|
|
|
this.form_view = new session.web.FormView(this, this.ds_compose, this.options.form_view_id, {
|
2012-07-16 15:39:47 +00:00
|
|
|
action_buttons: false,
|
|
|
|
pager: false,
|
|
|
|
initial_mode: 'edit',
|
2012-08-01 16:13:03 +00:00
|
|
|
disable_autofocus: true,
|
|
|
|
});
|
2012-07-11 09:55:45 +00:00
|
|
|
// add the form, bind events, activate the form
|
2012-09-26 07:17:09 +00:00
|
|
|
var msg_node = this.$('div.oe_mail_msg_content');
|
2012-09-06 11:14:44 +00:00
|
|
|
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');
|
2012-09-26 07:17:09 +00:00
|
|
|
var button_attach = this.$('button.oe_mail_compose_message_attachment');
|
2012-09-06 11:14:44 +00:00
|
|
|
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
|
2012-09-26 07:17:09 +00:00
|
|
|
var input_node = this.$('input[name=ufile]');
|
2012-09-06 11:14:44 +00:00
|
|
|
button_attach.detach().insertAfter(input_node);
|
|
|
|
// set the function called when attachments are added
|
2012-09-26 07:17:09 +00:00
|
|
|
this.$('input.oe_form_binary_file').change(this.on_attachment_change);
|
2012-09-06 11:14:44 +00:00
|
|
|
this.bind_events();
|
|
|
|
this.form_view.do_show();
|
|
|
|
},
|
|
|
|
|
2012-09-11 16:17:00 +00:00
|
|
|
on_attachment_change: function (event) {
|
|
|
|
var $target = $(event.target);
|
|
|
|
if ($target.val() !== '') {
|
2012-09-26 07:17:09 +00:00
|
|
|
this.$('form.oe_form_binary_form').submit();
|
2012-09-06 11:14:44 +00:00
|
|
|
session.web.blockUI();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-09-11 16:17:00 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-09-06 11:14:44 +00:00
|
|
|
display_attachments: function () {
|
2012-09-26 07:17:09 +00:00
|
|
|
var attach_node = this.$('div.oe_mail_compose_message_attachments');
|
2012-09-06 11:14:44 +00:00
|
|
|
var rendered = session.web.qweb.render('mail.thread.message.attachments', {'record': this});
|
|
|
|
attach_node.empty();
|
|
|
|
$(rendered).appendTo(attach_node);
|
2012-09-26 07:17:09 +00:00
|
|
|
this.$('.oe_mail_msg_attachments').show();
|
2012-09-06 11:14:44 +00:00
|
|
|
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, []);
|
2012-06-15 15:35:15 +00:00
|
|
|
},
|
2012-07-10 13:06:31 +00:00
|
|
|
|
2012-08-22 16:21:51 +00:00
|
|
|
/**
|
2012-09-03 15:20:25 +00:00
|
|
|
* 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) {
|
2012-08-22 16:21:51 +00:00
|
|
|
if (! this.form_view) return;
|
2012-09-03 15:20:25 +00:00
|
|
|
var self = this;
|
2012-09-06 11:14:44 +00:00
|
|
|
this.attachments = [];
|
2012-09-03 15:20:25 +00:00
|
|
|
this.options.context = _.extend(this.options.context, new_context || {});
|
|
|
|
this.ds_compose.context = _.extend(this.ds_compose.context, this.options.context);
|
2012-08-22 16:21:51 +00:00
|
|
|
return this.ds_compose.call('default_get', [
|
2012-09-12 11:28:32 +00:00
|
|
|
['subject', 'body_text', 'body', 'partner_ids', 'composition_mode',
|
2012-09-11 09:40:07 +00:00
|
|
|
'use_template', 'template_id', 'model', 'res_id', 'parent_id', 'content_subtype'],
|
2012-08-22 16:21:51 +00:00
|
|
|
this.ds_compose.get_context(),
|
2012-09-12 11:28:32 +00:00
|
|
|
]).then( function (result) {
|
|
|
|
self.form_view.on_processed_onchange({'value': result}, []);
|
|
|
|
self.attachment_ids = [];
|
|
|
|
self.display_attachments();
|
|
|
|
});
|
2012-08-22 16:21:51 +00:00
|
|
|
},
|
|
|
|
|
2012-06-15 15:35:15 +00:00
|
|
|
/**
|
2012-07-04 13:29:58 +00:00
|
|
|
* Bind events in the widget. Each event is slightly described
|
2012-06-15 15:35:15 +00:00
|
|
|
* in the function. */
|
|
|
|
bind_events: function() {
|
|
|
|
var self = this;
|
2012-09-06 11:14:44 +00:00
|
|
|
// event: add a new attachment
|
|
|
|
$(window).on(this.fileupload_id, function() {
|
|
|
|
var args = [].slice.call(arguments).slice(1);
|
|
|
|
var attachment = args[0];
|
|
|
|
attachment['url'] = mail.ChatterUtils.get_attachment_url(self.session, attachment);
|
|
|
|
self.attachment_ids.push(attachment);
|
|
|
|
self.display_attachments();
|
|
|
|
session.web.unblockUI();
|
|
|
|
});
|
2012-09-11 16:17:00 +00:00
|
|
|
// event: delete an attachment
|
|
|
|
this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete);
|
2012-06-14 08:40:33 +00:00
|
|
|
},
|
2012-06-21 15:24:28 +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
|
|
|
* ------------------------------------------------------------
|
|
|
|
* Thread Widget
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* This widget handles the display of a thread of messages. The
|
|
|
|
* [thread_level] parameter sets the thread level number:
|
2012-03-02 17:07:49 +00:00
|
|
|
* - root message
|
|
|
|
* - - sub message (parent_id = root message)
|
2012-03-05 17:37:42 +00:00
|
|
|
* - - - sub sub message (parent id = sub message)
|
2012-03-02 17:07:49 +00:00
|
|
|
* - - sub message (parent_id = root message)
|
|
|
|
*/
|
2012-05-10 12:10:58 +00:00
|
|
|
|
2012-03-02 17:07:49 +00:00
|
|
|
mail.Thread = session.web.Widget.extend({
|
2012-07-03 12:20:20 +00:00
|
|
|
template: 'mail.thread',
|
2012-02-27 16:04:42 +00:00
|
|
|
|
|
|
|
/**
|
2012-03-05 17:37:42 +00:00
|
|
|
* @param {Object} parent parent
|
2012-09-12 10:40:11 +00:00
|
|
|
* @param {Array} [domain]
|
|
|
|
* @param {Object} [context] context of the thread. It should
|
2012-09-03 15:20:25 +00:00
|
|
|
contain at least default_model, default_res_id. Please refer to
|
|
|
|
the ComposeMessage widget for more information about it.
|
2012-09-12 10:40:11 +00:00
|
|
|
* @param {Object} [options]
|
2012-09-03 15:20:25 +00:00
|
|
|
* @param {Number} [options.message_ids=null] ids for message_fetch
|
|
|
|
* @param {Number} [options.message_data=null] already formatted message
|
|
|
|
data, for subthreads getting data from their parent
|
2012-09-12 10:40:11 +00:00
|
|
|
* @param {Number} [options.thread_level=0] number of thread levels
|
|
|
|
* @param {Boolean} [options.use_composer] use the advanced composer, or
|
2012-09-03 15:20:25 +00:00
|
|
|
the default basic textarea if not set
|
|
|
|
* @param {Number} [options.truncate_limit=250] number of character to
|
2012-07-11 09:55:45 +00:00
|
|
|
* display before having a "show more" link; note that the text
|
|
|
|
* will not be truncated if it does not have 110% of the parameter
|
2012-09-27 13:48:23 +00:00
|
|
|
* @param {Number} [options.expandable_number=5] number message show
|
|
|
|
* for each click on "show more message"
|
|
|
|
* @param {Number} [options.expandable_max=5] number message show
|
|
|
|
* on begin before the first click on "show more message"
|
|
|
|
* @param {Boolean} [options.not_expendable] display all thread
|
|
|
|
* on the wall thread level (no hierarchy)
|
2012-02-27 16:04:42 +00:00
|
|
|
*/
|
2012-09-12 10:22:17 +00:00
|
|
|
init: function(parent, domain, context, options) {
|
2012-02-23 16:32:36 +00:00
|
|
|
this._super(parent);
|
2012-09-12 10:22:17 +00:00
|
|
|
this.domain = domain || [];
|
|
|
|
this.context = _.extend({
|
2012-09-03 15:20:25 +00:00
|
|
|
default_model: 'mail.thread',
|
|
|
|
default_res_id: 0,
|
2012-09-12 10:22:17 +00:00
|
|
|
default_parent_id: false }, context || {});
|
2012-09-27 08:30:56 +00:00
|
|
|
|
2012-09-12 10:22:17 +00:00
|
|
|
// options
|
|
|
|
this.options = {
|
|
|
|
message_ids: options.message_ids || null,
|
|
|
|
message_data: options.message_data || null,
|
|
|
|
thread_level: options.thread_level || 0,
|
|
|
|
use_composer: options.use_composer || false,
|
|
|
|
show_header_compose: options.show_header_compose != undefined ? options.show_header_compose: true,
|
|
|
|
show_record_name: options.show_record_name != undefined ? options.show_record_name: true,
|
2012-09-03 15:20:25 +00:00
|
|
|
show_reply: options.show_reply || false,
|
|
|
|
show_reply_by_email: options.show_reply_by_email || false,
|
2012-09-12 10:22:17 +00:00
|
|
|
show_dd_reply_by_email:options.show_dd_reply_by_email != undefined ? options.show_dd_reply_by_email: true,
|
|
|
|
show_dd_delete: options.show_dd_delete || false,
|
|
|
|
show_dd_hide: options.show_dd_hide || false,
|
|
|
|
truncate_limit: options.truncate_limit || 250,
|
2012-09-27 13:48:23 +00:00
|
|
|
expandable_number: options.expandable_number || 5,
|
2012-09-27 16:15:58 +00:00
|
|
|
expandable_max: options.expandable_max || 5,
|
2012-09-27 13:48:23 +00:00
|
|
|
not_expendable: options.not_expendable || false,
|
2012-09-03 15:20:25 +00:00
|
|
|
}
|
2012-09-12 10:22:17 +00:00
|
|
|
// datasets and internal vars
|
2012-09-27 08:30:56 +00:00
|
|
|
this.id= options.id || false;
|
2012-09-27 13:48:23 +00:00
|
|
|
this.top_parent= (options.top_parent && options.top_parent.browse_thread) ? options.top_parent : (parent.browse_thread ? parent : this);
|
2012-09-27 08:30:56 +00:00
|
|
|
this.model= options.model || false;
|
2012-09-18 12:23:15 +00:00
|
|
|
this.records = {};
|
2012-09-27 08:30:56 +00:00
|
|
|
this.thread = {};
|
|
|
|
|
2012-09-12 10:22:17 +00:00
|
|
|
this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model);
|
|
|
|
this.ds_notification = new session.web.DataSetSearch(this, 'mail.notification');
|
|
|
|
this.ds_message = new session.web.DataSetSearch(this, 'mail.message');
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
start: function() {
|
2012-09-03 15:20:25 +00:00
|
|
|
// TDE TODO: check for deferred, not sure it is correct
|
2012-02-23 16:32:36 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-07-11 11:17:22 +00:00
|
|
|
this.bind_events();
|
2012-09-19 10:13:39 +00:00
|
|
|
this.display_user_avatar();
|
2012-09-03 15:20:25 +00:00
|
|
|
// fetch and display message, using message_ids if set
|
|
|
|
var display_done = $.when(this.message_fetch(true, [], {})).then(this.proxy('do_customize_display'));
|
2012-06-15 08:36:56 +00:00
|
|
|
// add message composition form view
|
2012-09-12 10:22:17 +00:00
|
|
|
if (this.options.show_header_compose && this.options.use_composer) {
|
2012-07-11 09:55:45 +00:00
|
|
|
var compose_done = this.instantiate_composition_form();
|
2012-06-19 18:28:10 +00:00
|
|
|
}
|
2012-07-10 13:06:31 +00:00
|
|
|
return display_done && compose_done;
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
2012-07-10 13:06:31 +00:00
|
|
|
|
2012-08-21 10:43:45 +00:00
|
|
|
/** Customize the display
|
|
|
|
* - show_header_compose: show the composition form in the header */
|
2012-05-14 12:32:31 +00:00
|
|
|
do_customize_display: function() {
|
2012-09-12 10:22:17 +00:00
|
|
|
if (this.options.show_header_compose) {
|
2012-09-26 07:17:09 +00:00
|
|
|
this.$('div.oe_mail_thread_action').eq(0).show();
|
2012-09-12 10:22:17 +00:00
|
|
|
}
|
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-09-27 16:15:58 +00:00
|
|
|
this.$('*').unbind('click');
|
2012-09-11 16:38:53 +00:00
|
|
|
// event: click on 'More' at bottom of thread
|
2012-09-20 14:46:45 +00:00
|
|
|
this.$el.on('click', 'a.oe_mail_fetch_more', this.do_message_fetch_more);
|
2012-07-11 09:55:45 +00:00
|
|
|
// event: click on 'Reply' in msg
|
2012-09-28 13:27:23 +00:00
|
|
|
this.$el.on('click', 'a.oe_reply', function (event) {
|
2012-08-22 17:23:46 +00:00
|
|
|
var act_dom = $(this).parents('li.oe_mail_thread_msg').eq(0).find('div.oe_mail_thread_action:first');
|
|
|
|
act_dom.toggle();
|
2012-03-13 17:41:05 +00:00
|
|
|
});
|
2012-09-28 13:27:23 +00:00
|
|
|
// event: writing in basic textarea of composition form (quick reply)
|
|
|
|
// event: onblur for hide 'Reply'
|
|
|
|
this.$('textarea.oe_mail_compose_textarea:first')
|
|
|
|
.keyup(function (event) {
|
|
|
|
var charCode = (event.which) ? event.which : window.event.keyCode;
|
|
|
|
if (event.shiftKey && charCode == 13) { this.value = this.value+"\n"; }
|
|
|
|
else if (charCode == 13) { return self.message_post(); }
|
|
|
|
})
|
|
|
|
.blur(function (event) {
|
|
|
|
$(this).parents('.oe_mail_thread_action:first').toggle();
|
|
|
|
});
|
2012-09-11 16:38:53 +00:00
|
|
|
// event: click on 'Attachment(s)' in msg
|
2012-08-27 08:37:05 +00:00
|
|
|
this.$el.on('click', 'a.oe_mail_msg_view_attachments', function (event) {
|
2012-08-22 17:23:46 +00:00
|
|
|
var act_dom = $(this).parent().parent().parent().find('.oe_mail_msg_attachments');
|
|
|
|
act_dom.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-09-11 16:38:53 +00:00
|
|
|
this.$el.on('click', 'a.oe_mail_msg_delete', this.on_message_delete);
|
|
|
|
// event: click on 'Reply by email' in msg side menu
|
2012-09-28 13:27:23 +00:00
|
|
|
this.$el.on('click', 'a.oe_reply_by_email', function (event) {
|
2012-09-11 16:38:53 +00:00
|
|
|
if (! self.compose_message_widget) return true;
|
2012-07-11 09:55:45 +00:00
|
|
|
var msg_id = event.srcElement.dataset.msg_id;
|
|
|
|
if (! msg_id) return false;
|
2012-09-03 15:20:25 +00:00
|
|
|
self.compose_message_widget.refresh({
|
|
|
|
'default_composition_mode': 'reply',
|
|
|
|
'default_parent_id': parseInt(msg_id),
|
|
|
|
'default_content_subtype': 'html'} );
|
2012-06-22 01:21:02 +00:00
|
|
|
});
|
2012-09-18 12:23:15 +00:00
|
|
|
// event: click on 'Vote' button
|
|
|
|
this.$el.on('click', 'button.oe_mail_msg_vote', this.on_vote);
|
2012-03-13 17:41:05 +00:00
|
|
|
},
|
2012-08-20 16:49:24 +00:00
|
|
|
|
2012-09-11 16:38:53 +00:00
|
|
|
on_message_delete: function (event) {
|
|
|
|
if (! confirm(_t("Do you really want to delete this message?"))) { return false; }
|
2012-09-28 13:27:23 +00:00
|
|
|
|
|
|
|
var source = $(event.srcElement).parents('[data-msg_id]:first');
|
|
|
|
var msg_id = source.data("msg_id");
|
|
|
|
var msg_model = source.data("msg_model");
|
|
|
|
if (!msg_id || !msg_model) return false;
|
|
|
|
|
|
|
|
var thread=this.browse_thread({'id':msg_id, 'model':msg_model});
|
|
|
|
if(thread){
|
|
|
|
thread.animated_destroy({fadeTime:250});
|
|
|
|
var ids = [thread.id]
|
|
|
|
// delete this thread and his childs
|
|
|
|
var ids = ids.concat( thread.get_child_thread_ids() );
|
|
|
|
this.ds_message.unlink(ids);
|
|
|
|
}
|
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-09-27 08:30:56 +00:00
|
|
|
var source = $(event.srcElement).parents('[data-msg_id]:first');
|
|
|
|
var msg_id = source.data("msg_id");
|
|
|
|
var msg_model = source.data("msg_model");
|
|
|
|
if (!msg_id || !msg_model) return false;
|
|
|
|
|
|
|
|
var thread=this.browse_thread({'id':msg_id, 'model':msg_model});
|
|
|
|
if(thread){
|
|
|
|
thread.animated_destroy({fadeTime:250});
|
|
|
|
var ids = [thread.id]
|
|
|
|
// if this thread is read, all childs thread display is read
|
|
|
|
var ids = ids.concat( thread.get_child_thread_ids() );
|
2012-09-28 13:27:23 +00:00
|
|
|
thread.ds_notification.call('set_message_read', [ids,$(event.srcElement).hasClass("oe_read")]);
|
2012-09-27 08:30:56 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* get all child message id liked to this message
|
|
|
|
*/
|
|
|
|
get_child_thread_ids: function(){
|
|
|
|
var res=[];
|
|
|
|
if(arguments[0]) res.push(this.id);
|
|
|
|
for(var i in this.thread){
|
|
|
|
res = res.concat( this.thread[i].get_child_thread_ids(true) );
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** browse thread and message
|
|
|
|
* @param {object}{int} option.id
|
|
|
|
* @param {object}{string} option.model
|
|
|
|
* @param {object}{boolean} option._go_thread_wall
|
|
|
|
* private for check the top thread
|
2012-09-27 13:48:23 +00:00
|
|
|
* @param {object}{boolean} option.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-09-27 13:48:23 +00:00
|
|
|
return this.top_parent.browse_thread(options);
|
2012-09-27 08:30:56 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 13:27:23 +00:00
|
|
|
if(options.id && options.model){
|
2012-09-27 16:15:58 +00:00
|
|
|
if(this.id==options.id && this.model==options.model)
|
|
|
|
return this;
|
2012-09-27 08:30:56 +00:00
|
|
|
|
2012-09-27 16:15:58 +00:00
|
|
|
for(var i in this.thread){
|
|
|
|
var res=this.thread[i].browse_thread(options);
|
|
|
|
if(res) return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if option top_thread, return the top if no found thread
|
|
|
|
if(options.top_thread){
|
|
|
|
return this;
|
2012-09-27 08:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
animated_destroy: function(options) {
|
|
|
|
var self=this;
|
2012-09-28 13:27:23 +00:00
|
|
|
//graphic effects
|
2012-09-27 08:30:56 +00:00
|
|
|
if(options.fadeTime)
|
|
|
|
self.$el.parents(".oe_mail_thread_msg:first").fadeOut(options.fadeTime, function(){
|
|
|
|
self.destroy();
|
|
|
|
});
|
|
|
|
else
|
|
|
|
self.destroy();
|
|
|
|
|
|
|
|
for(var i in this.thread){
|
|
|
|
this.thread[i].animated_destroy({fadeTime:0});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-09-18 12:23:15 +00:00
|
|
|
on_vote: function (event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
var self = this;
|
|
|
|
var message_id = $(event.srcElement).parent().data().msg_id;
|
|
|
|
var vote_node = $(event.srcElement).parents('li').eq(0);
|
|
|
|
if (! message_id) { return false; }
|
|
|
|
return this.ds_message.call('vote_toggle', [[parseInt(message_id)]]).pipe(
|
|
|
|
self.toggle_vote(message_id, vote_node));
|
2012-03-13 17:41:05 +00:00
|
|
|
},
|
2012-08-20 16:49:24 +00:00
|
|
|
|
2012-08-21 10:43:45 +00:00
|
|
|
/**
|
|
|
|
* Override-hack of do_action: automatically reload the chatter.
|
|
|
|
* Normally it should be called only when clicking on 'Post/Send'
|
|
|
|
* in the composition form. */
|
|
|
|
do_action: function(action, on_close) {
|
2012-09-11 16:38:53 +00:00
|
|
|
//TDE: TODO: instead of reloading, push the message ?
|
2012-08-21 15:06:22 +00:00
|
|
|
this.message_clean();
|
|
|
|
this.message_fetch();
|
2012-08-21 10:43:45 +00:00
|
|
|
if (this.compose_message_widget) {
|
2012-09-03 15:20:25 +00:00
|
|
|
this.compose_message_widget.refresh({
|
|
|
|
'default_composition_mode': 'comment',
|
2012-09-12 10:22:17 +00:00
|
|
|
'default_parent_id': this.context.default_parent_id,
|
2012-09-03 15:20:25 +00:00
|
|
|
'default_content_subtype': 'plain'} );
|
|
|
|
}
|
2012-08-21 10:43:45 +00:00
|
|
|
},
|
|
|
|
|
2012-09-03 15:20:25 +00:00
|
|
|
/** Instantiate the composition form, with every parameters in context
|
|
|
|
or in the widget context. */
|
|
|
|
instantiate_composition_form: function(context) {
|
2012-09-28 13:27:23 +00:00
|
|
|
var self=this;
|
2012-08-21 10:43:45 +00:00
|
|
|
if (this.compose_message_widget) {
|
|
|
|
this.compose_message_widget.destroy();
|
|
|
|
}
|
|
|
|
this.compose_message_widget = new mail.ComposeMessage(this, {
|
2012-09-12 10:22:17 +00:00
|
|
|
'context': _.extend(context || {}, this.context),
|
2012-09-03 15:20:25 +00:00
|
|
|
});
|
2012-09-26 07:17:09 +00:00
|
|
|
var composition_node = this.$('div.oe_mail_thread_action');
|
2012-08-21 10:43:45 +00:00
|
|
|
composition_node.empty();
|
2012-09-28 13:27:23 +00:00
|
|
|
var compose_done = this.compose_message_widget.appendTo(composition_node)
|
|
|
|
.then(function(){
|
|
|
|
self.$("button.oe_mail_compose_message_button_send").mouseup(function(){
|
|
|
|
self.browse_thread({'top_thread':1}).message_fetch();
|
|
|
|
});
|
|
|
|
});
|
2012-08-21 10:43:45 +00:00
|
|
|
return compose_done;
|
|
|
|
},
|
|
|
|
|
2012-09-11 09:40:07 +00:00
|
|
|
refresh_composition_form: function (context) {
|
|
|
|
if (! this.compose_message_widget) return;
|
|
|
|
return this.compose_message_widget.refresh(context);
|
|
|
|
},
|
|
|
|
|
2012-08-21 10:43:45 +00:00
|
|
|
/** Clean the thread */
|
|
|
|
message_clean: function() {
|
2012-09-27 08:30:56 +00:00
|
|
|
this.$('ul.oe_mail_thread_display').empty();
|
2012-02-27 16:04:42 +00:00
|
|
|
},
|
2012-08-21 09:20:15 +00:00
|
|
|
|
|
|
|
/** Fetch messages
|
2012-09-03 15:20:25 +00:00
|
|
|
* @param {Bool} initial_mode: initial mode: try to use message_data or
|
|
|
|
* message_ids, if nothing available perform a message_read; otherwise
|
|
|
|
* directly perform a message_read
|
2012-09-12 10:22:17 +00:00
|
|
|
* @param {Array} additional_domain: added to this.domain
|
|
|
|
* @param {Object} additional_context: added to this.context
|
2012-08-21 09:20:15 +00:00
|
|
|
*/
|
2012-09-03 15:20:25 +00:00
|
|
|
message_fetch: function (initial_mode, additional_domain, additional_context) {
|
2012-02-29 08:59:53 +00:00
|
|
|
var self = this;
|
2012-09-03 15:20:25 +00:00
|
|
|
// domain and context: options + additional
|
2012-09-20 14:46:45 +00:00
|
|
|
fetch_domain = _.flatten([this.domain, additional_domain || []], true);
|
|
|
|
fetch_context = _.extend({}, this.context, additional_context || {});
|
2012-09-28 13:27:23 +00:00
|
|
|
|
|
|
|
fetch_context.message_loaded=[];
|
|
|
|
self.$("li[data-msg_id][data-msg_model]").each(function(){
|
|
|
|
fetch_context.message_loaded.push($(this).data("msg_id"))
|
|
|
|
});
|
|
|
|
|
2012-09-11 14:17:40 +00:00
|
|
|
// initial mode: try to use message_data or message_ids
|
2012-09-03 15:20:25 +00:00
|
|
|
if (initial_mode && this.options.message_data) {
|
2012-09-27 13:48:23 +00:00
|
|
|
return this.message_display_create_thread(this.options.message_data);
|
2012-09-03 15:20:25 +00:00
|
|
|
}
|
2012-09-27 16:15:58 +00:00
|
|
|
message_ids = this.options.message_ids && this.options.message_ids[0] ? this.options.message_ids : false;
|
2012-09-20 14:46:45 +00:00
|
|
|
return this.ds_message.call('message_read', [message_ids, fetch_domain, this.options.thread_level, fetch_context, this.context.default_parent_id || undefined]
|
2012-09-27 13:48:23 +00:00
|
|
|
).then(this.proxy('message_treat_new_data'));
|
2012-04-04 12:00:53 +00:00
|
|
|
},
|
2012-08-21 09:20:15 +00:00
|
|
|
|
2012-08-21 10:43:45 +00:00
|
|
|
/* Display a list of records
|
2012-09-03 15:20:25 +00:00
|
|
|
* A specific case is done for 'expandable' messages that are messages
|
2012-09-27 13:48:23 +00:00
|
|
|
* create new thread and liked it
|
|
|
|
* displayed under a 'show more' button form
|
2012-09-03 15:20:25 +00:00
|
|
|
*/
|
2012-09-27 13:48:23 +00:00
|
|
|
message_display_create_thread: function (records) {
|
2012-03-05 16:59:10 +00:00
|
|
|
var self = this;
|
2012-09-27 13:48:23 +00:00
|
|
|
_(records).each(function (record, inc) {
|
2012-08-21 09:20:15 +00:00
|
|
|
if (record.type == 'expandable') {
|
2012-08-21 12:10:30 +00:00
|
|
|
self.fetch_more_domain = record.domain;
|
|
|
|
self.fetch_more_context = record.context;
|
2012-09-20 14:46:45 +00:00
|
|
|
var rendered = session.web.qweb.render('mail.thread.message.expandable', {'record': record});
|
2012-09-27 08:30:56 +00:00
|
|
|
$(rendered).appendTo(self.$el.children('ul.oe_mail_thread_display:first'));
|
2012-08-21 09:20:15 +00:00
|
|
|
}
|
2012-09-27 13:48:23 +00:00
|
|
|
else if(inc<=self.options.expandable_max) {
|
2012-09-28 13:27:23 +00:00
|
|
|
|
|
|
|
//if thread exists, don't create new thread
|
|
|
|
if(self.browse_thread({'model': record.model,'id': record.id,}))
|
|
|
|
return false;
|
|
|
|
|
2012-09-27 13:48:23 +00:00
|
|
|
/*create thread*/
|
2012-09-27 08:30:56 +00:00
|
|
|
var thread = new mail.Thread(self, self.domain,
|
2012-09-12 10:22:17 +00:00
|
|
|
{ 'default_model': record.model,
|
2012-09-06 12:20:46 +00:00
|
|
|
'default_res_id': record.res_id,
|
2012-09-03 15:20:25 +00:00
|
|
|
'default_parent_id': record.id },
|
2012-09-27 08:30:56 +00:00
|
|
|
{ 'model': record.model,
|
|
|
|
'id': record.id,
|
|
|
|
'message_data': record.child_ids,
|
2012-09-12 10:22:17 +00:00
|
|
|
'thread_level': self.options.thread_level - 1,
|
|
|
|
'show_header_compose': false,
|
2012-09-28 13:27:23 +00:00
|
|
|
'show_reply': self.options.show_reply,
|
2012-09-12 10:22:17 +00:00
|
|
|
'show_reply_by_email': self.options.show_reply_by_email,
|
|
|
|
'show_dd_hide': self.options.show_dd_hide,
|
2012-09-26 07:17:09 +00:00
|
|
|
'show_dd_delete': self.options.show_dd_delete,
|
2012-09-27 13:48:23 +00:00
|
|
|
'top_parent': self.top_parent
|
|
|
|
});
|
|
|
|
|
|
|
|
// options to display on one level of thread
|
|
|
|
var parent_thread=self;
|
|
|
|
if(self.options.not_expendable){
|
|
|
|
parent_thread=self.browse_thread({'top_thread':true});
|
|
|
|
}
|
|
|
|
|
|
|
|
/*create the parent message*/
|
|
|
|
$rendered=parent_thread.display_record(record);
|
|
|
|
$rendered.append('<div class="oe_mail_thread_subthread"/>');
|
|
|
|
|
|
|
|
/*insert thread in parent message*/
|
|
|
|
thread.appendTo($rendered.find('div.oe_mail_thread_subthread'));
|
|
|
|
/*liked the thread*/
|
2012-09-27 08:30:56 +00:00
|
|
|
self.thread[record.model+":"+record.id]=thread;
|
2012-03-05 16:59:10 +00:00
|
|
|
}
|
2012-02-23 16:32:36 +00:00
|
|
|
});
|
2012-09-27 13:48:23 +00:00
|
|
|
self.display_expandable();
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Hide messages if they are more message that expandable_max
|
|
|
|
* display "show more messages"
|
|
|
|
*/
|
|
|
|
display_expandable: function(){
|
|
|
|
var self =this;
|
2012-09-27 16:15:58 +00:00
|
|
|
var rec = self.$('>ul>li.oe_mail_thread_msg:not([data-msg_id="-1"]):gt('+(self.options.expandable_max-1)+')');
|
|
|
|
if(rec.size()>0){
|
2012-09-27 13:48:23 +00:00
|
|
|
rec.hide();
|
2012-09-27 16:15:58 +00:00
|
|
|
self.$('>ul>li.oe_mail_thread_msg[data-msg_id="-1"]').show();
|
|
|
|
return false;
|
2012-09-27 13:48:23 +00:00
|
|
|
} else {
|
2012-09-27 16:15:58 +00:00
|
|
|
self.$('>ul>li.oe_mail_thread_msg:not([data-msg_id="-1"])').show();
|
|
|
|
self.$('>ul>li.oe_mail_thread_msg[data-msg_id="-1"]').hide();
|
|
|
|
return true;
|
2012-09-27 13:48:23 +00:00
|
|
|
}
|
2012-09-27 16:15:58 +00:00
|
|
|
debugger;
|
2012-02-27 11:07:54 +00:00
|
|
|
},
|
2012-03-02 17:07:49 +00:00
|
|
|
|
2012-08-21 10:43:45 +00:00
|
|
|
/** 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
|
2012-09-19 10:13:39 +00:00
|
|
|
* - record.attachment_ids[].url: url of each attachment */
|
2012-08-21 10:43:45 +00:00
|
|
|
display_record: function (record) {
|
|
|
|
// formatting and additional fields
|
2012-09-27 08:30:56 +00:00
|
|
|
record.timestamp = Date.parse(record.date).getTime();
|
2012-08-21 10:43:45 +00:00
|
|
|
record.date = session.web.format_value(record.date, {type:"datetime"});
|
|
|
|
record.timerelative = $.timeago(record.date);
|
2012-06-21 21:55:27 +00:00
|
|
|
if (record.type == 'email') {
|
2012-08-21 10:43:45 +00:00
|
|
|
record.avatar = ('/mail/static/src/img/email_icon.png');
|
2012-07-03 12:20:20 +00:00
|
|
|
} else {
|
2012-09-06 11:14:44 +00:00
|
|
|
record.avatar = mail.ChatterUtils.get_image(this.session, 'res.partner', 'image_small', record.author_id[0]);
|
2012-06-21 21:55:27 +00:00
|
|
|
}
|
2012-09-06 11:14:44 +00:00
|
|
|
for (var l in record.attachment_ids) {
|
|
|
|
var attach = record.attachment_ids[l];
|
|
|
|
attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach);
|
2012-08-21 10:43:45 +00:00
|
|
|
}
|
2012-09-18 12:23:15 +00:00
|
|
|
// add to internal storage
|
|
|
|
this.records[record.id] = record;
|
2012-08-21 10:43:45 +00:00
|
|
|
// render, add the expand feature
|
2012-09-12 10:22:17 +00:00
|
|
|
var rendered = session.web.qweb.render('mail.thread.message', {'record': record, 'thread': this, 'options': this.options});
|
2012-09-27 13:48:23 +00:00
|
|
|
|
2012-09-27 08:30:56 +00:00
|
|
|
// check older and newer message for insert
|
|
|
|
var parent_newer = false;
|
|
|
|
var parent_older = false;
|
2012-09-27 13:48:23 +00:00
|
|
|
self.$('> ul.oe_mail_thread_display:first > li').each(function(){
|
2012-09-27 08:30:56 +00:00
|
|
|
var timestamp=$(this).data("msg_timestamp");
|
|
|
|
if(timestamp > record.timestamp){
|
|
|
|
if(!parent_newer || parent_newer>timestamp) parent_newer = timestamp;
|
2012-09-27 16:15:58 +00:00
|
|
|
} else if(timestamp>0 && timestamp < record.timestamp) {
|
2012-09-27 13:48:23 +00:00
|
|
|
if(!parent_older || parent_older<timestamp) parent_older = timestamp;
|
|
|
|
}
|
2012-09-27 08:30:56 +00:00
|
|
|
});
|
|
|
|
|
2012-09-27 13:48:23 +00:00
|
|
|
var $rendered = $(rendered);
|
|
|
|
|
2012-09-27 08:30:56 +00:00
|
|
|
if(parent_newer)
|
2012-09-27 13:48:23 +00:00
|
|
|
$rendered.insertAfter(this.$('> ul.oe_mail_thread_display:first > li[data-msg_timestamp='+parent_newer+']'));
|
2012-09-27 08:30:56 +00:00
|
|
|
else if(parent_older)
|
2012-09-27 13:48:23 +00:00
|
|
|
$rendered.insertBefore(this.$('> ul.oe_mail_thread_display:first > li[data-msg_timestamp='+parent_older+']'));
|
2012-09-27 08:30:56 +00:00
|
|
|
else
|
2012-09-27 16:15:58 +00:00
|
|
|
$rendered.prependTo(this.$('> ul.oe_mail_thread_display:first'));
|
|
|
|
|
2012-09-28 13:27:23 +00:00
|
|
|
$rendered.hide().fadeIn(750);
|
|
|
|
|
2012-09-27 08:30:56 +00:00
|
|
|
|
2012-09-27 13:48:23 +00:00
|
|
|
this.$('> div.oe_mail_msg_body').expander({
|
2012-09-12 10:22:17 +00:00
|
|
|
slicePoint: this.options.truncate_limit,
|
2012-07-30 07:52:10 +00:00
|
|
|
expandText: 'read more',
|
|
|
|
userCollapseText: '[^]',
|
2012-07-02 12:52:18 +00:00
|
|
|
detailClass: 'oe_mail_msg_tail',
|
2012-07-02 11:10:35 +00:00
|
|
|
moreClass: 'oe_mail_expand',
|
2012-07-30 07:52:10 +00:00
|
|
|
lessClass: 'oe_mail_reduce',
|
2012-03-05 16:59:10 +00:00
|
|
|
});
|
2012-09-27 13:48:23 +00:00
|
|
|
|
|
|
|
return $rendered;
|
2012-04-05 10:29:17 +00:00
|
|
|
},
|
2012-07-03 12:20:20 +00:00
|
|
|
|
2012-09-18 12:23:15 +00:00
|
|
|
// Render vote Display template.
|
|
|
|
toggle_vote: function (message_id, vote_node) {
|
|
|
|
var self = this;
|
|
|
|
var record = this.records[message_id];
|
|
|
|
if (record.has_voted) {
|
|
|
|
var idx = _.map(record.vote_user_ids, function (x) { return x[0]; }).indexOf(message_id);
|
|
|
|
record.vote_user_ids.splice(idx, 1);
|
|
|
|
}
|
|
|
|
else {
|
2012-09-18 15:05:44 +00:00
|
|
|
record.vote_user_ids.push([this.session.uid, 'You']);
|
2012-09-18 12:23:15 +00:00
|
|
|
}
|
|
|
|
record.has_voted = ! record.has_voted;
|
|
|
|
var vote_element = session.web.qweb.render('mail.thread.message.vote', {'record': record});
|
|
|
|
vote_node.empty();
|
|
|
|
vote_node.html(vote_element);
|
2012-04-05 10:29:17 +00:00
|
|
|
},
|
2012-07-03 12:20:20 +00:00
|
|
|
|
2012-08-21 10:43:45 +00:00
|
|
|
display_user_avatar: function () {
|
2012-09-06 11:14:44 +00:00
|
|
|
var avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid);
|
2012-09-26 07:17:09 +00:00
|
|
|
return this.$('img.oe_mail_icon').attr('src', avatar);
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
|
|
|
|
2012-09-26 07:17:09 +00:00
|
|
|
/* Display the message if if the msg_id don't exists.
|
|
|
|
* If the record have a parent, insert parent or inside parent */
|
2012-09-27 13:48:23 +00:00
|
|
|
message_treat_new_data: function(records) {
|
2012-09-26 07:17:09 +00:00
|
|
|
var self=this;
|
2012-09-27 13:48:23 +00:00
|
|
|
_(records.reverse()).each(function (record) {
|
|
|
|
if(!self.browse_thread({'id':record.id, 'model':record.model})){
|
|
|
|
if(record.parent_id){
|
|
|
|
var thread=self.browse_thread({'id':record.parent_id, 'model':record.model});
|
|
|
|
if( thread && !thread.$('.oe_mail_thread_msg[data-msg_id="'+record.id+'"]').size() ) {
|
|
|
|
thread.message_display_create_thread( [record] );
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
var thread=self.browse_thread({'top_thread':true});
|
|
|
|
thread.message_display_create_thread( [record] );
|
|
|
|
}
|
2012-09-26 07:17:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/*post a message and flatch the message*/
|
2012-08-21 10:43:45 +00:00
|
|
|
message_post: function (body) {
|
2012-08-22 07:45:45 +00:00
|
|
|
var self = this;
|
2012-08-21 10:43:45 +00:00
|
|
|
if (! body) {
|
2012-09-26 07:17:09 +00:00
|
|
|
var comment_node = this.$('textarea');
|
2012-08-21 10:43:45 +00:00
|
|
|
var body = comment_node.val();
|
|
|
|
comment_node.val('');
|
|
|
|
}
|
2012-09-27 17:23:17 +00:00
|
|
|
if(body.match(/\S+/))
|
|
|
|
return this.ds_thread.call('message_post_api', [
|
|
|
|
[this.context.default_res_id], body, false, 'comment', false, this.context.default_parent_id, undefined])
|
|
|
|
.then(this.proxy('message_treat_new_data'));
|
|
|
|
else
|
|
|
|
return false;
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
2012-08-21 10:43:45 +00:00
|
|
|
|
|
|
|
/** Action: 'shows more' to fetch new messages */
|
2012-09-20 14:46:45 +00:00
|
|
|
do_message_fetch_more: function (event) {
|
|
|
|
event.stopPropagation();
|
2012-09-27 13:48:23 +00:00
|
|
|
|
|
|
|
var source = $(event.srcElement).parents('[data-msg_id]:first');
|
|
|
|
var msg_id = source.data("msg_id");
|
|
|
|
var msg_model = source.data("msg_model");
|
|
|
|
|
2012-09-27 16:15:58 +00:00
|
|
|
var thread=this.browse_thread({'id':msg_id, 'model':msg_model, 'top_thread': true});
|
2012-09-27 13:48:23 +00:00
|
|
|
if(thread){
|
|
|
|
thread.options.expandable_max+=thread.options.expendable_number;
|
2012-09-27 16:15:58 +00:00
|
|
|
if(thread.display_expandable())
|
|
|
|
return thread.message_fetch(false, this.fetch_more_domain, this.fetch_more_context);
|
2012-09-27 13:48:23 +00:00
|
|
|
}
|
2012-08-21 10:43:45 +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-08-21 11:41:28 +00:00
|
|
|
this.options.thread_level = this.options.thread_level || 0;
|
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-08-21 11:41:28 +00:00
|
|
|
|
2012-03-21 15:31:41 +00:00
|
|
|
set_value: function() {
|
2012-08-23 15:02:29 +00:00
|
|
|
var self = this;
|
2012-03-21 15:31:41 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-08-21 11:41:28 +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,
|
|
|
|
default_model: this.view.model });
|
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-03-21 15:31:41 +00:00
|
|
|
// create and render Thread widget
|
2012-09-18 09:44:23 +00:00
|
|
|
var show_header_compose = this.view.is_action_enabled('edit') ||
|
|
|
|
(this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value());
|
2012-09-27 13:48:23 +00:00
|
|
|
|
|
|
|
this.thread = new mail.Thread(self, domain, this.options.context,
|
2012-09-12 10:22:17 +00:00
|
|
|
{ 'thread_level': this.options.thread_level,
|
2012-09-18 09:44:23 +00:00
|
|
|
'show_header_compose': show_header_compose,
|
|
|
|
'use_composer': show_header_compose,
|
2012-09-12 10:22:17 +00:00
|
|
|
'show_dd_delete': true,
|
2012-09-27 13:48:23 +00:00
|
|
|
'show_reply_by_email': show_header_compose,
|
|
|
|
'not_expendable':true
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.$('ul.oe_mail_wall_threads').empty();
|
|
|
|
var render_res = session.web.qweb.render('mail.wall_thread_container', {});
|
|
|
|
$(render_res).appendTo(this.$('ul.oe_mail_wall_threads'));
|
|
|
|
return this.thread.appendTo( this.$('li.oe_mail_wall_thread:last') );
|
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 || {};
|
|
|
|
this.options.thread_level = options.thread_level || 1;
|
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();
|
|
|
|
return (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-03-30 15:11:47 +00:00
|
|
|
self.searchview.on_search.add(self.do_searchview_search);
|
|
|
|
});
|
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 || []
|
|
|
|
}, function (results) {
|
2012-04-05 11:34:19 +00:00
|
|
|
self.search_results['context'] = results.context;
|
|
|
|
self.search_results['domain'] = results.domain;
|
|
|
|
self.search_results['groupby'] = results.group_by;
|
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-09-12 10:22:17 +00:00
|
|
|
/** Clean and display the threads */
|
2012-09-12 09:21:43 +00:00
|
|
|
message_render: function () {
|
2012-09-11 14:17:40 +00:00
|
|
|
var domain = this.options.domain.concat(this.search_results['domain']);
|
2012-09-26 07:17:09 +00:00
|
|
|
|
|
|
|
this.thread = new mail.Thread(this, domain, this.options.context,
|
2012-09-12 10:22:17 +00:00
|
|
|
{ 'thread_level': this.options.thread_level,
|
|
|
|
'use_composer': true,
|
|
|
|
'show_reply': this.options.thread_level > 0,
|
2012-09-28 13:27:23 +00:00
|
|
|
'show_dd_hide': true,
|
2012-08-20 15:52:02 +00:00
|
|
|
}
|
2012-08-21 09:20:15 +00:00
|
|
|
);
|
2012-09-27 13:48:23 +00:00
|
|
|
|
|
|
|
this.$('ul.oe_mail_wall_threads').empty();
|
|
|
|
var render_res = session.web.qweb.render('mail.wall_thread_container', {});
|
|
|
|
$(render_res).appendTo(this.$('ul.oe_mail_wall_threads'));
|
2012-09-27 08:30:56 +00:00
|
|
|
return this.thread.appendTo( this.$('li.oe_mail_wall_thread:last') );
|
2012-08-21 09:20:15 +00:00
|
|
|
},
|
2012-02-08 16:42:29 +00:00
|
|
|
});
|
2012-02-01 16:22:13 +00:00
|
|
|
};
|