From c870e8bbf389c1d84c35ee1c0b654931cef1d02a Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 26 Jun 2013 12:32:30 -0400 Subject: [PATCH] testing user search in admin panel --- public/src/forum/admin/users.js | 106 +++++++++++++++++++++++++++++++ public/src/forum/footer.js | 3 + public/templates/admin/users.tpl | 99 +---------------------------- src/user.js | 12 ++++ src/websockets.js | 8 +++ 5 files changed, 131 insertions(+), 97 deletions(-) create mode 100644 public/src/forum/admin/users.js diff --git a/public/src/forum/admin/users.js b/public/src/forum/admin/users.js new file mode 100644 index 0000000000..99d6d8aa0f --- /dev/null +++ b/public/src/forum/admin/users.js @@ -0,0 +1,106 @@ + +(function() { + jQuery('document').ready(function() { + + var yourid = templates.get('yourid'); + + var url = window.location.href, + parts = url.split('/'), + active = parts[parts.length-1]; + + jQuery('.nav-pills li').removeClass('active'); + jQuery('.nav-pills li a').each(function() { + if (this.getAttribute('href').match(active)) { + jQuery(this.parentNode).addClass('active'); + return false; + } + }); + + 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()); + }); + + + + socket.on('api:admin.user.search', function(data) { + console.log(data); + }); + + function isUserAdmin(element) { + var parent = $(element).parents('.users-box'); + return (parent.attr('data-admin') !== "0"); + } + + function getUID(element) { + var parent = $(element).parents('.users-box'); + return parent.attr('data-uid'); + } + + jQuery('.admin-btn').each(function(index, element) { + var adminBtn = $(element); + var isAdmin = isUserAdmin(adminBtn); + + if(isAdmin) + adminBtn.addClass('btn-success'); + else + adminBtn.removeClass('btn-success'); + + }); + + jQuery('.delete-btn').each(function(index, element) { + var deleteBtn = $(element); + var isAdmin = isUserAdmin(deleteBtn); + + if(isAdmin) + deleteBtn.addClass('disabled'); + else + deleteBtn.show(); + }); + + jQuery('.admin-btn').on('click', function() { + var adminBtn = $(this); + var isAdmin = isUserAdmin(adminBtn); + var parent = adminBtn.parents('.users-box'); + var uid = getUID(adminBtn); + + if(isAdmin) { + socket.emit('api:admin.user.removeAdmin', uid); + adminBtn.removeClass('btn-success'); + parent.find('.delete-btn').removeClass('disabled'); + parent.attr('data-admin', 0); + } + else { + bootbox.confirm('Do you really want to make "' + parent.attr('data-username') +'" an admin?', function(confirm) { + if(confirm) { + socket.emit('api:admin.user.makeAdmin', uid); + adminBtn.addClass('btn-success'); + parent.find('.delete-btn').addClass('disabled'); + parent.attr('data-admin', 1); + } + }); + } + + return false; + }); + + jQuery('.delete-btn').on('click', function() { + var deleteBtn = $(this); + var isAdmin = isUserAdmin(deleteBtn); + var parent = deleteBtn.parents('.users-box'); + var uid = getUID(deleteBtn); + + if(!isAdmin) { + bootbox.confirm('Do you really want to delete "' + parent.attr('data-username') +'"?', function(confirm) { + socket.emit('api:admin.user.deleteUser', uid); + }); + } + + return false; + }); + + }); + +}()); \ No newline at end of file diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index 6403518721..f3d40432f9 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -132,6 +132,9 @@ socket.emit('api:notifications.hasFlag'); + + + require(['mobileMenu'], function(mobileMenu) { mobileMenu.init(); }); diff --git a/public/templates/admin/users.tpl b/public/templates/admin/users.tpl index 1b900b9255..bac6328897 100644 --- a/public/templates/admin/users.tpl +++ b/public/templates/admin/users.tpl @@ -9,7 +9,7 @@ @@ -36,105 +36,10 @@
Delete
- - \ No newline at end of file + \ No newline at end of file diff --git a/src/user.js b/src/user.js index 7729509660..de561ca4f9 100644 --- a/src/user.js +++ b/src/user.js @@ -253,6 +253,18 @@ var utils = require('./../public/src/utils.js'), }); } + User.search = function(username, callback) { + console.log('searching '+username); + RDB.keys('username:'+ username + '*:uid', function(err, data) { + if(err === null) { + console.log(data); + callback(data); + } + else + console.log(err); + }); + } + User.sendConfirmationEmail = function (email) { if (global.config['email:host'] && global.config['email:port'] && global.config['email:from']) { var confirm_code = utils.generateUUID(), diff --git a/src/websockets.js b/src/websockets.js index 4c4ba1508c..ea4bb44adf 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -431,6 +431,14 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), admin.user.deleteUser(uid, theirid, socket); } }); + + socket.on('api:admin.user.search', function(username) { + if(uid && uid > 0) { + user.search(username, function(data) { + socket.emit('api:admin.user.search', data); + }); + } + }); }); }(SocketIO));