From 85b266cb79ff5e4083242b1d0e77d04b2bec3ee8 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 16 Jul 2022 18:50:53 +0300 Subject: [PATCH] message ref --- client/src/views/notification/items/assign.js | 5 ++-- .../notification/items/email-received.js | 13 +++------ .../notification/items/entity-removed.js | 10 +++---- .../src/views/notification/items/message.js | 10 +++---- client/src/views/stream/message.js | 27 ++++++++++++++----- client/src/views/stream/notes/assign.js | 8 +++--- .../src/views/stream/notes/create-related.js | 6 ++--- client/src/views/stream/notes/create.js | 8 +++--- .../src/views/stream/notes/email-received.js | 10 +++---- client/src/views/stream/notes/email-sent.js | 10 +++---- client/src/views/stream/notes/relate.js | 6 ++--- 11 files changed, 55 insertions(+), 58 deletions(-) diff --git a/client/src/views/notification/items/assign.js b/client/src/views/notification/items/assign.js index 9aec034904..e8e409cf54 100644 --- a/client/src/views/notification/items/assign.js +++ b/client/src/views/notification/items/assign.js @@ -42,11 +42,10 @@ define('views/notification/items/assign', ['views/notification/items/base'], fun this.messageData['entityType'] = Espo.Utils .upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase()); - this.messageData['html:entity'] = + this.messageData['entity'] = $('') .attr('href', '#' + data.entityType + '/view/' + data.entityId) - .text(data.entityName) - .get(0).outerHTML; + .text(data.entityName); this.createMessage(); }, diff --git a/client/src/views/notification/items/email-received.js b/client/src/views/notification/items/email-received.js index f3a5f4f00b..35676689f9 100644 --- a/client/src/views/notification/items/email-received.js +++ b/client/src/views/notification/items/email-received.js @@ -50,26 +50,21 @@ define('views/notification/items/email-received', ['views/notification/items/bas Espo.Utils.upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase()); if (data.personEntityId) { - this.messageData['html:from'] = + this.messageData['from'] = $('') .attr('href', '#' + data.personEntityType + '/view/' + data.personEntityId) - .text(data.personEntityName) - .get(0).outerHTML; + .text(data.personEntityName); } else { let text = data.fromString || this.translate('empty address'); - this.messageData['html:from'] = - $('') - .text(text) - .get(0).outerHTML; + this.messageData['from'] = $('').text(text); } this.emailId = data.emailId; this.emailName = data.emailName; this.createMessage(); - } - + }, }); }); diff --git a/client/src/views/notification/items/entity-removed.js b/client/src/views/notification/items/entity-removed.js index ec81f47bc3..f4f3b9e66b 100644 --- a/client/src/views/notification/items/entity-removed.js +++ b/client/src/views/notification/items/entity-removed.js @@ -42,17 +42,15 @@ define('views/notification/items/entity-removed', ['views/notification/items/bas this.messageData['entityType'] = Espo.Utils.upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase()) - this.messageData['html:user'] = + this.messageData['user'] = $('') .attr('href', '#User/view/' + data.userId) - .text(data.userName) - .get(0).outerHTML; + .text(data.userName); - this.messageData['html:entity'] = + this.messageData['entity'] = $('') .attr('href', '#' + data.entityType + '/view/' + data.entityId) - .text(data.entityName) - .get(0).outerHTML; + .text(data.entityName); this.createMessage(); }, diff --git a/client/src/views/notification/items/message.js b/client/src/views/notification/items/message.js index 103097855e..d9e4806ec5 100644 --- a/client/src/views/notification/items/message.js +++ b/client/src/views/notification/items/message.js @@ -56,17 +56,15 @@ function (Dep, marked, DOMPurify) { this.messageData['entityType'] = Espo.Utils.upperCaseFirst((this.translate(data.entityType, 'scopeNames') || '').toLowerCase()) - this.messageData['html:user'] = + this.messageData['user'] = $('') .attr('href', '#User/view/' + data.userId) - .text(data.userName) - .get(0).outerHTML; + .text(data.userName); - this.messageData['html:entity'] = + this.messageData['entity'] = $('') .attr('href', '#' + data.entityType + '/view/' + data.entityId) - .text(data.entityName) - .get(0).outerHTML; + .text(data.entityName); this.createMessage(); }, diff --git a/client/src/views/stream/message.js b/client/src/views/stream/message.js index eb35c26b1a..908cb23498 100644 --- a/client/src/views/stream/message.js +++ b/client/src/views/stream/message.js @@ -36,7 +36,7 @@ define('views/stream/message', ['view'], function (Dep) { setup: function () { let template = this.options.messageTemplate; - let data = this.options.messageData; + let data = this.options.messageData || {}; this.dataForTemplate = {}; @@ -46,24 +46,39 @@ define('views/stream/message', ['view'], function (Dep) { if (key.indexOf('html:') === 0) { key = key.substring(5); this.dataForTemplate[key] = value; + template = template.replace('{' + key + '}', '{{{' + key + '}}}'); - template = template.replace('{' + key + '}', '{{{' + key +'}}}'); + continue; + } + if (value instanceof jQuery) { + this.dataForTemplate[key] = value.get(0).outerHTML; + template = template.replace('{' + key + '}', '{{{' + key + '}}}'); + + continue; + } + + if (value instanceof Element) { + this.dataForTemplate[key] = value.outerHTML; + template = template.replace('{' + key + '}', '{{{' + key + '}}}'); + + continue; + } + + if (!value.indexOf) { continue; } if (value.indexOf('field:') === 0) { let field = value.substring(6); this.createField(key, field); - - template = template.replace('{' + key + '}', '{{{' + key +'}}}'); + template = template.replace('{' + key + '}', '{{{' + key + '}}}'); continue; } this.dataForTemplate[key] = value; - - template = template.replace('{' + key + '}', '{{' + key +'}}'); + template = template.replace('{' + key + '}', '{{' + key + '}}'); } this.templateContent = template; diff --git a/client/src/views/stream/notes/assign.js b/client/src/views/stream/notes/assign.js index 1b4210797d..bbf3227cc9 100644 --- a/client/src/views/stream/notes/assign.js +++ b/client/src/views/stream/notes/assign.js @@ -48,10 +48,10 @@ define('views/stream/notes/assign', ['views/stream/note'], function (Dep) { this.assignedUserId = data.assignedUserId || null; this.assignedUserName = data.assignedUserName || null; - this.messageData['html:assignee'] = $('') - .attr('href', '#User/view/' + data.assignedUserId) - .text(data.assignedUserName) - .get(0).outerHTML; + this.messageData['assignee'] = + $('') + .attr('href', '#User/view/' + data.assignedUserId) + .text(data.assignedUserName); if (this.isUserStream) { if (this.assignedUserId) { diff --git a/client/src/views/stream/notes/create-related.js b/client/src/views/stream/notes/create-related.js index a7b9f5dba0..5e43667a12 100644 --- a/client/src/views/stream/notes/create-related.js +++ b/client/src/views/stream/notes/create-related.js @@ -58,12 +58,10 @@ define('views/stream/notes/create-related', ['views/stream/note'], function (Dep this.messageData['relatedEntityType'] = this.translateEntityType(this.entityType); - this.messageData['html:relatedEntity'] = + this.messageData['relatedEntity'] = $('') .attr('href', '#' + this.entityType + '/view/' + this.entityId) - .text(this.entityName) - .get(0).outerHTML; - + .text(this.entityName); this.createMessage(); }, diff --git a/client/src/views/stream/notes/create.js b/client/src/views/stream/notes/create.js index 771828261a..230d8f8a55 100644 --- a/client/src/views/stream/notes/create.js +++ b/client/src/views/stream/notes/create.js @@ -52,10 +52,10 @@ define('views/stream/notes/create', ['views/stream/note'], function (Dep) { this.assignedUserId = data.assignedUserId || null; this.assignedUserName = data.assignedUserName || null; - this.messageData['html:assignee'] = $('') - .attr('href', '#User/view/' + this.assignedUserId) - .text(this.assignedUserName) - .get(0).outerHTML; + this.messageData['assignee'] = + $('') + .attr('href', '#User/view/' + this.assignedUserId) + .text(this.assignedUserName); let isYou = false; diff --git a/client/src/views/stream/notes/email-received.js b/client/src/views/stream/notes/email-received.js index 740e23d2e0..07e91ba650 100644 --- a/client/src/views/stream/notes/email-received.js +++ b/client/src/views/stream/notes/email-received.js @@ -76,11 +76,10 @@ define('views/stream/notes/email-received', ['views/stream/note'], function (Dep } } - this.messageData['html:email'] = + this.messageData['email'] = $('') .attr('href', '#Email/view/' + data.emailId) - .text(data.emailName) - .get(0).outerHTML; + .text(data.emailName); this.messageName = 'emailReceived'; @@ -91,11 +90,10 @@ define('views/stream/notes/email-received', ['views/stream/note'], function (Dep if (data.personEntityId) { this.messageName += 'From'; - this.messageData['html:from'] = + this.messageData['from'] = $('') .attr('href', '#' + data.personEntityType + '/view/' + data.personEntityId) - .text(data.personEntityName) - .get(0).outerHTML; + .text(data.personEntityName); } if ( diff --git a/client/src/views/stream/notes/email-sent.js b/client/src/views/stream/notes/email-sent.js index 94e43e4e44..1d8b280b8a 100644 --- a/client/src/views/stream/notes/email-sent.js +++ b/client/src/views/stream/notes/email-sent.js @@ -68,19 +68,17 @@ define('views/stream/notes/email-sent', ['views/stream/note'], function (Dep) { } } - this.messageData['html:email'] = + this.messageData['email'] = $('') .attr('href', '#Email/view/' + data.emailId) - .text(data.emailName) - .get(0).outerHTML; + .text(data.emailName); this.messageName = 'emailSent'; - this.messageData['html:by'] = + this.messageData['by'] = $('') .attr('href', '#' + data.personEntityType + '/view/' + data.personEntityId) - .text(data.personEntityName) - .get(0).outerHTML; + .text(data.personEntityName); if (this.isThis) { this.messageName += 'This'; diff --git a/client/src/views/stream/notes/relate.js b/client/src/views/stream/notes/relate.js index 1edf827f3c..badee16744 100644 --- a/client/src/views/stream/notes/relate.js +++ b/client/src/views/stream/notes/relate.js @@ -57,14 +57,12 @@ define('views/stream/notes/relate', ['views/stream/note'], function (Dep) { this.messageData['relatedEntityType'] = this.translateEntityType(this.entityType); - this.messageData['html:relatedEntity'] = + this.messageData['relatedEntity'] = $('') .attr('href', '#' + this.entityType + '/view/' + this.entityId) - .text(this.entityName) - .get(0).outerHTML; + .text(this.entityName); this.createMessage(); }, }); }); -