[REF] mail_thread: refactoring of Chatter. Followers are now managed by another widget (mail.followers). Code removed from mail.js to mail_followers.js, same for xml. Mail_group is the test-object to receive tne new widget, specified in form view.
bzr revid: tde@openerp.com-20120810130542-0dern12lk4e7yfc9
This commit is contained in:
parent
f7c452baf5
commit
e7a654eba3
|
@ -102,9 +102,11 @@ The main features of the module are:
|
||||||
'js': [
|
'js': [
|
||||||
'static/lib/jquery.expander/jquery.expander.js',
|
'static/lib/jquery.expander/jquery.expander.js',
|
||||||
'static/src/js/mail.js',
|
'static/src/js/mail.js',
|
||||||
|
'static/src/js/mail_followers.js',
|
||||||
],
|
],
|
||||||
'qweb': [
|
'qweb': [
|
||||||
'static/src/xml/mail.xml',
|
'static/src/xml/mail.xml',
|
||||||
|
'static/src/xml/mail_followers.xml',
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -78,11 +78,12 @@
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<field name="message_subscriber_ids"/>
|
|
||||||
</sheet>
|
</sheet>
|
||||||
<div class="oe_chatter oe_mail_group_footer">
|
<div class="oe_chatter">
|
||||||
<field name="message_ids" widget="mail_thread"
|
<field name="message_ids" widget="mail_thread"
|
||||||
options='{"thread_level": 1}'/>
|
options='{"thread_level": 1}'/>
|
||||||
|
<field name="message_subscriber_ids" widget="mail_followers"
|
||||||
|
context="{'lapin': 'nouille'}"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
|
|
|
@ -89,10 +89,14 @@
|
||||||
/* RecordThread
|
/* RecordThread
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
||||||
.openerp div.oe_mail_recthread {
|
.openerp .oe_form div.oe_chatter {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.openerp div.oe_mail_recthread {
|
||||||
|
/*overflow: auto;*/
|
||||||
|
}
|
||||||
|
|
||||||
.openerp div.oe_mail_recthread_main {
|
.openerp div.oe_mail_recthread_main {
|
||||||
float: left;
|
float: left;
|
||||||
width: 560px;
|
width: 560px;
|
||||||
|
|
|
@ -4,6 +4,8 @@ openerp.mail = function(session) {
|
||||||
|
|
||||||
var mail = session.mail = {};
|
var mail = session.mail = {};
|
||||||
|
|
||||||
|
openerp_mail_followers(session, mail); // import mail_followers.js
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ------------------------------------------------------------
|
* ------------------------------------------------------------
|
||||||
* FormView
|
* FormView
|
||||||
|
@ -838,32 +840,17 @@ openerp.mail = function(session) {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this.params = this.get_definition_options();
|
this.params = this.get_definition_options();
|
||||||
this.params.thread_level = this.params.thread_level || 0;
|
this.params.thread_level = this.params.thread_level || 0;
|
||||||
this.params.see_subscribers = true;
|
|
||||||
this.params.see_subscribers_options = this.params.see_subscribers_options || false;
|
|
||||||
this.thread = null;
|
this.thread = null;
|
||||||
this.ds = new session.web.DataSet(this, this.view.model);
|
this.ds = new session.web.DataSet(this, this.view.model);
|
||||||
this.ds_users = new session.web.DataSet(this, 'res.users');
|
this.ds_users = new session.web.DataSet(this, 'res.users');
|
||||||
},
|
},
|
||||||
|
|
||||||
start: function() {
|
start: function() {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
// NB: all the widget should be modified to check the actual_mode property on view, not use
|
// 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
|
// any other method to know if the view is in create mode anymore
|
||||||
this.view.on("change:actual_mode", this, this._check_visibility);
|
this.view.on("change:actual_mode", this, this._check_visibility);
|
||||||
this._check_visibility();
|
this._check_visibility();
|
||||||
|
|
||||||
mail.ChatterUtils.bind_events(this);
|
mail.ChatterUtils.bind_events(this);
|
||||||
this.$element.find('button.oe_mail_button_followers').click(function () { self.do_toggle_followers(); });
|
|
||||||
if (! this.params.see_subscribers_options) {
|
|
||||||
this.$element.find('button.oe_mail_button_followers').hide(); }
|
|
||||||
this.$element.find('button.oe_mail_button_follow').click(function () { self.do_follow(); })
|
|
||||||
.mouseover(function () { $(this).html('Follow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
|
|
||||||
.mouseleave(function () { $(this).html('Not following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
|
|
||||||
this.$element.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); })
|
|
||||||
.mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
|
|
||||||
.mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
|
|
||||||
this.reinit();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_check_visibility: function() {
|
_check_visibility: function() {
|
||||||
|
@ -874,72 +861,20 @@ openerp.mail = function(session) {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
reinit: function() {
|
|
||||||
this.params.see_subscribers = true;
|
|
||||||
this.params.see_subscribers_options = this.params.see_subscribers_options || false;
|
|
||||||
this.$element.find('button.oe_mail_button_followers').html('Hide followers')
|
|
||||||
this.$element.find('button.oe_mail_button_follow').hide();
|
|
||||||
this.$element.find('button.oe_mail_button_unfollow').hide();
|
|
||||||
},
|
|
||||||
|
|
||||||
set_value: function() {
|
set_value: function() {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
var self = this;
|
|
||||||
this.reinit();
|
|
||||||
if (! this.view.datarecord.id ||
|
if (! this.view.datarecord.id ||
|
||||||
session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) {
|
session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) {
|
||||||
this.$element.find('.oe_mail_thread').hide();
|
this.$element.find('.oe_mail_thread').hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// fetch followers
|
|
||||||
var fetch_sub_done = this.fetch_subscribers();
|
|
||||||
// create and render Thread widget
|
// create and render Thread widget
|
||||||
this.$element.find('div.oe_mail_recthread_main').empty();
|
this.$element.find('div.oe_mail_recthread_main').empty();
|
||||||
if (this.thread) this.thread.destroy();
|
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,
|
this.thread = new mail.Thread(this, {'res_model': this.view.model, 'res_id': this.view.datarecord.id, 'uid': this.session.uid,
|
||||||
'thread_level': this.params.thread_level, 'show_post_comment': true, 'limit': 15});
|
'thread_level': this.params.thread_level, 'show_post_comment': true, 'limit': 15});
|
||||||
var thread_done = this.thread.appendTo(this.$element.find('div.oe_mail_recthread_main'));
|
var thread_done = this.thread.appendTo(this.$element.find('div.oe_mail_recthread_main'));
|
||||||
return fetch_sub_done && thread_done;
|
return thread_done;
|
||||||
},
|
|
||||||
|
|
||||||
fetch_subscribers: function () {
|
|
||||||
return this.ds.call('message_read_subscribers', [[this.view.datarecord.id]]).then(this.proxy('display_subscribers'));
|
|
||||||
},
|
|
||||||
|
|
||||||
display_subscribers: function (records) {
|
|
||||||
var self = this;
|
|
||||||
this.is_subscriber = false;
|
|
||||||
var user_list = this.$element.find('ul.oe_mail_followers_display').empty();
|
|
||||||
this.$element.find('div.oe_mail_recthread_followers h4').html('Followers (' + records.length + ')');
|
|
||||||
_(records).each(function (record) {
|
|
||||||
if (record.id == self.session.uid) { self.is_subscriber = true; }
|
|
||||||
record.avatar_url = mail.ChatterUtils.get_image(self.session.prefix, self.session.session_id, 'res.users', 'image_small', record.id);
|
|
||||||
$(session.web.qweb.render('mail.record_thread.subscriber', {'record': record})).appendTo(user_list);
|
|
||||||
});
|
|
||||||
if (self.is_subscriber) {
|
|
||||||
self.$element.find('button.oe_mail_button_follow').hide();
|
|
||||||
self.$element.find('button.oe_mail_button_unfollow').show(); }
|
|
||||||
else {
|
|
||||||
self.$element.find('button.oe_mail_button_follow').show();
|
|
||||||
self.$element.find('button.oe_mail_button_unfollow').hide(); }
|
|
||||||
},
|
|
||||||
|
|
||||||
do_follow: function () {
|
|
||||||
return this.ds.call('message_subscribe', [[this.view.datarecord.id]]).pipe(this.proxy('fetch_subscribers'));
|
|
||||||
},
|
|
||||||
|
|
||||||
do_unfollow: function () {
|
|
||||||
var self = this;
|
|
||||||
return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).then(function (record) {
|
|
||||||
if (record == false) self.do_notify("Impossible to unsubscribe", "You are automatically subscribed to this record. You cannot unsubscribe.");
|
|
||||||
}).pipe(this.proxy('fetch_subscribers'));
|
|
||||||
},
|
|
||||||
|
|
||||||
do_toggle_followers: function () {
|
|
||||||
this.params.see_subscribers = ! this.params.see_subscribers;
|
|
||||||
if (this.params.see_subscribers) { this.$element.find('button.oe_mail_button_followers').html('Hide followers'); }
|
|
||||||
else { this.$element.find('button.oe_mail_button_followers').html('Show followers'); }
|
|
||||||
this.$element.find('div.oe_mail_recthread_followers').toggle();
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
openerp_mail_followers = function(session, mail) {
|
||||||
|
var _t = session.web._t,
|
||||||
|
_lt = session.web._lt;
|
||||||
|
|
||||||
|
var mail_followers = session.mail_followers = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ------------------------------------------------------------
|
||||||
|
* mail_thread Widget
|
||||||
|
* ------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This widget handles the display of the Chatter on documents.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Add mail_thread widget to registry */
|
||||||
|
session.web.form.widgets.add('mail_followers', 'openerp.mail_followers.Followers');
|
||||||
|
|
||||||
|
/** mail_thread widget: thread of comments */
|
||||||
|
mail_followers.Followers = session.web.form.AbstractField.extend({
|
||||||
|
// QWeb template to use when rendering the object
|
||||||
|
template: 'mail.followers',
|
||||||
|
|
||||||
|
init: function() {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
this.params = this.get_definition_options();
|
||||||
|
this.params.see_subscribers = true;
|
||||||
|
this.params.see_subscribers_options = this.params.see_subscribers_options || false;
|
||||||
|
this.ds = new session.web.DataSetSearch(this, this.view.model);
|
||||||
|
this.ds_users = new session.web.DataSetSearch(this, 'res.users');
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
start: function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// session.mail.ChatterUtils.bind_events(this);
|
||||||
|
this.$element.find('button.oe_mail_button_followers').click(function () { self.do_toggle_followers(); });
|
||||||
|
if (! this.params.see_subscribers_options) {
|
||||||
|
this.$element.find('button.oe_mail_button_followers').hide(); }
|
||||||
|
this.$element.find('button.oe_mail_button_follow').click(function () { self.do_follow(); })
|
||||||
|
.mouseover(function () { $(this).html('Follow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
|
||||||
|
.mouseleave(function () { $(this).html('Not following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
|
||||||
|
this.$element.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); })
|
||||||
|
.mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
|
||||||
|
.mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
|
||||||
|
this.reinit();
|
||||||
|
},
|
||||||
|
|
||||||
|
_check_visibility: function() {
|
||||||
|
this.$element.toggle(this.view.get("actual_mode") !== "create");
|
||||||
|
},
|
||||||
|
|
||||||
|
destroy: function () {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
reinit: function() {
|
||||||
|
this.params.see_subscribers = true;
|
||||||
|
this.params.see_subscribers_options = this.params.see_subscribers_options || false;
|
||||||
|
this.$element.find('button.oe_mail_button_followers').html('Hide followers')
|
||||||
|
this.$element.find('button.oe_mail_button_follow').hide();
|
||||||
|
this.$element.find('button.oe_mail_button_unfollow').hide();
|
||||||
|
},
|
||||||
|
|
||||||
|
set_value: function(value_) {
|
||||||
|
console.log(value_);
|
||||||
|
// debugger
|
||||||
|
this.reinit();
|
||||||
|
if (! this.view.datarecord.id ||
|
||||||
|
session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) {
|
||||||
|
this.$element.find('div.oe_mail_recthread_aside').hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return this.fetch_subscribers(value_);
|
||||||
|
},
|
||||||
|
|
||||||
|
fetch_subscribers: function (value_) {
|
||||||
|
return this.ds_users.call('read', [value_ || this.get_value(), ['name', 'image_small']]).then(this.proxy('display_subscribers'));
|
||||||
|
},
|
||||||
|
|
||||||
|
display_subscribers: function (records) {
|
||||||
|
var self = this;
|
||||||
|
this.is_subscriber = false;
|
||||||
|
var user_list = this.$element.find('ul.oe_mail_followers_display').empty();
|
||||||
|
this.$element.find('div.oe_mail_recthread_followers h4').html('Followers (' + records.length + ')');
|
||||||
|
_(records).each(function (record) {
|
||||||
|
if (record.id == self.session.uid) { self.is_subscriber = true; }
|
||||||
|
record.avatar_url = mail.ChatterUtils.get_image(self.session.prefix, self.session.session_id, 'res.users', 'image_small', record.id);
|
||||||
|
$(session.web.qweb.render('mail.followers.partner', {'record': record})).appendTo(user_list);
|
||||||
|
});
|
||||||
|
if (this.is_subscriber) {
|
||||||
|
this.$element.find('button.oe_mail_button_follow').hide();
|
||||||
|
this.$element.find('button.oe_mail_button_unfollow').show(); }
|
||||||
|
else {
|
||||||
|
this.$element.find('button.oe_mail_button_follow').show();
|
||||||
|
this.$element.find('button.oe_mail_button_unfollow').hide(); }
|
||||||
|
},
|
||||||
|
|
||||||
|
do_follow: function () {
|
||||||
|
return this.ds.call('message_subscribe', [[this.view.datarecord.id]]).pipe(this.proxy('fetch_subscribers'));
|
||||||
|
},
|
||||||
|
|
||||||
|
do_unfollow: function () {
|
||||||
|
var self = this;
|
||||||
|
return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).pipe(function (record) {
|
||||||
|
// debugger
|
||||||
|
var new_value = self.view.datarecord.message_subscriber_ids;
|
||||||
|
// return [new_value.splice(_.indexOf(new_value, self.session.uid, true), 1);]
|
||||||
|
return [2]
|
||||||
|
}).pipe(this.proxy('set_value'));
|
||||||
|
},
|
||||||
|
|
||||||
|
do_toggle_followers: function () {
|
||||||
|
this.params.see_subscribers = ! this.params.see_subscribers;
|
||||||
|
if (this.params.see_subscribers) { this.$element.find('button.oe_mail_button_followers').html('Hide followers'); }
|
||||||
|
else { this.$element.find('button.oe_mail_button_followers').html('Show followers'); }
|
||||||
|
this.$element.find('div.oe_mail_recthread_followers').toggle();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
|
@ -58,28 +58,8 @@
|
||||||
<div class="oe_mail_recthread_main">
|
<div class="oe_mail_recthread_main">
|
||||||
<!-- contains the document thread -->
|
<!-- contains the document thread -->
|
||||||
</div>
|
</div>
|
||||||
<div class="oe_mail_recthread_aside">
|
|
||||||
<div class="oe_mail_recthread_actions">
|
|
||||||
<button type="button" class="oe_mail_button_follow oe_mail_button_mouseout">Not following</button>
|
|
||||||
<button type="button" class="oe_mail_button_unfollow oe_mail_button_mouseout">Following</button>
|
|
||||||
<button type="button" class="oe_mail_button_followers">Show followers</button>
|
|
||||||
</div>
|
|
||||||
<div class="oe_mail_recthread_followers">
|
|
||||||
<h4>Followers</h4>
|
|
||||||
<ul class="oe_mail_followers_display"></ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--
|
|
||||||
record_thread.subscriber template
|
|
||||||
Template used to display a subscriber.
|
|
||||||
-->
|
|
||||||
<li t-name="mail.record_thread.subscriber">
|
|
||||||
<img class="oe_mail_thumbnail oe_mail_frame" t-attf-src="{record.avatar_url}"/>
|
|
||||||
<a t-attf-href="#model=res.users&id=#{record.id}"><t t-raw="record.name"/></a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
mail.compose_message template
|
mail.compose_message template
|
||||||
This template holds the composition form to write a note or send
|
This template holds the composition form to write a note or send
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<template>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
followers main template
|
||||||
|
Template used to display the followers and the actions in a record.
|
||||||
|
-->
|
||||||
|
<div t-name="mail.followers" class="oe_mail_recthread_aside">
|
||||||
|
<div class="oe_mail_recthread_actions">
|
||||||
|
<button type="button" class="oe_mail_button_follow oe_mail_button_mouseout">Not following</button>
|
||||||
|
<button type="button" class="oe_mail_button_unfollow oe_mail_button_mouseout">Following</button>
|
||||||
|
<button type="button" class="oe_mail_button_followers">Show followers</button>
|
||||||
|
</div>
|
||||||
|
<div class="oe_mail_recthread_followers">
|
||||||
|
<h4>Followers</h4>
|
||||||
|
<ul class="oe_mail_followers_display"></ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
followers.partner template
|
||||||
|
Template used to display a partner following the record
|
||||||
|
-->
|
||||||
|
<li t-name="mail.followers.partner">
|
||||||
|
<img class="oe_mail_thumbnail oe_mail_frame" t-attf-src="{record.avatar_url}"/>
|
||||||
|
<a t-attf-href="#model=res.users&id=#{record.id}"><t t-raw="record.name"/></a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</template>
|
Loading…
Reference in New Issue