mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
remove duplicate code
fix issue where clicking on the same user in 2 locations on the page would not work correctly centralize logic
This commit is contained in:
parent
7b484937d0
commit
9c81f2c6af
@ -1,14 +1,9 @@
|
|||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
tagName: 'a',
|
tagName: 'a',
|
||||||
attributeBindings: ['href'],
|
attributeBindings: ['href','data-user-card'],
|
||||||
classNames: ['trigger-user-card'],
|
classNames: ['trigger-user-card'],
|
||||||
href: Em.computed.alias('post.usernameUrl'),
|
href: Em.computed.oneWay('post.usernameUrl'),
|
||||||
|
"data-user-card": Em.computed.oneWay('post.username'),
|
||||||
click: function(e) {
|
|
||||||
this.appEvents.trigger('poster:expand', $(e.target));
|
|
||||||
this.sendAction('action', this.get('post'));
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function(buffer) {
|
render: function(buffer) {
|
||||||
var avatar = Handlebars.helpers.avatar(this.get('post'), {hash: {imageSize: 'large'}});
|
var avatar = Handlebars.helpers.avatar(this.get('post'), {hash: {imageSize: 'large'}});
|
||||||
|
@ -26,7 +26,7 @@ var PosterNameComponent = Em.Component.extend({
|
|||||||
linkClass += ' ' + primaryGroupName;
|
linkClass += ' ' + primaryGroupName;
|
||||||
}
|
}
|
||||||
// Main link
|
// Main link
|
||||||
buffer.push("<span class='" + linkClass + "'><a href='" + url + "' data-auto-route='true'>" + username + "</a>");
|
buffer.push("<span class='" + linkClass + "'><a href='" + url + "' data-auto-route='true' data-user-card='" + username + "'>" + username + "</a>");
|
||||||
|
|
||||||
// Add a glyph if we have one
|
// Add a glyph if we have one
|
||||||
var glyph = this.posterGlyph(post);
|
var glyph = this.posterGlyph(post);
|
||||||
@ -38,7 +38,7 @@ var PosterNameComponent = Em.Component.extend({
|
|||||||
// Are we showing full names?
|
// Are we showing full names?
|
||||||
if (name && this.get('displayNameOnPosts') && (this.sanitizeName(name) !== this.sanitizeName(username))) {
|
if (name && this.get('displayNameOnPosts') && (this.sanitizeName(name) !== this.sanitizeName(username))) {
|
||||||
name = Handlebars.Utils.escapeExpression(name);
|
name = Handlebars.Utils.escapeExpression(name);
|
||||||
buffer.push("<span class='full-name'><a href='" + url + "' data-auto-route='true'>" + name + "</a></span>");
|
buffer.push("<span class='full-name'><a href='" + url + "' data-auto-route='true' data-user-card='" + username + "'>" + name + "</a></span>");
|
||||||
}
|
}
|
||||||
|
|
||||||
// User titles
|
// User titles
|
||||||
@ -59,20 +59,6 @@ var PosterNameComponent = Em.Component.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
click: function(e) {
|
|
||||||
var $target = $(e.target),
|
|
||||||
href = $target.attr('href'),
|
|
||||||
url = this.get('post.usernameUrl');
|
|
||||||
|
|
||||||
if (!Em.isEmpty(href) && href !== url) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
this.appEvents.trigger('poster:expand', $target);
|
|
||||||
this.sendAction('expandAction', this.get('post'));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Overwrite this to give a user a custom font awesome glyph.
|
Overwrite this to give a user a custom font awesome glyph.
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ export default ObjectController.extend({
|
|||||||
participant: null,
|
participant: null,
|
||||||
avatar: null,
|
avatar: null,
|
||||||
userLoading: null,
|
userLoading: null,
|
||||||
|
cardTarget: null,
|
||||||
|
|
||||||
postStream: Em.computed.alias('controllers.topic.postStream'),
|
postStream: Em.computed.alias('controllers.topic.postStream'),
|
||||||
enoughPostsForFiltering: Em.computed.gte('participant.post_count', 2),
|
enoughPostsForFiltering: Em.computed.gte('participant.post_count', 2),
|
||||||
@ -34,7 +35,7 @@ export default ObjectController.extend({
|
|||||||
return img && img.indexOf('fa-') !== 0;
|
return img && img.indexOf('fa-') !== 0;
|
||||||
}.property('user.card_badge.image'),
|
}.property('user.card_badge.image'),
|
||||||
|
|
||||||
show: function(username, uploadedAvatarId) {
|
show: function(username, target) {
|
||||||
// XSS protection (should be encapsulated)
|
// XSS protection (should be encapsulated)
|
||||||
username = username.replace(/[^A-Za-z0-9_]/g, "");
|
username = username.replace(/[^A-Za-z0-9_]/g, "");
|
||||||
var url = "/users/" + username;
|
var url = "/users/" + username;
|
||||||
@ -48,16 +49,12 @@ export default ObjectController.extend({
|
|||||||
var currentUsername = this.get('username'),
|
var currentUsername = this.get('username'),
|
||||||
wasVisible = this.get('visible');
|
wasVisible = this.get('visible');
|
||||||
|
|
||||||
if (uploadedAvatarId) {
|
this.set('avatar', null);
|
||||||
this.set('avatar', {username: username, uploaded_avatar_id: uploadedAvatarId});
|
|
||||||
} else {
|
|
||||||
this.set('avatar', null);
|
|
||||||
}
|
|
||||||
this.set('username', username);
|
this.set('username', username);
|
||||||
|
|
||||||
// If we click the avatar again, close it.
|
// If we click the avatar again, close it (unless its diff element on the screen).
|
||||||
if (username === currentUsername && wasVisible) {
|
if (target === this.get('cardTarget') && wasVisible) {
|
||||||
this.setProperties({ visible: false, username: null, avatar: null });
|
this.setProperties({ visible: false, username: null, avatar: null, cardTarget: null });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,8 +73,9 @@ export default ObjectController.extend({
|
|||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
self.set('user', null);
|
self.set('user', null);
|
||||||
|
|
||||||
self.set('userLoading', username);
|
self.set('userLoading', username);
|
||||||
|
self.set('cardTarget', target);
|
||||||
|
|
||||||
Discourse.User.findByUsername(username).then(function (user) {
|
Discourse.User.findByUsername(username).then(function (user) {
|
||||||
self.setProperties({ user: user, avatar: user, visible: true});
|
self.setProperties({ user: user, avatar: user, visible: true});
|
||||||
}).finally(function(){
|
}).finally(function(){
|
||||||
@ -87,6 +85,7 @@ export default ObjectController.extend({
|
|||||||
|
|
||||||
close: function() {
|
close: function() {
|
||||||
this.set('visible', false);
|
this.set('visible', false);
|
||||||
|
this.set('cardTarget', null);
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -19,11 +19,6 @@ var ApplicationRoute = Discourse.Route.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
expandUser: function(user) {
|
|
||||||
this.controllerFor('user-card').show(user.get('username'), user.get('uploaded_avatar_id'));
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
|
|
||||||
error: function(err, transition) {
|
error: function(err, transition) {
|
||||||
if (err.status === 404) {
|
if (err.status === 404) {
|
||||||
// 404
|
// 404
|
||||||
|
@ -38,18 +38,6 @@ Discourse.TopicRoute = Discourse.Route.extend({
|
|||||||
this.controllerFor("topic-admin-menu").send("show");
|
this.controllerFor("topic-admin-menu").send("show");
|
||||||
},
|
},
|
||||||
|
|
||||||
// Modals that can pop up within a topic
|
|
||||||
expandPostUser: function(post) {
|
|
||||||
this.controllerFor('user-card').show(post.get('username'), post.get('uploaded_avatar_id'));
|
|
||||||
},
|
|
||||||
|
|
||||||
expandPostUsername: function(username) {
|
|
||||||
username = username.replace(/^@/, '');
|
|
||||||
if (!Em.isEmpty(username)) {
|
|
||||||
this.controllerFor('user-card').show(username);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
showFlags: function(post) {
|
showFlags: function(post) {
|
||||||
Discourse.Route.showModal(this, 'flag', post);
|
Discourse.Route.showModal(this, 'flag', post);
|
||||||
this.controllerFor('flag').setProperties({ selected: null });
|
this.controllerFor('flag').setProperties({ selected: null });
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
<div class='topic-avatar'>
|
<div class='topic-avatar'>
|
||||||
<div class='contents'>
|
<div class='contents'>
|
||||||
<div>
|
<div>
|
||||||
{{poster-avatar action="expandPostUser" post=this classNames="main-avatar"}}
|
{{poster-avatar post=this classNames="main-avatar"}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='topic-body'>
|
<div class='topic-body'>
|
||||||
<div class="topic-meta-data">
|
<div class="topic-meta-data">
|
||||||
{{poster-name post=this expandAction="expandPostUser"}}
|
{{poster-name post=this}}
|
||||||
{{#if view.parentView.previousPost}}<a href='{{unbound url}}' class="post-info arrow" title="{{i18n topic.jump_reply_up}}"><i class='fa fa-arrow-up'></i></a>{{/if}}
|
{{#if view.parentView.previousPost}}<a href='{{unbound url}}' class="post-info arrow" title="{{i18n topic.jump_reply_up}}"><i class='fa fa-arrow-up'></i></a>{{/if}}
|
||||||
<div class='post-info post-date'>{{age-with-tooltip created_at}}</div>
|
<div class='post-info post-date'>{{age-with-tooltip created_at}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<div class='topic-avatar'>
|
<div class='topic-avatar'>
|
||||||
<div class="contents">
|
<div class="contents">
|
||||||
{{#unless userDeleted}}
|
{{#unless userDeleted}}
|
||||||
{{poster-avatar action="expandPostUser" post=this classNames="main-avatar"}}
|
{{poster-avatar post=this classNames="main-avatar"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<i class="fa fa-trash-o deleted-user-avatar"></i>
|
<i class="fa fa-trash-o deleted-user-avatar"></i>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
<div class='topic-body'>
|
<div class='topic-body'>
|
||||||
<div class='topic-meta-data'>
|
<div class='topic-meta-data'>
|
||||||
{{poster-name post=this expandAction="expandPostUser"}}
|
{{poster-name post=this}}
|
||||||
<div class='post-info'>
|
<div class='post-info'>
|
||||||
<a class='post-date' {{bind-attr href="shareUrl" data-share-url="shareUrl" data-post-number="post_number"}}>{{age-with-tooltip created_at}}</a>
|
<a class='post-date' {{bind-attr href="shareUrl" data-share-url="shareUrl" data-post-number="post_number"}}>{{age-with-tooltip created_at}}</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -30,10 +30,8 @@ export default Discourse.View.extend(CleansUp, {
|
|||||||
$('html').off(clickOutsideEventName).on(clickOutsideEventName, function(e) {
|
$('html').off(clickOutsideEventName).on(clickOutsideEventName, function(e) {
|
||||||
if (self.get('controller.visible')) {
|
if (self.get('controller.visible')) {
|
||||||
var $target = $(e.target);
|
var $target = $(e.target);
|
||||||
if ($target.closest('.trigger-user-card').length > 0) { return; }
|
if ($target.closest('[data-user-card]').data('userCard') ||
|
||||||
if (self.$().has(e.target).length !== 0) { return; }
|
$target.closest('a.mention').length > 0) {
|
||||||
|
|
||||||
if ($target.data("userCard")|| $target.closest('a.mention')) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,19 +41,22 @@ export default Discourse.View.extend(CleansUp, {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var expand = function(username, $target){
|
||||||
|
self._posterExpand($target);
|
||||||
|
self.get('controller').show(username, $target[0]);
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
$('#main-outlet').on(clickDataExpand, '[data-user-card]', function(e) {
|
$('#main-outlet').on(clickDataExpand, '[data-user-card]', function(e) {
|
||||||
var $target = $(e.currentTarget);
|
var $target = $(e.currentTarget);
|
||||||
self._posterExpand($target);
|
var username = $target.data('user-card');
|
||||||
self.get('controller').show($target.data('user-card'));
|
return expand(username, $target);
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#main-outlet').on(clickMention, 'a.mention', function(e) {
|
$('#main-outlet').on(clickMention, 'a.mention', function(e) {
|
||||||
var $target = $(e.target);
|
var $target = $(e.target);
|
||||||
self._posterExpand($target);
|
|
||||||
var username = $target.text().replace(/^@/, '');
|
var username = $target.text().replace(/^@/, '');
|
||||||
self.get('controller').show(username);
|
return expand(username, $target);
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
}.on('didInsertElement'),
|
}.on('didInsertElement'),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user