Add channel list search to ACP

This commit is contained in:
calzoneman 2013-08-07 10:30:16 -04:00
parent 278570f3ed
commit 4af0291470
3 changed files with 95 additions and 0 deletions

29
acp.js
View File

@ -60,6 +60,35 @@ module.exports = function (Server) {
user.socket.emit("acp-userdata", rows); user.socket.emit("acp-userdata", rows);
}); });
user.socket.on("acp-lookup-channel", function (data) {
var db = Server.db.getConnection();
if(!db) {
return;
}
var query;
if(data.field === "owner") {
query = Server.db.createQuery(
"SELECT * FROM channels WHERE owner LIKE ?",
["%" + data.value + "%"]
);
} else if (data.field === "name") {
query = Server.db.createQuery(
"SELECT * FROM channels WHERE name LIKE ?",
["%" + data.value + "%"]
);
} else {
return;
}
var results = db.querySync(query);
if(!results)
return;
var rows = results.fetchAllSync();
user.socket.emit("acp-channeldata", rows);
});
user.socket.on("acp-reset-password", function(data) { user.socket.on("acp-reset-password", function(data) {
if(Auth.getGlobalRank(data.name) >= user.global_rank) if(Auth.getGlobalRank(data.name) >= user.global_rank)
return; return;

View File

@ -42,6 +42,7 @@
<li id="li_announce"><a href="javascript:void(0)" id="show_announce">Announcement Manager</a></li> <li id="li_announce"><a href="javascript:void(0)" id="show_announce">Announcement Manager</a></li>
<li id="li_gbans"><a href="javascript:void(0)" id="show_gbans">Global Bans</a></li> <li id="li_gbans"><a href="javascript:void(0)" id="show_gbans">Global Bans</a></li>
<li id="li_userlookup"><a href="javascript:void(0)" id="show_userlookup">Users</a></li> <li id="li_userlookup"><a href="javascript:void(0)" id="show_userlookup">Users</a></li>
<li id="li_chanlookup"><a href="javascript:void(0)" id="show_chanlookup">Channels</a></li>
<li id="li_chanloaded"><a href="javascript:void(0)" id="show_chanloaded">Loaded Channels</a></li> <li id="li_chanloaded"><a href="javascript:void(0)" id="show_chanloaded">Loaded Channels</a></li>
<li id="li_actionlog"><a href="javascript:void(0)" id="show_actionlog">Action Log</a></li> <li id="li_actionlog"><a href="javascript:void(0)" id="show_actionlog">Action Log</a></li>
<li id="li_stats"><a href="javascript:void(0)" id="show_stats">Server Stats</a></li> <li id="li_stats"><a href="javascript:void(0)" id="show_stats">Server Stats</a></li>
@ -163,6 +164,26 @@
</thead> </thead>
</table> </table>
</div> </div>
<div class="span12" id="chanlookup">
<h3>Channels</h3>
<form class="form-inline" action="javascript:void(0)">
<input type="text" id="chanlookup_value" placeholder="Name">
<select id="chanlookup_field">
<option value="name">Channel Name</option>
<option value="owner">Channel Owner</option>
</select>
<button class="btn" id="chanlookup_submit">Search</button>
</form>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th id="chanlookup_id">ID</th>
<th id="chanlookup_name">Name</th>
<th id="chanlookup_owner">Owner</th>
</tr>
</thead>
</table>
</div>
<div class="span12" id="channellist"> <div class="span12" id="channellist">
<h3>Loaded Channels</h3> <h3>Loaded Channels</h3>
<button class="btn" id="listloaded_refresh">Refresh</button> <button class="btn" id="listloaded_refresh">Refresh</button>

View File

@ -80,6 +80,17 @@ $("#userlookup_email").click(function() {
tableResort($("#userlookup table"), "email"); tableResort($("#userlookup table"), "email");
}); });
menuHandler("#show_chanlookup", "#chanlookup");
$("#chanlookup_id").click(function() {
tableResort($("#chanlookup table"), "id");
});
$("#chanlookup_name").click(function() {
tableResort($("#chanlookup table"), "name");
});
$("#chanlookup_owner").click(function() {
tableResort($("#chanlookup table"), "owner");
});
menuHandler("#show_chanloaded", "#channellist"); menuHandler("#show_chanloaded", "#channellist");
$("#show_chanloaded").click(function() { $("#show_chanloaded").click(function() {
socket.emit("acp-list-loaded"); socket.emit("acp-list-loaded");
@ -240,6 +251,13 @@ $("#userlookup_submit").click(function() {
socket.emit("acp-lookup-user", $("#userlookup_name").val()); socket.emit("acp-lookup-user", $("#userlookup_name").val());
}); });
$("#chanlookup_submit").click(function () {
socket.emit("acp-lookup-channel", {
field: $("#chanlookup_field").val(),
value: $("#chanlookup_value").val()
});
});
function setupCallbacks() { function setupCallbacks() {
socket.on("connect", function() { socket.on("connect", function() {
if(NAME && SESSION) { if(NAME && SESSION) {
@ -384,6 +402,33 @@ function setupCallbacks() {
alert("Password reset successful. Reset hash: " + data.hash); alert("Password reset successful. Reset hash: " + data.hash);
}); });
socket.on("acp-channeldata", function(data) {
var tbl = $("#chanlookup table");
var p = tbl.data("paginator");
if(p) {
p.items = data;
}
else {
var opts = {
preLoadPage: function () {
tbl.find("tbody").remove();
},
generator: function (u, page, index) {
var tr = $("<tr/>").appendTo(tbl);
$("<td/>").text(u.id).appendTo(tr);
$("<td/>").text(u.name).appendTo(tr);
$("<td/>").text(u.owner).appendTo(tr);
}
};
p = Paginate(data, opts);
p.paginator.insertBefore(tbl);
tbl.data("paginator", p);
}
tbl.data("sortby", "id");
tbl.data("sort_desc", false);
tableResort(tbl);
});
socket.on("acp-list-loaded", function(data) { socket.on("acp-list-loaded", function(data) {
$("#channellist tbody").remove(); $("#channellist tbody").remove();
data.sort(function(a, b) { data.sort(function(a, b) {