[ADD] Added delete / hide for OpenSocial, on widget and in API. TODO: when deleting a comment, delete its childs.

bzr revid: tde@openerp.com-20120321172018-6pq33317302ttg9b
This commit is contained in:
Thibault Delavallée
2012-03-21 18:20:18 +01:00
parent 9da33f326e
commit 4ea3a7a131
3 changed files with 56 additions and 22 deletions
+16
View File
@@ -690,4 +690,20 @@ class mail_thread(osv.osv):
subscription_obj.unlink(cr, uid, to_delete_sub_ids, context=context)
return True
#------------------------------------------------------
# Notification API
#------------------------------------------------------
def message_remove_pushed_notif(self, cr, uid, ids, msg_ids, remove_childs=True, context=None):
if context is None:
context = {}
notif_obj = self.pool.get('mail.notification')
msg_obj = self.pool.get('mail.message')
if remove_childs:
notif_msg_ids = msg_obj.search(cr, uid, [('id', 'child_of', msg_ids)], context=context)
else:
notif_msg_ids = msg_ids
to_del_notif_ids = notif_obj.search(cr, uid, ['&', ('user_id', '=', uid), ('message_id', 'in', notif_msg_ids)], context=context)
return notif_obj.unlink(cr, uid, to_del_notif_ids, context=context)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+32 -18
View File
@@ -9,9 +9,8 @@ openerp.mail = function(session) {
'Thread', 'openerp.mail.Thread');
/**
* ThreadDisplay widget: this widget handles the display of a thread of messages.
* Two displays are managed through the [thread_level] parameter that sets
* the level number in the thread:
* ThreadDisplay widget: this widget handles the display of a thread of
* messages. The [thread_level] parameter sets the thread level number:
* - root message
* - - sub message (parent_id = root message)
* - - - sub sub message (parent id = sub message)
@@ -47,26 +46,26 @@ openerp.mail = function(session) {
this.params.limit = this.params.limit || 2;
this.params.offset = this.params.offset || 0;
this.params.records = this.params.records || null;
/* DataSets and internal vars */
// datasets and internal vars
this.ds = new session.web.DataSet(this, this.params.res_model);
this.ds_users = new session.web.DataSet(this, 'res.users');
this.ds_msg = new session.web.DataSet(this, 'mail.message');
this.name = 'Unknown record'
this.sorted_comments = {'root_ids': [], 'root_id_msg_list': {}};
/* Display vars */
// display customization vars
this.display = {};
this.display.show_post_comment = this.params.show_post_comment || false;
this.display.show_reply = (this.params.thread_level > 0);
this.display.show_delete = true;
this.display.show_hide = true;
this.display.show_hide = this.params.show_hide || false;
this.display.show_more = (this.params.thread_level == 0);
// not used currently
this.intlinks_mapping = {};
},
start: function() {
var self = this;
this._super.apply(this, arguments);
var self = this;
// customize display
this.$element.find('p.oe_mail_p_nomore').hide();
if (! this.display.show_post_comment) this.$element.find('div.oe_mail_thread_act').hide();
@@ -86,7 +85,7 @@ openerp.mail = function(session) {
add_events: function() {
var self = this;
// event: click on 'more'
// event: click on 'more' at bottom of thread
this.$element.find('button.oe_mail_button_more').click(function () {
self.do_more();
});
@@ -96,24 +95,34 @@ openerp.mail = function(session) {
if (event.shiftKey && charCode == 13) { this.value = this.value+"\n"; }
else if (charCode == 13) { self.do_comment(); }
});
// event: click on 'reply'
// event: click on 'reply' in msg
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_reply', 'click', function (event) {
var act_dom = $(this).parents('div.oe_mail_thread_display').find('div.oe_mail_thread_act:first');
act_dom.toggle();
});
// event: click on 'delete'
// event: click on 'delete' in msg
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_delete', 'click', function (event) {
console.log('deleting');
//console.log('deleting');
var msg_id = event.srcElement.dataset.id;
if (! msg_id) return false;
self.ds_msg.unlink([parseInt(msg_id)]).then();
var call_defer = self.ds_msg.unlink([parseInt(msg_id)]);
$(event.srcElement).parents('li.oe_mail_thread_msg').eq(0).hide();
if (self.params.thread_level > 0) {
$(event.srcElement).parents('ul.oe_mail_thread').eq(0).hide();
}
return false;
});
// event: click on 'hide'
// event: click on 'hide' in msg
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_hide', 'click', function (event) {
console.log('hiding');
//console.log('hiding');
var msg_id = event.srcElement.dataset.id;
if (! msg_id) return false;
//console.log(msg_id);
var call_defer = self.ds.call('message_remove_pushed_notif', [[self.params.res_id], [parseInt(msg_id)], true]);
$(event.srcElement).parents('li.oe_mail_thread_msg').eq(0).hide();
if (self.params.thread_level > 0) {
$(event.srcElement).parents('ul.oe_mail_thread').eq(0).hide();
}
return false;
});
// event: click on an internal link
@@ -211,8 +220,8 @@ openerp.mail = function(session) {
record.body_text = this.do_replace_internal_links(record.body_text);
if (record.tr_body_text) record.tr_body_text = this.do_replace_internal_links(record.tr_body_text);
// render
$(session.web.qweb.render('ThreadMsg', {'record': record, 'res_model': this.params.res_model, 'res_id': this.params.res_id, 'name': this.name,
'display': this.display})).appendTo(this.$element.children('div.oe_mail_thread_display:first'));
$(session.web.qweb.render('ThreadMsg', {'record': record, 'thread': this, 'params': this.params, 'display': this.display})
).appendTo(this.$element.children('div.oe_mail_thread_display:first'));
// truncated: hide full-text, show summary, add buttons
if (record.tr_body_text) {
var node_body = this.$element.find('span.oe_mail_msg_body:last').append(' <a href="#" class="reduce">[ ... Show less]</a>');
@@ -376,6 +385,11 @@ openerp.mail = function(session) {
regex_res = regex_intlink.exec(string);
}
},
/** checks if tue current user is the message author */
_is_author: function (id) {
return (this.session.uid == id);
},
});
@@ -504,7 +518,7 @@ openerp.mail = function(session) {
init: function (parent, params) {
this._super(parent);
this.params = params || {};
this.params.limit = params.limit || 2;
this.params.limit = params.limit || 50;
this.params.search_view_id = params.search_view_id || false;
this.params.thread_level = params.thread_level || 1;
this.params.search = {};
@@ -622,7 +636,7 @@ openerp.mail = function(session) {
$('<div class="oe_mail_wall_thread">').html(render_res).appendTo(self.$element.find('div.oe_mail_wall_threads'));
var thread = new mail.Thread(self, {
'res_model': model_name, 'res_id': records[0]['res_id'], 'uid': self.session.uid, 'records': records,
'parent_id': false, 'thread_level': self.params.thread_level}
'parent_id': false, 'thread_level': self.params.thread_level, 'show_hide': true}
);
var thread_displayed = thread.appendTo(self.$element.find('div.oe_mail_wall_thread:last'));
});
+8 -4
View File
@@ -65,7 +65,7 @@
<t t-name="NoteDisplay">
<p class="oe_mail_msg">
<a href="#" class="intlink oe_mail_oe_intlink" t-attf-data-res-model='{res_model}' t-attf-data-res-id='{res_id}'><t t-raw="name"/></a>
<a href="#" class="intlink oe_mail_oe_intlink" t-attf-data-res-model='{params.res_model}' t-attf-data-res-id='{params.res_id}'><t t-raw="thread.name"/></a>
<span class="oe_mail_msg_body"><t t-raw="record.body_text"/></span>
<t t-if="record.tr_body_text"><span class="oe_mail_msg_body_short"><t t-raw="record.tr_body_text"/></span></t>
<br />
@@ -73,9 +73,13 @@
<a href="#" class="intlink oe_mail_oe_intlink" data-res-model='res.users' t-attf-data-res-id='{record.user_id[0]}'><t t-raw="record.user_id[1]"/></a>
on <t t-raw="record.date"/>
</span>
<t t-if="display.show_reply"><span class="oe_mail_oe_space"><a href="#" class="oe_mail_msg_reply">Reply</a></span></t>
<t t-if="display.show_delete"><span class="oe_mail_oe_space"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_delete">Delete</a></span></t>
<t t-if="display.show_hide"><span class="oe_mail_oe_space"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_hide">Hide</a></span></t>
<t t-if="display['show_reply']"><span class="oe_mail_oe_space"><a href="#" class="oe_mail_msg_reply oe_mail_oe_intlink">Reply</a></span></t>
<t t-if="display['show_delete']">
<t t-if="thread._is_author(record.user_id[0])"><span class="oe_mail_oe_space"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_delete oe_mail_oe_intlink">Delete</a></span></t>
</t>
<t t-if="display['show_hide']">
<t t-if="!(thread._is_author(record.user_id[0]))"><span class="oe_mail_oe_space"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_hide oe_mail_oe_intlink">Hide</a></span></t>
</t>
</p>
</t>