Work on user ranks

This commit is contained in:
calzoneman 2014-01-08 23:45:26 -06:00
parent 9306200a87
commit 2fadd70297
5 changed files with 63 additions and 11 deletions

View File

@ -1404,7 +1404,6 @@ Channel.prototype.handleQueue = function (user, data) {
maxlength: this.hasPermission(user, "exceedmaxlength") ? 0 : this.opts.maxlength
}, function (err, media) {
if (err) {
console.log(err);
user.socket.emit("queueFail", {
msg: err,
link: link
@ -2539,20 +2538,42 @@ Channel.prototype.handleSetRank = function (user, data) {
var updateDB = function () {
self.getRank(name, function (err, oldrank) {
if (self.dead || err) {
if (self.dead) {
return;
}
if (err) {
user.socket.emit("channelRankFail", {
msg: "Updating user rank failed: " + err
});
return;
}
if (oldrank >= user.rank) {
user.socket.emit("channelRankFail", {
msg: "Updating user rank failed: " + name + " has equal or higher " +
"rank than you"
});
return;
}
db.channels.setRank(self.name, name, rank, function (err, res) {
if (self.dead || err) {
if (self.dead) {
return;
}
if (err) {
user.socket.emit("channelRankFail", {
msg: "Updating user rank failed: " + err
});
return;
}
self.logger.log("*** " + user.name + " set " + name + "'s rank to " + rank);
self.sendAll("setUserRank", {
name: name,
rank: rank
});
});
});
};
@ -2565,11 +2586,6 @@ Channel.prototype.handleSetRank = function (user, data) {
if (receiver.loggedIn) {
updateDB();
}
self.sendAll("setUserRank", {
name: name,
rank: rank
});
} else if (self.registered) {
updateDB();
}

View File

@ -167,7 +167,7 @@ html(lang="en")
li: a(href="#cs-motdeditor", data-toggle="tab", tabindex="-1") Edit MOTD
li: a(href="#cs-csseditor", data-toggle="tab", tabindex="-1") Edit CSS
li: a(href="#cs-jseditor", data-toggle="tab", tabindex="-1") Edit Javascript
li: a(href="#cs-chanranks", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestChannelRanks')") Edit user ranks
li: a(href="#cs-chanranks", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestChannelRanks')") Edit moderators
li: a(href="#cs-banlist", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestBanlist')") Ban list
.modal-body
.tab-content

View File

@ -92,6 +92,12 @@ mixin recentjoins
mixin chanranks
#cs-chanranks.tab-pane
form.form-inline(action="javascript:void(0)", role="form")
.input-group
input#cs-chanranks-name.form-control(type="text", placeholder="Name")
span.input-group-btn
button#cs-chanranks-mod.btn.btn-success +Mod
button#cs-chanranks-adm.btn.btn-info +Admin
table.table.table-striped
thead
tr

View File

@ -505,7 +505,7 @@ Callbacks = {
});
entries.forEach(function (entry) {
var tr = $("<tr/>");
var tr = $("<tr/>").addClass("cs-chanrank-tr-" + entry.name);
var name = $("<td/>").text(entry.name).appendTo(tr);
name.addClass(getNameColor(entry.rank));
var rankwrap = $("<td/>");
@ -523,6 +523,7 @@ Callbacks = {
rankedit.hide();
rank.hide();
editbox = $("<input/>").addClass("form-control")
.attr("type", "text")
.attr("placeholder", entry.rank)
.appendTo(rankwrap)
.focus();
@ -553,6 +554,10 @@ Callbacks = {
});
},
channelRankFail: function (data) {
makeAlert("Error", data.msg, "alert-danger").prependTo($("#cs-chanranks"));
},
setChannelRank: function(data) {
var ents = $("#channelranks").data("entries");
if(typeof ents === "undefined" || ents === null)
@ -752,6 +757,11 @@ Callbacks = {
},
setUserRank: function (data) {
var tr = $(".cs-chanrank-tr-" + data.name);
var tds = tr.find("td");
$(tds[0]).removeClass().addClass(getNameColor(data.rank));
$(tds[1]).find("span").text(data.rank);
var user = findUserlistItem(data.name);
if (user === null) {
return;
@ -764,8 +774,9 @@ Callbacks = {
}
formatUserlistItem(user);
addUserDropdown(user);
if(USEROPTS.sort_rank)
if (USEROPTS.sort_rank) {
sortUserlist();
}
},
setUserIcon: function (data) {

View File

@ -490,3 +490,22 @@ if (location.protocol === "https:") {
makeAlert(title, text, "alert-warning")
.appendTo($("#announcements"));
}
/* channel ranks stuff */
$("#cs-chanranks-mod").click(function () {
var name = $("#cs-chanranks-name").val();
var rank = 2;
socket.emit("setChannelRank", {
user: name,
rank: rank
});
});
$("#cs-chanranks-adm").click(function () {
var name = $("#cs-chanranks-name").val();
var rank = 3;
socket.emit("setChannelRank", {
user: name,
rank: rank
});
});