mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 09:36:16 +01:00
closes #1728
This commit is contained in:
@@ -4,5 +4,7 @@
|
||||
"most_reputation": "Most Reputation",
|
||||
"search": "Search",
|
||||
"enter_username": "Enter a username to search",
|
||||
"load_more": "Load More"
|
||||
"load_more": "Load More",
|
||||
"user-not-found": "User not found!",
|
||||
"users-found-search-took": "%1 user(s) found! Search took %2 ms."
|
||||
}
|
||||
@@ -32,43 +32,54 @@ define('forum/users', function() {
|
||||
}
|
||||
|
||||
timeoutId = setTimeout(function() {
|
||||
function reset() {
|
||||
notify.html('<i class="fa fa-search"></i>');
|
||||
notify.parent().removeClass('btn-warning label-warning btn-success label-success');
|
||||
}
|
||||
var username = $('#search-user').val();
|
||||
var notify = $('#user-notfound-notify');
|
||||
|
||||
if (username == '') {
|
||||
$('#user-notfound-notify').html('<i class="fa fa-circle-o"></i>');
|
||||
$('#user-notfound-notify').parent().removeClass('btn-warning label-warning btn-success label-success');
|
||||
if (username === '') {
|
||||
notify.html('<i class="fa fa-circle-o"></i>');
|
||||
notify.parent().removeClass('btn-warning label-warning btn-success label-success');
|
||||
return;
|
||||
}
|
||||
|
||||
if (lastSearch === username) return;
|
||||
if (lastSearch === username) {
|
||||
return;
|
||||
}
|
||||
lastSearch = username;
|
||||
|
||||
$('#user-notfound-notify').html('<i class="fa fa-spinner fa-spin"></i>');
|
||||
notify.html('<i class="fa fa-spinner fa-spin"></i>');
|
||||
|
||||
socket.emit('user.search', username, function(err, data) {
|
||||
if(err) {
|
||||
return app.alert(err.message);
|
||||
if (err) {
|
||||
reset();
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
$('#user-notfound-notify').html('You need to be logged in to search!');
|
||||
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ajaxify.loadTemplate('users', function(usersTemplate) {
|
||||
var html = templates.parse(templates.getBlock(usersTemplate, 'users'), data);
|
||||
|
||||
translator.translate(html, function(translated) {
|
||||
$('#users-container').html(translated);
|
||||
|
||||
|
||||
if (data && data.users.length === 0) {
|
||||
$('#user-notfound-notify').html('User not found!');
|
||||
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
||||
if (!data.users.length) {
|
||||
translator.translate('[[users:user-not-found]]', function(translated) {
|
||||
notify.html(translated);
|
||||
notify.parent().addClass('btn-warning label-warning');
|
||||
});
|
||||
} else {
|
||||
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.');
|
||||
$('#user-notfound-notify').parent().addClass('btn-success label-success');
|
||||
translator.translate('[[users:users-found-search-took, ' + data.users.length + ', ' + data.timing + ']]', function(translated) {
|
||||
notify.html(translated);
|
||||
notify.parent().addClass('btn-success label-success');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,6 +50,9 @@ SocketUser.increaseViewCount = function(socket, uid, callback) {
|
||||
};
|
||||
|
||||
SocketUser.search = function(socket, username, callback) {
|
||||
if (!socket.uid) {
|
||||
return callback(new Error('[[error:not-logged-in]]'));
|
||||
}
|
||||
user.search(username, callback);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user