From 3c3ad7d115ac2df1c8362ad09cdf50b3b821c68a Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 23 Jun 2014 19:10:59 -0400 Subject: [PATCH] closes #1728 --- public/language/en_GB/users.json | 4 ++- public/src/forum/users.js | 43 ++++++++++++++++++++------------ src/socket.io/user.js | 3 +++ 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/public/language/en_GB/users.json b/public/language/en_GB/users.json index c41127ad9d..0e391e4505 100644 --- a/public/language/en_GB/users.json +++ b/public/language/en_GB/users.json @@ -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." } \ No newline at end of file diff --git a/public/src/forum/users.js b/public/src/forum/users.js index 7f8eee3647..589d88ba34 100644 --- a/public/src/forum/users.js +++ b/public/src/forum/users.js @@ -32,43 +32,54 @@ define('forum/users', function() { } timeoutId = setTimeout(function() { + function reset() { + notify.html(''); + 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(''); - $('#user-notfound-notify').parent().removeClass('btn-warning label-warning btn-success label-success'); + if (username === '') { + notify.html(''); + 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(''); + notify.html(''); 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'); + }); } }); }); diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 5cf805362b..58ebcc0ca7 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -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); };