Revise channel ranks editor (Fixes #162)

This commit is contained in:
calzoneman 2013-06-05 11:40:59 -04:00
parent 33f4ffcec2
commit 33744da634
5 changed files with 104 additions and 66 deletions

View File

@ -537,7 +537,6 @@ Channel.prototype.userJoin = function(user) {
if(user.name != "") { if(user.name != "") {
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
if(this.users[i].name.toLowerCase() == user.name.toLowerCase()) { if(this.users[i].name.toLowerCase() == user.name.toLowerCase()) {
console.log("DBG");
this.kick(this.users[i], "Duplicate login"); this.kick(this.users[i], "Duplicate login");
} }
} }
@ -760,6 +759,14 @@ Channel.prototype.sendAll = function(message, data) {
NWS.inRoom(this.name).emit(message, data); NWS.inRoom(this.name).emit(message, data);
} }
Channel.prototype.sendAllWithPermission = function(perm, msg, data) {
for(var i = 0; i < this.users.length; i++) {
if(Rank.hasPermission(this.users[i], perm)) {
this.users[i].socket.emit(msg, data);
}
}
}
Channel.prototype.broadcastPlaylistMeta = function() { Channel.prototype.broadcastPlaylistMeta = function() {
var total = 0; var total = 0;
for(var i = 0; i < this.queue.length; i++) { for(var i = 0; i < this.queue.length; i++) {
@ -1671,6 +1678,46 @@ Channel.prototype.sendMessage = function(username, msg, msgclass, data) {
/* REGION Rank stuff */ /* REGION Rank stuff */
Channel.prototype.trySetRank = function(user, data) {
if(!Rank.hasPermission(user, "promote"))
return;
if(typeof data.user !== "string" || typeof data.rank !== "number")
return;
if(data.rank >= user.rank)
return;
if(data.rank < 1)
return;
var receiver;
for(var i = 0; i < this.users.length; i++) {
if(this.users[i].name == data.user) {
receiver = this.users[i];
break;
}
}
if(receiver) {
if(receiver.rank >= user.rank)
return;
receiver.rank = data.rank;
if(receiver.loggedIn) {
this.saveRank(receiver);
}
this.broadcastUserUpdate(receiver);
}
else {
var rrank = this.getRank(data.user);
if(rrank >= user.rank)
return;
Database.setChannelRank(this.name, data.user, data.rank);
}
this.sendAllWithPermission("acl", "setChannelRank", data);
}
Channel.prototype.tryPromoteUser = function(actor, data) { Channel.prototype.tryPromoteUser = function(actor, data) {
if(!Rank.hasPermission(actor, "promote")) { if(!Rank.hasPermission(actor, "promote")) {
return; return;
@ -1705,7 +1752,7 @@ Channel.prototype.tryPromoteUser = function(actor, data) {
Database.setChannelRank(this.name, data.name, rank); Database.setChannelRank(this.name, data.name, rank);
} }
this.logger.log("*** " + actor.name + " promoted " + data.name + " from " + (rank - 1) + " to " + rank); this.logger.log("*** " + actor.name + " promoted " + data.name + " from " + (rank - 1) + " to " + rank);
this.broadcastRankTable(); //this.broadcastRankTable();
} }
} }
@ -1742,7 +1789,7 @@ Channel.prototype.tryDemoteUser = function(actor, data) {
Database.setChannelRank(this.name, data.name, rank); Database.setChannelRank(this.name, data.name, rank);
} }
this.logger.log("*** " + actor.name + " demoted " + data.name + " from " + (rank + 1) + " to " + rank); this.logger.log("*** " + actor.name + " demoted " + data.name + " from " + (rank + 1) + " to " + rank);
this.broadcastRankTable(); //this.broadcastRankTable();
} }
} }

View File

