2012-02-01 16:22:13 +00:00
|
|
|
openerp.mail = function(session) {
|
2012-02-02 14:18:43 +00:00
|
|
|
|
|
|
|
var mail = session.mail = {};
|
|
|
|
|
2012-02-06 09:06:18 +00:00
|
|
|
session.web.form.widgets.add(
|
|
|
|
'ThreadView', 'openerp.mail.ThreadView');
|
2012-02-08 15:25:21 +00:00
|
|
|
session.web.page.readonly.add(
|
|
|
|
'ThreadView', 'openerp.mail.ThreadView');
|
2012-02-06 09:06:18 +00:00
|
|
|
|
|
|
|
/* ThreadView Widget: thread of comments */
|
|
|
|
mail.ThreadView = session.web.form.Field.extend({
|
|
|
|
// QWeb template to use when rendering the object
|
2012-02-06 15:10:09 +00:00
|
|
|
template: 'ThreadView',
|
2012-02-06 09:06:18 +00:00
|
|
|
|
|
|
|
init: function() {
|
2012-02-08 15:25:21 +00:00
|
|
|
// this.timeout;
|
2012-02-06 15:10:09 +00:00
|
|
|
this.follow_state = 0;
|
2012-02-06 09:06:18 +00:00
|
|
|
this._super.apply(this, arguments);
|
2012-02-06 17:19:11 +00:00
|
|
|
/* DataSets */
|
2012-02-06 09:06:18 +00:00
|
|
|
this.ds = new session.web.DataSet(this, this.view.model);
|
2012-02-06 12:46:31 +00:00
|
|
|
this.ds_sub = new session.web.DataSet(this, 'mail.subscription');
|
2012-02-08 15:25:21 +00:00
|
|
|
// this.ds_msg = new session.web.DataSet(this, 'mail.message');
|
2012-02-02 14:18:43 +00:00
|
|
|
},
|
2012-02-06 11:26:23 +00:00
|
|
|
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super.apply(this, arguments);
|
2012-02-06 15:10:09 +00:00
|
|
|
/* bind follow and unfollow buttons */
|
2012-02-06 11:26:23 +00:00
|
|
|
self.$element.find('button.oe_mail_action_follow').bind('click', function () { self.do_follow(); });
|
2012-02-06 15:10:09 +00:00
|
|
|
self.$element.find('button.oe_mail_action_follow').hide();
|
2012-02-06 11:26:23 +00:00
|
|
|
self.$element.find('button.oe_mail_action_unfollow').bind('click', function () { self.do_unfollow(); });
|
2012-02-06 15:10:09 +00:00
|
|
|
self.$element.find('button.oe_mail_action_unfollow').hide();
|
2012-02-06 17:19:11 +00:00
|
|
|
self.$element.find('button.oe_mail_action_comment').bind('click', function () { self.do_comment(); });
|
2012-02-06 15:10:09 +00:00
|
|
|
/* find wich (un)follow buttons to show */
|
|
|
|
var call_res = this.ds.call('message_is_subscriber', [[this.session.uid]]).then(function (records) {
|
2012-02-08 15:25:21 +00:00
|
|
|
if (records == true) { self.follow_state = 1; self.$element.find('button.oe_mail_action_unfollow').show(); }
|
|
|
|
else { self.follow_state = 0; self.$element.find('button.oe_mail_action_follow').show(); }
|
2012-02-06 15:10:09 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-02-06 09:06:18 +00:00
|
|
|
stop: function () {
|
2012-02-06 11:26:23 +00:00
|
|
|
// clearTimeout(this.timeout);
|
2012-02-06 09:06:18 +00:00
|
|
|
this._super();
|
2012-02-02 14:18:43 +00:00
|
|
|
},
|
|
|
|
|
2012-02-06 09:06:18 +00:00
|
|
|
set_value: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
if (! this.view.datarecord.id) { return; }
|
2012-02-08 15:25:21 +00:00
|
|
|
return this.fetch_messages();
|
2012-02-06 09:06:18 +00:00
|
|
|
},
|
2012-02-02 14:18:43 +00:00
|
|
|
|
2012-02-06 09:06:18 +00:00
|
|
|
fetch_messages: function () {
|
|
|
|
return this.ds.call('message_load', [[this.view.datarecord.id]]).then(
|
|
|
|
this.proxy('display_records'));
|
2012-02-02 14:18:43 +00:00
|
|
|
},
|
2012-02-06 09:06:18 +00:00
|
|
|
|
|
|
|
display_records: function (records) {
|
2012-02-08 15:25:21 +00:00
|
|
|
this.$element.find('div.oe_mail_comments').empty();
|
2012-02-06 09:06:18 +00:00
|
|
|
var self = this;
|
|
|
|
_(records).each(function (record) {
|
2012-02-06 17:19:11 +00:00
|
|
|
var template = 'ThreadMsgView';
|
|
|
|
var render_res = session.web.qweb.render(template, {
|
|
|
|
'record': record,
|
|
|
|
});
|
2012-02-08 15:25:21 +00:00
|
|
|
$('<div class="oe_mail_msg">').html(render_res).appendTo(self.$element.find('div.oe_mail_comments'));
|
2012-02-06 09:06:18 +00:00
|
|
|
});
|
2012-02-06 11:26:23 +00:00
|
|
|
// this.timeout = setTimeout(this.proxy('fetch_messages'), 5000);
|
|
|
|
},
|
|
|
|
|
|
|
|
do_follow: function () {
|
2012-02-06 15:10:09 +00:00
|
|
|
this.$element.find('button.oe_mail_action_unfollow').show();
|
|
|
|
this.$element.find('button.oe_mail_action_follow').hide();
|
2012-02-08 15:25:21 +00:00
|
|
|
return this.ds_sub.create({'res_model': this.view.model, 'user_id': this.session.uid, 'res_id': this.view.datarecord.id}).then();
|
2012-02-06 11:26:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
do_unfollow: function () {
|
2012-02-06 15:10:09 +00:00
|
|
|
this.$element.find('button.oe_mail_action_follow').show();
|
|
|
|
this.$element.find('button.oe_mail_action_unfollow').hide();
|
2012-02-08 15:25:21 +00:00
|
|
|
return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).then();
|
2012-02-06 17:19:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
do_comment: function () {
|
|
|
|
var body_text = this.$element.find('textarea').val();
|
2012-02-08 15:25:21 +00:00
|
|
|
return this.ds.call('message_append_note', [[this.view.datarecord.id], 'Reply comment', body_text, type='comment']).then(
|
|
|
|
this.proxy('fetch_messages'));
|
2012-02-06 17:19:11 +00:00
|
|
|
},
|
2012-02-02 14:18:43 +00:00
|
|
|
});
|
|
|
|
|
2012-02-01 16:22:13 +00:00
|
|
|
};
|
2012-02-02 14:18:43 +00:00
|
|
|
|
2012-02-01 16:22:13 +00:00
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|