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-08-08 07:56:00 +00:00
|
|
|
if (action.res_model == 'mail.compose.message' && this.fields && this.fields.message_ids && this.fields.message_ids.view.get("actual_mode") != 'create') {
|
2012-07-17 15:57:02 +00:00
|
|
|
var record_thread = this.fields.message_ids;
|
|
|
|
var thread = record_thread.thread;
|
|
|
|
thread.instantiate_composition_form('comment', true, false, 0, action.context);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this._super(action, on_close);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
|
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-06-21 15:24:28 +00:00
|
|
|
* This class holds a few tools method that will be used by
|
2012-06-18 16:03:57 +00:00
|
|
|
* the various Chatter widgets.
|
|
|
|
*/
|
|
|
|
|
2012-06-21 15:24:28 +00:00
|
|
|
mail.ChatterUtils = {
|
2012-06-18 16:03:57 +00:00
|
|
|
|
2012-07-19 12:03:15 +00:00
|
|
|
/* generic chatter events binding */
|
|
|
|
bind_events: function(widget) {
|
|
|
|
// event: click on an internal link to a document: model, login
|
|
|
|
widget.$element.delegate('a.oe_mail_internal_link', 'click', function (event) {
|
2012-06-19 12:12:11 +00:00
|
|
|
event.preventDefault();
|
|
|
|
// lazy implementation: fetch data and try to redirect
|
|
|
|
if (! event.srcElement.dataset.resModel) return false;
|
|
|
|
else var res_model = event.srcElement.dataset.resModel;
|
|
|
|
var res_login = event.srcElement.dataset.resLogin;
|
2012-07-19 12:03:15 +00:00
|
|
|
if (! res_login) return false;
|
|
|
|
var ds = new session.web.DataSet(widget, res_model);
|
|
|
|
var defer = ds.call('search', [[['login', '=', res_login]]]).pipe(function (records) {
|
|
|
|
if (records[0]) {
|
|
|
|
widget.do_action({ type: 'ir.actions.act_window', res_model: res_model, res_id: parseInt(records[0]), views: [[false, 'form']]});
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
});
|
2012-06-19 12:12:11 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-06-18 16:03:57 +00:00
|
|
|
/** get an image in /web/binary/image?... */
|
|
|
|
get_image: function(session_prefix, session_id, model, field, id) {
|
|
|
|
return session_prefix + '/web/binary/image?session_id=' + session_id + '&model=' + model + '&field=' + field + '&id=' + (id || '');
|
|
|
|
},
|
2012-06-19 12:12:11 +00:00
|
|
|
|
|
|
|
/** checks if tue current user is the message author */
|
2012-07-11 09:55:45 +00:00
|
|
|
is_author: function (widget, message_user_id) {
|
|
|
|
return (widget.session && widget.session.uid != 0 && widget.session.uid == message_user_id);
|
2012-06-19 12:12:11 +00:00
|
|
|
},
|
2012-06-20 08:57:58 +00:00
|
|
|
|
2012-06-21 15:24:28 +00:00
|
|
|
/**
|
|
|
|
* CONTENT MANIPULATION
|
|
|
|
*
|
|
|
|
* Regular expressions
|
|
|
|
* - (^|\s)@((\w|@|\.)*): @login@log.log, supports inner '@' for
|
|
|
|
* logins that are emails
|
|
|
|
* 1. '(void)'
|
|
|
|
* 2. login@log.log
|
|
|
|
* - (^|\s)\[(\w+).(\w+),(\d)\|*((\w|[@ .,])*)\]: [ir.attachment,3|My Label],
|
|
|
|
* for internal links to model ir.attachment, id=3, and with
|
|
|
|
* optional label 'My Label'. Note that having a '|Label' is not
|
|
|
|
* mandatory, because the regex should still be correct.
|
|
|
|
* 1. '(void)'
|
|
|
|
* 2. 'ir'
|
|
|
|
* 3. 'attachment'
|
|
|
|
* 4. '3'
|
|
|
|
* 5. 'My Label'
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces some expressions
|
|
|
|
* - @login - shorcut to link to a res.user, given its login
|
|
|
|
* - [ir.attachment,3|My Label] - shortcut to an internal
|
|
|
|
* document
|
|
|
|
* - :name - shortcut to an image
|
|
|
|
*/
|
|
|
|
do_replace_expressions: function (string) {
|
|
|
|
var self = this;
|
|
|
|
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-06-15 08:36:56 +00:00
|
|
|
* This form is an OpenERP form_view, build on a mail.compose.message
|
|
|
|
* wizard.
|
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-08-20 13:59:58 +00:00
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {String} [options.res_model] res_model of document [REQUIRED]
|
|
|
|
* @param {Number} [options.res_id] res_id of record [REQUIRED]
|
|
|
|
* @param {Number} [options.email_mode] true/false, tells whether
|
2012-07-10 13:06:31 +00:00
|
|
|
* we are in email sending mode
|
2012-08-20 13:59:58 +00:00
|
|
|
* @param {Number} [options.formatting] true/false, tells whether
|
2012-07-10 13:06:31 +00:00
|
|
|
* we are in advance formatting mode
|
2012-08-20 13:59:58 +00:00
|
|
|
* @param {String} [options.model] mail.compose.message.mode (see
|
2012-07-10 13:06:31 +00:00
|
|
|
* composition wizard)
|
2012-08-20 13:59:58 +00:00
|
|
|
* @param {Number} [options.msg_id] id of a message in case we are in
|
2012-07-10 13:06:31 +00:00
|
|
|
* reply mode
|
2012-07-06 15:52:26 +00:00
|
|
|
*/
|
2012-08-20 13:59:58 +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-06-19 09:57:30 +00:00
|
|
|
// options
|
2012-08-20 13:59:58 +00:00
|
|
|
this.options = options || {};
|
|
|
|
this.options.context = options.context || {};
|
|
|
|
this.options.email_mode = options.email_mode || false;
|
|
|
|
this.options.formatting = options.formatting || false;
|
|
|
|
this.options.mode = options.mode || 'comment';
|
|
|
|
this.options.form_xml_id = options.form_xml_id || 'email_compose_message_wizard_form_chatter';
|
|
|
|
this.options.form_view_id = false;
|
|
|
|
if (this.options.mode == 'reply') {
|
|
|
|
this.options.active_id = this.options.msg_id;
|
2012-07-10 13:06:31 +00:00
|
|
|
} else {
|
2012-08-20 13:59:58 +00:00
|
|
|
this.options.active_id = this.options.res_id;
|
2012-07-10 13:06:31 +00:00
|
|
|
}
|
2012-07-12 14:18:57 +00:00
|
|
|
this.email_mode = false;
|
|
|
|
this.formatting = false;
|
2012-06-14 08:40:33 +00:00
|
|
|
},
|
2012-07-10 13:06:31 +00:00
|
|
|
|
2012-07-16 13:54:03 +00:00
|
|
|
/**
|
|
|
|
* Reinitialize the widget field values to the default values. The
|
|
|
|
* purpose is to avoid to destroy and re-build a form view. Default
|
|
|
|
* values are therefore given as for an onchange. */
|
|
|
|
reinit: function() {
|
|
|
|
var self = this;
|
|
|
|
if (! this.form_view) return;
|
2012-08-17 12:06:06 +00:00
|
|
|
var call_defer = this.ds_compose.call('default_get', [['subject', 'body', 'body_html', 'dest_partner_ids'], this.ds_compose.get_context()]).then(
|
2012-07-16 13:54:03 +00:00
|
|
|
function (result) {
|
|
|
|
self.form_view.on_processed_onchange({'value': result}, []);
|
|
|
|
});
|
2012-07-20 13:01:27 +00:00
|
|
|
return call_defer;
|
2012-07-16 13:54:03 +00:00
|
|
|
},
|
|
|
|
|
2012-07-16 13:28:22 +00:00
|
|
|
/**
|
|
|
|
* Override-hack of do_action: clean the form */
|
|
|
|
do_action: function(action, on_close) {
|
|
|
|
// this.init_comments();
|
|
|
|
return this._super(action, on_close);
|
|
|
|
},
|
|
|
|
|
2012-06-15 08:36:56 +00:00
|
|
|
/**
|
2012-07-10 13:06:31 +00:00
|
|
|
* Widget start function
|
2012-07-04 13:29:58 +00:00
|
|
|
* - builds and initializes the form view */
|
2012-06-19 09:57:30 +00:00
|
|
|
start: function() {
|
2012-06-14 11:44:18 +00:00
|
|
|
var self = this;
|
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
|
|
|
|
var user_avatar = mail.ChatterUtils.get_image(this.session.prefix,
|
2012-07-30 08:40:20 +00:00
|
|
|
this.session.session_id, 'res.users', 'image_small', this.session.uid);
|
2012-07-04 13:29:58 +00:00
|
|
|
this.$element.find('img.oe_mail_icon').attr('src', user_avatar);
|
|
|
|
this.$element.find('div.oe_mail_msg_content').empty();
|
2012-07-16 15:39:47 +00:00
|
|
|
// create a context for the default_get of the compose form
|
2012-07-17 15:57:02 +00:00
|
|
|
var widget_context = {
|
2012-08-20 13:59:58 +00:00
|
|
|
'active_model': this.options.res_model,
|
|
|
|
'active_id': this.options.active_id,
|
|
|
|
'mail.compose.message.mode': this.options.mode,
|
2012-07-16 15:39:47 +00:00
|
|
|
};
|
2012-08-20 13:59:58 +00:00
|
|
|
var context = _.extend({}, this.options.context, widget_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
|
|
|
|
var data_ds = new session.web.DataSetSearch(this, 'ir.model.data');
|
2012-08-20 13:59:58 +00:00
|
|
|
var deferred_form_id =data_ds.call('get_object_reference', ['mail', this.options.form_xml_id]).then( function (result) {
|
2012-07-16 15:39:47 +00:00
|
|
|
if (result) {
|
2012-08-20 13:59:58 +00:00
|
|
|
self.options.form_view_id = result[1];
|
2012-04-05 09:48:42 +00:00
|
|
|
}
|
2012-07-16 15:39:47 +00:00
|
|
|
}).pipe(this.proxy('create_form_view'));
|
|
|
|
return deferred_form_id;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a FormView, then append it to the to widget DOM. */
|
|
|
|
create_form_view: function () {
|
|
|
|
var self = this;
|
|
|
|
// 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-06-19 09:57:30 +00:00
|
|
|
var msg_node = this.$element.find('div.oe_mail_msg_content');
|
|
|
|
return $.when(this.form_view.appendTo(msg_node)).pipe(function() {
|
2012-06-15 15:35:15 +00:00
|
|
|
self.bind_events();
|
2012-06-14 11:44:18 +00:00
|
|
|
self.form_view.do_show();
|
2012-08-20 13:59:58 +00:00
|
|
|
if (self.options.email_mode) { self.toggle_email_mode(); }
|
|
|
|
if (self.options.formatting) { self.toggle_formatting_mode(); }
|
2012-06-15 15:35:15 +00:00
|
|
|
});
|
|
|
|
},
|
2012-07-10 13:06:31 +00:00
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
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-07-18 11:08:15 +00:00
|
|
|
this.$element.find('button.oe_form_button').click(function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
2012-07-12 12:44:40 +00:00
|
|
|
// event: click on 'Send an Email' link that toggles the form for
|
2012-07-06 15:52:26 +00:00
|
|
|
// sending an email (partner_ids)
|
|
|
|
this.$element.find('a.oe_mail_compose_message_email').click(function (event) {
|
2012-06-15 15:35:15 +00:00
|
|
|
event.preventDefault();
|
2012-07-12 14:18:57 +00:00
|
|
|
self.toggle_email_mode();
|
2012-07-06 15:52:26 +00:00
|
|
|
});
|
|
|
|
// event: click on 'Formatting' icon-link that toggles the advanced
|
|
|
|
// formatting options for writing a message (subject, body_html)
|
|
|
|
this.$element.find('a.oe_mail_compose_message_formatting').click(function (event) {
|
|
|
|
event.preventDefault();
|
2012-07-12 14:18:57 +00:00
|
|
|
self.toggle_formatting_mode();
|
2012-04-05 09:48:42 +00:00
|
|
|
});
|
2012-07-06 15:52:26 +00:00
|
|
|
// event: click on 'Attachment' icon-link that opens the dialog to
|
|
|
|
// add an attachment.
|
|
|
|
this.$element.find('a.oe_mail_compose_message_attachment').click(function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
// not yet implemented
|
2012-07-10 13:06:31 +00:00
|
|
|
self.set_body_value('attachment', 'attachment');
|
2012-07-06 15:52:26 +00:00
|
|
|
});
|
|
|
|
// event: click on 'Checklist' icon-link that toggles the options
|
|
|
|
// for adding checklist.
|
|
|
|
this.$element.find('a.oe_mail_compose_message_checklist').click(function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
// not yet implemented
|
2012-07-10 13:06:31 +00:00
|
|
|
self.set_body_value('checklist', 'checklist');
|
2012-06-14 11:44:18 +00:00
|
|
|
});
|
2012-06-14 08:40:33 +00:00
|
|
|
},
|
2012-07-10 13:06:31 +00:00
|
|
|
|
2012-07-12 14:18:57 +00:00
|
|
|
/**
|
|
|
|
* Toggle the formatting mode. */
|
|
|
|
toggle_formatting_mode: function() {
|
2012-07-13 14:23:33 +00:00
|
|
|
var self = this;
|
2012-07-12 14:18:57 +00:00
|
|
|
this.formatting = ! this.formatting;
|
2012-07-13 14:23:33 +00:00
|
|
|
// calls onchange
|
2012-08-20 13:59:58 +00:00
|
|
|
var call_defer = this.ds_compose.call('onchange_formatting', [[], this.formatting, this.options.res_model, this.options.res_id]).then(
|
2012-07-13 14:23:33 +00:00
|
|
|
function (result) {
|
|
|
|
self.form_view.on_processed_onchange(result, []);
|
|
|
|
});
|
2012-07-12 14:18:57 +00:00
|
|
|
// update context of datasetsearch
|
|
|
|
this.ds_compose.context.formatting = this.formatting;
|
|
|
|
// toggle display
|
|
|
|
this.$element.find('span.oe_mail_compose_message_subject').toggleClass('oe_mail_compose_message_invisible');
|
2012-08-17 12:06:06 +00:00
|
|
|
this.$element.find('div.oe_mail_compose_message_body').toggleClass('oe_mail_compose_message_invisible');
|
2012-07-12 14:18:57 +00:00
|
|
|
this.$element.find('div.oe_mail_compose_message_body_html').toggleClass('oe_mail_compose_message_invisible');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the email mode. */
|
|
|
|
toggle_email_mode: function() {
|
2012-07-13 14:23:33 +00:00
|
|
|
var self = this;
|
2012-07-12 14:18:57 +00:00
|
|
|
this.email_mode = ! this.email_mode;
|
2012-07-13 14:23:33 +00:00
|
|
|
// calls onchange
|
2012-08-20 13:59:58 +00:00
|
|
|
var call_defer = this.ds_compose.call('onchange_email_mode', [[], this.email_mode, this.options.res_model, this.options.res_id]).then(
|
2012-07-13 14:23:33 +00:00
|
|
|
function (result) {
|
|
|
|
self.form_view.on_processed_onchange(result, []);
|
|
|
|
});
|
2012-07-12 14:18:57 +00:00
|
|
|
// update context of datasetsearch
|
|
|
|
this.ds_compose.context.email_mode = this.email_mode;
|
|
|
|
// update 'Post' button -> 'Send'
|
|
|
|
// update 'Send an Email' link -> 'Post a comment'
|
|
|
|
if (this.email_mode) {
|
2012-07-19 12:03:15 +00:00
|
|
|
this.$element.find('button.oe_mail_compose_message_button_send').html('<span>Send</span>');
|
2012-07-12 14:18:57 +00:00
|
|
|
this.$element.find('a.oe_mail_compose_message_email').html('Comment');
|
|
|
|
} else {
|
2012-07-19 12:03:15 +00:00
|
|
|
this.$element.find('button.oe_mail_compose_message_button_send').html('<span>Post</span>');
|
2012-07-12 14:18:57 +00:00
|
|
|
this.$element.find('a.oe_mail_compose_message_email').html('Send an Email');
|
|
|
|
}
|
|
|
|
// toggle display
|
|
|
|
this.$element.find('div.oe_mail_compose_message_partner_ids').toggleClass('oe_mail_compose_message_invisible');
|
|
|
|
},
|
|
|
|
|
2012-07-10 13:06:31 +00:00
|
|
|
/**
|
|
|
|
* Update the values of the composition form; with possible different
|
2012-08-17 12:06:06 +00:00
|
|
|
* values for body and body_html. */
|
|
|
|
set_body_value: function(body, body_html) {
|
|
|
|
this.form_view.fields.body.set_value(body);
|
2012-07-10 13:06:31 +00:00
|
|
|
this.form_view.fields.body_html.set_value(body_html);
|
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-06-15 08:36:56 +00:00
|
|
|
* This widget has 2 ways of initialization, either you give records
|
|
|
|
* to be rendered, either it will fetch [limit] messages related to
|
|
|
|
* [res_model]:[res_id].
|
2012-03-02 17:07:49 +00:00
|
|
|
*/
|
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-08-20 13:59:58 +00:00
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {String} [options.res_model] res_model of document [REQUIRED]
|
|
|
|
* @param {Number} [options.res_id] res_id of record [REQUIRED]
|
|
|
|
* @param {Number} [options.uid] user id [REQUIRED]
|
|
|
|
* @param {Bool} [options.parent_id=false] parent_id of message
|
|
|
|
* @param {Number} [options.thread_level=0] number of levels in the thread
|
2012-07-11 09:55:45 +00:00
|
|
|
* (only 0 or 1 currently)
|
2012-08-20 13:59:58 +00:00
|
|
|
* @param {Bool} [options.is_wall=false] thread is displayed in the wall
|
|
|
|
* @param {Number} [options.msg_more_limit=150] 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
|
|
|
|
* (ex: 110 characters needed to be truncated and be displayed as
|
|
|
|
* a 100-characters message)
|
2012-08-20 13:59:58 +00:00
|
|
|
* @param {Number} [options.limit=100] maximum number of messages to fetch
|
|
|
|
* @param {Number} [options.offset=0] offset for fetching messages
|
|
|
|
* @param {Number} [options.records=null] records to show instead of fetching messages
|
2012-02-27 16:04:42 +00:00
|
|
|
*/
|
2012-02-23 16:32:36 +00:00
|
|
|
init: function(parent, params) {
|
|
|
|
this._super(parent);
|
2012-07-10 13:06:31 +00:00
|
|
|
// options
|
2012-02-27 16:04:42 +00:00
|
|
|
this.params = params;
|
2012-03-02 17:07:49 +00:00
|
|
|
this.params.parent_id = this.params.parent_id || false;
|
|
|
|
this.params.thread_level = this.params.thread_level || 0;
|
2012-07-11 09:55:45 +00:00
|
|
|
this.params.is_wall = this.params.is_wall || (this.params.records != undefined) || false;
|
2012-07-30 07:52:10 +00:00
|
|
|
this.params.msg_more_limit = this.params.msg_more_limit || 250;
|
2012-03-22 16:32:24 +00:00
|
|
|
this.params.limit = this.params.limit || 100;
|
2012-07-19 12:03:15 +00:00
|
|
|
// this.params.limit = 3; // tmp for testing
|
2012-02-27 16:04:42 +00:00
|
|
|
this.params.offset = this.params.offset || 0;
|
|
|
|
this.params.records = this.params.records || null;
|
2012-08-19 16:28:32 +00:00
|
|
|
|
2012-03-21 17:20:18 +00:00
|
|
|
// datasets and internal vars
|
2012-07-11 09:55:45 +00:00
|
|
|
this.ds = new session.web.DataSetSearch(this, this.params.res_model);
|
|
|
|
this.ds_msg = new session.web.DataSetSearch(this, 'mail.message');
|
2012-04-05 10:29:17 +00:00
|
|
|
this.comments_structure = {'root_ids': [], 'new_root_ids': [], 'msgs': {}, 'tree_struct': {}, 'model_to_root_ids': {}};
|
2012-03-21 17:20:18 +00:00
|
|
|
// display customization vars
|
2012-03-12 15:25:29 +00:00
|
|
|
this.display = {};
|
2012-03-13 17:06:48 +00:00
|
|
|
this.display.show_post_comment = this.params.show_post_comment || false;
|
2012-05-15 12:23:06 +00:00
|
|
|
this.display.show_reply = (this.params.thread_level > 0 && this.params.is_wall);
|
2012-05-14 10:08:20 +00:00
|
|
|
this.display.show_delete = ! this.params.is_wall;
|
|
|
|
this.display.show_hide = this.params.is_wall;
|
|
|
|
this.display.show_reply_by_email = ! this.params.is_wall;
|
2012-03-12 17:33:23 +00:00
|
|
|
this.display.show_more = (this.params.thread_level == 0);
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
start: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-03-14 08:51:28 +00:00
|
|
|
// add events
|
2012-07-11 11:17:22 +00:00
|
|
|
this.bind_events();
|
2012-06-19 18:28:10 +00:00
|
|
|
// display user, fetch comments
|
2012-03-27 09:15:04 +00:00
|
|
|
this.display_current_user();
|
2012-08-19 16:28:32 +00:00
|
|
|
|
2012-04-04 12:00:53 +00:00
|
|
|
if (this.params.records) var display_done = this.display_comments_from_parameters(this.params.records);
|
2012-03-27 09:15:04 +00:00
|
|
|
else var display_done = this.init_comments();
|
2012-05-14 12:32:31 +00:00
|
|
|
// customize display
|
2012-07-10 13:06:31 +00:00
|
|
|
$.when(display_done).then(this.proxy('do_customize_display'));
|
2012-06-15 08:36:56 +00:00
|
|
|
// add message composition form view
|
2012-07-11 09:55:45 +00:00
|
|
|
if (this.display.show_post_comment) {
|
|
|
|
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-07-16 13:28:22 +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) {
|
|
|
|
this.init_comments();
|
2012-07-16 13:54:03 +00:00
|
|
|
if (this.compose_message_widget) {
|
|
|
|
this.compose_message_widget.reinit(); }
|
2012-07-16 13:28:22 +00:00
|
|
|
return this._super(action, on_close);
|
|
|
|
},
|
|
|
|
|
2012-07-17 15:57:02 +00:00
|
|
|
instantiate_composition_form: function(mode, email_mode, formatting, msg_id, context) {
|
2012-07-10 13:06:31 +00:00
|
|
|
if (this.compose_message_widget) {
|
|
|
|
this.compose_message_widget.destroy();
|
|
|
|
}
|
|
|
|
this.compose_message_widget = new mail.ComposeMessage(this, {
|
2012-07-06 15:52:26 +00:00
|
|
|
'extended_mode': false, 'uid': this.params.uid, 'res_model': this.params.res_model,
|
2012-07-12 14:18:57 +00:00
|
|
|
'res_id': this.params.res_id, 'mode': mode || 'comment', 'msg_id': msg_id,
|
2012-07-17 15:57:02 +00:00
|
|
|
'email_mode': email_mode || false, 'formatting': formatting || false,
|
|
|
|
'context': context || false } );
|
2012-07-04 13:29:58 +00:00
|
|
|
var composition_node = this.$element.find('div.oe_mail_thread_action');
|
|
|
|
composition_node.empty();
|
2012-07-10 13:06:31 +00:00
|
|
|
var compose_done = this.compose_message_widget.appendTo(composition_node);
|
|
|
|
return compose_done;
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
2012-07-10 13:06:31 +00:00
|
|
|
|
2012-05-14 12:32:31 +00:00
|
|
|
do_customize_display: function() {
|
2012-07-10 13:06:31 +00:00
|
|
|
if (this.display.show_post_comment) { this.$element.find('div.oe_mail_thread_action').eq(0).show(); }
|
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-06-19 12:12:11 +00:00
|
|
|
// generic events from Chatter Mixin
|
2012-07-19 12:03:15 +00:00
|
|
|
mail.ChatterUtils.bind_events(this);
|
2012-03-21 17:20:18 +00:00
|
|
|
// event: click on 'more' at bottom of thread
|
2012-03-14 08:51:28 +00:00
|
|
|
this.$element.find('button.oe_mail_button_more').click(function () {
|
|
|
|
self.do_more();
|
|
|
|
});
|
2012-07-11 09:55:45 +00:00
|
|
|
// event: writing in basic textarea of composition form (quick reply)
|
|
|
|
this.$element.find('textarea.oe_mail_compose_textarea').keyup(function (event) {
|
2012-03-14 08:51:28 +00:00
|
|
|
var charCode = (event.which) ? event.which : window.event.keyCode;
|
|
|
|
if (event.shiftKey && charCode == 13) { this.value = this.value+"\n"; }
|
2012-04-04 16:00:56 +00:00
|
|
|
else if (charCode == 13) { return self.do_comment(); }
|
2012-03-14 08:51:28 +00:00
|
|
|
});
|
2012-07-11 09:55:45 +00:00
|
|
|
// event: click on 'Reply' in msg
|
2012-03-13 17:41:05 +00:00
|
|
|
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_reply', 'click', function (event) {
|
2012-06-21 15:00:02 +00:00
|
|
|
var act_dom = $(this).parents('div.oe_mail_thread_display').find('div.oe_mail_thread_action:first');
|
2012-03-29 09:18:08 +00:00
|
|
|
act_dom.toggle();
|
2012-04-05 21:42:41 +00:00
|
|
|
event.preventDefault();
|
2012-03-13 17:41:05 +00:00
|
|
|
});
|
2012-07-11 11:17:22 +00:00
|
|
|
// event: click on 'attachment(s)' in msg
|
|
|
|
this.$element.delegate('a.oe_mail_msg_view_attachments', 'click', function (event) {
|
|
|
|
var act_dom = $(this).parent().parent().parent().find('.oe_mail_msg_attachments');
|
|
|
|
act_dom.toggle();
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
2012-07-11 09:55:45 +00:00
|
|
|
// event: click on 'Delete' in msg side menu
|
2012-03-13 17:41:05 +00:00
|
|
|
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_delete', 'click', function (event) {
|
2012-03-29 09:18:08 +00:00
|
|
|
if (! confirm(_t("Do you really want to delete this message?"))) { return false; }
|
|
|
|
var msg_id = event.srcElement.dataset.id;
|
|
|
|
if (! msg_id) return false;
|
|
|
|
var call_defer = self.ds_msg.unlink([parseInt(msg_id)]);
|
2012-07-04 13:29:58 +00:00
|
|
|
$(event.srcElement).parents('li.oe_mail_thread_msg').eq(0).hide();
|
2012-03-29 09:18:08 +00:00
|
|
|
if (self.params.thread_level > 0) {
|
2012-06-21 15:00:02 +00:00
|
|
|
$(event.srcElement).parents('.oe_mail_thread').eq(0).hide();
|
2012-03-29 09:18:08 +00:00
|
|
|
}
|
2012-07-11 09:55:45 +00:00
|
|
|
event.preventDefault();
|
|
|
|
return call_defer;
|
2012-03-13 17:41:05 +00:00
|
|
|
});
|
2012-07-11 09:55:45 +00:00
|
|
|
// event: click on 'Hide' in msg side menu
|
2012-03-14 08:51:28 +00:00
|
|
|
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_hide', 'click', function (event) {
|
2012-03-29 09:18:08 +00:00
|
|
|
if (! confirm(_t("Do you really want to hide this thread ?"))) { return false; }
|
|
|
|
var msg_id = event.srcElement.dataset.id;
|
|
|
|
if (! msg_id) return false;
|
2012-04-02 11:50:02 +00:00
|
|
|
var call_defer = self.ds.call('message_remove_pushed_notifications', [[self.params.res_id], [parseInt(msg_id)], true]);
|
2012-07-04 13:29:58 +00:00
|
|
|
$(event.srcElement).parents('li.oe_mail_thread_msg').eq(0).hide();
|
2012-03-29 09:18:08 +00:00
|
|
|
if (self.params.thread_level > 0) {
|
2012-06-21 12:48:43 +00:00
|
|
|
$(event.srcElement).parents('.oe_mail_thread').eq(0).hide();
|
2012-03-29 09:18:08 +00:00
|
|
|
}
|
2012-07-10 13:06:31 +00:00
|
|
|
event.preventDefault();
|
2012-07-11 09:55:45 +00:00
|
|
|
return call_defer;
|
2012-06-19 18:28:10 +00:00
|
|
|
});
|
2012-07-11 11:17:22 +00:00
|
|
|
// event: click on "Reply" in msg side menu (email style)
|
2012-07-11 09:55:45 +00:00
|
|
|
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_reply_by_email', 'click', function (event) {
|
|
|
|
var msg_id = event.srcElement.dataset.msg_id;
|
2012-07-12 14:18:57 +00:00
|
|
|
var email_mode = (event.srcElement.dataset.type == 'email');
|
|
|
|
var formatting = (event.srcElement.dataset.formatting == 'html');
|
2012-07-11 09:55:45 +00:00
|
|
|
if (! msg_id) return false;
|
2012-07-12 14:18:57 +00:00
|
|
|
self.instantiate_composition_form('reply', email_mode, formatting, msg_id);
|
2012-07-11 09:55:45 +00:00
|
|
|
event.preventDefault();
|
2012-06-22 01:21:02 +00:00
|
|
|
});
|
2012-03-13 17:41:05 +00:00
|
|
|
},
|
|
|
|
|
2012-03-21 15:31:41 +00:00
|
|
|
destroy: function () {
|
|
|
|
this._super.apply(this, arguments);
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
|
|
|
|
2012-02-27 16:04:42 +00:00
|
|
|
init_comments: function() {
|
|
|
|
var self = this;
|
|
|
|
this.params.offset = 0;
|
2012-04-05 10:29:17 +00:00
|
|
|
this.comments_structure = {'root_ids': [], 'new_root_ids': [], 'msgs': {}, 'tree_struct': {}, 'model_to_root_ids': {}};
|
2012-02-27 16:04:42 +00:00
|
|
|
this.$element.find('div.oe_mail_thread_display').empty();
|
2012-05-14 15:20:18 +00:00
|
|
|
var domain = this.get_fetch_domain(this.comments_structure);
|
2012-03-07 13:44:09 +00:00
|
|
|
return this.fetch_comments(this.params.limit, this.params.offset, domain).then();
|
2012-02-27 16:04:42 +00:00
|
|
|
},
|
|
|
|
|
2012-03-06 15:09:46 +00:00
|
|
|
fetch_comments: function (limit, offset, domain) {
|
2012-02-29 08:59:53 +00:00
|
|
|
var self = this;
|
2012-07-03 12:20:20 +00:00
|
|
|
var defer = this.ds.call('message_read', [[this.params.res_id], (this.params.thread_level > 0), (this.comments_structure['root_ids']),
|
2012-05-14 15:20:18 +00:00
|
|
|
(limit+1) || (this.params.limit+1), offset||this.params.offset, domain||undefined ]).then(function (records) {
|
2012-03-22 16:32:24 +00:00
|
|
|
if (records.length <= self.params.limit) self.display.show_more = false;
|
2012-07-19 12:03:15 +00:00
|
|
|
// else { self.display.show_more = true; records.pop(); }
|
|
|
|
// else { self.display.show_more = true; records.splice(0, 1); }
|
|
|
|
else { self.display.show_more = true; }
|
2012-02-29 08:59:53 +00:00
|
|
|
self.display_comments(records);
|
2012-05-14 15:20:18 +00:00
|
|
|
// TODO: move to customize display
|
2012-03-27 09:15:04 +00:00
|
|
|
if (self.display.show_more == true) self.$element.find('div.oe_mail_thread_more:last').show();
|
|
|
|
else self.$element.find('div.oe_mail_thread_more:last').hide();
|
2012-06-20 14:02:04 +00:00
|
|
|
});
|
|
|
|
|
2012-02-29 08:59:53 +00:00
|
|
|
return defer;
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
2012-03-05 16:59:10 +00:00
|
|
|
|
2012-04-04 12:00:53 +00:00
|
|
|
display_comments_from_parameters: function (records) {
|
|
|
|
if (records.length > 0 && records.length < (records[0].child_ids.length+1) ) this.display.show_more = true;
|
|
|
|
else this.display.show_more = false;
|
|
|
|
var defer = this.display_comments(records);
|
2012-05-14 15:20:18 +00:00
|
|
|
// TODO: move to customize display
|
2012-04-04 12:00:53 +00:00
|
|
|
if (this.display.show_more == true) $('div.oe_mail_thread_more').eq(-2).show();
|
|
|
|
else $('div.oe_mail_thread_more').eq(-2).hide();
|
|
|
|
return defer;
|
|
|
|
},
|
|
|
|
|
2012-02-23 16:32:36 +00:00
|
|
|
display_comments: function (records) {
|
2012-03-05 16:59:10 +00:00
|
|
|
var self = this;
|
2012-07-19 12:03:15 +00:00
|
|
|
// sort the records
|
2012-08-20 13:07:30 +00:00
|
|
|
// mail.ChatterUtils.records_struct_add_records(this.comments_structure, records, this.params.parent_id);
|
2012-06-22 17:06:39 +00:00
|
|
|
//build attachments download urls and compute time-relative from dates
|
2012-06-22 01:21:02 +00:00
|
|
|
for (var k in records) {
|
|
|
|
records[k].timerelative = $.timeago(records[k].date);
|
|
|
|
if (records[k].attachments) {
|
|
|
|
for (var l in records[k].attachments) {
|
|
|
|
var url = self.session.origin + '/web/binary/saveas?session_id=' + self.session.session_id + '&model=ir.attachment&field=datas&filename_field=datas_fname&id='+records[k].attachments[l].id;
|
|
|
|
records[k].attachments[l].url = url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-05 16:59:10 +00:00
|
|
|
_(records).each(function (record) {
|
2012-03-05 17:37:42 +00:00
|
|
|
var sub_msgs = [];
|
2012-08-20 13:07:30 +00:00
|
|
|
if ((record.parent_id == undefined || record.parent_id == false || record.parent_id[0] == self.params.parent_id) && self.params.thread_level > 0 ) {
|
|
|
|
// var sub_list = self.comments_structure['tree_struct'][record.id]['direct_childs'];
|
|
|
|
// _(records).each(function (record) {
|
|
|
|
// //if (record.parent_id == false || record.parent_id[0] == self.params.parent_id) return;
|
|
|
|
// if (_.indexOf(sub_list, record.id) != -1) {
|
|
|
|
// sub_msgs.push(record);
|
|
|
|
// }
|
|
|
|
// });
|
2012-03-05 16:59:10 +00:00
|
|
|
self.display_comment(record);
|
|
|
|
self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid,
|
2012-05-15 12:23:06 +00:00
|
|
|
'records': sub_msgs, 'thread_level': (self.params.thread_level-1), 'parent_id': record.id,
|
|
|
|
'is_wall': self.params.is_wall});
|
2012-04-05 13:09:49 +00:00
|
|
|
self.$element.find('li.oe_mail_thread_msg:last').append('<div class="oe_mail_thread_subthread"/>');
|
2012-03-05 16:59:10 +00:00
|
|
|
self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last'));
|
|
|
|
}
|
|
|
|
else if (self.params.thread_level == 0) {
|
|
|
|
self.display_comment(record);
|
|
|
|
}
|
2012-02-23 16:32:36 +00:00
|
|
|
});
|
2012-08-20 13:07:30 +00:00
|
|
|
// mail.ChatterUtils.records_struct_update_after_display(this.comments_structure);
|
2012-02-27 16:04:42 +00:00
|
|
|
// update offset for "More" buttons
|
2012-03-06 15:09:46 +00:00
|
|
|
if (this.params.thread_level == 0) this.params.offset += records.length;
|
2012-02-27 11:07:54 +00:00
|
|
|
},
|
2012-03-02 17:07:49 +00:00
|
|
|
|
2012-06-21 15:24:28 +00:00
|
|
|
/** Displays a record, performs text/link formatting */
|
2012-03-02 17:07:49 +00:00
|
|
|
display_comment: function (record) {
|
2012-07-11 15:47:37 +00:00
|
|
|
// if (record.type == 'email' && record.state == 'received') {
|
2012-06-21 21:55:27 +00:00
|
|
|
if (record.type == 'email') {
|
|
|
|
record.mini_url = ('/mail/static/src/img/email_icon.png');
|
2012-07-03 12:20:20 +00:00
|
|
|
} else {
|
2012-08-20 13:07:30 +00:00
|
|
|
record.mini_url = mail.ChatterUtils.get_image(this.session.prefix, this.session.session_id, 'res.partner', 'image_small', record.author_id[0]);
|
2012-06-21 21:55:27 +00:00
|
|
|
}
|
2012-08-19 16:28:32 +00:00
|
|
|
// record.body = mail.ChatterUtils.do_replace_expressions(record.body);
|
2012-04-19 08:58:38 +00:00
|
|
|
// format date according to the user timezone
|
|
|
|
record.date = session.web.format_value(record.date, {type:"datetime"});
|
2012-07-11 09:55:45 +00:00
|
|
|
// is the user the author ?
|
2012-08-20 13:07:30 +00:00
|
|
|
record.is_author = mail.ChatterUtils.is_author(this, record.author_id[0]);
|
2012-03-02 17:07:49 +00:00
|
|
|
// render
|
2012-07-03 12:20:20 +00:00
|
|
|
var rendered = session.web.qweb.render('mail.thread.message', {'record': record, 'thread': this, 'params': this.params, 'display': this.display});
|
2012-05-10 15:15:38 +00:00
|
|
|
// expand feature
|
2012-08-05 15:10:16 +00:00
|
|
|
$(rendered).appendTo(this.$element.children('div.oe_mail_thread_display:first'));
|
|
|
|
this.$element.find('div.oe_mail_msg_record_body').expander({
|
2012-07-02 11:10:35 +00:00
|
|
|
slicePoint: this.params.msg_more_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-04-05 10:29:17 +00:00
|
|
|
},
|
2012-07-03 12:20:20 +00:00
|
|
|
|
2012-02-27 11:07:54 +00:00
|
|
|
display_current_user: function () {
|
2012-07-30 08:16:00 +00:00
|
|
|
var avatar = mail.ChatterUtils.get_image(this.session.prefix, this.session.session_id, 'res.users', 'image_small', this.params.uid);
|
2012-07-11 13:24:57 +00:00
|
|
|
return this.$element.find('img.oe_mail_icon').attr('src', avatar);
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
do_comment: function () {
|
2012-03-12 17:33:23 +00:00
|
|
|
var comment_node = this.$element.find('textarea');
|
2012-08-17 12:06:06 +00:00
|
|
|
var body = comment_node.val();
|
2012-03-12 17:33:23 +00:00
|
|
|
comment_node.val('');
|
2012-08-17 12:06:06 +00:00
|
|
|
return this.ds.call('message_post', [[this.params.res_id], body], {parent_id: this.params.parent_id, mtype: 'comment'}).then(
|
2012-03-07 13:44:09 +00:00
|
|
|
this.proxy('init_comments'));
|
2012-02-23 16:32:36 +00:00
|
|
|
},
|
|
|
|
|
2012-03-06 15:09:46 +00:00
|
|
|
/**
|
|
|
|
* Create a domain to fetch new comments according to
|
2012-05-14 15:20:18 +00:00
|
|
|
* comment already present in comments_structure
|
2012-07-19 12:03:15 +00:00
|
|
|
* @param {Object} comments_structure (see chatter utils)
|
2012-03-06 15:09:46 +00:00
|
|
|
* @returns {Array} fetch_domain (OpenERP domain style)
|
|
|
|
*/
|
2012-05-14 15:20:18 +00:00
|
|
|
get_fetch_domain: function (comments_structure) {
|
2012-03-06 15:09:46 +00:00
|
|
|
var domain = [];
|
2012-05-14 15:20:18 +00:00
|
|
|
var ids = comments_structure.root_ids.slice();
|
2012-04-05 10:29:17 +00:00
|
|
|
var ids2 = [];
|
2012-03-22 16:32:24 +00:00
|
|
|
// must be child of current parent
|
|
|
|
if (this.params.parent_id) { domain.push(['id', 'child_of', this.params.parent_id]); }
|
2012-05-14 15:20:18 +00:00
|
|
|
_(comments_structure.root_ids).each(function (id) { // each record
|
2012-03-06 15:09:46 +00:00
|
|
|
ids.push(id);
|
2012-04-05 10:29:17 +00:00
|
|
|
ids2.push(id);
|
2012-03-06 15:09:46 +00:00
|
|
|
});
|
2012-04-05 10:29:17 +00:00
|
|
|
if (this.params.parent_id != false) {
|
|
|
|
ids2.push(this.params.parent_id);
|
|
|
|
}
|
|
|
|
// must not be children of already fetched messages
|
2012-03-06 15:09:46 +00:00
|
|
|
if (ids.length > 0) {
|
|
|
|
domain.push('&');
|
|
|
|
domain.push('!');
|
|
|
|
domain.push(['id', 'child_of', ids]);
|
|
|
|
}
|
2012-04-05 10:29:17 +00:00
|
|
|
if (ids2.length > 0) {
|
|
|
|
domain.push(['id', 'not in', ids2]);
|
2012-03-06 15:09:46 +00:00
|
|
|
}
|
|
|
|
return domain;
|
|
|
|
},
|
|
|
|
|
2012-02-27 11:07:54 +00:00
|
|
|
do_more: function () {
|
2012-05-14 15:20:18 +00:00
|
|
|
domain = this.get_fetch_domain(this.comments_structure);
|
2012-03-06 15:09:46 +00:00
|
|
|
return this.fetch_comments(this.params.limit, this.params.offset, domain);
|
2012-02-24 16:09:20 +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-06-19 12:12:11 +00:00
|
|
|
* This widget handles the display of the Chatter on documents.
|
2012-06-15 08:36:56 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-20 09:18:22 +00:00
|
|
|
/* Add mail_thread widget to registry */
|
|
|
|
session.web.form.widgets.add('mail_thread', 'openerp.mail.RecordThread');
|
2012-02-06 09:06:18 +00:00
|
|
|
|
2012-07-03 12:20:20 +00:00
|
|
|
/** mail_thread widget: thread of comments */
|
2012-04-16 10:29:54 +00:00
|
|
|
mail.RecordThread = session.web.form.AbstractField.extend({
|
2012-02-06 09:06:18 +00:00
|
|
|
// QWeb template to use when rendering the object
|
2012-06-15 08:36:56 +00:00
|
|
|
template: 'mail.record_thread',
|
2012-02-23 16:32:36 +00:00
|
|
|
|
2012-05-15 10:05:30 +00:00
|
|
|
init: function() {
|
2012-02-06 09:06:18 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-08-20 13:07:30 +00:00
|
|
|
this.params = this.options;
|
2012-05-15 10:05:30 +00:00
|
|
|
this.params.thread_level = this.params.thread_level || 0;
|
2012-06-19 13:14:03 +00:00
|
|
|
this.thread = null;
|
2012-02-02 14:18:43 +00:00
|
|
|
},
|
2012-07-26 12:15:50 +00:00
|
|
|
|
2012-02-06 11:26:23 +00:00
|
|
|
start: function() {
|
2012-07-26 12:15:50 +00:00
|
|
|
// NB: all the widget should be modified to check the actual_mode property on view, not use
|
|
|
|
// any other method to know if the view is in create mode anymore
|
|
|
|
this.view.on("change:actual_mode", this, this._check_visibility);
|
|
|
|
this._check_visibility();
|
2012-07-19 12:03:15 +00:00
|
|
|
mail.ChatterUtils.bind_events(this);
|
2012-02-06 15:10:09 +00:00
|
|
|
},
|
2012-07-26 12:15:50 +00:00
|
|
|
|
|
|
|
_check_visibility: function() {
|
|
|
|
this.$element.toggle(this.view.get("actual_mode") !== "create");
|
|
|
|
},
|
|
|
|
|
2012-03-21 15:31:41 +00:00
|
|
|
destroy: function () {
|
2012-02-16 16:03:02 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-02-02 14:18:43 +00:00
|
|
|
},
|
|
|
|
|
2012-03-21 15:31:41 +00:00
|
|
|
set_value: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-07-10 09:42:50 +00:00
|
|
|
if (! this.view.datarecord.id ||
|
2012-07-10 15:34:09 +00:00
|
|
|
session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) {
|
2012-07-10 09:42:50 +00:00
|
|
|
this.$element.find('.oe_mail_thread').hide();
|
|
|
|
return;
|
|
|
|
}
|
2012-08-20 13:07:30 +00:00
|
|
|
// debugger
|
2012-03-21 15:31:41 +00:00
|
|
|
// create and render Thread widget
|
2012-06-15 08:36:56 +00:00
|
|
|
this.$element.find('div.oe_mail_recthread_main').empty();
|
2012-03-21 15:31:41 +00:00
|
|
|
if (this.thread) this.thread.destroy();
|
|
|
|
this.thread = new mail.Thread(this, {'res_model': this.view.model, 'res_id': this.view.datarecord.id, 'uid': this.session.uid,
|
2012-06-19 13:14:03 +00:00
|
|
|
'thread_level': this.params.thread_level, 'show_post_comment': true, 'limit': 15});
|
2012-06-15 08:36:56 +00:00
|
|
|
var thread_done = this.thread.appendTo(this.$element.find('div.oe_mail_recthread_main'));
|
2012-08-10 13:05:42 +00:00
|
|
|
return thread_done;
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* WallView Widget
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* This widget handles the display of the Chatter on the Wall.
|
|
|
|
*/
|
|
|
|
|
2012-02-08 16:42:29 +00:00
|
|
|
/* Add WallView widget to registry */
|
2012-06-20 09:18:22 +00:00
|
|
|
session.web.client_actions.add('mail.wall', 'session.mail.Wall');
|
2012-07-03 12:20:20 +00:00
|
|
|
|
2012-02-08 16:42:29 +00:00
|
|
|
/* WallView widget: a wall of messages */
|
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
|
|
|
|
* @param {Object} [params]
|
|
|
|
* @param {Number} [params.limit=20] number of messages to show and fetch
|
2012-07-19 12:03:15 +00:00
|
|
|
* @var {Array} comments_structure (see chatter utils)
|
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
|
|
|
// console.log(options);
|
|
|
|
this.options = options || {};
|
|
|
|
this.options.domain = options.domain || [];
|
|
|
|
this.options.context = options.context || {};
|
|
|
|
this.options.context.res_model = options.res_model || 'mail.thread';
|
|
|
|
this.options.context.res_id = options.res_id || false;
|
|
|
|
this.options.thread_level = options.thread_level || 1;
|
2012-04-04 11:20:37 +00:00
|
|
|
this.thread_list = [];
|
2012-08-20 15:52:02 +00:00
|
|
|
this.ds_msg = new session.web.DataSet(this, 'mail.message');
|
|
|
|
// for search view
|
2012-04-05 11:34:19 +00:00
|
|
|
this.search = {'domain': [], 'context': {}, 'groupby': {}}
|
|
|
|
this.search_results = {'domain': [], 'context': {}, 'groupby': {}}
|
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-08-20 15:52:02 +00:00
|
|
|
this.bind_events();
|
2012-03-30 15:11:47 +00:00
|
|
|
// load mail.message search view
|
2012-08-19 17:53:09 +00:00
|
|
|
var search_view_ready = this.load_search_view({}, false);
|
2012-07-11 13:14:30 +00:00
|
|
|
// load composition form
|
|
|
|
var compose_done = this.instantiate_composition_form();
|
2012-03-30 15:11:47 +00:00
|
|
|
// fetch first threads
|
2012-08-20 15:52:02 +00:00
|
|
|
var messages_fetched = this.message_fetch();
|
|
|
|
return (search_view_ready && compose_done && messages_fetched);
|
2012-07-16 13:28:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function () {
|
2012-02-24 15:21:59 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-08-20 15:52:02 +00:00
|
|
|
if (this.thread_list) {
|
|
|
|
// #TODO: destroy threads
|
|
|
|
}
|
|
|
|
|
2012-02-08 17:08:08 +00:00
|
|
|
},
|
2012-07-11 13:14:30 +00:00
|
|
|
|
|
|
|
instantiate_composition_form: function(mode, msg_id) {
|
|
|
|
if (this.compose_message_widget) {
|
|
|
|
this.compose_message_widget.destroy();
|
|
|
|
}
|
|
|
|
this.compose_message_widget = new mail.ComposeMessage(this, {
|
2012-08-20 13:07:30 +00:00
|
|
|
'extended_mode': false, 'uid': this.session.uid, 'res_model': this.options.res_model,
|
|
|
|
'res_id': this.options.res_id, 'mode': mode || 'comment', 'msg_id': msg_id });
|
2012-07-11 13:14:30 +00:00
|
|
|
var composition_node = this.$element.find('div.oe_mail_wall_action');
|
|
|
|
composition_node.empty();
|
|
|
|
var compose_done = this.compose_message_widget.appendTo(composition_node);
|
|
|
|
return compose_done;
|
|
|
|
},
|
|
|
|
|
2012-08-20 15:52:02 +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) {
|
|
|
|
this.init_and_fetch_comments();
|
|
|
|
if (this.compose_message_widget) {
|
|
|
|
this.compose_message_widget.reinit(); }
|
|
|
|
return this._super(action, on_close);
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Bind events */
|
|
|
|
bind_events: function () {
|
2012-03-30 15:11:47 +00:00
|
|
|
var self = this;
|
2012-08-20 15:52:02 +00:00
|
|
|
// Click on 'show more'
|
|
|
|
this.$element.find('button.oe_mail_wall_button_more').click(function () {
|
|
|
|
return self.do_fetch_more();
|
|
|
|
});
|
2012-03-30 15:11:47 +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-08-19 17:53:09 +00:00
|
|
|
load_search_view: 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-08-20 15:52:02 +00:00
|
|
|
return this.searchview.appendTo(this.$element.find('.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
|
|
|
|
|
|
|
/**
|
|
|
|
* Aggregate the domains, contexts and groupbys in parameter
|
|
|
|
* with those from search form, and then calls fetch_comments
|
|
|
|
* to actually fetch comments
|
|
|
|
* @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-08-20 15:52:02 +00:00
|
|
|
self.message_clean();
|
|
|
|
return self.message_fetch();
|
2012-02-28 11:07:40 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-08-20 15:52:02 +00:00
|
|
|
/** Clean the wall */
|
|
|
|
message_clean: function() {
|
2012-06-21 12:48:43 +00:00
|
|
|
this.$element.find('ul.oe_mail_wall_threads').empty();
|
2012-02-24 15:21:59 +00:00
|
|
|
},
|
2012-02-28 08:56:07 +00:00
|
|
|
|
2012-08-20 15:52:02 +00:00
|
|
|
/** Fetch messages
|
2012-03-30 15:11:47 +00:00
|
|
|
* @param {Array} domain
|
|
|
|
* @param {Array} context
|
2012-02-28 08:56:07 +00:00
|
|
|
*/
|
2012-08-20 15:52:02 +00:00
|
|
|
message_fetch: function (additional_domain, additional_context) {
|
|
|
|
this.search['domain'] = _.union(this.options.domain, this.search_results.domain);
|
|
|
|
this.search['context'] = _.extend(this.options.context, this.search_results.context);
|
2012-04-05 11:34:19 +00:00
|
|
|
if (additional_domain) var fetch_domain = this.search['domain'].concat(additional_domain);
|
|
|
|
else var fetch_domain = this.search['domain'];
|
|
|
|
if (additional_context) var fetch_context = _.extend(this.search['context'], additional_context);
|
|
|
|
else var fetch_context = this.search['context'];
|
2012-08-20 15:52:02 +00:00
|
|
|
return this.ds_msg.call('message_read',
|
|
|
|
[false, fetch_domain, this.options.thread_level, fetch_context]
|
|
|
|
).then(this.proxy('display_comments'));
|
2012-02-08 17:08:08 +00:00
|
|
|
},
|
2012-02-28 08:51:11 +00:00
|
|
|
|
2012-08-20 15:52:02 +00:00
|
|
|
/** Display comments
|
|
|
|
* @param {Array} records tree structure of records
|
2012-02-28 08:51:11 +00:00
|
|
|
*/
|
2012-02-21 15:39:42 +00:00
|
|
|
display_comments: function (records) {
|
2012-08-20 13:07:30 +00:00
|
|
|
console.log(records);
|
|
|
|
// debugger
|
2012-02-08 17:08:08 +00:00
|
|
|
var self = this;
|
2012-08-20 15:52:02 +00:00
|
|
|
var _expendable = false;
|
2012-08-20 13:07:30 +00:00
|
|
|
_(records).each(function (root_record) {
|
2012-08-20 15:52:02 +00:00
|
|
|
/* expandable type: add a 'Show more button' */
|
|
|
|
if (root_record.type == 'expandable') {
|
|
|
|
_expendable = true;
|
|
|
|
self.update_fetch_more(true);
|
|
|
|
self.fetch_more_domain = root_record.domain;
|
|
|
|
self.fetch_more_context = root_record.context;
|
|
|
|
}
|
|
|
|
// display classic root record
|
|
|
|
else {
|
|
|
|
var render_res = session.web.qweb.render('mail.wall_thread_container', {});
|
|
|
|
$('<li class="oe_mail_wall_thread">').html(render_res).appendTo(self.$element.find('ul.oe_mail_wall_threads'));
|
|
|
|
var thread = new mail.Thread(self, {
|
|
|
|
'res_model': root_record.model, 'res_id': root_record.res_id,
|
|
|
|
'uid': self.session.uid, 'records': [root_record],
|
|
|
|
'parent_id': false, 'thread_level': self.options.thread_level,
|
|
|
|
'show_hide': true, 'is_wall': true
|
|
|
|
}
|
2012-04-04 11:20:37 +00:00
|
|
|
);
|
2012-08-20 15:52:02 +00:00
|
|
|
self.thread_list.push(thread);
|
|
|
|
thread.appendTo(self.$element.find('li.oe_mail_wall_thread:last'));
|
|
|
|
}
|
2012-02-08 17:08:08 +00:00
|
|
|
});
|
2012-08-20 15:52:02 +00:00
|
|
|
if (! _expendable) {
|
|
|
|
self.update_fetch_more(false);
|
|
|
|
}
|
2012-02-28 08:51:11 +00:00
|
|
|
},
|
2012-03-05 19:20:52 +00:00
|
|
|
|
2012-08-20 15:52:02 +00:00
|
|
|
/** Display 'show more' button */
|
|
|
|
update_fetch_more: function (new_value) {
|
2012-08-19 17:53:09 +00:00
|
|
|
if (new_value) {
|
|
|
|
this.$element.find('div.oe_mail_wall_more:last').show();
|
|
|
|
} else {
|
|
|
|
this.$element.find('div.oe_mail_wall_more:last').hide();
|
|
|
|
}
|
2012-03-30 15:11:47 +00:00
|
|
|
},
|
|
|
|
|
2012-08-20 15:52:02 +00:00
|
|
|
/** Action: 'shows more' to fetch new messages */
|
|
|
|
do_fetch_more: function () {
|
|
|
|
return this.message_fetch(this.fetch_more_domain, this.fetch_more_context);
|
2012-02-28 11:07:40 +00:00
|
|
|
},
|
2012-02-08 16:42:29 +00:00
|
|
|
});
|
2012-02-01 16:22:13 +00:00
|
|
|
};
|