[CLEAN] Misc cleaning of code: removed debug statements, added some notes.
bzr revid: tde@openerp.com-20121029112117-kup1q99c2nbkgar7
This commit is contained in:
@@ -89,7 +89,6 @@ Main Features
|
||||
'static/lib/jquery.expander/jquery.expander.js',
|
||||
'static/src/js/mail.js',
|
||||
'static/src/js/mail_followers.js',
|
||||
'static/src/js/mail_uploader.js',
|
||||
],
|
||||
'qweb': [
|
||||
'static/src/xml/mail.xml',
|
||||
|
||||
@@ -84,10 +84,16 @@ class mail_notification(osv.Model):
|
||||
return False
|
||||
|
||||
def set_message_read(self, cr, uid, msg_ids, read=None, context=None):
|
||||
""" TDE note: add a comment, verify method calls, because js seems obfuscated. """
|
||||
# TDE note: child_of to set unread ?
|
||||
""" Set a message and its child messages as (un)read for uid.
|
||||
|
||||
:param bool read: read / unread
|
||||
"""
|
||||
# TDE note: use child_of or front-end send correct values ?
|
||||
user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
|
||||
notif_ids = self.search(cr, uid, [('partner_id', '=', user_pid), ('message_id', 'in', msg_ids)], context=context)
|
||||
notif_ids = self.search(cr, uid, [
|
||||
('partner_id', '=', user_pid),
|
||||
('message_id', 'in', msg_ids)
|
||||
], context=context)
|
||||
|
||||
# all message have notifications: already set them as (un)read
|
||||
if len(notif_ids) == len(msg_ids):
|
||||
|
||||
@@ -65,6 +65,7 @@ class mail_message(osv.Model):
|
||||
def _get_record_name(self, cr, uid, ids, name, arg, context=None):
|
||||
""" Return the related document name, using name_get. It is done using
|
||||
SUPERUSER_ID, to be sure to have the record name correctly stored. """
|
||||
# TDE note: regroup by model/ids, to have less queries to perform
|
||||
result = dict.fromkeys(ids, False)
|
||||
for message in self.read(cr, uid, ids, ['model', 'res_id'], context=context):
|
||||
if not message.get('model') or not message.get('res_id'):
|
||||
@@ -79,10 +80,11 @@ class mail_message(osv.Model):
|
||||
notif_obj = self.pool.get('mail.notification')
|
||||
notif_ids = notif_obj.search(cr, uid, [
|
||||
('partner_id', 'in', [partner_id]),
|
||||
('message_id', 'in', ids)
|
||||
('message_id', 'in', ids),
|
||||
('read', '=', False),
|
||||
], context=context)
|
||||
for notif in notif_obj.browse(cr, uid, notif_ids, context=context):
|
||||
res[notif.message_id.id] = not notif.read
|
||||
res[notif.message_id.id] = True
|
||||
return res
|
||||
|
||||
def _search_to_read(self, cr, uid, obj, name, domain, context=None):
|
||||
@@ -117,9 +119,9 @@ class mail_message(osv.Model):
|
||||
help="Message type: email for email message, notification for system "\
|
||||
"message, comment for other messages such as user replies"),
|
||||
'email_from': fields.char('From',
|
||||
help="Email address of the sender, to use if it does not match any partner."),
|
||||
help="Email address of the sender. This field is set when no matching partner is found for incoming emails."),
|
||||
'author_id': fields.many2one('res.partner', 'Author',
|
||||
help="Partner that did write the message. If not set, try to use the From field instead."),
|
||||
help="Author of the message. If not set, email_from may hold an email address that did not match any partner."),
|
||||
'partner_ids': fields.many2many('res.partner', string='Recipients'),
|
||||
'notified_partner_ids': fields.many2many('res.partner', 'mail_notification',
|
||||
'message_id', 'partner_id', 'Recipients'),
|
||||
@@ -204,6 +206,7 @@ class mail_message(osv.Model):
|
||||
|
||||
:param dict message: read result of a mail.message
|
||||
"""
|
||||
# TDE note: this method should be optimized, to lessen the number of queries, will be done ASAP
|
||||
is_author = False
|
||||
if message['author_id']:
|
||||
is_author = message['author_id'][0] == self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=None)['partner_id'][0]
|
||||
@@ -321,7 +324,6 @@ class mail_message(osv.Model):
|
||||
], context=context, limit=self._message_read_more_limit)
|
||||
if not not_loaded_ids:
|
||||
continue
|
||||
# print 'not_loaded_ids', not_loaded_ids
|
||||
|
||||
# all_not_loaded_ids += not_loaded_ids
|
||||
# group childs not read
|
||||
@@ -386,6 +388,7 @@ class mail_message(osv.Model):
|
||||
ancestors and expandables
|
||||
:return list: list of message structure for the Chatter widget
|
||||
"""
|
||||
# print 'message_read', ids, domain, message_unload_ids, thread_level, context, parent_id, limit
|
||||
assert thread_level in [0, 1], 'message_read() thread_level should be 0 (flat) or 1 (1 level of thread); given %s.' % thread_level
|
||||
domain = domain if domain is not None else []
|
||||
message_unload_ids = message_unload_ids if message_unload_ids is not None else []
|
||||
@@ -458,9 +461,10 @@ class mail_message(osv.Model):
|
||||
- otherwise: remove the id
|
||||
"""
|
||||
# Rules do not apply to administrator
|
||||
# print '_search', uid, args
|
||||
if uid == SUPERUSER_ID:
|
||||
return super(mail_message, self)._search(cr, uid, args, offset=offset, limit=limit, order=order,
|
||||
context=context, count=count, access_rights_uid=access_rights_uid)
|
||||
context=context, count=count, access_rights_uid=access_rights_uid)
|
||||
# Perform a super with count as False, to have the ids, not a counter
|
||||
ids = super(mail_message, self)._search(cr, uid, args, offset=offset, limit=limit, order=order,
|
||||
context=context, count=False, access_rights_uid=access_rights_uid)
|
||||
@@ -630,6 +634,8 @@ class mail_message(osv.Model):
|
||||
# Messaging API
|
||||
#------------------------------------------------------
|
||||
|
||||
# TDE note: this code is not used currently, will be improved in a future merge, when quoted context
|
||||
# will be added to email send for notifications. Currently only WIP.
|
||||
MAIL_TEMPLATE = """<div>
|
||||
% if message:
|
||||
${display_message(message)}
|
||||
|
||||
@@ -7,7 +7,7 @@ openerp.mail = function (session) {
|
||||
openerp_mail_followers(session, mail); // import mail_followers.js
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------
|
||||
* ------------------------------------------------------------
|
||||
* FormView
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
@@ -17,16 +17,15 @@ openerp.mail = function (session) {
|
||||
|
||||
session.web.FormView = session.web.FormView.extend({
|
||||
do_action: function (action) {
|
||||
console.log(action);
|
||||
|
||||
if (action.res_model == 'mail.compose.message') {
|
||||
/* hack for stop context propagation of wrong value
|
||||
* delete this hack when a global method to clean context is create
|
||||
*/
|
||||
var context_keys = ['default_template_id', 'default_composition_mode',
|
||||
'default_use_template', 'default_partner_ids', 'default_model',
|
||||
'default_res_id', 'default_content_subtype', 'active_id', 'lang',
|
||||
'bin_raw', 'tz', 'active_model', 'edi_web_url_view', 'active_ids', 'default_subject']
|
||||
'default_res_id', 'default_content_subtype', , 'default_subject',
|
||||
'default_body', 'active_id', 'lang', 'bin_raw', 'tz',
|
||||
'active_model', 'edi_web_url_view', 'active_ids']
|
||||
for (var key in action.context) {
|
||||
if (_.indexOf(context_keys, key) == -1) {
|
||||
action.context[key] = null;
|
||||
@@ -40,7 +39,7 @@ openerp.mail = function (session) {
|
||||
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------
|
||||
* ------------------------------------------------------------
|
||||
* ChatterUtils
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
@@ -53,20 +52,18 @@ openerp.mail = function (session) {
|
||||
|
||||
mail.ChatterUtils = {
|
||||
|
||||
/**
|
||||
*Get an image in /web/binary/image?... */
|
||||
/* Get an image in /web/binary/image?... */
|
||||
get_image: function (session, model, field, id) {
|
||||
return session.prefix + '/web/binary/image?session_id=' + session.session_id + '&model=' + model + '&field=' + field + '&id=' + (id || '');
|
||||
},
|
||||
|
||||
/**
|
||||
*Get the url of an attachment {'id': id} */
|
||||
/* Get the url of an attachment {'id': id} */
|
||||
get_attachment_url: function (session, attachment) {
|
||||
return session.origin + '/web/binary/saveas?session_id=' + session.session_id + '&model=ir.attachment&field=datas&filename_field=datas_fname&id=' + attachment['id'];
|
||||
},
|
||||
|
||||
/**
|
||||
*Replaces some expressions
|
||||
* Replaces some expressions
|
||||
* - :name - shortcut to an image
|
||||
*/
|
||||
do_replace_expressions: function (string) {
|
||||
@@ -83,23 +80,23 @@ openerp.mail = function (session) {
|
||||
return string;
|
||||
},
|
||||
|
||||
/* replace textarea text into html text
|
||||
* (add <p>, <a>)
|
||||
* TDE note : should not be here, but server-side I think ...
|
||||
*/
|
||||
/**
|
||||
* Replaces textarea text into html text (add <p>, <a>)
|
||||
* TDE note : should be done server-side, in Python -> use mail.compose.message ?
|
||||
*/
|
||||
get_text2html: function (text) {
|
||||
return text
|
||||
.replace(/[\n\r]/g,'<br/>')
|
||||
.replace(/((?:https?|ftp):\/\/[\S]+)/g,'<a href="$1">$1</a> ')
|
||||
},
|
||||
|
||||
/**
|
||||
* return the complete domain with "&"
|
||||
/* Returns the complete domain with "&"
|
||||
* TDE note: please add some comments to explain how/why
|
||||
*/
|
||||
expend_domain: function (domain) {
|
||||
expand_domain: function (domain) {
|
||||
var new_domain = [];
|
||||
var nb_and = -1;
|
||||
|
||||
// TDE note: smarted code maybe ?
|
||||
for ( var k = domain.length-1; k >= 0 ; k-- ) {
|
||||
if ( typeof domain[k] != 'array' && typeof domain[k] != 'object' ) {
|
||||
nb_and -= 2;
|
||||
@@ -118,16 +115,15 @@ openerp.mail = function (session) {
|
||||
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------
|
||||
* ------------------------------------------------------------
|
||||
* ComposeMessage widget
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
* This widget handles the display of a form to compose a new message.
|
||||
* This form is a mail.compose.message form_view.
|
||||
* On first time : display a compact textarea but is not the compose form.
|
||||
* When the user focus this box, the compose message is intantiate and
|
||||
* with focus on the textarea.
|
||||
*/
|
||||
* On first time : display a compact textarea that is not the compose form.
|
||||
* When the user focuses the textarea, the compose message is instantiated.
|
||||
*/
|
||||
|
||||
mail.ThreadComposeMessage = session.web.Widget.extend({
|
||||
template: 'mail.compose_message',
|
||||
@@ -284,7 +280,7 @@ openerp.mail = function (session) {
|
||||
on_compose_fullmail: function (default_composition_mode) {
|
||||
if (default_composition_mode == 'reply') {
|
||||
var context = {
|
||||
'default_composition_mode': 'reply',
|
||||
'default_composition_mode': default_composition_mode,
|
||||
'default_parent_id': this.id,
|
||||
'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''),
|
||||
'default_attachment_ids': this.attachment_ids,
|
||||
@@ -292,10 +288,9 @@ openerp.mail = function (session) {
|
||||
} else {
|
||||
var context = {
|
||||
'default_model': this.context.default_model,
|
||||
'default_res_model': this.context.default_model,
|
||||
'default_res_id': this.context.default_res_id,
|
||||
'default_content_subtype': 'html',
|
||||
'default_composition_mode': 'comment',
|
||||
'default_composition_mode': default_composition_mode,
|
||||
'default_parent_id': this.id,
|
||||
'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''),
|
||||
'default_attachment_ids': this.attachment_ids,
|
||||
@@ -411,7 +406,7 @@ openerp.mail = function (session) {
|
||||
});
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------
|
||||
* ------------------------------------------------------------
|
||||
* Thread Message Expandable Widget
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
@@ -501,7 +496,7 @@ openerp.mail = function (session) {
|
||||
});
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------
|
||||
* ------------------------------------------------------------
|
||||
* Thread Message Widget
|
||||
* ------------------------------------------------------------
|
||||
* This widget handles the display of a messages in a thread.
|
||||
@@ -588,9 +583,7 @@ openerp.mail = function (session) {
|
||||
this.ds_follow = new session.web.DataSetSearch(this, 'mail.followers');
|
||||
},
|
||||
|
||||
/**
|
||||
*Convert date, timerelative and avatar in displayable data.
|
||||
*/
|
||||
/* Convert date, timerelative and avatar in displayable data. */
|
||||
formating_data: function () {
|
||||
|
||||
//formating and add some fields for render
|
||||
@@ -665,9 +658,7 @@ openerp.mail = function (session) {
|
||||
this.$el.on('click', '.oe_star', this.on_star);
|
||||
},
|
||||
|
||||
/**
|
||||
* call the on_compose_message on the thread of this message.
|
||||
*/
|
||||
/* Call the on_compose_message on the thread of this message. */
|
||||
on_message_reply:function (event) {
|
||||
event.stopPropagation();
|
||||
this.thread.on_compose_message();
|
||||
@@ -686,7 +677,7 @@ openerp.mail = function (session) {
|
||||
},
|
||||
|
||||
/**
|
||||
* instantiate the thread object of this message.
|
||||
* Instantiate the thread object of this message.
|
||||
* Each message have only one thread.
|
||||
*/
|
||||
create_thread: function () {
|
||||
@@ -1294,8 +1285,8 @@ openerp.mail = function (session) {
|
||||
|
||||
if ( msg_up && msg_up.type == "expandable" && msg_down && msg_down.type == "expandable") {
|
||||
// concat two expandable message and add this message to this dom
|
||||
msg_up.domain = mail.ChatterUtils.expend_domain( msg_up.domain );
|
||||
msg_down.domain = mail.ChatterUtils.expend_domain( msg_down.domain );
|
||||
msg_up.domain = mail.ChatterUtils.expand_domain( msg_up.domain );
|
||||
msg_down.domain = mail.ChatterUtils.expand_domain( msg_down.domain );
|
||||
|
||||
msg_down.domain = ['|','|'].concat( msg_up.domain ).concat( message_dom ).concat( msg_down.domain );
|
||||
|
||||
@@ -1310,7 +1301,7 @@ openerp.mail = function (session) {
|
||||
|
||||
} else if ( msg_up && msg_up.type == "expandable") {
|
||||
// concat preview expandable message and this message to this dom
|
||||
msg_up.domain = mail.ChatterUtils.expend_domain( msg_up.domain );
|
||||
msg_up.domain = mail.ChatterUtils.expand_domain( msg_up.domain );
|
||||
msg_up.domain = ['|'].concat( msg_up.domain ).concat( message_dom );
|
||||
|
||||
msg_up.nb_messages++;
|
||||
@@ -1319,7 +1310,7 @@ openerp.mail = function (session) {
|
||||
|
||||
} else if ( msg_down && msg_down.type == "expandable") {
|
||||
// concat next expandable message and this message to this dom
|
||||
msg_down.domain = mail.ChatterUtils.expend_domain( msg_down.domain );
|
||||
msg_down.domain = mail.ChatterUtils.expand_domain( msg_down.domain );
|
||||
msg_down.domain = ['|'].concat( msg_down.domain ).concat( message_dom );
|
||||
|
||||
// it's maybe a message expandable for the max limit read message
|
||||
|
||||
@@ -115,8 +115,8 @@ openerp_mail_followers = function(session, mail) {
|
||||
}).pipe(self.proxy('display_generic'));
|
||||
},
|
||||
_format_followers: function(count){
|
||||
console.log('FORMAT FOLLWERS :',count);
|
||||
function _t(str){return str;}
|
||||
// TDE note: why redefining _t ?
|
||||
function _t(str) { return str; }
|
||||
var str = '';
|
||||
if(count <= 0){
|
||||
str = _t('No followers');
|
||||
@@ -125,7 +125,6 @@ openerp_mail_followers = function(session, mail) {
|
||||
}else{
|
||||
str = ''+count+' '+_t('followers');
|
||||
}
|
||||
console.log('URGH:',str);
|
||||
return str;
|
||||
},
|
||||
/* Display generic info about follower, for people not having access to res_partner */
|
||||
@@ -149,7 +148,8 @@ openerp_mail_followers = function(session, mail) {
|
||||
record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id);
|
||||
$(session.web.qweb.render('mail.followers.partner', {'record': record})).appendTo(node_user_list);
|
||||
});
|
||||
if (truncated.length < records.length) { //FIXME USE A TEMPLATE !
|
||||
// FVA note: be sure it is correctly translated
|
||||
if (truncated.length < records.length) {
|
||||
$('<div class="oe_partner">And ' + (records.length - truncated.length) + ' more.</div>').appendTo(node_user_list);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user