[MERGE] merge trunk-social-tde branch.
bzr revid: bth@tinyerp.com-20120314052341-0dgmhlq8pc6s4tnl
This commit is contained in:
@@ -367,7 +367,7 @@ class hr_holidays(osv.osv):
|
||||
return result
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
sub_ids = self._message_get_subscribers_ids(cr, uid, ids, context=context);
|
||||
sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context);
|
||||
# add the employee and its manager if specified to the subscribed users
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.employee_id.parent_id:
|
||||
|
||||
+25
-19
@@ -2,7 +2,7 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2010-2011 OpenERP SA (<http://www.openerp.com>)
|
||||
# Copyright (C) 2010-today OpenERP SA (<http://www.openerp.com>)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -29,9 +29,9 @@ from PIL import Image
|
||||
|
||||
class mail_group(osv.osv):
|
||||
"""
|
||||
A mail_group is a collection of users sharing messages in a discussion group.
|
||||
Mail groups are different from user groups because they don't have a specific field holding users.
|
||||
Group users are users that follow the mail group, using the subscription/follow mechanism of OpenChatter.
|
||||
A mail_group is a collection of users sharing messages in a discussion
|
||||
group. Group users are users that follow the mail group, using the
|
||||
subscription/follow mechanism of OpenSocial.
|
||||
"""
|
||||
|
||||
_name = 'mail.group'
|
||||
@@ -42,26 +42,31 @@ class mail_group(osv.osv):
|
||||
|
||||
def action_group_leave(self, cr, uid, ids, context={}):
|
||||
return self.message_unsubscribe(cr, uid, ids, context=context);
|
||||
|
||||
def _get_photo_mini(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if not obj.photo:
|
||||
result[obj.id] = False
|
||||
continue
|
||||
|
||||
image_stream = io.BytesIO(obj.photo.decode('base64'))
|
||||
img = Image.open(image_stream)
|
||||
img.thumbnail((120, 100), Image.ANTIALIAS)
|
||||
img_stream = StringIO.StringIO()
|
||||
img.save(img_stream, "JPEG")
|
||||
result[obj.id] = img_stream.getvalue().encode('base64')
|
||||
return result
|
||||
def onchange_photo_mini(self, cr, uid, ids, value, context=None):
|
||||
return {'value': {'photo': value, 'photo_mini': self._photo_resize(cr, uid, value) } }
|
||||
|
||||
def _set_photo_mini(self, cr, uid, id, name, value, args, context=None):
|
||||
self.write(cr, uid, [id], {'photo': value}, context=context)
|
||||
return True
|
||||
|
||||
def _photo_resize(self, cr, uid, photo, context=None):
|
||||
image_stream = io.BytesIO(photo.decode('base64'))
|
||||
img = Image.open(image_stream)
|
||||
img.thumbnail((120, 100), Image.ANTIALIAS)
|
||||
img_stream = StringIO.StringIO()
|
||||
img.save(img_stream, "JPEG")
|
||||
return img_stream.getvalue().encode('base64')
|
||||
|
||||
def _get_photo_mini(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
for group in self.browse(cr, uid, ids, context=context):
|
||||
if not group.photo:
|
||||
result[group.id] = False
|
||||
else:
|
||||
result[group.id] = self._photo_resize(cr, uid, group.photo, context=context)
|
||||
return result
|
||||
|
||||
def is_subscriber(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
for id in ids:
|
||||
@@ -83,7 +88,7 @@ class mail_group(osv.osv):
|
||||
def get_members_nbr(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
for id in ids:
|
||||
result[id] = len(self._message_get_subscribers_ids(cr, uid, [id], context=context))
|
||||
result[id] = len(self.message_get_subscribers_ids(cr, uid, [id], context=context))
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
@@ -105,6 +110,7 @@ class mail_group(osv.osv):
|
||||
|
||||
_defaults = {
|
||||
'public': True,
|
||||
'responsible_id': (lambda s, cr, uid, ctx: uid),
|
||||
}
|
||||
|
||||
mail_group()
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
</group>
|
||||
<group colspan="1" col="2">
|
||||
<separator string="Group image" colspan="2"/>
|
||||
<field name="photo_mini" widget='image' nolabel="1"/>
|
||||
<field name="photo_mini" widget='image' nolabel="1" on_change="onchange_photo_mini(photo_mini)"/>
|
||||
</group>
|
||||
<group colspan="1" col="2">
|
||||
<separator string="Privacy settings" colspan="2"/>
|
||||
|
||||
+11
-21
@@ -2,7 +2,7 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2010-2011 OpenERP SA (<http://www.openerp.com>)
|
||||
# Copyright (C) 2010-today OpenERP SA (<http://www.openerp.com>)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -72,10 +72,10 @@ class mail_message_common(osv.osv_memory):
|
||||
_rec_name = 'subject'
|
||||
_columns = {
|
||||
'subject': fields.char('Subject', size=512, required=True),
|
||||
'model': fields.char('Related Document model', size=128, select=1), # was readonly
|
||||
'res_id': fields.integer('Related Document ID', select=1), # was readonly
|
||||
'model': fields.char('Related Document model', size=128, select=1),
|
||||
'res_id': fields.integer('Related Document ID', select=1),
|
||||
'date': fields.datetime('Date'),
|
||||
'email_from': fields.char('From', size=128, help='Message sender, taken from user preferences. If empty, this is not a mail but a message.'),
|
||||
'email_from': fields.char('From', size=128, help='Message sender, taken from user preferences.'),
|
||||
'email_to': fields.char('To', size=256, help='Message recipients'),
|
||||
'email_cc': fields.char('Cc', size=256, help='Carbon copy message recipients'),
|
||||
'email_bcc': fields.char('Bcc', size=256, help='Blind carbon copy message recipients'),
|
||||
@@ -89,16 +89,19 @@ class mail_message_common(osv.osv_memory):
|
||||
"select plaintext or rich text contents accordingly", readonly=1),
|
||||
'body_text': fields.text('Text contents', help="Plain-text version of the message"),
|
||||
'body_html': fields.text('Rich-text contents', help="Rich-text/HTML version of the message"),
|
||||
'parent_id': fields.many2one('mail.message', 'Parent message', help="Parent message, used for displaying as threads with hierarchy"),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'subtype': 'plain',
|
||||
'date': (lambda *a: datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')),
|
||||
'date': (lambda *a: fields.datetime.now()),
|
||||
}
|
||||
|
||||
class mail_message(osv.osv):
|
||||
'''Model holding RFC2822 email messages, and providing facilities
|
||||
to parse, queue and send new messages
|
||||
'''Model holding messages: system notification (replacing res.log
|
||||
notifications), comments (for OpenSocial feature) and
|
||||
RFC2822 email messages. This model also provides facilities to
|
||||
parse, queue and send new email messages.
|
||||
|
||||
Messages that do not have a value for the email_from column
|
||||
are simple log messages (e.g. document state changes), while
|
||||
@@ -178,31 +181,18 @@ class mail_message(osv.osv):
|
||||
], 'State', readonly=True),
|
||||
'auto_delete': fields.boolean('Auto Delete', help="Permanently delete this email after sending it, to save space"),
|
||||
'original': fields.binary('Original', help="Original version of the message, as it was sent on the network", readonly=1),
|
||||
# note feature: add type (email, comment, notification) and need_action
|
||||
'type': fields.selection([
|
||||
('email', 'e-mail'),
|
||||
('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"),
|
||||
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'state': 'received',
|
||||
'type': 'comment',
|
||||
}
|
||||
|
||||
#------------------------------------------------------
|
||||
# Generic api
|
||||
#------------------------------------------------------
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
# temporary log directly created messages (to debug OpenSocial)
|
||||
if not 'mail.thread' in context:
|
||||
_logger.warning('Creating message without using mail.thread API')
|
||||
_logger.warning('Message details: %s', str(vals))
|
||||
msg_id = super(mail_message, self).create(cr, uid, vals, context)
|
||||
return msg_id
|
||||
|
||||
#------------------------------------------------------
|
||||
# E-Mail api
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<field name="name">mail.message.tree.short</field>
|
||||
<field name="model">mail.message</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="sequence">15</field>
|
||||
<field name="priority">20</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Messages">
|
||||
<field name="date"/>
|
||||
@@ -23,7 +23,7 @@
|
||||
<field name="name">mail.message.form.short</field>
|
||||
<field name="model">mail.message</field>
|
||||
<field name="type">form</field>
|
||||
<field name="sequence">15</field>
|
||||
<field name="priority">20</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Message">
|
||||
<group colspan="2" col="2">
|
||||
@@ -47,6 +47,7 @@
|
||||
<field name="name">mail.message.search.short</field>
|
||||
<field name="model">mail.message</field>
|
||||
<field name="type">search</field>
|
||||
<field name="priority">20</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Messages Search">
|
||||
<field name="user_id"/>
|
||||
@@ -210,7 +211,7 @@
|
||||
action="action_view_mail_message" />
|
||||
|
||||
<record id="action_mail_all_feeds" model="ir.actions.client">
|
||||
<field name="name">(w)All Feeds</field>
|
||||
<field name="name">All Feeds</field>
|
||||
<field name="tag">mail.all_feeds</field>
|
||||
<field name="params" eval="{'search_view_id': ref('view_message_search_short')}"/>
|
||||
</record>
|
||||
@@ -218,7 +219,7 @@
|
||||
<record id="action_mail_my_feeds" model="ir.actions.client">
|
||||
<field name="name">My Feeds</field>
|
||||
<field name="tag">mail.all_feeds</field>
|
||||
<field name="params" eval="{'search_view_id': ref('view_message_search_short')}"/>
|
||||
<field name="params" eval="{'search_view_id': ref('view_message_search_short'), 'my_feeds': True}"/>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2010-2011 OpenERP SA (<http://www.openerp.com>)
|
||||
# Copyright (C) 2009-today OpenERP SA (<http://www.openerp.com>)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -19,49 +19,44 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import tools
|
||||
from osv import osv
|
||||
from osv import fields
|
||||
from tools.translate import _
|
||||
|
||||
class mail_subscription(osv.osv):
|
||||
"""
|
||||
mail_subscription holds the data related to the follow mechanism inside OpenERP.
|
||||
A subscription can be of following:
|
||||
A subscription is characterized by:
|
||||
- res_model: model of the followed objects
|
||||
- res_id: ID of resource OR
|
||||
- res_domain: a domain filtering followed objects - currently removed
|
||||
- res_id: ID of resource (may be 0 for every objects)
|
||||
"""
|
||||
_name = 'mail.subscription'
|
||||
_rec_name = 'id'
|
||||
_order = 'res_model asc'
|
||||
_columns = {
|
||||
'res_model': fields.char('Related Document Model', size=128,
|
||||
select=1, required=True),
|
||||
'res_id': fields.integer('Related Document ID', select=1),
|
||||
#'res_domain': fields.char('res_domain', size=256),
|
||||
'user_id': fields.many2one('res.users', string='Related User ID',
|
||||
ondelete='cascade', required=True, select=1),
|
||||
}
|
||||
_defaults = {
|
||||
}
|
||||
mail_subscription()
|
||||
|
||||
class mail_notification(osv.osv):
|
||||
"""
|
||||
TODO
|
||||
mail_notification is a relational table modeling messages pushed to users.
|
||||
- read: todo
|
||||
"""
|
||||
_name = 'mail.notification'
|
||||
_rec_name = 'id'
|
||||
_log_access = False
|
||||
_order = 'message_id desc'
|
||||
_columns = {
|
||||
'user_id': fields.many2one('res.users', string='User',
|
||||
ondelete='cascade', required=True, select=1),
|
||||
'message_id': fields.many2one('mail.message', string='Message',
|
||||
ondelete='cascade', required=True),
|
||||
ondelete='cascade', required=True, select=1),
|
||||
'read': fields.boolean('Read'),
|
||||
# TODO: add a timestamp ? or use message date ?
|
||||
}
|
||||
_defaults = {
|
||||
'read': False,
|
||||
}
|
||||
mail_notification()
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
<field name="sequence">10</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Subscription">
|
||||
<field name="user_id"/>
|
||||
<field name="res_model"/>
|
||||
<field name="res_id"/>
|
||||
<field name="user_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -53,4 +53,4 @@
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</openerp>
|
||||
|
||||
+63
-57
@@ -2,7 +2,7 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2009-Today OpenERP SA (<http://www.openerp.com>)
|
||||
# Copyright (C) 2009-today OpenERP SA (<http://www.openerp.com>)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -41,16 +41,23 @@ class mail_thread(osv.osv):
|
||||
name collisions with methods of the models that will inherit
|
||||
from this mixin.
|
||||
|
||||
``mail.thread`` adds a one2many of mail.messages, acting as the
|
||||
thread's history, and a few methods that may be overridden to
|
||||
implement model-specific behavior upon arrival of new messages.
|
||||
``mail.thread`` is designed to work without adding any field
|
||||
to the extended models. All functionalities and expected behavior
|
||||
are managed by mail.thread, using model name and record ids.
|
||||
A widget has been designed for the 6.1 and following version of OpenERP
|
||||
web-client. However, due to technical limitations, ``mail.thread``
|
||||
adds a simulated one2many field, to display the web widget by
|
||||
overriding the default field displayed. Using this field
|
||||
is not recommanded has it will disappeear in future version
|
||||
of OpenERP, leading to a pure mixin class.
|
||||
|
||||
Inheriting classes are not required to implement any method, as the
|
||||
default implementation will work for any model. However it is common
|
||||
to override at least the ``message_new`` and ``message_update``
|
||||
methods (calling ``super``) to add model-specific behavior at
|
||||
creation and update of a thread.
|
||||
|
||||
creation and update of a thread; and ``message_get_subscribers``
|
||||
to manage more precisely the social aspect of the thread through
|
||||
the followers.
|
||||
'''
|
||||
_name = 'mail.thread'
|
||||
_description = 'Email Thread'
|
||||
@@ -63,12 +70,10 @@ class mail_thread(osv.osv):
|
||||
res[thread.id] = [obj['id'] for obj in records]
|
||||
return res
|
||||
|
||||
# OpenSocial: removed message_ids and copy method, this will be replaced by message_load
|
||||
# OpenSocial: message_ids_social is a dummy field that should not be used
|
||||
_columns = {
|
||||
'message_ids_social': fields.function(_get_message_ids, method=True,
|
||||
type='one2many', obj='mail.message', string='Temp messages',
|
||||
),
|
||||
#widget='mail.ThreadView'),
|
||||
type='one2many', obj='mail.message', string='Temp messages'),
|
||||
}
|
||||
|
||||
#------------------------------------------------------
|
||||
@@ -86,6 +91,28 @@ class mail_thread(osv.osv):
|
||||
self.message_subscribe(cr, uid, ids, [uid], context=context)
|
||||
return write_res;
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
"""Override unlink, to automatically delete
|
||||
- subscriptions
|
||||
- messages
|
||||
that are linked with res_model and res_id, not through
|
||||
a foreign key with a 'cascade' ondelete attribute.
|
||||
Notifications will be deleted with messages
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
subscr_obj = self.pool.get('mail.subscription')
|
||||
msg_obj = self.pool.get('mail.message')
|
||||
|
||||
subscr_to_del_ids = subscr_obj.search(cr, uid, [('res_model', '=', self._name), ('res_id', 'in', ids)], context=context)
|
||||
subscr_obj.unlink(cr, uid, subscr_to_del_ids, context=context)
|
||||
|
||||
msg_to_del_ids = msg_obj.search(cr, uid, [('model', '=', self._name), ('res_id', 'in', ids)], context=context)
|
||||
msg_obj.unlink(cr, uid, msg_to_del_ids, context=context)
|
||||
|
||||
super(mail_thread, self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
#------------------------------------------------------
|
||||
# Generic message api
|
||||
#------------------------------------------------------
|
||||
@@ -98,34 +125,31 @@ class mail_thread(osv.osv):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
need_action_pushed = False
|
||||
user_to_push_ids = []
|
||||
subscription_obj = self.pool.get('mail.subscription')
|
||||
notification_obj = self.pool.get('mail.notification')
|
||||
|
||||
need_action_pushed = False
|
||||
|
||||
# create message
|
||||
msg_id = self.pool.get('mail.message').create(cr, uid, vals, context=context)
|
||||
obj = self.browse(cr, uid, [thread_id], context=context)[0]
|
||||
thread_obj = self.browse(cr, uid, [thread_id], context=context)[0]
|
||||
|
||||
# automatically subscribe the writer of the message if not subscribed
|
||||
if vals['user_id']:
|
||||
if not self.message_is_subscriber(cr, uid, [thread_id], context=context):
|
||||
self.message_subscribe(cr, uid, [thread_id], context=context)
|
||||
if vals['user_id'] and not self.message_is_subscriber(cr, vals['user_id'], [thread_id], context=context):
|
||||
self.message_subscribe(cr, uid, [thread_id], [vals['user_id']], context=context)
|
||||
|
||||
# push the message to suscribed users
|
||||
users = self.message_get_subscribers(cr, uid, [thread_id], context=context)
|
||||
for user in users:
|
||||
notification_obj.create(cr, uid, {'user_id': user['id'], 'message_id': msg_id}, context=context)
|
||||
# push to need_action_user_id
|
||||
if obj.need_action_user_id == user['id']: need_action_pushed = True
|
||||
# push to need_action_user_id if user does not follow the object
|
||||
if obj.need_action_user_id and not need_action_pushed:
|
||||
notification_obj.create(cr, uid, {'user_id': obj.need_action_user_id.id, 'message_id': msg_id}, context=context)
|
||||
|
||||
user_to_push_ids += [user['id'] for user in users]
|
||||
# parse message to get requested users
|
||||
user_ids = self.message_parse_users(cr, uid, [msg_id], vals['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)
|
||||
user_to_push_ids += self.message_parse_users(cr, uid, [msg_id], vals['body_text'], context=context)
|
||||
# push to need_action_user_id if set
|
||||
if thread_obj.need_action_user_id and thread_obj.need_action_user_id.id not in user_to_push_ids:
|
||||
user_to_push_ids.append(thread_obj.need_action_user_id.id)
|
||||
|
||||
# effectively push message to users
|
||||
for id in user_to_push_ids:
|
||||
notification_obj.create(cr, uid, {'user_id': id, 'message_id': msg_id}, context=context)
|
||||
|
||||
return msg_id
|
||||
|
||||
@@ -261,8 +285,6 @@ class mail_thread(osv.osv):
|
||||
'reply_to': reply_to,
|
||||
'original': original,
|
||||
}
|
||||
#mail_message.create(cr, uid, data, context=context)
|
||||
context['mail.thread'] = True
|
||||
self.message_create(cr, uid, thread.id, data, context=context)
|
||||
return True
|
||||
|
||||
@@ -282,7 +304,7 @@ class mail_thread(osv.osv):
|
||||
to determine the model of the thread to
|
||||
update (instead of the current model).
|
||||
"""
|
||||
# 6.2 OpenSocial feature: add default email type for old API
|
||||
# OpenSocial: add default email type for old API
|
||||
if not 'type' in msg_dict: msg_dict['type'] = 'email'
|
||||
return self.message_append(cr, uid, ids,
|
||||
subject = msg_dict.get('subject'),
|
||||
@@ -307,7 +329,8 @@ class mail_thread(osv.osv):
|
||||
|
||||
# Message loading
|
||||
def _message_get_parent_ids(self, cr, uid, ids, child_ids, root_ids, context=None):
|
||||
if context is None: context = {}
|
||||
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]
|
||||
@@ -325,7 +348,8 @@ class mail_thread(osv.osv):
|
||||
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 = {}
|
||||
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)
|
||||
@@ -365,17 +389,13 @@ class mail_thread(osv.osv):
|
||||
|
||||
# Message tools
|
||||
def message_get_discussions_nbr(self, cr, uid, ids, context=None):
|
||||
count = 0
|
||||
message_obj = self.pool.get('mail.message')
|
||||
for id in ids:
|
||||
count += message_obj.search(cr, uid, [('model', '=', self._name), ('res_id', '=', id)], count=True) # TODO: add parent_id when merging branch
|
||||
count = message_obj.search(cr, uid, [('model', '=', self._name), ('res_id', '=', ids), ('parent_id', '=', False)], count=True)
|
||||
return count
|
||||
|
||||
def message_get_messages_nbr(self, cr, uid, ids, context=None):
|
||||
count = 0
|
||||
message_obj = self.pool.get('mail.message')
|
||||
for id in ids:
|
||||
count += message_obj.search(cr, uid, [('model', '=', self._name), ('res_id', '=', id)], count=True)
|
||||
count = message_obj.search(cr, uid, [('model', '=', self._name), ('res_id', 'in', ids)], count=True)
|
||||
return count
|
||||
|
||||
#------------------------------------------------------
|
||||
@@ -628,32 +648,18 @@ class mail_thread(osv.osv):
|
||||
def message_append_note(self, cr, uid, ids, subject, body, parent_id=False, type='notification', context=None):
|
||||
return self.message_append(cr, uid, ids, subject, body_text=body, parent_id=parent_id, type=type, context=context)
|
||||
|
||||
# old log overrided method: now calls message_append_note
|
||||
def log(self, cr, uid, id, message, secondary=False, context=None):
|
||||
""" OpenSocial add: new res_log implementation
|
||||
A res.log is now a mail.message, as all messages in OpenERP
|
||||
It has a notification type.
|
||||
It can have a need_action flag attached if an user
|
||||
has to perform a given action.
|
||||
See mail.message, mail.subscription and mail.notification for more details.
|
||||
"""
|
||||
if context and context.get('disable_log'):
|
||||
#return True # old behavior
|
||||
print 'Log diabled, but we do not care currently about that. We want you to have our logs !'
|
||||
#return self.message_append_note(cr, uid, [id], 'System notification', message, context=context)
|
||||
|
||||
#------------------------------------------------------
|
||||
# Subscription mechanism
|
||||
#------------------------------------------------------
|
||||
|
||||
def _message_get_subscribers_ids(self, cr, uid, ids, context=None):
|
||||
subscription_obj = self.pool.get('mail.subscription')
|
||||
sub_ids = subscription_obj.search(cr, uid, ['&', ('res_model', '=', self._name), ('res_id', 'in', ids)], context=context)
|
||||
subs = subscription_obj.read(cr, uid, sub_ids, context=context)
|
||||
def message_get_subscribers_ids(self, cr, uid, ids, context=None):
|
||||
subscr_obj = self.pool.get('mail.subscription')
|
||||
subscr_ids = subscr_obj.search(cr, uid, ['&', ('res_model', '=', self._name), ('res_id', 'in', ids)], context=context)
|
||||
subs = subscr_obj.read(cr, uid, subscr_ids, context=context)
|
||||
return [sub['user_id'][0] for sub in subs]
|
||||
|
||||
def message_get_subscribers(self, cr, uid, ids, context=None):
|
||||
user_ids = self._message_get_subscribers_ids(cr, uid, ids, context=context)
|
||||
user_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context)
|
||||
users = self.pool.get('res.users').read(cr, uid, user_ids, fields=['id', 'name', 'avatar_mini'], context=context)
|
||||
return users
|
||||
|
||||
|
||||
@@ -10,16 +10,16 @@
|
||||
|
||||
<!-- left-side menu: Feeds !-->
|
||||
<menuitem id="mail_feeds" name="Feeds" parent="mail_feeds_main"/>
|
||||
<record id="mail_myfeeds" model="ir.ui.menu">
|
||||
<field name="name">My Feeds</field>
|
||||
<record id="mail_wallfeeds" model="ir.ui.menu">
|
||||
<field name="name">All Feeds</field>
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="action" ref="action_mail_my_feeds"/>
|
||||
<field name="action" ref="action_mail_all_feeds"/>
|
||||
<field name="parent_id" ref="mail_feeds"/>
|
||||
</record>
|
||||
<record id="mail_wallfeeds" model="ir.ui.menu">
|
||||
<field name="name">(w)All Feeds</field>
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="action" ref="action_mail_all_feeds"/>
|
||||
<record id="mail_myfeeds" model="ir.ui.menu">
|
||||
<field name="name">My Feeds</field>
|
||||
<field name="sequence" eval="11"/>
|
||||
<field name="action" ref="action_mail_my_feeds"/>
|
||||
<field name="parent_id" ref="mail_feeds"/>
|
||||
</record>
|
||||
<!-- left-side menu: Tmp !-->
|
||||
|
||||
@@ -50,11 +50,12 @@ openerp.mail = function(session) {
|
||||
/* DataSets and internal vars */
|
||||
this.ds = new session.web.DataSet(this, this.params.res_model);
|
||||
this.ds_users = new session.web.DataSet(this, 'res.users');
|
||||
this.ds_msg = new session.web.DataSet(this, 'mail.message');
|
||||
this.name = 'Unknown record'
|
||||
this.sorted_comments = {'root_ids': [], 'root_id_msg_list': {}};
|
||||
/* Display vars */
|
||||
this.display = {};
|
||||
this.display.show_post_comment = false;
|
||||
this.display.show_post_comment = this.params.show_post_comment || false;
|
||||
this.display.show_reply = (this.params.thread_level > 0);
|
||||
this.display.show_delete = true;
|
||||
this.display.show_hide = true;
|
||||
@@ -76,10 +77,10 @@ openerp.mail = function(session) {
|
||||
if (event.shiftKey && charCode == 13) { this.value = this.value+"\n"; }
|
||||
else if (charCode == 13) { self.do_comment(); }
|
||||
});
|
||||
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_reply', 'click', function (event) {
|
||||
var act_dom = $(this).parents('div.oe_mail_thread_display').find('div.oe_mail_thread_act:first');
|
||||
act_dom.toggle();
|
||||
});
|
||||
|
||||
// add event
|
||||
this.add_events();
|
||||
|
||||
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;
|
||||
@@ -109,6 +110,23 @@ openerp.mail = function(session) {
|
||||
return display_done
|
||||
},
|
||||
|
||||
add_events: function() {
|
||||
var self = this;
|
||||
// event: click on 'reply'
|
||||
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_reply', 'click', function (event) {
|
||||
var act_dom = $(this).parents('div.oe_mail_thread_display').find('div.oe_mail_thread_act:first');
|
||||
act_dom.toggle();
|
||||
});
|
||||
// event: click on 'delete'
|
||||
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_delete', 'click', function (event) {
|
||||
console.log('deleting');
|
||||
var msg_id = event.srcElement.dataset.id;
|
||||
if (! msg_id) return false;
|
||||
self.ds_msg.unlink([parseInt(msg_id)]).then();
|
||||
return false;
|
||||
});
|
||||
},
|
||||
|
||||
stop: function () {
|
||||
//this._super.apply(this, arguments);
|
||||
},
|
||||
@@ -377,9 +395,11 @@ openerp.mail = function(session) {
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
/* bind and hide buttons */
|
||||
self.$element.find('button.oe_mail_button_followers').bind('click', function () { self.do_toggle_followers(); });
|
||||
self.$element.find('button.oe_mail_button_follow').bind('click', function () { self.do_follow(); }).hide();
|
||||
self.$element.find('button.oe_mail_button_unfollow').bind('click', function () { self.do_unfollow(); }).hide();
|
||||
self.$element.find('button.oe_mail_button_followers').bind('click', function () { self.do_toggle_followers(); }).hide();
|
||||
self.$element.find('button.oe_mail_button_follow').click(function () { self.do_follow(); }).hide()
|
||||
.mouseover(function () { $(this).html('Follow'); }).mouseleave(function () { $(this).html('Not following'); });
|
||||
self.$element.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); }).hide()
|
||||
.mouseover(function () { $(this).html('Unfollow'); }).mouseleave(function () { $(this).html('Following'); });
|
||||
},
|
||||
|
||||
stop: function () {
|
||||
@@ -387,7 +407,6 @@ openerp.mail = function(session) {
|
||||
},
|
||||
|
||||
set_value: function() {
|
||||
console.log('set_value');
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
this.see_sub = 1;
|
||||
@@ -406,7 +425,7 @@ openerp.mail = function(session) {
|
||||
/* 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 = new mail.Thread(this, {'res_model': this.view.model, 'res_id': this.view.datarecord.id, 'uid': this.session.uid, 'show_post_comment': true});
|
||||
this.thread.appendTo(this.$element.find('div.oe_mail_recthread_left'));
|
||||
return fetch_fol_done && fetch_sub_done;
|
||||
},
|
||||
@@ -428,12 +447,12 @@ openerp.mail = function(session) {
|
||||
|
||||
do_follow: function () {
|
||||
this.do_toggle_follow();
|
||||
return this.ds.call('message_subscribe', [[this.view.datarecord.id]]).when();
|
||||
return this.ds.call('message_subscribe', [[this.view.datarecord.id]]).then(this.proxy('fetch_subscribers'));
|
||||
},
|
||||
|
||||
do_unfollow: function () {
|
||||
this.do_toggle_follow();
|
||||
return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).when();
|
||||
return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).then(this.proxy('fetch_subscribers'));
|
||||
},
|
||||
|
||||
do_toggle_follow: function () {
|
||||
@@ -450,9 +469,7 @@ openerp.mail = function(session) {
|
||||
},
|
||||
|
||||
thread_get_avatar_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 || '');
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
</div>
|
||||
<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>
|
||||
<button type="button" class="oe_mail_button_follow">Not following</button>
|
||||
<button type="button" class="oe_mail_button_unfollow">Following</button>
|
||||
<button type="button" class="oe_mail_button_followers">Display followers</button>
|
||||
</div>
|
||||
<div class="oe_mail_followers">
|
||||
@@ -77,8 +77,8 @@
|
||||
on <t t-raw="record.date"/>
|
||||
</span>
|
||||
<t t-if="display.show_reply"><span class="oe_mail_oe_space"><a href="#" class="oe_mail_msg_reply">Reply</a></span></t>
|
||||
<t t-if="display.show_delete"><span class="oe_mail_oe_space"><a href="#" class="oe_mail_msg_delete">Delete</a></span></t>
|
||||
<t t-if="display.show_hide"><span class="oe_mail_oe_space"><a href="#" class="oe_mail_msg_hide">Hide</a></span></t>
|
||||
<t t-if="display.show_delete"><span class="oe_mail_oe_space"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_delete">Delete</a></span></t>
|
||||
<t t-if="display.show_hide"><span class="oe_mail_oe_space"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_hide">Hide</a></span></t>
|
||||
</p>
|
||||
</t>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user