New poster-name component, designed to be extended to add additional
information.
This commit is contained in:
parent
2e4d8b2e13
commit
152dc499e1
|
@ -0,0 +1,78 @@
|
|||
var PosterNameComponent = Em.Component.extend({
|
||||
classNames: ['names'],
|
||||
displayNameOnPosts: Discourse.computed.setting('display_name_on_posts'),
|
||||
|
||||
render: function(buffer) {
|
||||
var post = this.get('post');
|
||||
|
||||
if (post) {
|
||||
var name = post.get('name'),
|
||||
username = post.get('username'),
|
||||
linkClass = 'username';
|
||||
|
||||
if (post.get('staff')) { linkClass += ' staff'; }
|
||||
if (post.get('new_user')) { linkClass += ' new-user'; }
|
||||
|
||||
// Main link
|
||||
buffer.push("<span class='" + linkClass + "'><a href='#'>" + username + "</a>");
|
||||
|
||||
// Add a glyph if we have one
|
||||
var glyph = this.posterGlyph(post);
|
||||
if (!Em.isEmpty(glyph)) {
|
||||
buffer.push("<i class='fa fa-" + glyph + "'></i>");
|
||||
}
|
||||
buffer.push("</span>");
|
||||
|
||||
// Are we showing full names?
|
||||
if (name && (name === username) && this.get('displayNameOnPosts')) {
|
||||
buffer.push("<span class='full-name'><a href='#'>" + name + "</a></span>");
|
||||
}
|
||||
|
||||
// User titles
|
||||
var title = post.get('user_title');
|
||||
if (!Em.isEmpty(title)) {
|
||||
var primaryGroupName = post.get('primary_group_name');
|
||||
|
||||
buffer.push('<span class="user-title">');
|
||||
if (Em.isEmpty(primaryGroupName)) {
|
||||
buffer.push(title);
|
||||
} else {
|
||||
buffer.push("<a href='#' class='user-group'>" + title + "</a>");
|
||||
}
|
||||
buffer.push("</span>");
|
||||
}
|
||||
|
||||
PosterNameComponent.trigger('renderedName', buffer);
|
||||
}
|
||||
},
|
||||
|
||||
click: function(e) {
|
||||
var $target = $(e.target);
|
||||
if ($target.hasClass('user-group')) {
|
||||
Discourse.URL.routeTo("/groups/" + this.get('post.primary_group_name'));
|
||||
} else {
|
||||
this.sendAction('expandAction', this.get('post'));
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
Overwrite this to give a user a custom font awesome glyph.
|
||||
|
||||
@method posterGlyph
|
||||
@param {Post} the related post.
|
||||
@return {String} the glyph to render (or null for none)
|
||||
**/
|
||||
posterGlyph: function(post) {
|
||||
if (post.get('admin')) {
|
||||
return 'trophy';
|
||||
} else if (post.get('moderator')) {
|
||||
return 'magic';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Support for event triggering
|
||||
PosterNameComponent.reopenClass(Em.Evented);
|
||||
|
||||
export default PosterNameComponent;
|
|
@ -46,15 +46,23 @@ Discourse.Resolver = Ember.DefaultResolver.extend({
|
|||
return this._super(fullName);
|
||||
},
|
||||
|
||||
resolveController: function(parsedName) {
|
||||
var moduleName = 'discourse/controllers/' + parsedName.fullNameWithoutType,
|
||||
customResolve: function(parsedName) {
|
||||
var moduleName = 'discourse/' + parsedName.type + 's/' + parsedName.fullNameWithoutType,
|
||||
module = requirejs.entries[moduleName];
|
||||
|
||||
if (module) {
|
||||
module = require(moduleName, null, null, true /* force sync */);
|
||||
if (module && module['default']) { module = module['default']; }
|
||||
}
|
||||
return module || this._super(parsedName);
|
||||
return module;
|
||||
},
|
||||
|
||||
resolveController: function(parsedName) {
|
||||
return this.customResolve(parsedName) || this._super(parsedName);
|
||||
},
|
||||
|
||||
resolveComponent: function(parsedName) {
|
||||
return this.customResolve(parsedName) || this._super(parsedName);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,22 +38,7 @@
|
|||
|
||||
<div class='topic-body span14'>
|
||||
<div class='topic-meta-data'>
|
||||
<div class="names">
|
||||
<span {{bind-attr class="staff new_user :username"}}><a href='{{unbound usernameUrl}}' {{action showPosterExpansion this}}>{{unbound username}}</a>{{#if admin}}<i class='fa fa-trophy'></i>{{else}}{{#if moderator}}<i class='fa fa-magic'></i>{{/if}}{{/if}}
|
||||
</span>
|
||||
|
||||
{{#if showName}}
|
||||
<span class="full-name"><a href='{{unbound usernameUrl}}' {{action showPosterExpansion this}}>{{unbound name}}</a></span>
|
||||
{{/if}}
|
||||
|
||||
{{#if user_title}}
|
||||
{{#if primary_group_name}}
|
||||
<span class="user-title"><a href='/groups/{{unbound primary_group_name}}' class='user-group'>{{unbound user_title}}</a></span>
|
||||
{{else}}
|
||||
<span class="user-title" {{action showPosterExpansion this}}>{{unbound user_title}}</span>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
{{poster-name post=this expandAction="showPosterExpansion"}}
|
||||
<div class='post-info'>
|
||||
<a href='#' class='post-date' {{bind-attr data-share-url="shareUrl"}} {{bind-attr data-post-number="post_number"}}>{{unboundAgeWithTooltip created_at}}</a>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue