mirror of https://github.com/calzoneman/sync.git
Revise channel ranks editor (Fixes #162)
This commit is contained in:
parent
33f4ffcec2
commit
33744da634
53
channel.js
53
channel.js
|
@ -537,7 +537,6 @@ Channel.prototype.userJoin = function(user) {
|
|||
if(user.name != "") {
|
||||
for(var i = 0; i < this.users.length; i++) {
|
||||
if(this.users[i].name.toLowerCase() == user.name.toLowerCase()) {
|
||||
console.log("DBG");
|
||||
this.kick(this.users[i], "Duplicate login");
|
||||
}
|
||||
}
|
||||
|
@ -760,6 +759,14 @@ Channel.prototype.sendAll = function(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() {
|
||||
var total = 0;
|
||||
for(var i = 0; i < this.queue.length; i++) {
|
||||
|
@ -1671,6 +1678,46 @@ Channel.prototype.sendMessage = function(username, msg, msgclass, data) {
|
|||
|
||||
/* 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) {
|
||||
if(!Rank.hasPermission(actor, "promote")) {
|
||||
return;
|
||||
|
@ -1705,7 +1752,7 @@ Channel.prototype.tryPromoteUser = function(actor, data) {
|
|||
Database.setChannelRank(this.name, data.name, 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);
|
||||
}
|
||||
this.logger.log("*** " + actor.name + " demoted " + data.name + " from " + (rank + 1) + " to " + rank);
|
||||
this.broadcastRankTable();
|
||||
//this.broadcastRankTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
6
user.js
6
user.js
|
@ -146,6 +146,12 @@ User.prototype.initCallbacks = function() {
|
|||
}
|
||||
}.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) {
|
||||
if(this.channel != null) {
|
||||
this.channel.banName(this, data.name || "");
|
||||
|
|
|
@ -361,40 +361,18 @@ Callbacks = {
|
|||
}
|
||||
}
|
||||
loadACLPage(0);
|
||||
return;
|
||||
for(var i = 0; i < entries.length; i++) {
|
||||
var tr = $("<tr/>").appendTo(tbl);
|
||||
var name = $("<td/>").text(entries[i].name).appendTo(tr);
|
||||
name.addClass(getNameColor(entries[i].rank));
|
||||
var rank = $("<td/>").text(entries[i].rank).appendTo(tr);
|
||||
var control = $("<td/>").appendTo(tr);
|
||||
var up = $("<button/>").addClass("btn btn-mini btn-success")
|
||||
.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));
|
||||
},
|
||||
|
||||
setChannelRank: function(data) {
|
||||
var ents = $("#channelranks").data("entries");
|
||||
for(var i = 0; i < ents.length; i++) {
|
||||
if(ents[i].name == data.user) {
|
||||
ents[i].rank = data.rank;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$("#channelranks").data("entries", ents);
|
||||
loadACLPage($("#channelranks").data("page"));
|
||||
},
|
||||
|
||||
voteskip: function(data) {
|
||||
|
@ -515,6 +493,7 @@ Callbacks = {
|
|||
formatUserlistItem(users[i], data);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
userLeave: function(data) {
|
||||
|
|
|
@ -499,7 +499,6 @@ function loadLoginlogPage(page) {
|
|||
.text("Ban IP Range")
|
||||
.appendTo(bantd);
|
||||
var callback = (function(id, name) { return function() {
|
||||
console.log(id, name);
|
||||
socket.emit("banIP", {
|
||||
id: id,
|
||||
name: name,
|
||||
|
@ -509,7 +508,6 @@ function loadLoginlogPage(page) {
|
|||
} })(entries[i].id, entries[i].names[0]);
|
||||
ban.click(callback);
|
||||
var callback2 = (function(id, name) { return function() {
|
||||
console.log(id, name);
|
||||
socket.emit("banIP", {
|
||||
id: id,
|
||||
name: name,
|
||||
|
@ -561,6 +559,7 @@ function loadLoginlogPage(page) {
|
|||
|
||||
function loadACLPage(page) {
|
||||
var entries = $("#channelranks").data("entries");
|
||||
$("#channelranks").data("page", page);
|
||||
var start = page * 20;
|
||||
var tbl = $("#channelranks table");
|
||||
if(tbl.children().length > 1) {
|
||||
|
@ -570,34 +569,42 @@ function loadACLPage(page) {
|
|||
var tr = $("<tr/>").appendTo(tbl);
|
||||
var name = $("<td/>").text(entries[i].name).appendTo(tr);
|
||||
name.addClass(getNameColor(entries[i].rank));
|
||||
var rank = $("<td/>").text(entries[i].rank).appendTo(tr);
|
||||
var control = $("<td/>").appendTo(tr);
|
||||
var up = $("<button/>").addClass("btn btn-mini btn-success")
|
||||
.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
|
||||
var rank = $("<td/>").text(entries[i].rank)
|
||||
.css("min-width", "220px")
|
||||
.appendTo(tr);
|
||||
(function(name) {
|
||||
rank.click(function() {
|
||||
if(this.find(".rank-edit").length > 0)
|
||||
return;
|
||||
var r = this.text();
|
||||
this.text("");
|
||||
var edit = $("<input/>").attr("type", "text")
|
||||
.attr("placeholder", r)
|
||||
.addClass("rank-edit")
|
||||
.appendTo(this)
|
||||
.focus();
|
||||
if(parseInt(r) >= RANK) {
|
||||
edit.attr("disabled", true);
|
||||
}
|
||||
function save() {
|
||||
var r = this.val();
|
||||
var r2 = r;
|
||||
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) {
|
||||
down.attr("disabled", true);
|
||||
}
|
||||
else {
|
||||
down.click(function(name) { return function() {
|
||||
socket.emit("demote", {
|
||||
name: name
|
||||
});
|
||||
}}(entries[i].name));
|
||||
}
|
||||
}
|
||||
edit.blur(save.bind(edit));
|
||||
edit.keydown(function(ev) {
|
||||
if(ev.keyCode == 13)
|
||||
save.bind(edit)();
|
||||
});
|
||||
}.bind(rank));
|
||||
})(entries[i].name);
|
||||
}
|
||||
if($("#acl_pagination").length > 0) {
|
||||
$("#acl_pagination").find("li").each(function() {
|
||||
|
|
|
@ -288,8 +288,7 @@
|
|||
<table class="table table-striped">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>Rank</th>
|
||||
<th>Control</th>
|
||||
<th>Rank (Click to edit)</th>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue