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);
|
return this._super(fullName);
|
||||||
},
|
},
|
||||||
|
|
||||||
resolveController: function(parsedName) {
|
customResolve: function(parsedName) {
|
||||||
var moduleName = 'discourse/controllers/' + parsedName.fullNameWithoutType,
|
var moduleName = 'discourse/' + parsedName.type + 's/' + parsedName.fullNameWithoutType,
|
||||||
module = requirejs.entries[moduleName];
|
module = requirejs.entries[moduleName];
|
||||||
|
|
||||||
if (module) {
|
if (module) {
|
||||||
module = require(moduleName, null, null, true /* force sync */);
|
module = require(moduleName, null, null, true /* force sync */);
|
||||||
if (module && module['default']) { module = module['default']; }
|
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,40 +38,25 @@
|
||||||
|
|
||||||
<div class='topic-body span14'>
|
<div class='topic-body span14'>
|
||||||
<div class='topic-meta-data'>
|
<div class='topic-meta-data'>
|
||||||
<div class="names">
|
{{poster-name post=this expandAction="showPosterExpansion"}}
|
||||||
<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}}
|
<div class='post-info'>
|
||||||
</span>
|
<a href='#' class='post-date' {{bind-attr data-share-url="shareUrl"}} {{bind-attr data-post-number="post_number"}}>{{unboundAgeWithTooltip created_at}}</a>
|
||||||
|
|
||||||
{{#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>
|
</div>
|
||||||
<div class='post-info'>
|
{{#if hasHistory}}
|
||||||
<a href='#' class='post-date' {{bind-attr data-share-url="shareUrl"}} {{bind-attr data-post-number="post_number"}}>{{unboundAgeWithTooltip created_at}}</a>
|
<div class='post-info edits'>
|
||||||
</div>
|
{{#if can_view_edit_history}}
|
||||||
{{#if hasHistory}}
|
<a href='#' class="{{unbound historyHeat}}" {{action showHistory this}} title="{{i18n post.last_edited_on}} {{rawDate updated_at}}">
|
||||||
<div class='post-info edits'>
|
{{editCount}}
|
||||||
{{#if can_view_edit_history}}
|
<i class='fa fa-pencil'></i>
|
||||||
<a href='#' class="{{unbound historyHeat}}" {{action showHistory this}} title="{{i18n post.last_edited_on}} {{rawDate updated_at}}">
|
</a>
|
||||||
{{editCount}}
|
{{else}}
|
||||||
<i class='fa fa-pencil'></i>
|
<span class="{{unbound historyHeat}}" title="{{i18n post.last_edited_on}} {{rawDate updated_at}}">
|
||||||
</a>
|
{{editCount}}
|
||||||
{{else}}
|
<i class='fa fa-pencil'></i>
|
||||||
<span class="{{unbound historyHeat}}" title="{{i18n post.last_edited_on}} {{rawDate updated_at}}">
|
</span>
|
||||||
{{editCount}}
|
|
||||||
<i class='fa fa-pencil'></i>
|
|
||||||
</span>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div {{bind-attr class=":select-posts controller.multiSelect::hidden"}}>
|
<div {{bind-attr class=":select-posts controller.multiSelect::hidden"}}>
|
||||||
|
|
Loading…
Reference in New Issue