diff --git a/app/assets/javascripts/discourse/components/poster-name.js.es6 b/app/assets/javascripts/discourse/components/poster-name.js.es6 new file mode 100644 index 00000000000..7f213f7c00e --- /dev/null +++ b/app/assets/javascripts/discourse/components/poster-name.js.es6 @@ -0,0 +1,77 @@ +import { setting } from 'discourse/lib/computed'; + +const PosterNameComponent = Em.Component.extend({ + classNames: ['names', 'trigger-user-card'], + displayNameOnPosts: setting('display_name_on_posts'), + + // sanitize name for comparison + sanitizeName(name){ + return name.toLowerCase().replace(/[\s_-]/g,''); + }, + + render(buffer) { + const post = this.get('post'); + + if (post) { + const username = post.get('username'), + primaryGroupName = post.get('primary_group_name'), + url = post.get('usernameUrl'); + + var linkClass = 'username', + name = post.get('name'); + + if (post.get('staff')) { linkClass += ' staff'; } + if (post.get('admin')) { linkClass += ' admin'; } + if (post.get('moderator')) { linkClass += ' moderator'; } + if (post.get('new_user')) { linkClass += ' new-user'; } + + if (!Em.isEmpty(primaryGroupName)) { + linkClass += ' ' + primaryGroupName; + } + // Main link + buffer.push("" + username + ""); + + // Add a glyph if we have one + const glyph = this.posterGlyph(post); + if (!Em.isEmpty(glyph)) { + buffer.push(glyph); + } + buffer.push(""); + + // Are we showing full names? + if (name && this.get('displayNameOnPosts') && (this.sanitizeName(name) !== this.sanitizeName(username))) { + name = Discourse.Utilities.escapeExpression(name); + buffer.push("" + name + ""); + } + + // User titles + let title = post.get('user_title'); + if (!Em.isEmpty(title)) { + + title = Discourse.Utilities.escapeExpression(title); + buffer.push(''); + if (Em.isEmpty(primaryGroupName)) { + buffer.push(title); + } else { + buffer.push("" + title + ""); + } + buffer.push(""); + } + + PosterNameComponent.trigger('renderedName', buffer, post); + } + }, + + // Overwrite this to give a user a custom font awesome glyph. + posterGlyph(post) { + if(post.get('moderator')) { + const desc = I18n.t('user.moderator_tooltip'); + return ''; + } + } +}); + +// Support for event triggering +PosterNameComponent.reopenClass(Em.Evented); + +export default PosterNameComponent;