summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2016-11-15 13:58:55 +0100
committerChristophe Simonis <chs@odoo.com>2016-11-15 13:58:55 +0100
commitdece72d010e23c88bdf5b2a1ace6ff0df2b2732f (patch)
treef9fc12d1f2f5f51acca168854702f75e316e1f0b /addons/mail/static/src/js
parent22d7be5b7397f9d9a811e071601a9ad07762dc55 (diff)
parentca2003839a9abc3f76f48d2382d512a4546aeab1 (diff)
[MERGE] forward port branch saas-12 up to ca20038
Diffstat (limited to 'addons/mail/static/src/js')
-rw-r--r--addons/mail/static/src/js/chat_manager.js10
-rw-r--r--addons/mail/static/src/js/utils.js20
2 files changed, 25 insertions, 5 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js
index 0b7b37ec49f..2f63dd61b5a 100644
--- a/addons/mail/static/src/js/chat_manager.js
+++ b/addons/mail/static/src/js/chat_manager.js
@@ -661,9 +661,17 @@ var chat_manager = {
post_message: function (data, options) {
options = options || {};
+
+ // This message will be received from the mail composer as html content subtype
+ // but the urls will not be linkified. If the mail composer takes the responsibility
+ // to linkify the urls we end up with double linkification a bit everywhere.
+ // Ideally we want to keep the content as text internally and only make html
+ // enrichment at display time but the current design makes this quite hard to do.
+ var body = utils.linkify(_.str.trim(data.content));
+
var msg = {
partner_ids: data.partner_ids,
- body: _.str.trim(data.content),
+ body: body,
attachment_ids: data.attachment_ids,
};
if ('subject' in data) {
diff --git a/addons/mail/static/src/js/utils.js b/addons/mail/static/src/js/utils.js
index 7c64ba48df0..db82b976945 100644
--- a/addons/mail/static/src/js/utils.js
+++ b/addons/mail/static/src/js/utils.js
@@ -61,12 +61,23 @@ function _parse_and_transform(nodes, transform_function) {
// suggested regexp (gruber url matching regexp, adapted to js, see https://gist.github.com/gruber/8891611)
var url_regexp = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi;
+function linkify(text, attrs) {
+ attrs = attrs || {};
+ if (attrs.target === undefined) {
+ attrs.target = '_blank';
+ }
+ attrs = _.map(attrs, function (value, key) {
+ return key + '="' + _.escape(value) + '"';
+ }).join(' ');
+ return text.replace(url_regexp, function (url) {
+ var href = (!/^(f|ht)tps?:\/\//i.test(url)) ? "http://" + url : url;
+ return '<a ' + attrs + ' href="' + href + '">' + url + '</a>';
+ });
+}
+
function add_link (node, transform_children) {
if (node.nodeType === 3) { // text node
- return node.data.replace(url_regexp, function (url) {
- var href = (!/^(f|ht)tps?:\/\//i.test(url)) ? "http://" + url : url;
- return '<a target="_blank" href="' + href + '">' + url + '</a>';
- });
+ return linkify(node.data);
}
if (node.tagName === "A") return node.outerHTML;
node.innerHTML = transform_children();
@@ -132,6 +143,7 @@ return {
send_notification: send_notification,
parse_and_transform: parse_and_transform,
add_link: add_link,
+ linkify: linkify,
strip_html: strip_html,
inline: inline,
parse_email: parse_email,