diff options
| author | Thibault Delavallée <tde@openerp.com> | 2012-03-02 18:07:49 +0100 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2012-03-02 18:07:49 +0100 |
| commit | 5b2b9fb1abe76a0f1b0bb2c0231bca26e5ee218a (patch) | |
| tree | 38aec157c165b2abf49b4fc2b33f0668a0bac3e2 | |
| parent | 4847f720442c3fa6faefa60398d245c5814eb2c1 (diff) | |
[ADD] Added a thread model in display. Seems working but needs refactoring in the next few days.
bzr revid: tde@openerp.com-20120302170749-gaxx90sxy7bi97b3
| -rw-r--r-- | addons/mail/mail_message.py | 1 | ||||
| -rw-r--r-- | addons/mail/mail_message_view.xml | 6 | ||||
| -rw-r--r-- | addons/mail/mail_thread.py | 45 | ||||
| -rw-r--r-- | addons/mail/static/src/css/mail.css | 55 | ||||
| -rw-r--r-- | addons/mail/static/src/js/mail.js | 316 | ||||
| -rw-r--r-- | addons/mail/static/src/xml/mail.xml | 51 |
6 files changed, 324 insertions, 150 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 @@ <field name="subject"/> <field name="user_id"/> <field name="model"/> - <field name="res_id" invisible="1"/> + <field name="res_id"/> </tree> </field> </record> @@ -30,13 +30,14 @@ <field name="subject"/> <field name="date"/> <field name="type"/> - <field name="body_text"/> <field name="need_action_user_id"/> + <field name="body_text"/> </group> <group colspan="2" col="2"> <field name="user_id" string="User" readonly="0"/> <field name="model"/> <field name="res_id"/> + <field name="parent_id"/> </group> </form> </field> @@ -51,6 +52,7 @@ <search string="Tweet Search"> <field name="user_id"/> <field name="model"/> + <field name="date"/> </search> </field> </record> 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,30 +79,28 @@ 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_act { + white-space: normal; + margin-bottom: 5px; + border-bottom: 1px solid #D2D9E7; } -.oe_mail_thread_display { +.oe_mail_thread_subthread { + padding-left: 25%; } -.oe_mail_thread_msg, .oe_mail_thread_act { - width: 80%; - white-space: normal; - margin-bottom: 5px; - border-bottom: 1px solid #D2D9E7; +.oe_mail_thread_more { + margin-left: 20%; + margin-right: 40%; + border: 1px solid #D2D9E7; + text-align: center; } .notification { @@ -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')); + 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('<div class="oe_mail_thread_subthread"/>'); + self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last')); + self.bidouille = record; + self.sub_com = []; + } + + } - // 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(' <a href="#" class="reduce">[ ... Show less]</a>'); - self.$element.find('p.oe_mail_msg_p:last').append($('<span class="oe_mail_msg_body_short">' + record.tr_body_text + ' <a href="#" class="expand">[ ... Show more]</a></span>')); - 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; }); + 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('<div class="oe_mail_thread_subthread"/>'); + 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(' <a href="#" class="reduce">[ ... Show less]</a>'); + var node_body_short = this.$element.find('span.oe_mail_msg_body_short:last').append(' <a href="#" class="expand">[ ... Show more]</a>'); + 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 () { - $('<div>').html( - '<img src="' + this.thread_get_avatar_mini('res.users', 'avatar_mini', this.params.uid) + '"/>' - ).appendTo(this.$element.find('div.oe_mail_msg_image')); + return this.$element.find('div.oe_mail_msg_image').empty().html( + '<img src="' + this.thread_get_avatar_mini('res.users', 'avatar_mini', this.params.uid) + '"/>'); }, 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, }); $('<div class="oe_mail_wall_thread">').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 @@ <div class="oe_mail_wall_threads"> </div> <div class="oe_mail_wall_more"> - <button class="oe_mail_wall_button_more" type="button">See more discussions - </button> - </div> - <div class="oe_mail_wall_nomore"> - You have loaded all discussions. + <button class="oe_mail_wall_button_more" type="button">See more discussions</button> + <p class="oe_mail_wall_nomore">You have loaded all discussions.</p> </div> </div> <div class="oe_mail_wall_right"> @@ -33,11 +30,11 @@ </div> </t> - <div t-name="Thread" class="oe_mail_thread_main"> + <div t-name="RecordThread" class="oe_mail_recthread"> <div class="separator horizontal">OpenSocial</div> - <div class="oe_mail_thread_left"> + <div class="oe_mail_recthread_left"> </div> - <div class="oe_mail_thread_right"> + <div class="oe_mail_recthread_right"> <div class="oe_mail_actions"> <button type="button" class="oe_mail_button_follow">Follow</button> <button type="button" class="oe_mail_button_unfollow">Unfollow</button> @@ -52,22 +49,18 @@ </div> </div> - <div t-name="ThreadDisplay" class="oe_mail_thread"> + <div t-name="Thread" class="oe_mail_thread"> <div class="oe_mail_thread_act"> - <div class="oe_mail_msg_image"> - </div> + <div class="oe_mail_msg_image">User_image</div> <div class="oe_mail_msg_content"> <textarea class="oe_mail_action_textarea" onfocus="this.value='';">Enter your comment here...</textarea><br /> <button type="button" class="oe_mail_button_comment">Post comment</button> </div> </div> - <div class="oe_mail_thread_display"> - </div> + <div class="oe_mail_thread_display"></div> <div class="oe_mail_thread_more"> - <button class="oe_mail_button_more" type="button">More</button> - </div> - <div class="oe_mail_thread_nomore"> - You have loaded all messages in this thread. + <button class="oe_mail_button_more" type="button">Load more messages</button> + <p class="oe_mail_p_nomore">You have loaded all messages in this thread.</p> </div> </div> @@ -76,31 +69,25 @@ <img t-att-src="record.mini_url"/> </div> <div class="oe_mail_msg_content"> - <t t-if="record.type == 'email'"> - <t t-call="EmailDisplay" /> - </t> - <t t-if="record.type == 'notification' || record.type == 'comment'"> - <t t-call="NotificationDisplay" /> - </t> + <t t-if="record.type == 'email'"><t t-call="EmailDisplay" /></t> + <t t-if="record.type == 'notification' || record.type == 'comment'"><t t-call="NoteDisplay" /></t> </div> + <t t-if="record.type == 'tmp'"><t t-call="ThreadDisplay" /></t> </div> - <t t-name="NotificationDisplay"> + <t t-name="NoteDisplay"> <p class="oe_mail_msg_p"> - <t t-if="record.type == 'notification'"> - <span class="oe_mail_msg_author">OpenERP System Notification</span> - </t> - <t t-if="record.type == 'comment'"> - <span class="oe_mail_msg_author"> - <a href="#" data-res-model='res.users' t-attf-data-res-id='{record.user_id[0]}'><t t-raw="record.user_id[1]"/></a> - </span> - </t> + <span class="oe_mail_msg_author"> + <a href="#" class="intlink" data-res-model='res.users' t-attf-data-res-id='{record.user_id[0]}'><t t-raw="record.user_id[1]"/></a> + <t t-if="record.type == 'notification'">via OpenERP System Notification</t> + </span> <t t-if="record.need_action_user_id != false"> - <span class="oe_mail_msg_need_action">Need action by <a href="#"><t t-raw="record.need_action_user_id[1]"/></a></span> </t> wrote on <span class="oe_mail_msg_date"><t t-raw="record.date"/></span> <br /> <span class="oe_mail_msg_body"><t t-raw="record.body_text"/></span> + <t t-if="record.tr_body_text"><span class="oe_mail_msg_body_short"><t t-raw="record.tr_body_text"/></span></t> </p> </t> |
