From 1bc3f0cec4353e558ef47cf29bcc7b974d4194b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 22 Feb 2012 15:04:03 +0100 Subject: [PATCH] [IMP] Wall: pushed message are now displayed in conversation, with a 1-level hierarchy based on source record. Wall and Thread: added support for user image. bzr revid: tde@openerp.com-20120222140403-fbjisr0u96jml5zv --- addons/mail/static/src/css/mail.css | 19 +++++---- addons/mail/static/src/js/mail.js | 61 +++++++++++++++++++++++------ addons/mail/static/src/xml/mail.xml | 45 +++++++++++++++------ 3 files changed, 92 insertions(+), 33 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index be5e8425630..9f4d8440205 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -50,24 +50,23 @@ .oe_mail_msg { } -/*.oe_mail_msg:after { - content: ""; - display: block; - clear: both; -}*/ - .oe_mail_comment { white-space: normal; margin-bottom: 5px; } +.oe_mail_comment:after { + content: ""; + display: block; + clear: both; +} + .oe_mail_msg_image { float: left; width: 14%; } .oe_mail_msg_image img { - width: 80%; margin-left: 10%; } @@ -105,3 +104,9 @@ .oe_mail_followers_vignette img { width: 80%; } + +/* Wall CSS */ +.oe_mail_thread_content div.oe_mail_comment { + margin-left: 5%; +} + diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index bd3021e9f1f..daf15e41d35 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -70,6 +70,7 @@ openerp.mail = function(session) { this.$element.find('div.oe_mail_msg').empty(); var self = this; _(records).each(function (record) { + record.mini_url = self.thread_get_mini('res.users', 'avatar_mini', record.user_id[0]); var template = 'ThreadMsgView'; var render_res = session.web.qweb.render(template, { 'record': record, @@ -77,14 +78,14 @@ openerp.mail = function(session) { $('
').html(render_res).appendTo(self.$element.find('div.oe_mail_msg')); }); }, - + display_followers: function (records) { this.$element.find('div.oe_mail_followers').empty(); var self = this; _(records).each(function (record) { -//
- //$('
').text(record.user_id[1]).appendTo(self.$element.find('div.oe_mail_followers')); - $('
').text(record.name).appendTo(self.$element.find('div.oe_mail_followers')); + $('
').html( + '' + record.name + '' + ).appendTo(self.$element.find('div.oe_mail_followers')); }); }, @@ -113,6 +114,12 @@ openerp.mail = function(session) { do_toggle_followers: function () { this.$element.find('div.oe_mail_followers').toggle(); }, + + thread_get_mini: function(model, field, id) { + id = id || ''; + var url = this.session.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + id; + return url; + }, }); /* Add WallView widget to registry */ @@ -128,6 +135,7 @@ openerp.mail = function(session) { this.filter_search = params['filter_search']; /* DataSets */ this.ds_msg = new session.web.DataSet(this, 'mail.message'); + this.ds_users = new session.web.DataSet(this, 'res.users'); }, start: function() { @@ -149,22 +157,49 @@ openerp.mail = function(session) { display_comments: function (records) { this.$element.find('div.oe_mail_msg').empty(); + sorted_records = this.sort_comments(records); var self = this; - _(records).each(function (record) { - console.log(record); - var template = 'ThreadMsgView'; - var render_res = session.web.qweb.render(template, { - 'record': record, + _(sorted_records).each(function (rec_models, model) { // each model + _(rec_models).each(function (record_id, id) { // each record + var template = 'WallThreadView'; + var render_res = session.web.qweb.render(template, { + 'record_model': model, + 'record_id': id, }); - $('
').html(render_res).appendTo(self.$element.find('div.oe_mail_msg')); + $('
').html(render_res).appendTo(self.$element.find('div.oe_mail_msg')); + _(record_id).each(function (record) { // each record + record.mini_url = self.thread_get_mini('res.users', 'avatar_mini', record.user_id[0]); + var template = 'ThreadMsgView'; + var render_res = session.web.qweb.render(template, { + 'record': record, + }); + $('
').html(render_res).appendTo(self.$element.find('div.oe_mail_thread_content:last')); + }); + }); }); }, + sort_comments: function (records) { + sorted_comments = {}; + _(records).each(function (record) { + if (! (record.model in sorted_comments)) { sorted_comments[record.model] = {}; } + if (! (record.res_id in sorted_comments[record.model])) { + sorted_comments[record.model][record.res_id] = []; } + sorted_comments[record.model][record.res_id].push(record); + }); + return sorted_comments; + }, + do_comment: function () { var body_text = this.$element.find('textarea').val(); - return this.ds_msg.call('create', [ - {'subject': 'Status tweet', 'model': 'res.users', 'body_text': body_text, 'type': 'comment', 'res_id': this.session.uid, 'user_id': this.session.uid} - ]).then(this.proxy('fetch_comments')); + return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, type='comment']).then( + this.proxy('fetch_comments')); + }, + + thread_get_mini: function(model, field, id) { + id = id || ''; + var url = this.session.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + id; + return url; }, }); }; diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index ff69ef4c29f..755357b7da3 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -25,9 +25,39 @@
- + +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ + +
+ Discussion about document (id: ) +
+
+
+
+ -
Image
+
+ +

@@ -46,16 +76,5 @@

- -
-
-
- -
-
-
-
-
-