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

@ -43,7 +43,26 @@
socket.emit('api:get_all_rooms');
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>

@ -11,33 +11,36 @@
<div class="search {search_display} well">
<input id="search-user" type="text" placeholder="Enter a username to search"/><br />
<i class="icon-spinner icon-spin none"></i>
<span id="user-notfound-notify" class="label label-important hide">User not found!</span><br/>
</div>
<!-- BEGIN users -->
<div class="users-box well" data-uid="{users.uid}" data-admin="{users.administrator}" data-username="{users.username}">
<a href="/users/{users.userslug}">
<img src="{users.picture}" class="user-8080-picture"/>
</a>
<br/>
<a href="/users/{users.userslug}">{users.username}</a>
<br/>
<div title="reputation">
<span id='reputation'>{users.reputation}</span>
<i class='icon-star'></i>
<ul class="users">
<!-- BEGIN users -->
<div class="users-box well" data-uid="{users.uid}" data-admin="{users.administrator}" data-username="{users.username}">
<a href="/users/{users.userslug}">
<img src="{users.picture}" class="user-8080-picture"/>
</a>
<br/>
<a href="/users/{users.userslug}">{users.username}</a>
<br/>
<div title="reputation">
<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 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>
<!-- END users -->
<!-- END users -->
</ul>
<input type="hidden" template-variable="yourid" value="{yourid}" />

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

Loading…
Cancel
Save