[MERGE] [IMP] chatter: improved 'Log a note'
authorThibault Delavallée <tde@openerp.com>
Mon, 25 Nov 2013 13:04:55 +0000 (14:04 +0100)
committerThibault Delavallée <tde@openerp.com>
Mon, 25 Nov 2013 13:04:55 +0000 (14:04 +0100)
- the button is now only displayed for employee users. This is done
by overriding the fields_view_get in mail.thread and adding options
to the widget according to the groups the user belongs to. Indeed
it is currently not possible to set widget options specific to
some groups. Therefore an override of fields view get was
necessary.
- small layout improvements: Log a note -> Log an internal note,
background color of notes updated.

bzr revid: tde@openerp.com-20131125130455-u8517iyr4jgdgoqn

1  2 
addons/mail/mail_thread.py
addons/mail/static/src/js/mail.js

@@@ -23,6 -23,6 +23,11 @@@ import base6
  import datetime
  import dateutil
  import email
++try:
++    import simplejson as json
++except ImportError:
++    import json
++from lxml import etree
  import logging
  import pytz
  import time
@@@ -306,6 -307,6 +311,28 @@@ class mail_thread(osv.AbstractModel)
                   "be inserted in kanban views."),
      }
  
++    def _get_user_chatter_options(self, cr, uid, context=None):
++        options = {
++            'display_log_button': False
++        }
++        group_ids = self.pool.get('res.users').browse(cr, uid, uid, context=context).groups_id
++        group_user_id = self.pool.get("ir.model.data").get_object_reference(cr, uid, 'base', 'group_user')[1]
++        is_employee = group_user_id in [group.id for group in group_ids]
++        if is_employee:
++            options['display_log_button'] = True
++        return options
++
++    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
++        res = super(mail_thread, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
++        if view_type == 'form':
++            doc = etree.XML(res['arch'])
++            for node in doc.xpath("//field[@name='message_ids']"):
++                options = json.loads(node.get('options', '{}'))
++                options.update(self._get_user_chatter_options(cr, uid, context=context))
++                node.set('options', json.dumps(options))
++            res['arch'] = etree.tostring(doc)
++        return res
++
      #------------------------------------------------------
      # CRUD overrides for automatic subscription and logging
      #------------------------------------------------------
@@@ -1800,15 -1801,17 +1800,17 @@@ openerp.mail = function (session) 
                  'read_action': 'unread',
                  'show_record_name': false,
                  'show_compact_message': 1,
 -                'display_log_button' : 1,
++                'display_log_button' : true,
              }, this.node.params);
              if (this.node.attrs.placeholder) {
                  this.node.params.compose_placeholder = this.node.attrs.placeholder;
              }
              if (this.node.attrs.readonly) {
                  this.node.params.readonly = this.node.attrs.readonly;
              }
 -            if (this.node.attrs.display_log_button){
 -                this.node.params.display_log_button = parseInt(this.node.attrs.display_log_button);
++            if ('display_log_button' in this.options) {
++                this.node.params.display_log_button = this.options.display_log_button;
+             }
              this.domain = this.node.params && this.node.params.domain || [];
  
              if (!this.ParentViewManager.is_action_enabled('edit')) {