From 58a1ddb834c27ec38ff7fcc5fd656ea0e05074be Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 11 Oct 2018 10:32:39 +0300 Subject: [PATCH] Find emails for sending invitation (begins with + or @) when adding comment. --- apps/common/main/lib/controller/Comments.js | 2 +- apps/common/main/lib/util/utils.js | 2 ++ apps/common/main/lib/view/Comments.js | 27 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 47d095e8b..a951be199 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -1341,7 +1341,7 @@ define([ this.api.asc_addComment(comment); this.view.showEditContainer(false); - + this.view.pickEMail(commentVal); if (!_.isUndefined(this.api.asc_SetDocumentPlaceChangedEnabled)) { this.api.asc_SetDocumentPlaceChangedEnabled(false); } diff --git a/apps/common/main/lib/util/utils.js b/apps/common/main/lib/util/utils.js index 397fc45aa..b5c70a486 100644 --- a/apps/common/main/lib/util/utils.js +++ b/apps/common/main/lib/util/utils.js @@ -90,6 +90,7 @@ Common.Utils = _.extend(new(function() { hostnameRe = /^(((https?)|(ftps?)):\/\/)?([\-\wа-яё]*:?[\-\wа-яё]*@)?(([\-\wа-яё]+\.)+[\wа-яё\-]{2,}(:\d+)?(\/[%\-\wа-яё]*(\.[\wа-яё]{2,})?(([\wа-яё\-\.\?\\\/+@&#;:`'~=%!,\(\)]*)(\.[\wа-яё]{2,})?)*)*\/?)/i, localRe = /^(((https?)|(ftps?)):\/\/)([\-\wа-яё]*:?[\-\wа-яё]*@)?(([\-\wа-яё]+)(:\d+)?(\/[%\-\wа-яё]*(\.[\wа-яё]{2,})?(([\wа-яё\-\.\?\\\/+@&#;:`'~=%!,\(\)]*)(\.[\wа-яё]{2,})?)*)*\/?)/i, emailStrongRe = /(mailto:)?([a-z0-9'\._-]+@[a-z0-9\.-]+\.[a-z0-9]{2,4})([a-яё0-9\._%+-=\?:&]*)/ig, + emailAddStrongRe = /(mailto:|\s[@]|\s[+])?([a-z0-9'\._-]+@[a-z0-9\.-]+\.[a-z0-9]{2,4})([a-яё0-9\._%+-=\?:&]*)/ig, ipStrongRe = /(((https?)|(ftps?)):\/\/([\-\wа-яё]*:?[\-\wа-яё]*@)?)(((1[0-9]{2}|2[0-4][0-9]|25[0-5]|[1-9][0-9]|[0-9])\.){3}(1[0-9]{2}|2[0-4][0-9]|25[0-5]|[1-9][0-9]|[0-9]))(:\d+)?(\/[%\-\wа-яё]*(\.[\wа-яё]{2,})?(([\wа-яё\-\.\?\\\/+@&#;:`~=%!,\(\)]*)(\.[\wа-яё]{2,})?)*)*\/?/ig, hostnameStrongRe = /((((https?)|(ftps?)):\/\/([\-\wа-яё]*:?[\-\wа-яё]*@)?)|(([\-\wа-яё]*:?[\-\wа-яё]*@)?www\.))((([\-\wа-яё]+\.)+[\wа-яё\-]{2,}|([\-\wа-яё]+))(:\d+)?(\/[%\-\wа-яё]*(\.[\wа-яё]{2,})?(([\wа-яё\-\.\?\\\/+@&#;:`~=%!,\(\)]*)(\.[\wа-яё]{2,})?)*)*\/?)/ig, documentSettingsType = { @@ -200,6 +201,7 @@ Common.Utils = _.extend(new(function() { hostnameRe: hostnameRe, localRe: localRe, emailStrongRe: emailStrongRe, + emailAddStrongRe: emailAddStrongRe, ipStrongRe: ipStrongRe, hostnameStrongRe: hostnameStrongRe, documentSettingsType: documentSettingsType, diff --git a/apps/common/main/lib/view/Comments.js b/apps/common/main/lib/view/Comments.js index 5d4619ee0..c0b99c708 100644 --- a/apps/common/main/lib/view/Comments.js +++ b/apps/common/main/lib/view/Comments.js @@ -674,6 +674,27 @@ define([ return ''; }); +/* message.replace(Common.Utils.emailAddStrongRe, function(subStr, addStr, mailStr) { + // var addition = subStr.match(/^(\s[@]|\s[+])(\S*)/) || ''; + // if (addition) { + // subStr = addition[2]; + // addition = addition[1]; // + or @ + // console.log(subStr); + // } + // if (addStr) + // console.log(subStr + ', ' + mailStr); // send email + var ref = (! /((^mailto:)\/\/)/i.test(mailStr) ) ? ('mailto:' + mailStr) : mailStr; + offset = arguments[arguments.length-2]; + len = subStr.length; + var elem = _.find(arr, function(item){ + return ( (offset>=item.start) && (offsetitem.start)); + }); + if (!elem) + arr.push({start: offset, end: len+offset, str: (addStr || '') + '' + mailStr + ''}); + return ''; + }); +*/ message.replace(Common.Utils.emailStrongRe, function(subStr) { var ref = (! /((^mailto:)\/\/)/i.test(subStr) ) ? ('mailto:' + subStr) : subStr; offset = arguments[arguments.length-2]; @@ -700,6 +721,12 @@ define([ return str_res; }, + pickEMail: function (message) { + var arr = Common.Utils.String.htmlEncode(message).match(/\B[@+][A-Z0-9._%+-]+@[A-Z0-9._]+\.[A-Z]+\b/gi); + console.log(arr); // send e-mails + return arr; + }, + textComments : 'Comments', textAnonym : 'Guest', textAddCommentToDoc : 'Add Comment to Document',