diff --git a/public/src/forum/admin/users.js b/public/src/forum/admin/users.js index 554f78660b..ea5ee631d3 100644 --- a/public/src/forum/admin/users.js +++ b/public/src/forum/admin/users.js @@ -195,105 +195,103 @@ define('forum/admin/users', function() { }); } - $('document').ready(function() { - - var timeoutId = 0, - loadingMoreUsers = false; - - var url = window.location.href, - parts = url.split('/'), - active = parts[parts.length - 1]; + var timeoutId = 0, + loadingMoreUsers = false; + + var url = window.location.href, + parts = url.split('/'), + active = parts[parts.length - 1]; + + $('.nav-pills li').removeClass('active'); + $('.nav-pills li a').each(function() { + var $this = $(this); + if ($this.attr('href').match(active)) { + $this.parent().addClass('active'); + return false; + } + }); - $('.nav-pills li').removeClass('active'); - $('.nav-pills li a').each(function() { - var $this = $(this); - if ($this.attr('href').match(active)) { - $this.parent().addClass('active'); - return false; - } - }); + $('#search-user').on('keyup', function() { + if (timeoutId !== 0) { + clearTimeout(timeoutId); + timeoutId = 0; + } - $('#search-user').on('keyup', function() { - if (timeoutId !== 0) { - clearTimeout(timeoutId); - timeoutId = 0; - } + timeoutId = setTimeout(function() { + var username = $('#search-user').val(); - timeoutId = setTimeout(function() { - var username = $('#search-user').val(); + $('.fa-spinner').removeClass('hidden'); - $('.fa-spinner').removeClass('none'); + socket.emit('admin.user.search', username, function(err, data) { + if(err) { + return app.alertError(err.message); + } - socket.emit('admin.user.search', username, function(err, data) { - if(err) { - return app.alertError(err.message); + ajaxify.loadTemplate('admin/users', function(adminUsers) { + $('.users').html(templates.parse(templates.getBlock(adminUsers, 'users'), data)); + + $('.fa-spinner').addClass('hidden'); + + if (data && data.users.length === 0) { + $('#user-notfound-notify').html('User not found!') + .show() + .addClass('label-danger') + .removeClass('label-success'); + } else { + $('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.') + .show() + .addClass('label-success') + .removeClass('label-danger'); } - - ajaxify.loadTemplate('admin/users', function(adminUsers) { - $('.users').html(templates.parse(templates.getBlock(adminUsers, 'users'), data)); - - $('.fa-spinner').addClass('none'); - - if (data && data.users.length === 0) { - $('#user-notfound-notify').html('User not found!') - .show() - .addClass('label-danger') - .removeClass('label-success'); - } else { - $('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.') - .show() - .addClass('label-success') - .removeClass('label-danger'); - } - }); }); - }, 250); + }); + }, 250); + }); + + handleUserCreate(); + + function onUsersLoaded(users) { + ajaxify.loadTemplate('admin/users', function(adminUsers) { + var html = $(templates.parse(templates.getBlock(adminUsers, 'users'), {users: users})); + $('#users-container').append(html); }); + } - handleUserCreate(); + function loadMoreUsers() { + var set = ''; + if (active === 'latest') { + set = 'users:joindate'; + } else if (active === 'sort-posts') { + set = 'users:postcount'; + } else if (active === 'sort-reputation') { + set = 'users:reputation'; + } - function onUsersLoaded(users) { - ajaxify.loadTemplate('admin/users', function(adminUsers) { - var html = $(templates.parse(templates.getBlock(adminUsers, 'users'), {users: users})); - $('#users-container').append(html); + if (set) { + loadingMoreUsers = true; + socket.emit('user.loadMore', { + set: set, + after: $('#users-container').children().length + }, function(err, data) { + if (data && data.users.length) { + onUsersLoaded(data.users); + } + loadingMoreUsers = false; }); } + } - function loadMoreUsers() { - var set = ''; - if (active === 'latest') { - set = 'users:joindate'; - } else if (active === 'sort-posts') { - set = 'users:postcount'; - } else if (active === 'sort-reputation') { - set = 'users:reputation'; - } + $('#load-more-users-btn').on('click', loadMoreUsers); - if (set) { - loadingMoreUsers = true; - socket.emit('user.loadMore', { - set: set, - after: $('#users-container').children().length - }, function(err, data) { - if (data && data.users.length) { - onUsersLoaded(data.users); - } - loadingMoreUsers = false; - }); - } - } + $(window).off('scroll').on('scroll', function() { + var bottom = ($(document).height() - $(window).height()) * 0.9; - $('#load-more-users-btn').on('click', loadMoreUsers); - - $(window).off('scroll').on('scroll', function() { - var bottom = ($(document).height() - $(window).height()) * 0.9; + if ($(window).scrollTop() > bottom && !loadingMoreUsers) { + loadMoreUsers(); + } + }); - if ($(window).scrollTop() > bottom && !loadingMoreUsers) { - loadMoreUsers(); - } - }); - }); }; return Users; diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js index 1d68d993c7..cf4661e28b 100644 --- a/src/controllers/admin/users.js +++ b/src/controllers/admin/users.js @@ -7,7 +7,7 @@ var usersController = {}; usersController.search = function(req, res, next) { res.render('admin/users', { - search_display: 'block', + search_display: '', loadmore_display: 'none', users: [] }); @@ -31,7 +31,7 @@ function getUsers(set, req, res, next) { return next(err); } res.render('admin/users', { - search_display: 'none', + search_display: 'hidden', loadmore_display: 'block', users: users, yourid: req.user.uid diff --git a/src/controllers/users.js b/src/controllers/users.js index 039bb4468f..c365188bb3 100644 --- a/src/controllers/users.js +++ b/src/controllers/users.js @@ -34,7 +34,7 @@ usersController.getOnlineUsers = function(req, res, next) { var anonymousUserCount = websockets.getOnlineAnonCount(); var userData = { - search_display: 'none', + search_display: 'hidden', loadmore_display: results.count > 50 ? 'block' : 'hide', users: results.users, anonymousUserCount: anonymousUserCount, @@ -74,7 +74,7 @@ function getUsers(set, res, next) { }); var userData = { - search_display: 'none', + search_display: 'hidden', loadmore_display: results.count > 50 ? 'block' : 'hide', users: results.users, show_anon: 'hide' @@ -87,7 +87,7 @@ function getUsers(set, res, next) { usersController.getUsersForSearch = function(req, res, next) { var data = { search_display: 'block', - loadmore_display: 'none', + loadmore_display: 'hidden', users: [], show_anon: 'hide' }; diff --git a/src/views/admin/users.tpl b/src/views/admin/users.tpl index a4334f3ecd..b7267fb67c 100644 --- a/src/views/admin/users.tpl +++ b/src/views/admin/users.tpl @@ -29,12 +29,12 @@ -