[IMP] chatter, follower: html/js for css imp

bzr revid: chm@openerp.com-20121010181611-rl167r9h0ejz8zdu
This commit is contained in:
Christophe Matthieu 2012-10-10 20:16:11 +02:00
parent 20d8b0fc76
commit 49a174df57
7 changed files with 52 additions and 122 deletions

View File

@ -292,7 +292,6 @@ class mail_message(osv.Model):
well formed threads.
:param domain: optional domain for searching ids
:param level: level of threads to display, 0 being flat
:param limit: number of messages to fetch
:param parent_id: if parent_id reached, stop searching for
further parents

View File

@ -403,8 +403,7 @@ openerp.mail = function(session) {
* Thread Message Expandable Widget
* ------------------------------------------------------------
*
* This widget handles the display the expandable message in a thread. The
* [thread_level] parameter sets the thread level number:
* This widget handles the display the expandable message in a thread.
* - thread
* - - visible message
* - - expandable
@ -468,7 +467,7 @@ openerp.mail = function(session) {
* - record.timerelative: relative time givein by timeago lib
* - record.avatar: image url
* - record.attachment_ids[].url: url of each attachmentThe
* [thread_level] parameter sets the thread level number:
* thread view :
* - root thread
* - - sub message (parent_id = root message)
* - - - sub thread
@ -769,11 +768,13 @@ openerp.mail = function(session) {
* ------------------------------------------------------------
*
* This widget handles the display of a thread of messages. The
* [thread_level] parameter sets the thread level number:
* - root message
* thread view:
* - root thread
* - - sub message (parent_id = root message)
* - - - sub sub message (parent id = sub message)
* - - - sub thread
* - - - - sub sub message (parent id = sub thread)
* - - sub message (parent_id = root message)
* - - - sub thread
*/
mail.Thread = session.web.Widget.extend({
template: 'mail.thread',
@ -787,7 +788,6 @@ openerp.mail = function(session) {
* @param {Object} [options]
* @param {Object} [message] read about mail.ThreadMessage object
* @param {Object} [thread]
* @param {Number} [thread_level=0] number of thread levels
* @param {Boolean} [use_composer] use the advanced composer, or
* the default basic textarea if not set
* @param {Number} [expandable_number=5] number message show
@ -810,7 +810,7 @@ openerp.mail = function(session) {
// options
this.options={
'thread' : {
'thread_level': options.options.thread.thread_level || 0,
'thread_level': (options.options.thread.thread_level+1) || 0,
'show_header_compose': (options.options.thread.show_header_compose != undefined ? options.options.thread.show_header_compose: false),
'use_composer': options.options.thread.use_composer || false,
'expandable_number': options.options.thread.expandable_number || 5,
@ -890,7 +890,7 @@ openerp.mail = function(session) {
if(this.options.thread.show_header_compose){
this.ComposeMessage.$el.show();
this.ComposeMessage.set_free_attachments();
//this.ComposeMessage.set_free_attachments();
}
var button_fetch = $('<button style="display:none;" class="oe_mail_wall_button_fetch"/>').click(function(event){
@ -1014,7 +1014,7 @@ openerp.mail = function(session) {
fetch_context = replace_context ? replace_context : this.context;
fetch_context.message_loaded= [this.id||0].concat( self.options.thread._parents[0].get_child_ids() );
return this.ds_message.call('message_read', [ids, fetch_domain, (this.options.thread.thread_level+1), fetch_context, this.context.default_parent_id || undefined]
return this.ds_message.call('message_read', [ids, fetch_domain, fetch_context, 0, this.context.default_parent_id || undefined]
).then(this.proxy('switch_new_message'));
},
@ -1066,8 +1066,8 @@ openerp.mail = function(session) {
});
}
var thread_messages = (self.options.thread.display_on_flat ? self.options.thread._parents[0].messages : []).concat(self.messages);
var thread = (self.options.thread.display_on_flat ? self.options.thread._parents[0] : self);
var thread_messages = (self.options.thread.display_on_flat && self.options.thread.thread_level ? self.options.thread._parents[0].messages : []).concat(self.messages);
var thread = (self.options.thread.display_on_flat && self.options.thread.thread_level ? self.options.thread._parents[0] : self);
// check older and newer message for insert
var parent_newer = false;
@ -1082,14 +1082,28 @@ openerp.mail = function(session) {
}
}
var sort = self.options.thread.thread_level==0 || (self.options.thread.display_on_flat && self.options.thread.thread_level<=1);
if(parent_older){
message.insertBefore(parent_older.$el);
if(sort){
message.insertBefore(parent_older.$el);
} else {
message.insertAfter(parent_older.$el);
}
}
else if(parent_newer){
message.insertAfter(parent_newer.$el);
if(sort){
message.insertAfter(parent_newer.$el);
} else {
message.insertBefore(parent_newer.$el);
}
}
else {
message.prependTo(thread.list_ul);
if(sort){
message.prependTo(thread.list_ul);
} else {
message.appendTo(thread.list_ul);
}
}
return message
},
@ -1129,7 +1143,6 @@ openerp.mail = function(session) {
this._super.apply(this, arguments);
this.options.domain = this.options.domain || [];
this.options.context = {'default_model': 'mail.thread', 'default_res_id': false};
this.options.thread_level = this.options.thread_level || 0;
},
start: function() {
@ -1172,7 +1185,6 @@ openerp.mail = function(session) {
'context': this.options.context,
'options':{
'thread':{
'thread_level': this.options.thread_level,
'show_header_compose': show_header_compose,
'use_composer': show_header_compose,
'display_on_flat':true
@ -1216,7 +1228,6 @@ openerp.mail = function(session) {
this.options = options || {};
this.options.domain = options.domain || [];
this.options.context = options.context || {};
this.options.thread_level = options.thread_level || 1;
this.search_results = {'domain': [], 'context': {}, 'groupby': {}}
this.ds_msg = new session.web.DataSetSearch(this, 'mail.message');
},
@ -1274,12 +1285,11 @@ openerp.mail = function(session) {
'context' : _.extend(this.options.context, search&&search.search_results['context'] ? search.search_results['context'] : {}),
'options': {
'thread' :{
'thread_level': this.options.thread_level,
'use_composer': true,
'show_header_compose': true,
'show_header_compose': false,
},
'message': {
'show_reply': this.options.thread_level > 0,
'show_reply': true,
'show_dd_hide': true,
'show_dd_delete': true,
},

View File

@ -40,6 +40,7 @@ openerp_mail_followers = function(session, mail) {
this._check_visibility();
this.reinit();
this.bind_events();
this.display_subtypes();
},
_check_visibility: function() {
@ -53,31 +54,15 @@ openerp_mail_followers = function(session, mail) {
bind_events: function() {
var self = this;
this.$('div.oe_mouse_subtypes')
.on('mouseover', function () {
$(this).removeClass('oe_mouseout').addClass('oe_mouseover');
self.display_subtypes();
})
.on('mouseleave', function () {
$(this).removeClass('oe_mouseover').addClass('oe_mouseout');
self.display_subtypes();
});
this.$('button.oe_follower')
.on('click', function () {
if($(this).hasClass('oe_notfollow'))
self.do_follow();
else
self.do_unfollow();
})
.on('mouseover', function () {
$(this).removeClass('oe_mouseout').addClass('oe_mouseover');
})
.on('mouseleave', function () {
$(this).removeClass('oe_mouseover').addClass('oe_mouseout');
});
this.$el.on('click', 'ul.oe_subtypes input', function () { self.do_update_subscription(); })
this.$el.on('click', 'ul.oe_subtypes input', self.do_update_subscription );
this.$el.on('click', 'button.oe_invite', function(event) {
action = {
@ -173,7 +158,8 @@ openerp_mail_followers = function(session, mail) {
set_subtypes:function(data){
var self = this;
var records = data[this.view.datarecord.id].message_subtype_data;
var records = (data[this.view.datarecord.id] || data[null]).message_subtype_data;
_(records).each(function (record, record_name) {
record.name = record_name;
record.followed = record.followed || undefined;
@ -194,16 +180,10 @@ openerp_mail_followers = function(session, mail) {
},
do_follow: function () {
var self =this;
_(this.$('.oe_msg_subtype_check')).each(function(record){
$(record).attr('checked','checked');
});
var context = new session.web.CompoundContext(this.build_context(), {});
return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, context]).pipe(function(value_){
self.read_value(value_);
if(!self.$('.oe_recthread_subtypes').is(":visible"))
self.display_subtypes(true);
});
this.do_update_subscription();
},
do_unfollow: function () {
@ -214,20 +194,25 @@ openerp_mail_followers = function(session, mail) {
return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], [this.session.uid], context]).pipe(this.proxy('read_value'));
},
do_update_subscription: function () {
var context = new session.web.CompoundContext(this.build_context(), {});
do_update_subscription: function (event) {
var self = this;
var checklist = new Array();
_(this.$('.oe_msg_subtype_check')).each(function(record){
_(this.$('.oe_mail_recthread_actions input[type="checkbox"]')).each(function(record){
if($(record).is(':checked')) {
checklist.push(parseInt($(record).data('id')))}
});
if(!checklist.length)
return this.do_unfollow();
else
return this.ds_model.call('message_subscribe_users',[[self.view.datarecord.id], undefined, checklist, context]).pipe(this.proxy('read_value'));
else{
var context = new session.web.CompoundContext(this.build_context(), {});
return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, context]).pipe(function(value_){
self.read_value(value_);
self.display_subtypes(true);
});
}
},
});

View File

@ -138,7 +138,7 @@
Compose a new message
</button>
<button type="button" class="oe_write_onwall" help="Your followers can read this message">
Write on your wall
Write to your followers
</button>
</td>
</tr>
@ -233,7 +233,7 @@
</ul>
<div class="oe_clear"/>
<div class="oe_mail_msg_body">
<t t-if="widget.options.message.show_record_name and widget.record_name and (!widget.subject) and widget.options.thread._parents.length&lt;=widget.options.thread.thread_level and widget.model!='res.partner'">
<t t-if="widget.options.message.show_record_name and widget.record_name and (!widget.subject) and !widget.options.thread.thread_level and !widget.options.thread.display_on_flat and widget.model!='res.partner'">
<a class="oe_mail_action_model" t-attf-href="#model=#{widget.model}&amp;id=#{widget.res_id}"><t t-raw="widget.record_name"/></a>
</t>
<t t-raw="widget.body"/>

View File

@ -13,9 +13,9 @@
<span class="oe_unfollow">Unfollow</span>
<span class="oe_following">Following</span>
</button>
<div class="oe_recthread_subtypes">
<ul class="oe_subtypes"></ul>
</div>
</div>
<div class="oe_recthread_subtypes">
<ul class="oe_subtypes"></ul>
</div>
</div>
<div class="oe_grey">

View File

@ -529,67 +529,6 @@ class test_mail(TestMailMockups):
self.assertEqual(message2.subject, _subject, 'mail.message subject incorrect')
self.assertEqual(message2.body, group_bird.description, 'mail.message body incorrect')
# FP Note: to be reviewed to be more generic, not depending on the algorythm of
# message_read
#def test_30_message_read(self):
# """ Tests designed for message_read. """
# # TDE NOTE: this test is not finished, as the message_read method is not fully specified.
# # It will be updated as soon as we have fixed specs !
# cr, uid = self.cr, self.uid
# group_pigs = self.mail_group.browse(cr, uid, self.group_pigs_id)
# def _compare_structures(struct1, struct2, n=0):
# # print '%scompare structure' % ('\t' * n)
# # self.assertEqual(len(struct1), len(struct2), 'message_read structure number of childs incorrect')
# for x in range(len(struct1)):
# if struct1[x].get('type') == 'expandable':
# continue
# # print '%s' % ('\t' * n), struct1[x]['id'], struct1[x]['child_nbr'], struct2[x]['id'], struct2[x].get('child_nbr', 'XX'), struct1[x].get('subject') or ''
# self.assertEqual(struct1[x]['id'], struct2[x]['id'], 'message_read failure %s' % struct1[x].get('subject'))
# _compare_structures(struct1[x]['child_ids'], struct2[x]['child_ids'], n + 1)
# # print '%send compare' % ('\t' * n)
# # ----------------------------------------
# # CASE2: message_read test
# # ----------------------------------------
# # 1. Add a few messages to pigs group
# msgid1 = group_pigs.message_post(body='1', subject='1', parent_id=False)
# msgid2 = group_pigs.message_post(body='2', subject='1-1', parent_id=msgid1)
# msgid3 = group_pigs.message_post(body='3', subject='1-2', parent_id=msgid1)
# msgid4 = group_pigs.message_post(body='4', subject='2', parent_id=False)
# msgid5 = group_pigs.message_post(body='5', subject='1-1-1', parent_id=msgid2)
# msgid6 = group_pigs.message_post(body='6', subject='2-1', parent_id=msgid4)
# # Test: read all messages flat
# tree_test = [{'id': msgid6, 'child_ids': []}, {'id': msgid5, 'child_ids': []},
# {'id': msgid4, 'child_ids': []}, {'id': msgid3, 'child_ids': []},
# {'id': msgid2, 'child_ids': []}, {'id': msgid1, 'child_ids': []}]
# tree = self.mail_message.message_read(cr, uid, ids=False, domain=[('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)], level=0, limit=15)
# _compare_structures(tree, tree_test)
# # Test: read with 1 level of thread
# tree_test = [{'id': msgid4, 'child_ids': [{'id': msgid6, 'child_ids': []}, ]},
# {'id': msgid1, 'child_ids': [
# {'id': msgid5, 'child_ids': []}, {'id': msgid3, 'child_ids': []},
# {'id': msgid2, 'child_ids': []},
# ]},
# ]
# tree = self.mail_message.message_read(cr, uid, ids=False, domain=[('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)], level=1, limit=15)
# _compare_structures(tree, tree_test)
# # Test: read with 2 levels of thread
# tree_test = [{'id': msgid4, 'child_ids': [{'id': msgid6, 'child_ids': []}, ]},
# {'id': msgid1, 'child_ids': [
# {'id': msgid3, 'child_ids': []},
# {'id': msgid2, 'child_ids': [{'id': msgid5, 'child_ids': []}, ]},
# ]},
# ]
# tree = self.mail_message.message_read(cr, uid, ids=False, domain=[('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)], level=2, limit=15)
# _compare_structures(tree, tree_test)
# # 2. Test expandables
# # TDE FIXME: add those tests when expandables are specified and implemented
def test_40_needaction(self):
""" Tests for mail.message needaction. """
cr, uid = self.cr, self.uid

View File

@ -20,10 +20,7 @@
</group>
<notebook>
<page string="Body">
<field name="body_text" nolabel="1"
attrs="{'invisible':[('content_subtype', '=', 'html')]}"/>
<field name="body" nolabel="1"
attrs="{'invisible':[('content_subtype', '=', 'plain')]}"/>
<field name="body" nolabel="1"/>
</page>
<page string="Attachments">
<field name="attachment_ids" colspan="4" nolabel="1"/>