From 5b2b9fb1abe76a0f1b0bb2c0231bca26e5ee218a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 2 Mar 2012 18:07:49 +0100 Subject: [PATCH 01/17] [ADD] Added a thread model in display. Seems working but needs refactoring in the next few days. bzr revid: tde@openerp.com-20120302170749-gaxx90sxy7bi97b3 --- addons/mail/mail_message.py | 1 + addons/mail/mail_message_view.xml | 6 +- addons/mail/mail_thread.py | 45 +++- addons/mail/static/src/css/mail.css | 57 ++--- addons/mail/static/src/js/mail.js | 318 +++++++++++++++++++++------- addons/mail/static/src/xml/mail.xml | 51 ++--- 6 files changed, 326 insertions(+), 152 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index b22b0c792a8..9197c363c1a 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -184,6 +184,7 @@ class mail_message(osv.osv): ('comment', 'Comment'), ('notification', 'System notification'), ], 'Type', help="Message type: e-mail for e-mail message, notification for system message, comment for other messages such as user replies"), + 'parent_id': fields.many2one('mail.message', 'Parent message', help="Parent message if message belongs to a thread"), 'need_action_user_id': fields.many2one('res.users', 'Action by user', help="User requested to perform an action"), } diff --git a/addons/mail/mail_message_view.xml b/addons/mail/mail_message_view.xml index 759a60cdb89..6b131477e46 100644 --- a/addons/mail/mail_message_view.xml +++ b/addons/mail/mail_message_view.xml @@ -13,7 +13,7 @@ - + @@ -30,13 +30,14 @@ - + + @@ -51,6 +52,7 @@ + diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 85c297fb07f..3abe801a1d4 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -97,7 +97,6 @@ class mail_thread(osv.osv): notification_obj = self.pool.get('mail.notification') # notifications do not come from any user, but from system - if vals.get('type') == 'notification': vals['user_id'] = False if not 'need_action_user_id' in vals: vals['need_action_user_id'] = False if not 'model' in vals: vals['model'] = False if not 'res_id' in vals: vals['res_id'] = 0 @@ -118,8 +117,19 @@ class mail_thread(osv.osv): # push to need_action_user_id if user does not follow the object if vals['need_action_user_id'] and not need_action_pushed: notification_obj.create(cr, uid, {'user_id': vals['need_action_user_id'], 'message_id': msg_id}, context=context) + + # parse message to get requested users + user_ids = self.message_parse_users(cr, uid, [msg_id], 'body_text', context=context) + for user_id in user_ids: + notification_obj.create(cr, uid, {'user_id': user_id, 'message_id': msg_id}, context=context) + return msg_id - + + def message_parse_users(self, cr, uid, ids, field_name='body_text', context=None): + '''Parse message content; if find @login: returns the related id''' + user_ids = [] + return user_ids + def message_capable_models(self, cr, uid, context=None): ret_dict = {} for model_name in self.pool.obj_list(): @@ -128,7 +138,7 @@ class mail_thread(osv.osv): ret_dict[model_name] = model._description return ret_dict - def message_append(self, cr, uid, threads, subject, body_text=None, + def message_append(self, cr, uid, threads, subject, parent_id=False, body_text=None, type='email', need_action_user_id=False, email_to=False, email_from=False, email_cc=None, email_bcc=None, reply_to=None, email_date=None, message_id=False, references=None, @@ -270,6 +280,7 @@ class mail_thread(osv.osv): if not 'type' in msg_dict: msg_dict['type'] = 'email' return self.message_append(cr, uid, ids, subject = msg_dict.get('subject'), + parent_id = msg_dict.get('parent_id', False), body_text = msg_dict.get('body_text'), type = msg_dict.get('type'), need_action_user_id = msg_dict.get('need_action_user_id'), @@ -290,23 +301,23 @@ class mail_thread(osv.osv): context = context) # Message loading - def message_load_ids(self, cr, uid, ids, limit=100, offset=0, context=None): + def message_load_ids(self, cr, uid, ids, limit=100, offset=0, domain=[], context=None): """ OpenSocial feature: return thread messages ids (for web compatibility) loading messages: search in mail.messages where res_id = ids, (res_)model = current model """ msg_obj = self.pool.get('mail.message') - msg_ids = msg_obj.search(cr, uid, ['&', ('res_id', 'in', ids), ('model', '=', self._name)], + msg_ids = msg_obj.search(cr, uid, ['&', ('res_id', 'in', ids), ('model', '=', self._name)] + domain, limit=limit, offset=offset, context=context) return msg_ids - def message_load(self, cr, uid, ids, limit=100, offset=0, context=None): + def message_load(self, cr, uid, ids, limit=100, offset=0, domain=[], context=None): """ OpenSocial feature: return thread messages loading messages: search in mail.messages where res_id = ids, (res_)model = current model """ - msg_ids = self.message_load_ids(cr, uid, ids, limit=limit, offset=offset, context=context) + msg_ids = self.message_load_ids(cr, uid, ids, limit=limit, offset=offset, domain=domain, context=context) return self.pool.get('mail.message').read(cr, uid, msg_ids, context=context) - def get_pushed_messages(self, cr, uid, ids, limit=100, offset=0, domain = None, context=None): + def get_pushed_messages(self, cr, uid, ids, limit=100, offset=0, domain=[], context=None): """OpenSocial: wall: get messages to display (=pushed notifications) :param filter_search: TODO :return: list of mail.messages, unsorted @@ -318,9 +329,21 @@ class mail_thread(osv.osv): notifications = notification_obj.browse(cr, uid, notification_ids, context=context) msg_ids = [notification.message_id.id for notification in notifications] # search messages: ids in notifications, add domain coming from wall search view - search_domain = [('id', 'in', msg_ids)] if domain == None else [('id', 'in', msg_ids)] + domain + search_domain = [('id', 'in', msg_ids)] + domain msg_ids = message_obj.search(cr, uid, search_domain, limit=limit, offset=offset, context=context) msgs = message_obj.read(cr, uid, msg_ids, context=context) + # fetch parent message to always have a correctly formated thread + msgs_tmp = msgs[:] + cur_iter = 0; max_iter = 10; modif = True + while (modif and cur_iter <= max_iter): + cur_iter += 1; modif = False + msg_ids_tmp = [] + new_msg_ids = [msg['parent_id'][0] for msg in msgs_tmp if msg['parent_id'] != False and msg['parent_id'][0] not in msg_ids] + msg_ids += new_msg_ids + msgs_tmp = message_obj.read(cr, uid, new_msg_ids, context=context) + msgs += msgs_tmp + # sort by id + msgs.sort(lambda a, b: b['id'].__cmp__(a['id'])) return msgs #------------------------------------------------------ @@ -570,8 +593,8 @@ class mail_thread(osv.osv): # Note specific #------------------------------------------------------ - def message_append_note(self, cr, uid, ids, subject, body, type='notification', need_action_user_id=False, context=None): - return self.message_append(cr, uid, ids, subject, body_text=body, type=type, need_action_user_id=need_action_user_id, context=context) + def message_append_note(self, cr, uid, ids, subject, body, parent_id=False, type='notification', need_action_user_id=False, context=None): + return self.message_append(cr, uid, ids, subject, body_text=body, parent_id=False, type=type, need_action_user_id=need_action_user_id, context=context) # old log overrided method: now calls message_append_note def log(self, cr, uid, id, message, secondary=False, context=None): diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 6b9b1e5c1c6..4f0eea033ea 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -1,4 +1,6 @@ -/* Wall */ +/* ------------------------------ */ +/* Wall */ +/* ------------------------------ */ .oe_mail_wall { overflow: auto; @@ -6,6 +8,10 @@ color: #4C4C4C; } +.oe_mail_wall_search { + width: 55%; +} + /* 2 columns view */ .oe_mail_wall_left { float: left; @@ -27,9 +33,11 @@ padding: 2px; } -/* Thread */ +/* ------------------------------ */ +/* RecordThread */ +/* ------------------------------ */ -.oe_mail_thread_main { +.oe_mail_recthread { overflow: auto; padding: 5px 5px 5px 5px; } @@ -46,15 +54,15 @@ .oe_mail_followers_action, .oe_mail_followers_display { } -/* Thread: 2 columns view */ -.oe_mail_thread_left { +/* RecordThread: 2 columns view */ +.oe_mail_recthread_left { float: left; - width: 65%; + width: 55%; } -.oe_mail_thread_right { +.oe_mail_recthread_right { float: right; - width: 34%; + width: 35%; } .oe_mail_button_follow, .oe_mail_button_unfollow, .oe_mail_button_followers { @@ -71,32 +79,30 @@ width: 80%; } -.oe_mail_thread_more, .oe_mail_thread_nomore { - margin-left: 20%; - margin-right: 40%; - border: 1px solid #D2D9E7; - background: #E0E0E0; - text-align: center; -} - -/* ThreadDisplay */ +/* ------------------------------ */ +/* ThreadDisplay */ +/* ------------------------------ */ .oe_mail_thread { } -.oe_mail_thread_act { -} - -.oe_mail_thread_display { -} - -.oe_mail_thread_msg, .oe_mail_thread_act { - width: 80%; +.oe_mail_thread_display, .oe_mail_thread_act { white-space: normal; margin-bottom: 5px; border-bottom: 1px solid #D2D9E7; } +.oe_mail_thread_subthread { + padding-left: 25%; +} + +.oe_mail_thread_more { + margin-left: 20%; + margin-right: 40%; + border: 1px solid #D2D9E7; + text-align: center; +} + .notification { background: #E0E0E0; } @@ -116,7 +122,6 @@ } .oe_mail_action_textarea { - width: 80%; height: 50px; padding: 5px; } diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index b8a82ff0192..2e270bd82a0 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -4,13 +4,29 @@ openerp.mail = function(session) { /* Add ThreadDisplay widget to registry */ session.web.form.widgets.add( - 'ThreadDisplay', 'openerp.mail.ThreadDisplay'); + 'Thread', 'openerp.mail.Thread'); session.web.page.readonly.add( - 'ThreadDisplay', 'openerp.mail.ThreadDisplay'); + 'Thread', 'openerp.mail.Thread'); - /* ThreadDisplay widget: display a thread of comments */ - mail.ThreadDisplay = session.web.Widget.extend({ - template: 'ThreadDisplay', + /** + * 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: + * 1/ 1-level thread: thread_level = 1 + * - root message + * - - sub message (parent_id = root message) + * - - sub message (parent_id = root message) + * 2/ flat thread: thread_level = 0 + * - root message + * - sub message (parent_id = root message) + * - sub message (parent_id = root message) + * This widget has 2 ways of initialization: + * 1/ give records + * 2/ do not give records: will fetch [limit] messages from + * the database, related to record [res_model]:[res_id]. + */ + mail.Thread = session.web.Widget.extend({ + template: 'Thread', /** * @@ -18,22 +34,31 @@ openerp.mail = function(session) { * @params {Object} [params] * @param {String} [params.res_model] res_model of mail.thread object * @param {Number} [params.res_id] res_id of record + * @param {Number} [params.parent_id=false] parent_id of message * @param {Number} [params.uid] user id - * @param {Number} [params.char_show_more=100] number of character to display before adding a "show more" + * @param {Number} [params.thread_level=0] number of levels in the thread (only 0 or 1 currently) + * @param {Number} [params.msg_more_limit=100] number of character to display before having a "show more" link; + * note that the text will not be truncated if it does not have 110% of + * the parameter (ex: 110 characters needed to be truncated and be displayed + * as a 100-characters message) * @param {Number} [params.limit=10] maximum number of messages to fetch - * @param {Number} [params.offset=0] offset for fetchign messages + * @param {Number} [params.offset=0] offset for fetching messages * @param {Number} [params.records=null] records to show instead of fetching messages */ init: function(parent, params) { this._super(parent); this.params = params; - this.params.limit = this.params.limit || 10; + this.params.parent_id = this.params.parent_id || false; + this.params.thread_level = this.params.thread_level || 0; + this.params.msg_more_limit = this.params.msg_more_limit || 100; + this.params.limit = this.params.limit || 2; this.params.offset = this.params.offset || 0; this.params.records = this.params.records || null; - this.params.char_show_more = this.params.char_show_more || 100; + /* DataSets and internal vars */ + this.parent_stack = []; + this.cur_thread_level = 0; this.map_hash = {}; - this.params.show_more = true; - /* define DataSets */ + this.params.thread_show_more = true; this.ds = new session.web.DataSet(this, this.params.res_model); this.ds_users = new session.web.DataSet(this, 'res.users'); }, @@ -42,27 +67,27 @@ openerp.mail = function(session) { var self = this; this._super.apply(this, arguments); /* events */ + this.$element.find('p.oe_mail_p_nomore').hide(); this.$element.find('button.oe_mail_button_comment').bind('click', function () { self.do_comment(); }); this.$element.find('button.oe_mail_button_more').bind('click', function () { self.do_more(); }); this.$element.find('div.oe_mail_thread_display').delegate('a.intlink', 'click', function (event) { // lazy implementation: fetch data and try to redirect if (! event.srcElement.dataset.resModel) return false; else var res_model = event.srcElement.dataset.resModel; - if (! event.srcElement.dataset.resLogin) return false; - else var res_login = event.srcElement.dataset.resLogin; - var ds = new session.web.DataSet(self, res_model); - var defer = ds.call('search', [[['login', '=', res_login]]]).then(function (records) { - if (records[0]) { - self.do_action({ - type: 'ir.actions.act_window', - res_model: res_model, - res_id: parseInt(records[0]), - views: [[false, 'form']] - }); - } - }); + var res_login = event.srcElement.dataset.resLogin; + var res_id = event.srcElement.dataset.resId; + if ((! res_login) && (! res_id)) return false; + if (! res_id) { + var ds = new session.web.DataSet(self, res_model); + var defer = ds.call('search', [[['login', '=', res_login]]]).then(function (records) { + if (records[0]) { + self.do_action({ type: 'ir.actions.act_window', res_model: res_model, res_id: parseInt(records[0]), views: [[false, 'form']]}); + } + else return false; + }); + } + else self.do_action({ type: 'ir.actions.act_window', res_model: res_model, res_id: parseInt(res_id), views: [[false, 'form']]}); }); - this.$element.find('div.oe_mail_thread_nomore').hide(); /* display user, fetch comments */ this.display_current_user(); if (this.params.records) return this.display_comments(this.params.records); @@ -77,72 +102,164 @@ openerp.mail = function(session) { var self = this; this.params.offset = 0; this.$element.find('div.oe_mail_thread_display').empty(); - return this.fetch_comments().then(); + return this.fetch_comments(this.params.limit, this.params.offset).then(); }, fetch_comments: function (limit, offset) { var self = this; var defer = this.ds.call('message_load', [[this.params.res_id], limit=(limit||this.params.limit), offset=(offset||this.params.offset)]); $.when(defer).then(function (records) { - if (records.length < self.params.limit) self.params.show_more = false; + if (records.length < self.params.limit) self.params.thread_show_more = false; self.display_comments(records); - if (self.params.show_more == true) { - self.$element.find('div.oe_mail_thread_more').show(); - self.$element.find('div.oe_mail_thread_nomore').hide(); } + if (self.params.thread_show_more == true) { + self.$element.find('button.oe_mail_button_more').show(); + self.$element.find('p.oe_mail_p_nomore').hide(); } else { - self.$element.find('div.oe_mail_thread_more').hide(); - self.$element.find('div.oe_mail_thread_nomore').show(); } + self.$element.find('button.oe_mail_button_more').hide(); + self.$element.find('p.oe_mail_p_nomore').show(); } }); return defer; }, display_comments: function (records) { var self = this; + // sort comments + var sorted_comments = this.sort_comments(records); + this.sorted_comments = sorted_comments; + this.bidouille = false; + this.sub_com = []; + console.log('display_comments'); + console.log(sorted_comments); + console.log(records); + //return true; + /* WIP: map matched regexp -> records to browse with name */ //_(records).each(function (record) { //self.do_check_internal_links(record.body_text); //}); - _(records).each(function (record) { - if (record.type == 'email') { record.mini_url = ('/mail/static/src/img/email_icon.png'); } - else { record.mini_url = self.thread_get_avatar_mini('res.users', 'avatar_mini', record.user_id[0]); } + + _(sorted_comments).each(function (record) { + console.log('new iteration'); + var sub_comments = [] - // body text manipulation - record.body_text = self.do_clean_text(record.body_text); - record.tr_body_text = self.do_truncate_string(record.body_text, self.params.char_show_more); - record.body_text = self.do_replace_internal_links(record.body_text); - if (record.tr_body_text) record.tr_body_text = self.do_replace_internal_links(record.tr_body_text); - - // render - $(session.web.qweb.render('ThreadMsg', {'record': record})).appendTo(self.$element.find('div.oe_mail_thread_display')); - - // truncated: hide full-text, show summary, add buttons - if (record.tr_body_text) { - var node = self.$element.find('span.oe_mail_msg_body:last').append(' [ ... Show less]'); - self.$element.find('p.oe_mail_msg_p:last').append($('' + record.tr_body_text + ' [ ... Show more]')); - var new_node = self.$element.find('span.oe_mail_msg_body_short:last'); - node.hide(); - node.find('a:last').click(function() { node.hide(); new_node.show(); return false; }); - new_node.find('a:last').click(function() { new_node.hide(); node.show(); return false; }); + if (record.parent_id == self.params.parent_id && self.params.thread_level > 0) { + if (! self.bidouille) { + self.bidouille = record; + } + else { + self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid, + 'records': self.sub_com, 'thread_level': (self.params.thread_level-1), + 'parent_id': record.id}); + self.$element.find('div.oe_mail_thread_msg:last').append('
'); + self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last')); + self.bidouille = record; + self.sub_com = []; + } + } + + else if (self.params.thread_level > 0) { + self.sub_com.push(record); + return true; + } + + self.display_comment(record); + }); + console.log(self.sub_com); + if (self.sub_com.length > 0) { + self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid, + 'records': self.sub_com, 'thread_level': (self.params.thread_level-1), + 'parent_id': self.bidouille.id}); + self.$element.find('div.oe_mail_thread_msg:last').append('
'); + self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last')); + self.sub_com = []; + } + + console.log('end display'); // update offset for "More" buttons this.params.offset += records.length; }, + + /** + * Display a record + */ + display_comment: function (record) { + if (record.type == 'email') { record.mini_url = ('/mail/static/src/img/email_icon.png'); } + else { record.mini_url = this.thread_get_avatar_mini('res.users', 'avatar_mini', record.user_id[0]); } + // body text manipulation + record.body_text = this.do_clean_text(record.body_text); + record.tr_body_text = this.do_truncate_string(record.body_text, this.params.msg_more_limit); + 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})).appendTo(this.$element.find('div.oe_mail_thread_display')); + // 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(' [ ... Show less]'); + var node_body_short = this.$element.find('span.oe_mail_msg_body_short:last').append(' [ ... Show more]'); + node_body.hide(); + node_body.find('a:last').click(function() { node_body.hide(); node_body_short.show(); return false; }); + node_body_short.find('a:last').click(function() { node_body_short.hide(); node_body.show(); return false; }); + } + }, + + /** + * Sorts records in an hierarchical way, based on parent_id + * @param {Array} records records from mail.message + * @returns {Object} sorted_comments: dict + * sorted_comments.res_model = {res_ids} + * sorted_comments.res_model.res_id = [records] + */ + sort_comments: function (records) { + //console.log('sort_comments'); + if (this.params.thread_level == 0) return records.slice(0); + + var done = false; + var cur_iter = 0; + var max_iter = 10; + + sorted_comments = []; + + tmp_records = records.slice(0); + + _(records).each(function (record, id) { + if (! record.parent_id) { + sorted_comments.push(record); + } + }); + + records.reverse(); + + _(records).each(function (record, id) { + var index = _.indexOf(_.pluck(sorted_comments, 'id'), record.parent_id[0]); + index = 0; + if (index > -1) { + if (record.parent_id) { + sorted_comments.splice(index+1, 0, record); + } + } + }); + + records.reverse(); + return sorted_comments; + }, display_current_user: function () { - $('
').html( - '' - ).appendTo(this.$element.find('div.oe_mail_msg_image')); + return this.$element.find('div.oe_mail_msg_image').empty().html( + ''); }, do_comment: function () { var body_text = this.$element.find('textarea').val(); - return this.ds.call('message_append_note', [[this.params.res_id], 'Reply comment', body_text, type='comment']).then( - this.proxy('init_comments')); + console.log(body_text + this.params.parent_id); + return true; + //return this.ds.call('message_append_note', [[this.params.res_id], 'Reply comment', body_text, parent_id=this.params.parent_id, type='comment']).then( + //this.proxy('init_comments')); }, do_more: function () { - return this.fetch_comments(this.limit, this.offset); + return this.fetch_comments(this.params.limit, this.params.offset); }, do_replace_internal_links: function (string) { @@ -205,20 +322,20 @@ openerp.mail = function(session) { /* Add ThreadView widget to registry */ session.web.form.widgets.add( - 'ThreadView', 'openerp.mail.ThreadView'); + 'ThreadView', 'openerp.mail.RecordThread'); session.web.page.readonly.add( - 'ThreadView', 'openerp.mail.ThreadView'); + 'ThreadView', 'openerp.mail.RecordThread'); /* ThreadView widget: thread of comments */ - mail.ThreadView = session.web.form.Field.extend({ + mail.RecordThread = session.web.form.Field.extend({ // QWeb template to use when rendering the object - form_template: 'Thread', + form_template: 'RecordThread', init: function() { this.is_sub = 0; this.see_sub = 0; this._super.apply(this, arguments); - this.thread_display = null; + this.thread = null; /* DataSets */ this.ds = new session.web.DataSet(this, this.view.model); this.ds_users = new session.web.DataSet(this, 'res.users'); @@ -252,9 +369,10 @@ openerp.mail = function(session) { /* fetch subscribers */ this.fetch_subscribers(); /* create ThreadDisplay widget and render it */ - this.$element.find('div.oe_mail_thread_left').empty(); - this.thread_display = new mail.ThreadDisplay(this, {'res_model': this.view.model, 'res_id': this.view.datarecord.id, 'uid': this.session.uid}); - this.thread_display.appendTo(this.$element.find('div.oe_mail_thread_left')); + this.$element.find('div.oe_mail_recthread_left').empty(); + if (this.thread) this.thread.stop(); + this.thread = new mail.Thread(this, {'res_model': this.view.model, 'res_id': this.view.datarecord.id, 'uid': this.session.uid}); + this.thread.appendTo(this.$element.find('div.oe_mail_recthread_left')); }, fetch_subscribers: function () { @@ -413,7 +531,7 @@ openerp.mail = function(session) { */ fetch_comments: function (domain, context, offset, limit) { var load_res = this.ds_thread.call('get_pushed_messages', - [[this.session.uid], limit = (limit || 100), offset = (offset || 0), domain = (domain || null), context = (context || null) ]).then( + [[this.session.uid], limit = (limit || 2), offset = (offset || 0), domain = (domain || []), context = (context || null) ]).then( this.proxy('display_comments')); return load_res; }, @@ -422,20 +540,24 @@ openerp.mail = function(session) { * @param {Array} records records to show in threads */ display_comments: function (records) { - var sorted_comments = this.sort_comments(records, this.sorted_comments); + var sorted_comments = this.sort_comments(records); var self = this; - _(sorted_comments).each(function (rec_models, model) { // each model - _(rec_models).each(function (record_id, id) { // each record + _(sorted_comments.model_list).each(function (model_name) { + _(sorted_comments.models[model_name].id_list).each(function (id) { + var records = sorted_comments.models[model_name].ids[id]; + console.log('records to send'); + console.log(records); var template = 'WallThreadContainer'; var render_res = session.web.qweb.render(template, { - 'record_model': model, + 'record_model': model_name, 'record_id': id, }); $('
').html(render_res).appendTo(self.$element.find('div.oe_mail_wall_threads')); - var thread_display = new mail.ThreadDisplay(self, - {'res_model': model, 'res_id': parseInt(id), 'uid': self.session.uid, 'records': record_id} + var thread = new mail.Thread(self, { + 'res_model': model_name, 'res_id': parseInt(id), 'uid': self.session.uid, 'records': records, + 'parent_id': false, 'thread_level': 1} ); - thread_display.appendTo(self.$element.find('div.oe_mail_wall_thread_content:last')); + thread.appendTo(self.$element.find('div.oe_mail_wall_thread_content:last')); }); }); $.extend(true, this.sorted_comments, sorted_comments); @@ -447,16 +569,49 @@ openerp.mail = function(session) { * @returns {Object} sorted_comments: dict * sorted_comments.res_model = {res_ids} * sorted_comments.res_model.res_id = [records] + * sorted = [{'hr_holidays': [{3: 'A'}, {2: 'B'}]}, {'crm': [{3: 'A'}, {2: 'B'}]}] */ sort_comments: function (records) { - sorted_comments = {} + sc = {'model_list': [], 'models': {}} + var cur_iter = 0; var max_iter = 10; var modif = true; + /* step1: get roots */ + while ( modif && (cur_iter++) < max_iter) { + modif = false; + _(records).each(function (record) { + if ($.inArray(record.model, sc['model_list']) == -1) { + sc['model_list'].push(record.model); + sc['models'][record.model] = {'id_list': [], 'id_to_root': {}, 'ids': {}}; + modif = true; + } + var sort_id = (record.parent_id) ? record.parent_id[0]: record.id; + if (record.parent_id == false) { + if (_.indexOf(sc['models'][record.model]['id_list'], sort_id) == -1) { + sc['models'][record.model]['id_list'].push(sort_id); + sc['models'][record.model]['ids'][sort_id] = []; + modif = true; + } + } + else { + var test = sc['models'][record.model]['id_to_root'][sort_id]; + if (_.indexOf(sc['models'][record.model]['id_list'], sort_id) != -1) { + sc['models'][record.model]['id_to_root'][record.id] = sort_id; + modif = true; + } + else if ( test ) { + sc['models'][record.model]['id_to_root'][record.id] = test; + modif = true; + } + } + }); + } + /* step2: add records */ _(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); + var root_id = sc['models'][record.model]['id_to_root'][record.id]; + if (! root_id) root_id = record.id; + sc['models'][record.model]['ids'][root_id].push(record); }); - return sorted_comments; + console.log(sc); + return sc; }, /** @@ -472,7 +627,8 @@ openerp.mail = function(session) { _(rec_models).each(function (record_id, id) { // each record ids.push(id); }); - domain.push('|', ['model', '!=', model], ['res_id', 'not in', ids]); + //domain.push('|', ['model', '!=', model], ['res_id', 'not in', ids]); + domain.push('|', ['model', '!=', model], '!', ['id', 'child_of', ids]); }); return domain; }, diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 1e4e301bc2e..3020e9b5580 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -14,11 +14,8 @@
- -
-
- You have loaded all discussions. + +

