user search in admin/users

v1.18.x
Baris Usakli 12 years ago
parent 7ca2c949dd
commit 941ed7e194

@ -3,6 +3,7 @@
jQuery('document').ready(function() { jQuery('document').ready(function() {
var yourid = templates.get('yourid'); var yourid = templates.get('yourid');
var timeoutId = 0;
var url = window.location.href, var url = window.location.href,
parts = url.split('/'), parts = url.split('/'),
@ -17,16 +18,19 @@
}); });
jQuery('#search-user').on('keyup', function () { jQuery('#search-user').on('keyup', function () {
console.log('derp'); if(timeoutId !== 0) {
clearTimeout(timeoutId);
timeoutId = 0;
}
timeoutId = setTimeout(function() {
jQuery('.icon-spinner').removeClass('none'); jQuery('.icon-spinner').removeClass('none');
console.log($('#search-user').val());
socket.emit('api:admin.user.search', $('#search-user').val()); socket.emit('api:admin.user.search', $('#search-user').val());
}, 250);
}); });
function isUserAdmin(element) { function isUserAdmin(element) {
var parent = $(element).parents('.users-box'); var parent = $(element).parents('.users-box');
return (parent.attr('data-admin') !== "0"); return (parent.attr('data-admin') !== "0");

@ -43,7 +43,26 @@
socket.emit('api:get_all_rooms'); socket.emit('api:get_all_rooms');
socket.on('api:admin.user.search', function(data) { socket.on('api:admin.user.search', function(data) {
console.log(data); var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
users: data
}),
userListEl = document.querySelector('.users');
userListEl.innerHTML = html;
jQuery('.icon-spinner').addClass('none');
if(data && data.length === 0) {
$('#user-notfound-notify').html('User not found!')
.show()
.addClass('label-important')
.removeClass('label-success');
}
else
$('#user-notfound-notify').html(data.length + ' user'+(data.length>1?'s':'') + ' found!')
.show()
.addClass('label-success')
.removeClass('label-important');
}); });
</script> </script>

@ -11,8 +11,10 @@
<div class="search {search_display} well"> <div class="search {search_display} well">
<input id="search-user" type="text" placeholder="Enter a username to search"/><br /> <input id="search-user" type="text" placeholder="Enter a username to search"/><br />
<i class="icon-spinner icon-spin none"></i> <i class="icon-spinner icon-spin none"></i>
<span id="user-notfound-notify" class="label label-important hide">User not found!</span><br/>
</div> </div>
<ul class="users">
<!-- BEGIN users --> <!-- BEGIN users -->
<div class="users-box well" data-uid="{users.uid}" data-admin="{users.administrator}" data-username="{users.username}"> <div class="users-box well" data-uid="{users.uid}" data-admin="{users.administrator}" data-username="{users.username}">
<a href="/users/{users.userslug}"> <a href="/users/{users.userslug}">
@ -38,6 +40,7 @@
</div> </div>
</div> </div>
<!-- END users --> <!-- END users -->
</ul>
<input type="hidden" template-variable="yourid" value="{yourid}" /> <input type="hidden" template-variable="yourid" value="{yourid}" />

@ -255,22 +255,17 @@ var utils = require('./../public/src/utils.js'),
User.search = function(username, callback) { User.search = function(username, callback) {
console.log('searching '+username); console.log('searching '+username);
RDB.keys('username:'+ username + '*:uid', function(err, keys) { RDB.keys('username:*'+ username + '*:uid', function(err, keys) {
if(err === null) { if(err === null) {
//console.log(data); if(keys && keys.length) {
/*var keys = [];
for(var i=0, ii=data.length; i<ii; ++i) {
keys.push('')
}*/
RDB.mget(keys, function(err, uids) { RDB.mget(keys, function(err, uids) {
console.log(uids);
User.getDataForUsers(uids, function(userdata) { User.getDataForUsers(uids, function(userdata) {
callback(userdata); callback(userdata);
}); });
}); });
}
else
callback([]);
} }
else else
console.log(err); console.log(err);
@ -378,7 +373,7 @@ var utils = require('./../public/src/utils.js'),
User.getDataForUsers = function(userIds, callback) { User.getDataForUsers = function(userIds, callback) {
var returnData = []; var returnData = [];
if(userIds.length === 0) { if(!userIds || userIds.length === 0) {
callback(returnData); callback(returnData);
return; return;
} }

Loading…
Cancel
Save