@ -146,6 +146,12 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on("setChannelRank", function(data) {
if(this.channel != null) {
this.channel.trySetRank(this, data);
}
}.bind(this));
this.socket.on("banName", function(data) { this.socket.on("banName", function(data) {
if(this.channel != null) { if(this.channel != null) {
this.channel.banName(this, data.name || ""); this.channel.banName(this, data.name || "");

View File

@ -361,40 +361,18 @@ Callbacks = {
} }
} }
loadACLPage(0); loadACLPage(0);
return; },
for(var i = 0; i < entries.length; i++) {
var tr = $("<tr/>").appendTo(tbl); setChannelRank: function(data) {
var name = $("<td/>").text(entries[i].name).appendTo(tr); var ents = $("#channelranks").data("entries");
name.addClass(getNameColor(entries[i].rank)); for(var i = 0; i < ents.length; i++) {
var rank = $("<td/>").text(entries[i].rank).appendTo(tr); if(ents[i].name == data.user) {
var control = $("<td/>").appendTo(tr); ents[i].rank = data.rank;
var up = $("<button/>").addClass("btn btn-mini btn-success") break;
.appendTo(control);
$("<i/>").addClass("icon-plus").appendTo(up);
var down = $("<button/>").addClass("btn btn-mini btn-danger")
.appendTo(control);
$("<i/>").addClass("icon-minus").appendTo(down);
if(entries[i].rank + 1 >= RANK) {
up.attr("disabled", true);
}
else {
up.click(function(name) { return function() {
socket.emit("promote", {
name: name
});
}}(entries[i].name));
}
if(entries[i].rank >= RANK) {
down.attr("disabled", true);
}
else {
down.click(function(name) { return function() {
socket.emit("demote", {
name: name
});
}}(entries[i].name));
} }
} }
$("#channelranks").data("entries", ents);
loadACLPage($("#channelranks").data("page"));
}, },
voteskip: function(data) { voteskip: function(data) {
@ -515,6 +493,7 @@ Callbacks = {
formatUserlistItem(users[i], data); formatUserlistItem(users[i], data);
} }
} }
}, },
userLeave: function(data) { userLeave: function(data) {

View File

@ -499,7 +499,6 @@ function loadLoginlogPage(page) {
.text("Ban IP Range") .text("Ban IP Range")
.appendTo(bantd); .appendTo(bantd);
var callback = (function(id, name) { return function() { var callback = (function(id, name) { return function() {
console.log(id, name);
socket.emit("banIP", { socket.emit("banIP", {
id: id, id: id,
name: name, name: name,
@ -509,7 +508,6 @@ function loadLoginlogPage(page) {
} })(entries[i].id, entries[i].names[0]); } })(entries[i].id, entries[i].names[0]);
ban.click(callback); ban.click(callback);
var callback2 = (function(id, name) { return function() { var callback2 = (function(id, name) { return function() {
console.log(id, name);
socket.emit("banIP", { socket.emit("banIP", {
id: id, id: id,
name: name, name: name,
@ -561,6 +559,7 @@ function loadLoginlogPage(page) {
function loadACLPage(page) { function loadACLPage(page) {
var entries = $("#channelranks").data("entries"); var entries = $("#channelranks").data("entries");
$("#channelranks").data("page", page);
var start = page * 20; var start = page * 20;
var tbl = $("#channelranks table"); var tbl = $("#channelranks table");
if(tbl.children().length > 1) { if(tbl.children().length > 1) {
@ -570,34 +569,42 @@ function loadACLPage(page) {
var tr = $("<tr/>").appendTo(tbl); var tr = $("<tr/>").appendTo(tbl);
var name = $("<td/>").text(entries[i].name).appendTo(tr); var name = $("<td/>").text(entries[i].name).appendTo(tr);
name.addClass(getNameColor(entries[i].rank)); name.addClass(getNameColor(entries[i].rank));
var rank = $("<td/>").text(entries[i].rank).appendTo(tr); var rank = $("<td/>").text(entries[i].rank)
var control = $("<td/>").appendTo(tr); .css("min-width", "220px")
var up = $("<button/>").addClass("btn btn-mini btn-success") .appendTo(tr);
.appendTo(control); (function(name) {
$("<i/>").addClass("icon-plus").appendTo(up); rank.click(function() {
var down = $("<button/>").addClass("btn btn-mini btn-danger") if(this.find(".rank-edit").length > 0)
.appendTo(control); return;
$("<i/>").addClass("icon-minus").appendTo(down); var r = this.text();
if(entries[i].rank + 1 >= RANK) { this.text("");
up.attr("disabled", true); var edit = $("<input/>").attr("type", "text")
.attr("placeholder", r)
.addClass("rank-edit")
.appendTo(this)
.focus();
if(parseInt(r) >= RANK) {
edit.attr("disabled", true);
} }
else { function save() {
up.click(function(name) { return function() { var r = this.val();
socket.emit("promote", { var r2 = r;
name: name if(r.trim() == "" || parseInt(r) >= RANK || parseInt(r) < 1)
r = this.attr("placeholder");
r = parseInt(r) + "";
this.parent().text(r);
socket.emit("setChannelRank", {
user: name,
rank: parseInt(r)
}); });
}}(entries[i].name));
} }
if(entries[i].rank >= RANK) { edit.blur(save.bind(edit));
down.attr("disabled", true); edit.keydown(function(ev) {
} if(ev.keyCode == 13)
else { save.bind(edit)();
down.click(function(name) { return function() {
socket.emit("demote", {
name: name
}); });
}}(entries[i].name)); }.bind(rank));
} })(entries[i].name);
} }
if($("#acl_pagination").length > 0) { if($("#acl_pagination").length > 0) {
$("#acl_pagination").find("li").each(function() { $("#acl_pagination").find("li").each(function() {

View File

@ -288,8 +288,7 @@
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<th>Name</th> <th>Name</th>
<th>Rank</th> <th>Rank (Click to edit)</th>
<th>Control</th>
</thead> </thead>
</table> </table>
</div> </div>