You have loaded all discussions.

@@ -33,11 +30,11 @@
-
+
OpenSocial
-
+
-
+
@@ -52,22 +49,18 @@
-
+
-
-
+
User_image

-
-
+
- -
-
- You have loaded all messages in this thread. + +

You have loaded all messages in this thread.

@@ -76,31 +69,25 @@
- - - - - - + +
+
- +

- - OpenERP System Notification - - - - - - + + + via OpenERP System Notification + - Need action by wrote on
+

From 15581b5286cb2861395f4475c1aeb826c709052d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 2 Mar 2012 18:35:11 +0100 Subject: [PATCH 02/17] [REF] Small refactoring of Wall. Refactoring still needed. bzr revid: tde@openerp.com-20120302173511-eyky2ibpzdvp0hgq --- addons/mail/static/src/js/mail.js | 47 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2e270bd82a0..6f9060c75c7 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -555,7 +555,7 @@ openerp.mail = function(session) { $('
').html(render_res).appendTo(self.$element.find('div.oe_mail_wall_threads')); var thread = new mail.Thread(self, { 'res_model': model_name, 'res_id': parseInt(id), 'uid': self.session.uid, 'records': records, - 'parent_id': false, 'thread_level': 1} + 'parent_id': false, 'thread_level': 2} ); thread.appendTo(self.$element.find('div.oe_mail_wall_thread_content:last')); }); @@ -565,40 +565,41 @@ openerp.mail = function(session) { /** * Add records to sorted_comments array - * @param {Array} records records from mail.message - * @returns {Object} sorted_comments: dict - * sorted_comments.res_model = {res_ids} - * sorted_comments.res_model.res_id = [records] - * sorted = [{'hr_holidays': [{3: 'A'}, {2: 'B'}]}, {'crm': [{3: 'A'}, {2: 'B'}]}] + * @param {Array} records records from mail.message sorted by date desc + * @returns {Object} sc sorted_comments: dict + * sc.model_list = [record.model names] + * sc.models.model = { + * 'id_list': list or root_ids + * 'id_to_anc': {'record_id': [ancestor_ids]}, still sorted by date desc + * 'ids': {'root_id': [records]}, still sorted by date desc + * }, for each model */ sort_comments: function (records) { sc = {'model_list': [], 'models': {}} var cur_iter = 0; var max_iter = 10; var modif = true; /* step1: get roots */ while ( modif && (cur_iter++) < max_iter) { + console.log(cur_iter); modif = false; _(records).each(function (record) { if ($.inArray(record.model, sc['model_list']) == -1) { sc['model_list'].push(record.model); - sc['models'][record.model] = {'id_list': [], 'id_to_root': {}, 'ids': {}}; + sc['models'][record.model] = {'id_list': [], 'id_to_anc': {}, 'ids': {}}; + } + var rmod = sc['models'][record.model]; + if (record.parent_id == false && (_.indexOf(rmod['id_list'], record.id) == -1)) { + rmod['id_list'].push(record.id); + rmod['ids'][record.id] = []; modif = true; - } - var sort_id = (record.parent_id) ? record.parent_id[0]: record.id; - if (record.parent_id == false) { - if (_.indexOf(sc['models'][record.model]['id_list'], sort_id) == -1) { - sc['models'][record.model]['id_list'].push(sort_id); - sc['models'][record.model]['ids'][sort_id] = []; - modif = true; - } - } + } else { - var test = sc['models'][record.model]['id_to_root'][sort_id]; - if (_.indexOf(sc['models'][record.model]['id_list'], sort_id) != -1) { - sc['models'][record.model]['id_to_root'][record.id] = sort_id; + var test = rmod['id_to_anc'][record.parent_id[0]]; + if (_.indexOf(rmod['id_list'], record.parent_id[0]) != -1) { + rmod['id_to_anc'][record.id] = record.parent_id[0]; modif = true; } else if ( test ) { - sc['models'][record.model]['id_to_root'][record.id] = test; + rmod['id_to_anc'][record.id] = test; modif = true; } } @@ -606,7 +607,7 @@ openerp.mail = function(session) { } /* step2: add records */ _(records).each(function (record) { - var root_id = sc['models'][record.model]['id_to_root'][record.id]; + var root_id = sc['models'][record.model]['id_to_anc'][record.id]; if (! root_id) root_id = record.id; sc['models'][record.model]['ids'][root_id].push(record); }); @@ -655,9 +656,7 @@ openerp.mail = function(session) { * Tools: get avatar mini (TODO: should be moved in some tools ?) */ 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; + return this.session.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + (id || ''); }, }); }; From 1a3a7c09882ba1036f5c5b9707e0f1d367df8a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 5 Mar 2012 10:05:21 +0100 Subject: [PATCH 03/17] [FIX] Thread widget: fixed bug when looping in records in form view: followers display was not correctly updated. bzr revid: tde@openerp.com-20120305090521-kgi26xvzuhlsckbz --- addons/mail/static/src/js/mail.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 6f9060c75c7..016de0fff16 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -95,7 +95,7 @@ openerp.mail = function(session) { }, stop: function () { - this._super.apply(this, arguments); + //this._super.apply(this, arguments); }, init_comments: function() { @@ -357,29 +357,30 @@ openerp.mail = function(session) { set_value: function() { var self = this; this._super.apply(this, arguments); + this.see_sub = 0; /* hide follow/unfollow/see followers buttons */ - self.$element.find('button.oe_mail_button_follow').hide(); - self.$element.find('button.oe_mail_button_unfollow').hide(); + this.$element.find('button.oe_mail_button_followers').html('Display followers') + this.$element.find('div.oe_mail_followers_display').hide(); + this.$element.find('button.oe_mail_button_follow').hide(); + this.$element.find('button.oe_mail_button_unfollow').hide(); if (! this.view.datarecord.id) { return; } /* find wich (un)follow buttons to show */ - var call_res = this.ds.call('message_is_subscriber', [[this.view.datarecord.id]]).then(function (records) { + var fetch_fol_done = this.ds.call('message_is_subscriber', [[this.view.datarecord.id]]).then(function (records) { if (records == true) { self.is_sub = 1; self.$element.find('button.oe_mail_button_unfollow').show(); } else { self.is_sub = 0; self.$element.find('button.oe_mail_button_follow').show(); } }); /* fetch subscribers */ - this.fetch_subscribers(); + var fetch_sub_done = this.fetch_subscribers(); /* create ThreadDisplay widget and render it */ this.$element.find('div.oe_mail_recthread_left').empty(); if (this.thread) this.thread.stop(); this.thread = new mail.Thread(this, {'res_model': this.view.model, 'res_id': this.view.datarecord.id, 'uid': this.session.uid}); this.thread.appendTo(this.$element.find('div.oe_mail_recthread_left')); + return fetch_fol_done && fetch_sub_done; }, fetch_subscribers: function () { - var follow_res = this.ds.call('message_get_subscribers', [[this.view.datarecord.id]]).then( - this.proxy('display_subscribers')); - this.$element.find('div.oe_mail_followers_display').hide(); - return follow_res; + return this.ds.call('message_get_subscribers', [[this.view.datarecord.id]]).then(this.proxy('display_subscribers')); }, display_subscribers: function (records) { @@ -394,12 +395,12 @@ openerp.mail = function(session) { do_follow: function () { this.do_toggle_follow(); - return this.ds.call('message_subscribe', [[this.view.datarecord.id]]).then(); + return this.ds.call('message_subscribe', [[this.view.datarecord.id]]).when(); }, do_unfollow: function () { this.do_toggle_follow(); - return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).then(); + return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).when(); }, do_toggle_follow: function () { From 4c70c04043f3f366e5832061e4e827d248c79f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 5 Mar 2012 17:59:10 +0100 Subject: [PATCH 04/17] [IMP] bzr diffWIPbzr diff Thread widget: threaded version of the widget now correctly handles message threads. bzr revid: tde@openerp.com-20120305165910-4nt0gm7t9u6f2ap0 --- addons/mail/static/src/js/mail.js | 101 +++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 016de0fff16..7510f557806 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -120,8 +120,55 @@ openerp.mail = function(session) { }); return defer; }, - + display_comments: function (records) { + console.log('deginb display'); + console.log(records); + var self = this; + // sort comments + var sorted_comments = this.new_sort_comments(records); + this.sorted_comments = sorted_comments; + this.bidouille = false; + this.sub_com = []; + + _(records).each(function (record) { + console.log('new iteration'); + self.sub_com = []; + + if ( (record.parent_id == false || record.parent_id[0] == self.params.parent_id) && self.params.thread_level > 0 ) { + var sub_list = self.sorted_comments['root_id_msg_list'][record.id]; + _(records).each(function (record) { + if (record.parent_id == false || record.parent_id[0] == self.params.parent_id) return; + if (_.indexOf(_.pluck(sub_list, 'id'), record.id) != -1) { + self.sub_com.push(record); + } + }); + + console.log('--found root'); + console.log(record); + console.log(sub_list); + console.log(self.sub_com); + + self.display_comment(record); + + self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid, + 'records': self.sub_com, 'thread_level': (self.params.thread_level-1), + 'parent_id': record.id}); + self.$element.find('div.oe_mail_thread_msg:last').append('
'); + self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last')); + } + + else if (self.params.thread_level == 0) { + self.display_comment(record); + } + + }); + console.log('end display'); + // update offset for "More" buttons + this.params.offset += records.length; + }, + + old_display_comments: function (records) { var self = this; // sort comments var sorted_comments = this.sort_comments(records); @@ -143,6 +190,8 @@ openerp.mail = function(session) { var sub_comments = [] if (record.parent_id == self.params.parent_id && self.params.thread_level > 0) { + self.display_comment(record); + if (! self.bidouille) { self.bidouille = record; } @@ -163,7 +212,9 @@ openerp.mail = function(session) { return true; } - self.display_comment(record); + else { + self.display_comment(record); + } }); console.log(self.sub_com); @@ -185,6 +236,10 @@ openerp.mail = function(session) { * Display a record */ display_comment: function (record) { + console.log('now displaying !'); + console.log(this.params.thread_level); + console.log(record) + if (record.type == 'email') { record.mini_url = ('/mail/static/src/img/email_icon.png'); } else { record.mini_url = this.thread_get_avatar_mini('res.users', 'avatar_mini', record.user_id[0]); } // body text manipulation @@ -193,7 +248,7 @@ 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})).appendTo(this.$element.find('div.oe_mail_thread_display')); + $(session.web.qweb.render('ThreadMsg', {'record': record})).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(' [ ... Show less]'); @@ -202,6 +257,7 @@ openerp.mail = function(session) { node_body.find('a:last').click(function() { node_body.hide(); node_body_short.show(); return false; }); node_body_short.find('a:last').click(function() { node_body_short.hide(); node_body.show(); return false; }); } + console.log('end now displaying'); }, /** @@ -245,6 +301,45 @@ openerp.mail = function(session) { return sorted_comments; }, + new_sort_comments: function (records) { + var self = this; + console.log('nsc'); + console.log(records); + console.log(self.params.parent_id); + console.log(self.params.thread_level); + sc = {'root_id_list': [], 'root_id_msg_list': {}, 'id_to_root': {}} + var cur_iter = 0; var max_iter = 10; var modif = true; + /* step1: get roots */ + while ( modif && (cur_iter++) < max_iter) { + modif = false; + _(records).each(function (record) { + if ( (record.parent_id == false || record.parent_id[0] == self.params.parent_id) && (_.indexOf(sc['root_id_list'], record.id) == -1)) { + sc['root_id_list'].push(record.id); + sc['root_id_msg_list'][record.id] = []; + modif = true; + } + else { + if (_.indexOf(sc['root_id_list'], record.parent_id[0]) != -1) { + sc['id_to_root'][record.id] = record.parent_id[0]; + modif = true; + } + else if ( sc['id_to_root'][record.parent_id[0]] ) { + sc['id_to_root'][record.id] = sc['id_to_root'][record.parent_id[0]]; + modif = true; + } + } + }); + } + /* step2: add records */ + _(records).each(function (record) { + var root_id = sc['id_to_root'][record.id]; + if (! root_id) return; + sc['root_id_msg_list'][root_id].push(record); + }); + console.log(sc); + return sc; + }, + display_current_user: function () { return this.$element.find('div.oe_mail_msg_image').empty().html( ''); From acfcade3cbcfc4c7b53861c99c2e19d29cfcc378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 5 Mar 2012 18:37:42 +0100 Subject: [PATCH 05/17] [REF] Thread widget: cleaning of code bzr revid: tde@openerp.com-20120305173742-0uzfemp6vqc8jcz0 --- addons/mail/static/src/js/mail.js | 189 +++++------------------------- 1 file changed, 31 insertions(+), 158 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 7510f557806..49745671a4c 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -12,26 +12,20 @@ openerp.mail = function(session) { * 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: - * 1/ 1-level thread: thread_level = 1 * - root message * - - sub message (parent_id = root message) + * - - - sub sub message (parent id = sub message) * - - sub message (parent_id = root message) - * 2/ flat thread: thread_level = 0 - * - root message - * - sub message (parent_id = root message) - * - sub message (parent_id = root message) - * This widget has 2 ways of initialization: - * 1/ give records - * 2/ do not give records: will fetch [limit] messages from - * the database, related to record [res_model]:[res_id]. + * This widget has 2 ways of initialization, either you give records to be rendered, + * either it will fetch [limit] messages related to [res_model]:[res_id]. */ mail.Thread = session.web.Widget.extend({ template: 'Thread', /** * - * @params {Object} parent parent - * @params {Object} [params] + * @param {Object} parent parent + * @param {Object} [params] * @param {String} [params.res_model] res_model of mail.thread object * @param {Number} [params.res_id] res_id of record * @param {Number} [params.parent_id=false] parent_id of message @@ -55,10 +49,8 @@ openerp.mail = function(session) { this.params.offset = this.params.offset || 0; this.params.records = this.params.records || null; /* DataSets and internal vars */ - this.parent_stack = []; - this.cur_thread_level = 0; this.map_hash = {}; - this.params.thread_show_more = true; + this.display_show_more = true; this.ds = new session.web.DataSet(this, this.params.res_model); this.ds_users = new session.web.DataSet(this, 'res.users'); }, @@ -122,112 +114,35 @@ openerp.mail = function(session) { }, display_comments: function (records) { - console.log('deginb display'); - console.log(records); var self = this; - // sort comments - var sorted_comments = this.new_sort_comments(records); - this.sorted_comments = sorted_comments; - this.bidouille = false; - this.sub_com = []; - - _(records).each(function (record) { - console.log('new iteration'); - self.sub_com = []; - - if ( (record.parent_id == false || record.parent_id[0] == self.params.parent_id) && self.params.thread_level > 0 ) { - var sub_list = self.sorted_comments['root_id_msg_list'][record.id]; - _(records).each(function (record) { - if (record.parent_id == false || record.parent_id[0] == self.params.parent_id) return; - if (_.indexOf(_.pluck(sub_list, 'id'), record.id) != -1) { - self.sub_com.push(record); - } - }); - - console.log('--found root'); - console.log(record); - console.log(sub_list); - console.log(self.sub_com); - - self.display_comment(record); - - self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid, - 'records': self.sub_com, 'thread_level': (self.params.thread_level-1), - 'parent_id': record.id}); - self.$element.find('div.oe_mail_thread_msg:last').append('
'); - self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last')); - } - - else if (self.params.thread_level == 0) { - self.display_comment(record); - } - - }); - console.log('end display'); - // update offset for "More" buttons - this.params.offset += records.length; - }, - - old_display_comments: function (records) { - var self = this; - // sort comments var sorted_comments = this.sort_comments(records); this.sorted_comments = sorted_comments; - this.bidouille = false; - this.sub_com = []; - console.log('display_comments'); - console.log(sorted_comments); - console.log(records); - //return true; /* WIP: map matched regexp -> records to browse with name */ //_(records).each(function (record) { //self.do_check_internal_links(record.body_text); //}); - _(sorted_comments).each(function (record) { - console.log('new iteration'); - var sub_comments = [] - - if (record.parent_id == self.params.parent_id && self.params.thread_level > 0) { + _(records).each(function (record) { + var sub_msgs = []; + if ((record.parent_id == false || record.parent_id[0] == self.params.parent_id) && self.params.thread_level > 0 ) { + var sub_list = self.sorted_comments['root_id_msg_list'][record.id]; + _(records).each(function (record) { + if (record.parent_id == false || record.parent_id[0] == self.params.parent_id) return; + if (_.indexOf(_.pluck(sub_list, 'id'), record.id) != -1) { + sub_msgs.push(record); + } + }); self.display_comment(record); - - if (! self.bidouille) { - self.bidouille = record; - } - else { - self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid, - 'records': self.sub_com, 'thread_level': (self.params.thread_level-1), - 'parent_id': record.id}); - self.$element.find('div.oe_mail_thread_msg:last').append('
'); - self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last')); - self.bidouille = record; - self.sub_com = []; - } - + self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid, + 'records': sub_msgs, 'thread_level': (self.params.thread_level-1), 'parent_id': record.id}); + self.$element.find('div.oe_mail_thread_msg:last').append('
'); + self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last')); } - - else if (self.params.thread_level > 0) { - self.sub_com.push(record); - return true; - } - - else { + else if (self.params.thread_level == 0) { self.display_comment(record); } - }); - console.log(self.sub_com); - if (self.sub_com.length > 0) { - self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid, - 'records': self.sub_com, 'thread_level': (self.params.thread_level-1), - 'parent_id': self.bidouille.id}); - self.$element.find('div.oe_mail_thread_msg:last').append('
'); - self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last')); - self.sub_com = []; - } - - console.log('end display'); // update offset for "More" buttons this.params.offset += records.length; }, @@ -236,10 +151,6 @@ openerp.mail = function(session) { * Display a record */ display_comment: function (record) { - console.log('now displaying !'); - console.log(this.params.thread_level); - console.log(record) - if (record.type == 'email') { record.mini_url = ('/mail/static/src/img/email_icon.png'); } else { record.mini_url = this.thread_get_avatar_mini('res.users', 'avatar_mini', record.user_id[0]); } // body text manipulation @@ -257,56 +168,19 @@ openerp.mail = function(session) { node_body.find('a:last').click(function() { node_body.hide(); node_body_short.show(); return false; }); node_body_short.find('a:last').click(function() { node_body_short.hide(); node_body.show(); return false; }); } - console.log('end now displaying'); }, - + /** - * Sorts records in an hierarchical way, based on parent_id - * @param {Array} records records from mail.message - * @returns {Object} sorted_comments: dict - * sorted_comments.res_model = {res_ids} - * sorted_comments.res_model.res_id = [records] + * Add records to sorted_comments array + * @param {Array} records records from mail.message sorted by date desc + * @returns {Object} sc sorted_comments: dict { + * 'root_id_list': list or root_ids + * 'root_id_msg_list': {'record_id': [ancestor_ids]}, still sorted by date desc + * 'id_to_root': {'root_id': [records]}, still sorted by date desc + * } */ sort_comments: function (records) { - //console.log('sort_comments'); - if (this.params.thread_level == 0) return records.slice(0); - - var done = false; - var cur_iter = 0; - var max_iter = 10; - - sorted_comments = []; - - tmp_records = records.slice(0); - - _(records).each(function (record, id) { - if (! record.parent_id) { - sorted_comments.push(record); - } - }); - - records.reverse(); - - _(records).each(function (record, id) { - var index = _.indexOf(_.pluck(sorted_comments, 'id'), record.parent_id[0]); - index = 0; - if (index > -1) { - if (record.parent_id) { - sorted_comments.splice(index+1, 0, record); - } - } - }); - - records.reverse(); - return sorted_comments; - }, - - new_sort_comments: function (records) { var self = this; - console.log('nsc'); - console.log(records); - console.log(self.params.parent_id); - console.log(self.params.thread_level); sc = {'root_id_list': [], 'root_id_msg_list': {}, 'id_to_root': {}} var cur_iter = 0; var max_iter = 10; var modif = true; /* step1: get roots */ @@ -336,7 +210,6 @@ openerp.mail = function(session) { if (! root_id) return; sc['root_id_msg_list'][root_id].push(record); }); - console.log(sc); return sc; }, @@ -347,7 +220,7 @@ openerp.mail = function(session) { do_comment: function () { var body_text = this.$element.find('textarea').val(); - console.log(body_text + this.params.parent_id); + console.log(body_text + '-' + this.params.parent_id); return true; //return this.ds.call('message_append_note', [[this.params.res_id], 'Reply comment', body_text, parent_id=this.params.parent_id, type='comment']).then( //this.proxy('init_comments')); @@ -375,7 +248,7 @@ openerp.mail = function(session) { }, do_truncate_string: function(string, max_length) { - if (string.length <= max_length) return false; + if (string.length <= (max_length * 1.2)) return false; else return string.slice(0, max_length); }, From bb352a172f3460770d412432df3e27e12f1d588f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 5 Mar 2012 20:20:52 +0100 Subject: [PATCH 06/17] [FIX] Wall widget: fixed the Wall 'load more' feature. Also cleaned the code. bzr revid: tde@openerp.com-20120305192052-wabvan89nt0hrj8o --- addons/mail/static/src/css/mail.css | 1 - addons/mail/static/src/js/mail.js | 104 ++++++++++++++-------------- addons/mail/static/src/xml/mail.xml | 3 - 3 files changed, 53 insertions(+), 55 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 4f0eea033ea..f8fef969475 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -24,7 +24,6 @@ } .oe_mail_wall_thread_content { - margin-left: 5%; } .oe_mail_wall_thread_content div.oe_mail_thread_act .oe_mail_action_textarea { diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 49745671a4c..f6ef9e252c5 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -411,11 +411,12 @@ openerp.mail = function(session) { init: function (parent, params) { this._super(parent); this.params = params || {}; - this.params.limit = params.limit || 20; + this.params.limit = params.limit || 2; this.params.search_view_id = params.search_view_id || false; this.params.search = {}; this.params.domain = []; - this.sorted_comments = {}; + this.sorted_comments = {'models': {}}; + this.display_show_more = true; /* DataSets */ this.ds_msg = new session.web.DataSet(this, 'mail.message'); this.ds_thread = new session.web.DataSet(this, 'mail.thread'); @@ -428,14 +429,14 @@ openerp.mail = function(session) { /* events and buttons */ this.$element.find('button.oe_mail_button_comment').bind('click', function () { self.do_comment(); }); this.$element.find('button.oe_mail_wall_button_more').bind('click', function () { self.do_more(); }); - this.$element.find('div.oe_mail_wall_nomore').hide(); + this.$element.find('p.oe_mail_wall_nomore').hide(); /* load mail.message search view */ var search_view_loaded = this.load_search_view(this.params.search_view_id, {}, false); var search_view_ready = $.when(search_view_loaded).then(function () { self.searchview.on_search.add(self.do_searchview_search); }); /* fetch comments */ - var comments_ready = this.init_comments(); + var comments_ready = this.init_comments(this.params.domain, {}, 0, this.params.limit); return (search_view_ready && comments_ready); }, @@ -486,7 +487,8 @@ openerp.mail = function(session) { init_comments: function(domain, context, offset, limit) { var self = this; this.params.domain = []; - this.sorted_comments = {}; + this.display_show_more = true; + this.sorted_comments = {'models': {}}; this.$element.find('div.oe_mail_wall_threads').empty(); return this.fetch_comments(domain, context, offset, limit); }, @@ -499,9 +501,16 @@ openerp.mail = function(session) { * @param {Number} limit number of messages to fetch */ fetch_comments: function (domain, context, offset, limit) { + var self = this; var load_res = this.ds_thread.call('get_pushed_messages', - [[this.session.uid], limit = (limit || 2), offset = (offset || 0), domain = (domain || []), context = (context || null) ]).then( - this.proxy('display_comments')); + [[this.session.uid], limit = (limit || 2), offset = (offset || 0), domain = (domain || []), context = (context || null) ]).then(function (records) { + if (records.length < self.params.limit) self.display_show_more = false; + self.display_comments(records); + if (! self.display_show_more) { + self.$element.find('button.oe_mail_wall_button_more:last').hide(); + self.$element.find('p.oe_mail_wall_nomore:last').show(); + } + }); return load_res; }, @@ -512,15 +521,10 @@ openerp.mail = function(session) { var sorted_comments = this.sort_comments(records); var self = this; _(sorted_comments.model_list).each(function (model_name) { - _(sorted_comments.models[model_name].id_list).each(function (id) { - var records = sorted_comments.models[model_name].ids[id]; - console.log('records to send'); - console.log(records); + _(sorted_comments.models[model_name].root_ids).each(function (id) { + var records = sorted_comments.models[model_name].msgs[id]; var template = 'WallThreadContainer'; - var render_res = session.web.qweb.render(template, { - 'record_model': model_name, - 'record_id': id, - }); + var render_res = session.web.qweb.render(template, {}); $('
').html(render_res).appendTo(self.$element.find('div.oe_mail_wall_threads')); var thread = new mail.Thread(self, { 'res_model': model_name, 'res_id': parseInt(id), 'uid': self.session.uid, 'records': records, @@ -529,7 +533,6 @@ openerp.mail = function(session) { thread.appendTo(self.$element.find('div.oe_mail_wall_thread_content:last')); }); }); - $.extend(true, this.sorted_comments, sorted_comments); }, /** @@ -537,38 +540,41 @@ openerp.mail = function(session) { * @param {Array} records records from mail.message sorted by date desc * @returns {Object} sc sorted_comments: dict * sc.model_list = [record.model names] - * sc.models.model = { - * 'id_list': list or root_ids - * 'id_to_anc': {'record_id': [ancestor_ids]}, still sorted by date desc - * 'ids': {'root_id': [records]}, still sorted by date desc + * sc.models[model_name] = { + * 'root_ids': [root record.ids], + * 'id_to_root': {record.id: root.id, ..}, + * 'msgs': {'root_id': [records]}, still sorted by date desc * }, for each model */ sort_comments: function (records) { - sc = {'model_list': [], 'models': {}} + var self = this; + var sc = {'model_list': [], 'models': {}} var cur_iter = 0; var max_iter = 10; var modif = true; /* step1: get roots */ while ( modif && (cur_iter++) < max_iter) { - console.log(cur_iter); modif = false; _(records).each(function (record) { - if ($.inArray(record.model, sc['model_list']) == -1) { + if (_.indexOf(sc['model_list'], record.model) == -1) { sc['model_list'].push(record.model); - sc['models'][record.model] = {'id_list': [], 'id_to_anc': {}, 'ids': {}}; + sc['models'][record.model] = {'root_ids': [], 'id_to_root': {}, 'msgs': {}}; + } + if (! self.sorted_comments['models'][record.model]) { + self.sorted_comments['models'][record.model] = {'root_ids': []}; } var rmod = sc['models'][record.model]; - if (record.parent_id == false && (_.indexOf(rmod['id_list'], record.id) == -1)) { - rmod['id_list'].push(record.id); - rmod['ids'][record.id] = []; + if (record.parent_id == false && (_.indexOf(rmod['root_ids'], record.id) == -1)) { + rmod['root_ids'].push(record.id); + rmod['msgs'][record.id] = []; + self.sorted_comments['models'][record.model]['root_ids'].push(record.id); modif = true; } else { - var test = rmod['id_to_anc'][record.parent_id[0]]; - if (_.indexOf(rmod['id_list'], record.parent_id[0]) != -1) { - rmod['id_to_anc'][record.id] = record.parent_id[0]; + if ((_.indexOf(rmod['root_ids'], record.parent_id[0]) != -1) && (! rmod['id_to_root'][record.id])) { + rmod['id_to_root'][record.id] = record.parent_id[0]; modif = true; } - else if ( test ) { - rmod['id_to_anc'][record.id] = test; + else if ( rmod['id_to_root'][record.parent_id[0]] && (! rmod['id_to_root'][record.id])) { + rmod['id_to_root'][record.id] = rmod['id_to_root'][record.parent_id[0]]; modif = true; } } @@ -576,11 +582,10 @@ openerp.mail = function(session) { } /* step2: add records */ _(records).each(function (record) { - var root_id = sc['models'][record.model]['id_to_anc'][record.id]; + var root_id = sc['models'][record.model]['id_to_root'][record.id]; if (! root_id) root_id = record.id; - sc['models'][record.model]['ids'][root_id].push(record); + sc['models'][record.model]['msgs'][root_id].push(record); }); - console.log(sc); return sc; }, @@ -592,27 +597,16 @@ openerp.mail = function(session) { */ get_fetch_domain: function (sorted_comments) { var domain = []; - _(sorted_comments).each(function (rec_models, model) { //each model + _(sorted_comments.models).each(function (sc_model, model_name) { //each model var ids = []; - _(rec_models).each(function (record_id, id) { // each record + _(sc_model.root_ids).each(function (id) { // each record ids.push(id); }); - //domain.push('|', ['model', '!=', model], ['res_id', 'not in', ids]); - domain.push('|', ['model', '!=', model], '!', ['id', 'child_of', ids]); + domain.push('|', ['model', '!=', model_name], '!', ['id', 'child_of', ids]); }); return domain; }, - - /** - * Action: Posts a comment - */ - do_comment: function () { - var body_text = this.$element.find('textarea').val(); - return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, type='comment']).then( - //this.proxy('fetch_comments')); - this.init_comments()); - }, - + /** * Action: Shows more discussions */ @@ -620,7 +614,15 @@ openerp.mail = function(session) { var domain = this.get_fetch_domain(this.sorted_comments); return this.fetch_comments(domain); }, - + + /** + * Action: Posts a comment + */ + do_comment: function () { + var body_text = this.$element.find('textarea:first').val(); + return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, type='comment']).then(this.init_comments()); + }, + /** * Tools: get avatar mini (TODO: should be moved in some tools ?) */ diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 3020e9b5580..aeb7618e05e 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -23,9 +23,6 @@
-
- Discussion about document (id: ) -
From 61a41ba305c938084407bd2d478c5b4a3ad1b8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 6 Mar 2012 09:34:19 +0100 Subject: [PATCH 07/17] [FIX] Wall widget: fixed class names for comment textarea and button. bzr revid: tde@openerp.com-20120306083419-iuy7x0casszq8ldi --- addons/mail/static/src/js/mail.js | 4 ++-- addons/mail/static/src/xml/mail.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index f6ef9e252c5..f33945aa70e 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -427,7 +427,7 @@ openerp.mail = function(session) { var self = this; this._super.apply(this, arguments); /* events and buttons */ - this.$element.find('button.oe_mail_button_comment').bind('click', function () { self.do_comment(); }); + this.$element.find('button.oe_mail_wall_button_comment').bind('click', function () { self.do_comment(); }); this.$element.find('button.oe_mail_wall_button_more').bind('click', function () { self.do_more(); }); this.$element.find('p.oe_mail_wall_nomore').hide(); /* load mail.message search view */ @@ -619,7 +619,7 @@ openerp.mail = function(session) { * Action: Posts a comment */ do_comment: function () { - var body_text = this.$element.find('textarea:first').val(); + var body_text = this.$element.find('textarea.oe_mail_wall_action_textarea').val(); return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, type='comment']).then(this.init_comments()); }, diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index aeb7618e05e..a51921dfc46 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -7,8 +7,8 @@
-
- +
+
From 17293421cc5185cecc8f3cd080cadc876203ab46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 6 Mar 2012 16:09:46 +0100 Subject: [PATCH 08/17] [FIX] Thread widget: fixed 'load more' feature on threads, now taking into account thread level. Will need code cleaning. bzr revid: tde@openerp.com-20120306150946-ni9ifzs1xc4jc8td --- addons/mail/static/src/js/mail.js | 73 ++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index f33945aa70e..4536c738cdc 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -50,6 +50,7 @@ openerp.mail = function(session) { this.params.records = this.params.records || null; /* DataSets and internal vars */ this.map_hash = {}; + this.sorted_comments = {'root_ids': [], 'root_id_msg_list': {}}; this.display_show_more = true; this.ds = new session.web.DataSet(this, this.params.res_model); this.ds_users = new session.web.DataSet(this, 'res.users'); @@ -93,31 +94,30 @@ openerp.mail = function(session) { init_comments: function() { var self = this; this.params.offset = 0; + this.sorted_comments = {'root_ids': [], 'root_id_msg_list': {}}; this.$element.find('div.oe_mail_thread_display').empty(); return this.fetch_comments(this.params.limit, this.params.offset).then(); }, - fetch_comments: function (limit, offset) { + fetch_comments: function (limit, offset, domain) { var self = this; - var defer = this.ds.call('message_load', [[this.params.res_id], limit=(limit||this.params.limit), offset=(offset||this.params.offset)]); + var defer = this.ds.call('message_load', [[this.params.res_id], limit=(limit||this.params.limit), offset=(offset||this.params.offset), domain=(domain||[]) ]); $.when(defer).then(function (records) { - if (records.length < self.params.limit) self.params.thread_show_more = false; + if (records.length < self.params.limit) self.display_show_more = false; self.display_comments(records); - if (self.params.thread_show_more == true) { - self.$element.find('button.oe_mail_button_more').show(); - self.$element.find('p.oe_mail_p_nomore').hide(); } - else { - self.$element.find('button.oe_mail_button_more').hide(); - self.$element.find('p.oe_mail_p_nomore').show(); } + if (self.display_show_more == false) { + self.$element.find('button.oe_mail_button_more:last').hide(); + self.$element.find('p.oe_mail_p_nomore:last').show(); } }); return defer; }, display_comments: function (records) { var self = this; - var sorted_comments = this.sort_comments(records); - this.sorted_comments = sorted_comments; - + if (this.params.thread_level > 0) { + this.sc = this.sort_comments(records); + } + /* WIP: map matched regexp -> records to browse with name */ //_(records).each(function (record) { //self.do_check_internal_links(record.body_text); @@ -126,7 +126,7 @@ openerp.mail = function(session) { _(records).each(function (record) { var sub_msgs = []; if ((record.parent_id == false || record.parent_id[0] == self.params.parent_id) && self.params.thread_level > 0 ) { - var sub_list = self.sorted_comments['root_id_msg_list'][record.id]; + var sub_list = self.sc['root_id_msg_list'][record.id]; _(records).each(function (record) { if (record.parent_id == false || record.parent_id[0] == self.params.parent_id) return; if (_.indexOf(_.pluck(sub_list, 'id'), record.id) != -1) { @@ -144,7 +144,7 @@ openerp.mail = function(session) { } }); // update offset for "More" buttons - this.params.offset += records.length; + if (this.params.thread_level == 0) this.params.offset += records.length; }, /** @@ -190,6 +190,7 @@ openerp.mail = function(session) { if ( (record.parent_id == false || record.parent_id[0] == self.params.parent_id) && (_.indexOf(sc['root_id_list'], record.id) == -1)) { sc['root_id_list'].push(record.id); sc['root_id_msg_list'][record.id] = []; + self.sorted_comments['root_ids'].push(record.id); modif = true; } else { @@ -209,6 +210,7 @@ openerp.mail = function(session) { var root_id = sc['id_to_root'][record.id]; if (! root_id) return; sc['root_id_msg_list'][root_id].push(record); + //self.sorted_comments['root_id_msg_list'][root_id].push(record.id); }); return sc; }, @@ -226,8 +228,46 @@ openerp.mail = function(session) { //this.proxy('init_comments')); }, + /** + * Create a domain to fetch new comments according to + * comment already present in sorted_comments + * @param {Object} sorted_comments (see sort_comments) + * @returns {Array} fetch_domain (OpenERP domain style) + */ + get_fetch_domain: function (sorted_comments) { + var domain = []; + var ids = []; + var dis2 = []; + if (this.params.parent_id) { + domain.push(['id', 'child_of', this.params.parent_id]); + } + _(sorted_comments.root_ids).each(function (id) { // each record + ids.push(id); + dis2.push(id); + }); + + if (ids.length > 0) { + domain.push('&'); + domain.push('!'); + domain.push(['id', 'child_of', ids]); + } + if (this.params.parent_id != false) { + dis2.push(this.params.parent_id); + } + if (dis2.length > 0) { + domain.push(['id', 'not in', dis2]); + } + + + return domain; + }, + do_more: function () { - return this.fetch_comments(this.params.limit, this.params.offset); + domain = this.get_fetch_domain(this.sorted_comments); + console.log(domain); + console.log(this.params.limit + '-' + this.params.offset + '-' + this.params.parent_id + '-' + this.params.res_id); + //return true; + return this.fetch_comments(this.params.limit, this.params.offset, domain); }, do_replace_internal_links: function (string) { @@ -519,6 +559,7 @@ openerp.mail = function(session) { */ display_comments: function (records) { var sorted_comments = this.sort_comments(records); + console.log(sorted_comments); var self = this; _(sorted_comments.model_list).each(function (model_name) { _(sorted_comments.models[model_name].root_ids).each(function (id) { @@ -527,7 +568,7 @@ openerp.mail = function(session) { var render_res = session.web.qweb.render(template, {}); $('
').html(render_res).appendTo(self.$element.find('div.oe_mail_wall_threads')); var thread = new mail.Thread(self, { - 'res_model': model_name, 'res_id': parseInt(id), 'uid': self.session.uid, 'records': records, + 'res_model': model_name, 'res_id': records[0]['res_id'], 'uid': self.session.uid, 'records': records, 'parent_id': false, 'thread_level': 2} ); thread.appendTo(self.$element.find('div.oe_mail_wall_thread_content:last')); From ef7807319ae6cd268e8a60bfbe4d49d88fde113b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 7 Mar 2012 14:10:22 +0100 Subject: [PATCH 09/17] [REF] mail_thread: added arguments to perform a flat search or an ascended search (search and then add parents, recursively until root_ids). Thread and Wall widgets: updated to use the updated message search API. bzr revid: tde@openerp.com-20120307131022-gy6hmvztarc4ksfz --- addons/mail/mail_thread.py | 54 +++++++++++++++++++------------ addons/mail/static/src/js/mail.js | 8 +++-- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 3abe801a1d4..489f73f23da 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -301,49 +301,61 @@ class mail_thread(osv.osv): context = context) # Message loading - def message_load_ids(self, cr, uid, ids, limit=100, offset=0, domain=[], context=None): + def _message_get_parent_ids(self, cr, uid, ids, child_ids, root_ids, context=None): + if context is None: context = {} + msg_obj = self.pool.get('mail.message') + msgs_tmp = msg_obj.read(cr, uid, child_ids, context=context) + parent_ids = [msg['parent_id'][0] for msg in msgs_tmp if msg['parent_id'] not in root_ids and msg['parent_id'][0] not in child_ids] + child_ids += parent_ids + cur_iter = 0; max_iter = 10; + while (parent_ids and (cur_iter < max_iter)): + cur_iter += 1 + msgs_tmp = msg_obj.read(cr, uid, parent_ids, context=context) + parent_ids = [msg['parent_id'][0] for msg in msgs_tmp if msg['parent_id'] not in root_ids and msg['parent_id'][0] not in child_ids] + child_ids += parent_ids + return child_ids + + def message_load_ids(self, cr, uid, ids, limit=100, offset=0, domain=[], ascent=False, root_ids=[False], context=None): """ OpenSocial feature: return thread messages ids (for web compatibility) loading messages: search in mail.messages where res_id = ids, (res_)model = current model + see get_pushed_messages for parameters explanation """ + if context is None: context = {} msg_obj = self.pool.get('mail.message') msg_ids = msg_obj.search(cr, uid, ['&', ('res_id', 'in', ids), ('model', '=', self._name)] + domain, limit=limit, offset=offset, context=context) + if (ascent): msg_ids = self._message_get_parent_ids(cr, uid, ids, msg_ids, root_ids, context=context) return msg_ids - def message_load(self, cr, uid, ids, limit=100, offset=0, domain=[], context=None): + def message_load(self, cr, uid, ids, limit=100, offset=0, domain=[], ascent=False, root_ids=[False], context=None): """ OpenSocial feature: return thread messages loading messages: search in mail.messages where res_id = ids, (res_)model = current model + see get_pushed_messages for parameters explanation """ - msg_ids = self.message_load_ids(cr, uid, ids, limit=limit, offset=offset, domain=domain, context=context) + msg_ids = self.message_load_ids(cr, uid, ids, limit, offset, domain, ascent, root_ids, context=context) return self.pool.get('mail.message').read(cr, uid, msg_ids, context=context) - def get_pushed_messages(self, cr, uid, ids, limit=100, offset=0, domain=[], context=None): + def get_pushed_messages(self, cr, uid, ids, limit=100, offset=0, domain=[], ascent=False, root_ids=[False], context=None): """OpenSocial: wall: get messages to display (=pushed notifications) - :param filter_search: TODO - :return: list of mail.messages, unsorted + :param domain: domain to add to the search; especially child_of is interesting when dealing with threaded display + :param deep: performs an ascended search; will add to fetched msgs all their parents until root_ids + WARNING: must be used in combinaison with a child_of domain + EXAMPLE: domain = ['id', 'child_of', [32, 33]], root_ids=[32,33] + :param root_ids: root_ids when performing an ascended search + :return: list of mail.messages sorted by date """ + if context is None: context = {} notification_obj = self.pool.get('mail.notification') - message_obj = self.pool.get('mail.message') + msg_obj = self.pool.get('mail.message') # get user notifications notification_ids = notification_obj.search(cr, uid, [('user_id', '=', uid)], context=context) notifications = notification_obj.browse(cr, uid, notification_ids, context=context) msg_ids = [notification.message_id.id for notification in notifications] # search messages: ids in notifications, add domain coming from wall search view search_domain = [('id', 'in', msg_ids)] + domain - msg_ids = message_obj.search(cr, uid, search_domain, limit=limit, offset=offset, context=context) - msgs = message_obj.read(cr, uid, msg_ids, context=context) - # fetch parent message to always have a correctly formated thread - msgs_tmp = msgs[:] - cur_iter = 0; max_iter = 10; modif = True - while (modif and cur_iter <= max_iter): - cur_iter += 1; modif = False - msg_ids_tmp = [] - new_msg_ids = [msg['parent_id'][0] for msg in msgs_tmp if msg['parent_id'] != False and msg['parent_id'][0] not in msg_ids] - msg_ids += new_msg_ids - msgs_tmp = message_obj.read(cr, uid, new_msg_ids, context=context) - msgs += msgs_tmp - # sort by id - msgs.sort(lambda a, b: b['id'].__cmp__(a['id'])) + msg_ids = msg_obj.search(cr, uid, search_domain, limit=limit, offset=offset, context=context) + if (ascent): msg_ids = self._message_get_parent_ids(cr, uid, ids, msg_ids, root_ids, context=context) + msgs = msg_obj.read(cr, uid, msg_ids, context=context) return msgs #------------------------------------------------------ diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 4536c738cdc..78cfaa5f974 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -100,8 +100,9 @@ openerp.mail = function(session) { }, fetch_comments: function (limit, offset, domain) { + console.log('fetch comments'); var self = this; - var defer = this.ds.call('message_load', [[this.params.res_id], limit=(limit||this.params.limit), offset=(offset||this.params.offset), domain=(domain||[]) ]); + var defer = this.ds.call('message_load', [[this.params.res_id], (limit||this.params.limit), (offset||this.params.offset), (domain||[]), (this.params.thread_level > 0), (this.sorted_comments['root_ids'])]); $.when(defer).then(function (records) { if (records.length < self.params.limit) self.display_show_more = false; self.display_comments(records); @@ -363,6 +364,7 @@ openerp.mail = function(session) { }, set_value: function() { + console.log('set_value'); var self = this; this._super.apply(this, arguments); this.see_sub = 0; @@ -542,8 +544,8 @@ openerp.mail = function(session) { */ fetch_comments: function (domain, context, offset, limit) { var self = this; - var load_res = this.ds_thread.call('get_pushed_messages', - [[this.session.uid], limit = (limit || 2), offset = (offset || 0), domain = (domain || []), context = (context || null) ]).then(function (records) { + var load_res = this.ds_thread.call('get_pushed_messages', + [[this.session.uid], (limit || 2), (offset || 0), (domain || []), true, [false], (context || null)]).then(function (records) { if (records.length < self.params.limit) self.display_show_more = false; self.display_comments(records); if (! self.display_show_more) { From d8661ec4dbd9817ab1feaaee1435d78ba9a6d8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 7 Mar 2012 14:21:29 +0100 Subject: [PATCH 10/17] [IMP] Wall widget: lessened sub-thread padding; slighty improved html organisation of subthreads bzr revid: tde@openerp.com-20120307132129-2jlza2crsncsnhmf --- addons/mail/static/src/css/mail.css | 2 +- addons/mail/static/src/js/mail.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index f8fef969475..91fda693193 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -92,7 +92,7 @@ } .oe_mail_thread_subthread { - padding-left: 25%; + padding-left: 5%; } .oe_mail_thread_more { diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 78cfaa5f974..1372ccc3803 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -137,7 +137,7 @@ openerp.mail = function(session) { self.display_comment(record); self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid, 'records': sub_msgs, 'thread_level': (self.params.thread_level-1), 'parent_id': record.id}); - self.$element.find('div.oe_mail_thread_msg:last').append('
'); + self.$element.find('div.oe_mail_thread_display:last').append('
'); self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last')); } else if (self.params.thread_level == 0) { From c612cd1c1c92073b7b460bdd6f756152e86f2689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 7 Mar 2012 14:25:20 +0100 Subject: [PATCH 11/17] [IMP] Wall widget: added thread_level parameter, now not hardcoded anymore bzr revid: tde@openerp.com-20120307132520-so3e50dmewoksr5s --- addons/mail/static/src/js/mail.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 1372ccc3803..fd282a953d6 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -455,6 +455,7 @@ openerp.mail = function(session) { this.params = params || {}; this.params.limit = params.limit || 2; this.params.search_view_id = params.search_view_id || false; + this.params.thread_level = params.thread_level || 1; this.params.search = {}; this.params.domain = []; this.sorted_comments = {'models': {}}; @@ -571,7 +572,7 @@ openerp.mail = function(session) { $('
').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': 2} + 'parent_id': false, 'thread_level': self.params.thread_level} ); thread.appendTo(self.$element.find('div.oe_mail_wall_thread_content:last')); }); From f75a3e90557fc5a8a20a59e3941bce06d5f84bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 7 Mar 2012 14:29:08 +0100 Subject: [PATCH 12/17] [IMP] Thread widget: comment and 'load more' are not displayed in threaded view, except for last level bzr revid: tde@openerp.com-20120307132908-xj6y92lo3a2ec2sf --- addons/mail/static/src/js/mail.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index fd282a953d6..f85707348f8 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -59,8 +59,10 @@ openerp.mail = function(session) { start: function() { var self = this; this._super.apply(this, arguments); - /* events */ + /* display customization and events */ this.$element.find('p.oe_mail_p_nomore').hide(); + if (this.params.thread_level > 0) this.$element.find('div.oe_mail_thread_act').hide(); + if (this.params.thread_level > 0) this.$element.find('div.oe_mail_thread_more').hide(); this.$element.find('button.oe_mail_button_comment').bind('click', function () { self.do_comment(); }); this.$element.find('button.oe_mail_button_more').bind('click', function () { self.do_more(); }); this.$element.find('div.oe_mail_thread_display').delegate('a.intlink', 'click', function (event) { From 366c08ae12a18c973ebdb27f1aa7441275bc542f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 7 Mar 2012 14:43:06 +0100 Subject: [PATCH 13/17] [FIX] Added parent_id when creating a message. bzr revid: tde@openerp.com-20120307134306-3fytcftoh0acdjv1 --- addons/mail/mail_thread.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 489f73f23da..fcbb009615e 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -216,6 +216,7 @@ class mail_thread(osv.osv): data = { 'subject': subject, 'user_id': uid, + 'parent_id': parent_id, 'model' : thread._name, 'partner_id': partner_id, 'res_id': thread.id, @@ -606,7 +607,7 @@ class mail_thread(osv.osv): #------------------------------------------------------ def message_append_note(self, cr, uid, ids, subject, body, parent_id=False, type='notification', need_action_user_id=False, context=None): - return self.message_append(cr, uid, ids, subject, body_text=body, parent_id=False, type=type, need_action_user_id=need_action_user_id, context=context) + return self.message_append(cr, uid, ids, subject, body_text=body, parent_id=parent_id, type=type, need_action_user_id=need_action_user_id, context=context) # old log overrided method: now calls message_append_note def log(self, cr, uid, id, message, secondary=False, context=None): From b347c3aa517d1e7d83c11a498543a2f0f18744b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 7 Mar 2012 14:44:09 +0100 Subject: [PATCH 14/17] [FIX] Thread widget: when commenting a comment, the correct domain is added when refectching comments; otherwise wrong messages were fetched. bzr revid: tde@openerp.com-20120307134409-iub2fmt1r3mkmgtq --- addons/mail/static/src/js/mail.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index f85707348f8..8bad0287bc2 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -98,7 +98,9 @@ openerp.mail = function(session) { this.params.offset = 0; this.sorted_comments = {'root_ids': [], 'root_id_msg_list': {}}; this.$element.find('div.oe_mail_thread_display').empty(); - return this.fetch_comments(this.params.limit, this.params.offset).then(); + domain = this.get_fetch_domain(this.sorted_comments); + console.log(domain); + return this.fetch_comments(this.params.limit, this.params.offset, domain).then(); }, fetch_comments: function (limit, offset, domain) { @@ -225,10 +227,9 @@ openerp.mail = function(session) { do_comment: function () { var body_text = this.$element.find('textarea').val(); - console.log(body_text + '-' + this.params.parent_id); - return true; - //return this.ds.call('message_append_note', [[this.params.res_id], 'Reply comment', body_text, parent_id=this.params.parent_id, type='comment']).then( - //this.proxy('init_comments')); + //console.log(body_text + '-' + this.params.parent_id + '-' + this.params.res_id); + return this.ds.call('message_append_note', [[this.params.res_id], 'Reply comment', body_text, this.params.parent_id, 'comment']).then( + this.proxy('init_comments')); }, /** From 6ce4a48ce9aade35c6574da9383f52414fb4ea6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 8 Mar 2012 11:40:55 +0100 Subject: [PATCH 15/17] [CLEAN] Cleaned a bit of unecessary xml/css bzr revid: tde@openerp.com-20120308104055-knvdgvj4a2z0k5fd --- addons/mail/static/src/css/mail.css | 5 +---- addons/mail/static/src/js/mail.js | 2 +- addons/mail/static/src/xml/mail.xml | 2 -- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 91fda693193..dd79e82a2a1 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -23,10 +23,7 @@ width: 34%; } -.oe_mail_wall_thread_content { -} - -.oe_mail_wall_thread_content div.oe_mail_thread_act .oe_mail_action_textarea { +.oe_mail_wall_thread div.oe_mail_thread_act .oe_mail_action_textarea { width: 100%; height: 20px; padding: 2px; diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8bad0287bc2..2f4b24ce087 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -577,7 +577,7 @@ openerp.mail = function(session) { '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} ); - thread.appendTo(self.$element.find('div.oe_mail_wall_thread_content:last')); + 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 a51921dfc46..5b4812129e5 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -23,8 +23,6 @@
-
-
From 63a16e70748d3bb960199dd82029c625c18147a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 8 Mar 2012 12:24:45 +0100 Subject: [PATCH 16/17] [ADD] mail.thread: added automatic forward of message when @login is present in body. Also fixed a bug when posting a comment from the wall. bzr revid: tde@openerp.com-20120308112445-ndv0b1x82kv2uanp --- addons/mail/mail_thread.py | 13 +++++++++---- addons/mail/static/src/css/mail.css | 7 ++++++- addons/mail/static/src/js/mail.js | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index fcbb009615e..5949ef6bbee 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -25,6 +25,7 @@ import base64 import email from email.utils import parsedate +import re import logging import xmlrpclib from osv import osv, fields @@ -119,15 +120,19 @@ class mail_thread(osv.osv): notification_obj.create(cr, uid, {'user_id': vals['need_action_user_id'], 'message_id': msg_id}, context=context) # parse message to get requested users - user_ids = self.message_parse_users(cr, uid, [msg_id], 'body_text', context=context) + user_ids = self.message_parse_users(cr, uid, [msg_id], vals['body_text'], context=context) for user_id in user_ids: + print 'pushed to %d' % (user_id) notification_obj.create(cr, uid, {'user_id': user_id, 'message_id': msg_id}, context=context) return msg_id - def message_parse_users(self, cr, uid, ids, field_name='body_text', context=None): - '''Parse message content; if find @login: returns the related id''' - user_ids = [] + def message_parse_users(self, cr, uid, ids, string, context=None): + '''Parse message content; if find @login -(^|\s)@(\w*)-: returns the related ids''' + regex = re.compile('(^|\s)@(\w*)') + login_lst = [item[1] for item in regex.findall(string)] + if not login_lst: return [] + user_ids = self.pool.get('res.users').search(cr, uid, [('login', 'in', login_lst)], context=context) return user_ids def message_capable_models(self, cr, uid, context=None): diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index dd79e82a2a1..1a0f433cbd0 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -82,7 +82,12 @@ .oe_mail_thread { } -.oe_mail_thread_display, .oe_mail_thread_act { +.oe_mail_thread_act { + white-space: normal; + margin-bottom: 5px; +} + +.oe_mail_thread_display { white-space: normal; margin-bottom: 5px; border-bottom: 1px solid #D2D9E7; diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2f4b24ce087..8adf116b964 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -667,7 +667,7 @@ openerp.mail = function(session) { */ do_comment: function () { var body_text = this.$element.find('textarea.oe_mail_wall_action_textarea').val(); - return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, type='comment']).then(this.init_comments()); + return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment']).then(this.init_comments()); }, /** From 0f18e4cf20d9f3e4d212022f70139b55aa952a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 8 Mar 2012 17:41:38 +0100 Subject: [PATCH 17/17] [REF] Thread and Wall widgets: html/css refactoring, based on MIT first design. bzr revid: tde@openerp.com-20120308164138-lar56562dibp8q4s --- addons/mail/static/src/css/mail.css | 156 ++++++++++++++++++---------- addons/mail/static/src/js/mail.js | 23 ++-- addons/mail/static/src/xml/mail.xml | 35 +++---- 3 files changed, 128 insertions(+), 86 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 1a0f433cbd0..526ee7ceb42 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -4,8 +4,7 @@ .oe_mail_wall { overflow: auto; - padding: 5px 5px 5px 5px; - color: #4C4C4C; + padding: 5px; } .oe_mail_wall_search { @@ -24,11 +23,14 @@ } .oe_mail_wall_thread div.oe_mail_thread_act .oe_mail_action_textarea { - width: 100%; height: 20px; padding: 2px; } +.oe_mail_wall_more { + text-align: center; +} + /* ------------------------------ */ /* RecordThread */ /* ------------------------------ */ @@ -58,64 +60,71 @@ .oe_mail_recthread_right { float: right; - width: 35%; + width: 25%; + margin-right: 5%; } -.oe_mail_button_follow, .oe_mail_button_unfollow, .oe_mail_button_followers { +.oe_mail_button_follow, .oe_mail_button_unfollow { width: 120px; } -/* Subscribers */ -.oe_mail_followers_vignette { - float: left; - width: 20%%; +.oe_mail_button_followers { + display: inline; + width: 120px; } -.oe_mail_followers_vignette img { - width: 80%; +.oe_mail_followers h4 { + margin: 0 0 8px; } /* ------------------------------ */ /* ThreadDisplay */ /* ------------------------------ */ -.oe_mail_thread { -} - -.oe_mail_thread_act { +div.oe_mail_thread_act { white-space: normal; margin-bottom: 5px; } -.oe_mail_thread_display { +div.oe_mail_thread_display { white-space: normal; margin-bottom: 5px; - border-bottom: 1px solid #D2D9E7; } -.oe_mail_thread_subthread { +div.oe_mail_thread_subthread { + margin-top: 8px; padding-left: 5%; } -.oe_mail_thread_more { - margin-left: 20%; - margin-right: 40%; - border: 1px solid #D2D9E7; - text-align: center; +div.oe_mail_thread_more { + border-bottom: 1px solid #D2D9E7; } -.notification { +div.oe_mail_thread_msg { + padding: 4px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + -o-border-radius: 4px; + -ms-border-radius: 4px; + border-radius: 4px; +} + +div.notification { background: #E0E0E0; } -.email { +div.email { background: #E0E0E0; } -.oe_mail_thread_msg:after, .oe_mail_thread_act:after { - content: ""; - display: block; - clear: both; +div.oe_mail_thread_msg:after, div.oe_mail_thread_act:after { + content: ""; + display: block; + clear: both; +} + +.oe_mail_msg_content { + margin-left: 60px; } .oe_mail_button_comment { @@ -128,30 +137,21 @@ } .oe_mail_msg_image { - float: left; + margin-right: 8px; width: 45px; - height: 40px; + height: 45px; text-align: center; overflow: hidden; - -moz-border-radius: 3px; - -webkit-border-radius: 3px; - -o-border-radius: 3px; - -ms-border-radius: 3px; - border-radius: 3px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + -o-border-radius: 4px; + -ms-border-radius: 4px; + border-radius: 4px; -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); -o-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); -box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); -} - -.oe_mail_msg_image img { - width: 40px; - height: auto; - clip: rect(10px, 100px, 110px, 0px); -} - -.oe_mail_msg_content { - margin-left: 50px; + clip: rect(5px, 40px, 45px, 0px); } .oe_mail_msg_p { @@ -167,18 +167,64 @@ color: #4E43E7; } -.oe_mail_msg_author { - color: #747474; +/* ------------------------------ */ +/* Styling (should be openerp) */ +/* ------------------------------ */ + +input.oe_mail, textarea.oe_mail { + width: 100%; + padding: 4px; + font-size: 12px; + border: 1px solid #cccccc; + -webkit-transition: border linear 0.2s, box-shadow linear 0.2s; + -moz-transition: border linear 0.2s, box-shadow linear 0.2s; + -ms-transition: border linear 0.2s, box-shadow linear 0.2s; + -o-transition: border linear 0.2s, box-shadow linear 0.2s; + transition: border linear 0.2s, box-shadow linear 0.2s; + -moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); + -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); + -box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + border-radius: 3px; } -.oe_mail_msg_author a { - color: #4E43E7; +input.oe_mail:focus, textarea.oe_mail:focus { + outline: 0; + border-color: rgba(82, 168, 236, 0.8); + -moz-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6); + -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6); + -box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6); } -.oe_mail_msg_need_action, .oe_mail_msg_need_action a { +p.oe_mail_msg { + padding: 0; + margin: 0; +} + +.oe_mail_oe_right { + float: right; + margin-right: 8px; +} + +.oe_mail_oe_left { + float: left; + margin-right: 8px; +} + +.oe_mail_oe_fade { + font-size: 12px; + color: #888888; +} + +.oe_mail_oe_bold { + font-weight: bold; +} + +a.oe_mail_oe_intlink { + color: #8786b7; +} + +.oe_mail_oe_warning, .oe_mail_oe_warning a { color: #C03000; } - -.oe_mail_msg_date { - color: #747474; -} diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8adf116b964..d9f6c3472c4 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -221,8 +221,7 @@ openerp.mail = function(session) { }, display_current_user: function () { - return this.$element.find('div.oe_mail_msg_image').empty().html( - ''); + return this.$element.find('img.oe_mail_msg_image').attr('src', this.thread_get_avatar_mini('res.users', 'avatar_mini', this.params.uid)); }, do_comment: function () { @@ -281,7 +280,7 @@ openerp.mail = function(session) { var regex_res = regex_login.exec(string); while (regex_res != null) { var login = regex_res[2]; - string = string.replace(regex_res[0], '@' + login + ''); + string = string.replace(regex_res[0], '@' + login + ''); regex_res = regex_login.exec(string); } return string; @@ -345,7 +344,7 @@ openerp.mail = function(session) { init: function() { this.is_sub = 0; - this.see_sub = 0; + this.see_sub = 1; this._super.apply(this, arguments); this.thread = null; /* DataSets */ @@ -370,10 +369,9 @@ openerp.mail = function(session) { console.log('set_value'); var self = this; this._super.apply(this, arguments); - this.see_sub = 0; + this.see_sub = 1; /* hide follow/unfollow/see followers buttons */ - this.$element.find('button.oe_mail_button_followers').html('Display followers') - this.$element.find('div.oe_mail_followers_display').hide(); + 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(); if (! this.view.datarecord.id) { return; } @@ -397,12 +395,13 @@ openerp.mail = function(session) { }, display_subscribers: function (records) { - this.$element.find('div.oe_mail_followers_display').empty(); var self = this; + var sub_node = this.$element.find('div.oe_mail_followers') + sub_node.empty(); + $('

').html('Followers (' + records.length + ')').appendTo(sub_node); _(records).each(function (record) { - $('
').html( - '' + record.name + '' - ).appendTo(self.$element.find('div.oe_mail_followers_display')); + var mini_url = self.thread_get_avatar_mini('res.users', 'avatar_mini', record.id); + $('' + record.name + '').appendTo(sub_node); }); }, @@ -426,7 +425,7 @@ openerp.mail = function(session) { this.see_sub = 1 - this.see_sub; if (this.see_sub == 1) { this.$element.find('button.oe_mail_button_followers').html('Hide followers'); } else { this.$element.find('button.oe_mail_button_followers').html('Display followers'); } - this.$element.find('div.oe_mail_followers_display').toggle(); + this.$element.find('div.oe_mail_followers').toggle(); }, thread_get_avatar_mini: function(model, field, id) { diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 5b4812129e5..295d46b96ba 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -7,7 +7,7 @@
-
+
+