v1.18.x
barisusakli 9 years ago
parent 74b23636cb
commit ae9606f5ee

@ -1,6 +1,6 @@
'use strict';
/* globals define, socket, app, ajaxify, templates */
/* globals define, socket, app, templates, bootbox */
define('forum/users', ['translator'], function(translator) {
var Users = {};
@ -104,15 +104,12 @@ define('forum/users', ['translator'], function(translator) {
function doSearch(page) {
var username = $('#search-user').val();
var notify = $('#user-notfound-notify');
page = page || 1;
if (!username) {
return loadPage(page);
}
notify.html('<i class="fa fa-spinner fa-spin"></i>');
socket.emit('user.search', {
query: username,
page: page,
@ -121,28 +118,15 @@ define('forum/users', ['translator'], function(translator) {
onlineOnly: $('.search .online-only').is(':checked')
}, function(err, data) {
if (err) {
resetSearchNotify();
return app.alertError(err.message);
}
if (!data) {
return resetSearchNotify();
}
renderSearchResults(data);
});
}
function resetSearchNotify() {
var notify = $('#user-notfound-notify');
notify.html('<i class="fa fa-search"></i>');
notify.parent().removeClass('btn-warning label-warning btn-success label-success');
}
function loadPage(page) {
socket.emit('user.loadSearchPage', {page: page, onlineOnly: $('.search .online-only').is(':checked')}, function(err, data) {
resetSearchNotify();
if (err) {
return app.alertError(err.message);
}
@ -152,7 +136,7 @@ define('forum/users', ['translator'], function(translator) {
}
function renderSearchResults(data) {
var notify = $('#user-notfound-notify');
$('#load-more-users-btn').addClass('hide');
templates.parse('partials/paginator', {pagination: data.pagination}, function(html) {
$('.pagination-container').replaceWith(html);
});
@ -160,20 +144,9 @@ define('forum/users', ['translator'], function(translator) {
templates.parse('users', 'users', data, function(html) {
translator.translate(html, function(translated) {
$('#users-container').html(translated);
if (!data.users.length) {
translator.translate('[[error:no-user]]', function(translated) {
notify.html(translated);
notify.parent().removeClass('btn-success label-success').addClass('btn-warning label-warning');
});
} else {
translator.translate('[[users:users-found-search-took, ' + data.matchCount + ', ' + data.timing + ']]', function(translated) {
notify.html(translated);
notify.parent().removeClass('btn-warning label-warning').addClass('btn-success label-success');
});
}
});
});
}
function onUserStatusChange(data) {

@ -41,7 +41,6 @@ usersController.getOnlineUsers = function(req, res, next) {
var userData = {
'route_users:online': true,
search_display: 'hidden',
loadmore_display: results.count > 50 ? 'block' : 'hide',
users: results.users,
anonymousUserCount: websockets.getOnlineAnonCount(),
@ -94,7 +93,6 @@ usersController.getUsers = function(set, start, stop, req, res, next) {
var pageCount = Math.ceil(data.count / (parseInt(meta.config.userSearchResultsPerPage, 10) || 20));
var userData = {
search_display: 'hidden',
loadmore_display: data.count > (stop - start + 1) ? 'block' : 'hide',
users: data.users,
pagination: pagination.create(1, pageCount),
@ -126,29 +124,6 @@ usersController.getUsersAndCount = function(set, uid, start, stop, callback) {
});
};
usersController.getUsersForSearch = function(req, res, next) {
if (!req.uid && parseInt(meta.config.allowGuestUserSearching, 10) !== 1) {
return helpers.notAllowed(req, res);
}
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20;
usersController.getUsersAndCount('users:joindate', req.uid, 0, resultsPerPage - 1, function(err, data) {
if (err) {
return next(err);
}
var userData = {
search_display: 'block',
loadmore_display: 'hidden',
users: data.users,
title: '[[pages:users/search]]',
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[global:users]]', url: '/users'}, {text: '[[global:search]]'}])
};
render(req, res, userData, next);
});
};
function render(req, res, data, next) {
plugins.fireHook('filter:users.build', { req: req, res: res, templateData: data }, function(err, data) {
if (err) {

@ -62,8 +62,7 @@ function userRoutes(app, middleware, controllers) {
setupPageRoute(app, '/users/online', middleware, middlewares, controllers.users.getOnlineUsers);
setupPageRoute(app, '/users/sort-posts', middleware, middlewares, controllers.users.getUsersSortedByPosts);
setupPageRoute(app, '/users/sort-reputation', middleware, middlewares, controllers.users.getUsersSortedByReputation);
setupPageRoute(app, '/users/search', middleware, middlewares, controllers.users.getUsersForSearch);
}
}
function groupRoutes(app, middleware, controllers) {

Loading…
Cancel
Save