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,14 +18,17 @@
}); });
jQuery('#search-user').on('keyup', function () { jQuery('#search-user').on('keyup', function () {
console.log('derp'); if(timeoutId !== 0) {
jQuery('.icon-spinner').removeClass('none'); clearTimeout(timeoutId);
console.log($('#search-user').val()); timeoutId = 0;
socket.emit('api:admin.user.search', $('#search-user').val()); }
});
timeoutId = setTimeout(function() {
jQuery('.icon-spinner').removeClass('none');
socket.emit('api:admin.user.search', $('#search-user').val());
}, 250);
});
function isUserAdmin(element) { function isUserAdmin(element) {

@ -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,33 +11,36 @@
<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>
<!-- BEGIN users --> <ul class="users">
<div class="users-box well" data-uid="{users.uid}" data-admin="{users.administrator}" data-username="{users.username}"> <!-- BEGIN users -->
<a href="/users/{users.userslug}"> <div class="users-box well" data-uid="{users.uid}" data-admin="{users.administrator}" data-username="{users.username}">
<img src="{users.picture}" class="user-8080-picture"/> <a href="/users/{users.userslug}">
</a> <img src="{users.picture}" class="user-8080-picture"/>
<br/> </a>
<a href="/users/{users.userslug}">{users.username}</a> <br/>
<br/> <a href="/users/{users.userslug}">{users.username}</a>
<div title="reputation"> <br/>
<span id='reputation'>{users.reputation}</span> <div title="reputation">
<i class='icon-star'></i> <span id='reputation'>{users.reputation}</span>
<i class='icon-star'></i>
</div>
<div title="post count">
<span id='postcount'>{users.postcount}</span>
<i class='icon-pencil'></i>
</div>
<div>
<a href="#" class="btn admin-btn">Admin</a>
</div>
<br/>
<div>
<a href="#" class="btn delete-btn btn-danger">Delete</a>
</div>
</div> </div>
<div title="post count"> <!-- END users -->
<span id='postcount'>{users.postcount}</span> </ul>
<i class='icon-pencil'></i>
</div>
<div>
<a href="#" class="btn admin-btn">Admin</a>
</div>
<br/>
<div>
<a href="#" class="btn delete-btn btn-danger">Delete</a>
</div>
</div>
<!-- END users -->
<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) {
RDB.mget(keys, function(err, uids) {
/*var keys = []; User.getDataForUsers(uids, function(userdata) {
for(var i=0, ii=data.length; i<ii; ++i) { callback(userdata);
keys.push('') });
}*/ });
}
RDB.mget(keys, function(err, uids) { else
console.log(uids); callback([]);
User.getDataForUsers(uids, function(userdata) {
callback(userdata);
});
});
} }
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