Browse Source

hashed url support

pull/117/head
Ivan Yelizariev 10 years ago
committed by Ildar Nasyrov
parent
commit
e300ea0e1a
No known key found for this signature in database GPG Key ID: D1FDACDF9B83578
  1. 24
      im_notif/im_notif_models.py
  2. 25
      im_notif/static/src/js/im_notif.js

24
im_notif/im_notif_models.py

@ -67,10 +67,14 @@ class mail_notification(models.Model):
return email_pids, im_uids
def _message2im(self, message):
url = 'ODOO_REF#id=%s&model=%s&view_type=form' % (
message.res_id,
message.model
def _message2im(self, cr, uid, message):
inbox_action = self.pool['ir.model.data'].xmlid_to_res_id(cr, SUPERUSER_ID, 'mail.action_mail_inbox_feeds')
inbox_url = '#action=%s' % inbox_action
url = None
if message.res_id:
url = '#id=%s&model=%s&view_type=form' % (
message.res_id,
message.model
)
author = message.author_id and message.author_id.name_get()
author = author and author[0][1] or message.email_from
@ -80,11 +84,15 @@ class mail_notification(models.Model):
'notification': _('System notification'),
}.get(message.type, '')
about = message.subject or message.record_name or 'UNDEFINED'
about = '[ABOUT] %s' % about
if url:
about = '<a href="%s">%s</a>' % (url, about)
im_text = [
'_____________________',
'_____________________',
'%s [FROM] %s' % (message.type, author),
'[ABOUT] %s: %s' % (message.subject or message.record_name or '', url)
about,
'_____________________',
'<a href="%s">_____[open_inbox]_____</a>' % inbox_url,
]
#im_text = im_text + body.split('\n')
return im_text
@ -106,7 +114,7 @@ class mail_notification(models.Model):
return True
def _do_notify_im(self, cr, uid, im_uids, message, context=None):
im_text = self._message2im(message)
im_text = self._message2im(cr, uid, message)
user_from = self.pool['ir.model.data'].xmlid_to_res_id(cr, SUPERUSER_ID, 'im_notif.notif_user')

25
im_notif/static/src/js/im_notif.js

@ -9,7 +9,7 @@
openerp.im_chat.Conversation.include({
escape_keep_url: function(str){
//var url_regex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi;
var url_regex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?|ODOO_REF#[\w#!:.?+=&%@!\-\/]+)/gi;
var url_regex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?|(<a)[^>]*href="([^"]*)"[^>]*>([^<]*)<\/a>)/gi;
var last = 0;
var txt = "";
while (true) {
@ -18,11 +18,24 @@
break;
txt += _.escape(str.slice(last, result.index));
last = url_regex.lastIndex;
var is_odoo_ref = result[0].match(/^ODOO_REF/)
var url = _.escape(result[0].replace(/^ODOO_REF/, ''));
if (is_odoo_ref)
url += '&rnd='+parseInt(Math.random()*1000);
txt += '<a href="' + url + '"' + (is_odoo_ref?'':' target="_blank"')+'>' + url + '</a>';
var href = '';
var content = '';
var is_odoo_ref = false;
if (result[8]=='<a'){
href = result[9];
if (href[0]=='#'){
href += '&rnd='+parseInt(Math.random()*1000);
content = result[10];
is_odoo_ref = true;
} else {
//only internal urls are allowed
href = '';
}
}else{
href = _.escape(result[0]);
content = href;
}
txt += '<a href="' + href + '"' + (is_odoo_ref?'':' target="_blank"')+'>' + content + '</a>';
}
txt += _.escape(str.slice(last, str.length));
return txt;

Loading…
Cancel
Save