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..231fa268796 --- /dev/null +++ b/app/assets/javascripts/discourse/components/poster-name.js.es6 @@ -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("" + username + ""); + + // Add a glyph if we have one + var glyph = this.posterGlyph(post); + if (!Em.isEmpty(glyph)) { + buffer.push(""); + } + buffer.push(""); + + // Are we showing full names? + if (name && (name === username) && this.get('displayNameOnPosts')) { + buffer.push("" + name + ""); + } + + // User titles + var title = post.get('user_title'); + if (!Em.isEmpty(title)) { + var primaryGroupName = post.get('primary_group_name'); + + buffer.push(''); + if (Em.isEmpty(primaryGroupName)) { + buffer.push(title); + } else { + buffer.push("" + title + ""); + } + buffer.push(""); + } + + 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; diff --git a/app/assets/javascripts/discourse/ember/resolver.js b/app/assets/javascripts/discourse/ember/resolver.js index 0ae8bfd322f..8d989eb7e7f 100644 --- a/app/assets/javascripts/discourse/ember/resolver.js +++ b/app/assets/javascripts/discourse/ember/resolver.js @@ -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); }, /** diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index 468fb5fb133..d864db6d918 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -38,40 +38,25 @@