forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Blaze in order to render templates -
no manual HTML concatenation anymore
- Loading branch information
Showing
4 changed files
with
31 additions
and
13 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
packages/rocketchat-message-attachments/client/fieldTypeThreadReference.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template name="fieldTypeThreadReference"> | ||
<div> | ||
<div class="thread-reference">{{value}}</div> | ||
<a href="threadUrl"> | ||
<button class="rc-button rc-button--primary thread-url"> | ||
{{> icon icon="jump"}} | ||
{{_ "View_thread"}} | ||
</button> | ||
</a> | ||
</div> | ||
</template> |
7 changes: 7 additions & 0 deletions
7
packages/rocketchat-message-attachments/client/fieldTypeThreadReference.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {registerFieldTemplate} from './renderField'; | ||
|
||
registerFieldTemplate('threadReference', 'fieldTypeThreadReference'); | ||
|
||
Template.fieldTypeThreadReference.helpers({ | ||
}); | ||
|
24 changes: 11 additions & 13 deletions
24
packages/rocketchat-message-attachments/client/renderField.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
const renderers = {}; | ||
|
||
export function registerFieldTemplate(fieldType, templateName) { | ||
renderers[fieldType] = templateName; | ||
} | ||
|
||
Template.renderField.helpers({ | ||
specializedRendering(field) { | ||
let html = ''; | ||
|
||
switch (field.type) { | ||
case 'threadReference': | ||
html = `<div><div class='thread-reference'>${ field.value }</div><a href='${ field.threadUrl }'>`; | ||
html += '<button class="rc-button rc-button--primary thread-url">'; | ||
html += '<svg class="rc-icon tab-button-icon tab-button-icon--jump" aria-hidden="true"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-jump"></use></svg>'; | ||
html += `${ TAPi18n.__('Thread_view') }</button>`; | ||
html += '</a></div>'; | ||
break; | ||
default: | ||
// consider the value already formatted as html | ||
html = field.value; | ||
if (field.type && renderers[field.type]) { | ||
html = Blaze.toHTMLWithData(Template[renderers[field.type]], field); | ||
} else { | ||
// consider the value already formatted as html | ||
html = field.value; | ||
} | ||
|
||
return html; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters