summaryrefslogtreecommitdiff
path: root/addons/mail/static/src
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2012-03-21 18:20:18 +0100
committerThibault Delavallée <tde@openerp.com>2012-03-21 18:20:18 +0100
commit4ea3a7a13183f8ff87bfd0eccfe275722fe632ea (patch)
tree78898fa342c381f3787b1a83ecf1dc95839f79b3 /addons/mail/static/src
parent9da33f326ece04b6744370fd51a157a7c32d7689 (diff)
[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
Diffstat (limited to 'addons/mail/static/src')
-rw-r--r--addons/mail/static/src/js/mail.js50
-rw-r--r--addons/mail/static/src/xml/mail.xml12
2 files changed, 40 insertions, 22 deletions
diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js
index 4ca9ba314e8..5dc1007326d 100644
--- a/addons/mail/static/src/js/mail.js
+++ b/addons/mail/static/src/js/mail.js
@@ -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'));
});
diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml
index 70d3f1ef6f6..2faf2d1950e 100644
--- a/addons/mail/static/src/xml/mail.xml
+++ b/addons/mail/static/src/xml/mail.xml
@@ -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>