Finish channel ranks / moderator list

This commit is contained in:
calzoneman 2014-01-09 17:16:09 -06:00
parent 2fadd70297
commit 8554c38c7d
6 changed files with 110 additions and 98 deletions

View File

@ -419,6 +419,11 @@ module.exports = {
callback = blackHole; callback = blackHole;
} }
if (rank < 2) {
module.exports.deleteRank(chan, name, callback);
return;
}
if (!valid(chan)) { if (!valid(chan)) {
callback("Invalid channel name", null); callback("Invalid channel name", null);
return; return;

View File

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

View File

@ -493,85 +493,12 @@ Callbacks = {
channelRanks: function(entries) { channelRanks: function(entries) {
var tbl = $("#cs-chanranks table"); var tbl = $("#cs-chanranks table");
tbl.find("tbody").remove(); tbl.data("entries", entries);
entries.sort(function(a, b) { formatCSModList();
if (a.rank === b.rank) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return y == x ? 0 : (x < y ? -1 : 1);
}
return b.rank - a.rank;
});
entries.forEach(function (entry) {
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/>");
var rank = $("<span/>").text(entry.rank).appendTo(rankwrap);
var rankedit = $("<button/>")
.addClass("btn btn-xs btn-default")
.css("margin-right", "10px")
.text("Edit")
.prependTo(rankwrap);
if (entry.rank >= CLIENT.rank) {
rankedit.addClass("disabled");
} else {
var editbox = null;
rankedit.click(function () {
rankedit.hide();
rank.hide();
editbox = $("<input/>").addClass("form-control")
.attr("type", "text")
.attr("placeholder", entry.rank)
.appendTo(rankwrap)
.focus();
var finish = function () {
if (editbox != null) {
socket.emit("setChannelRank", {
user: entry.name,
rank: parseInt(editbox.val())
});
editbox.remove();
}
rankedit.show();
rank.show();
};
editbox.blur(finish);
editbox.keydown(function (ev) {
if (ev.keyCode === 13) {
finish();
}
});
});
}
rankwrap.appendTo(tr);
tr.appendTo(tbl);
});
}, },
channelRankFail: function (data) { channelRankFail: function (data) {
makeAlert("Error", data.msg, "alert-danger").prependTo($("#cs-chanranks")); makeAlert("Error", data.msg, "alert-danger").insertAfter($("#cs-chanranks h4"));
},
setChannelRank: function(data) {
var ents = $("#channelranks").data("entries");
if(typeof ents === "undefined" || ents === null)
return;
for(var i = 0; i < ents.length; i++) {
if(ents[i].name == data.user) {
ents[i].rank = data.rank;
break;
}
}
$("#channelranks").data("entries", ents);
$("#channelranks table").data("paginator").loadPage(
$("#channelranks table").data("page")
);
}, },
readChanLog: function (data) { readChanLog: function (data) {
@ -757,10 +684,21 @@ Callbacks = {
}, },
setUserRank: function (data) { setUserRank: function (data) {
var tr = $(".cs-chanrank-tr-" + data.name); var entries = $("#cs-chanranks table").data("entries");
var tds = tr.find("td"); var found = false;
$(tds[0]).removeClass().addClass(getNameColor(data.rank)); for (var i = 0; i < entries.length; i++) {
$(tds[1]).find("span").text(data.rank); if (entries[i].name === data.name) {
entries[i].rank = data.rank;
found = i;
break;
}
}
if (found === false) {
entries.push(data);
} else if (entries[found].rank < 2) {
entries.splice(found, 1);
}
formatCSModList();
var user = findUserlistItem(data.name); var user = findUserlistItem(data.name);
if (user === null) { if (user === null) {

View File

@ -492,20 +492,13 @@ if (location.protocol === "https:") {
} }
/* channel ranks stuff */ /* channel ranks stuff */
$("#cs-chanranks-mod").click(function () { function chanrankSubmit(rank) {
var name = $("#cs-chanranks-name").val(); var name = $("#cs-chanranks-name").val();
var rank = 2;
socket.emit("setChannelRank", { socket.emit("setChannelRank", {
user: name, user: name,
rank: rank rank: rank
}); });
}); }
$("#cs-chanranks-mod").click(chanrankSubmit.bind(this, 2));
$("#cs-chanranks-adm").click(function () { $("#cs-chanranks-adm").click(chanrankSubmit.bind(this, 3));
var name = $("#cs-chanranks-name").val(); $("#cs-chanranks-owner").click(chanrankSubmit.bind(this, 4));
var rank = 3;
socket.emit("setChannelRank", {
user: name,
rank: rank
});
});

View File

@ -754,6 +754,8 @@ function setVisible(selector, bool) {
} }
function handleModPermissions() { function handleModPermissions() {
$("#cs-chanranks-adm").attr("disabled", CLIENT.rank < 4);
$("#cs-chanranks-owner").attr("disabled", CLIENT.rank < 4);
/* update channel controls */ /* update channel controls */
$("#opt_pagetitle").val(CHANNEL.opts.pagetitle); $("#opt_pagetitle").val(CHANNEL.opts.pagetitle);
$("#opt_pagetitle").attr("disabled", CLIENT.rank < 3); $("#opt_pagetitle").attr("disabled", CLIENT.rank < 3);
@ -1689,3 +1691,75 @@ function makeModal() {
}); });
return wrap; return wrap;
} }
function formatCSModList() {
var tbl = $("#cs-chanranks table");
tbl.find("tbody").remove();
var entries = tbl.data("entries") || [];
entries.sort(function(a, b) {
if (a.rank === b.rank) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return y == x ? 0 : (x < y ? -1 : 1);
}
return b.rank - a.rank;
});
entries.forEach(function (entry) {
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/>");
var rank = $("<span/>").text(entry.rank).appendTo(rankwrap);
var dd = $("<div/>").addClass("btn-group");
var toggle = $("<button/>")
.addClass("btn btn-xs btn-default dropdown-toggle")
.attr("data-toggle", "dropdown")
.html("Edit <span class=caret></span>")
.appendTo(dd);
if (CLIENT.rank <= entry.rank) {
toggle.addClass("disabled");
}
var menu = $("<ul/>").addClass("dropdown-menu")
.attr("role", "menu")
.appendTo(dd);
var ranks = [
{ name: "Remove Moderator", rank: 1 },
{ name: "Moderator", rank: 2 },
{ name: "Channel Admin", rank: 3 },
{ name: "Channel Owner", rank: 4 }
];
ranks.forEach(function (r) {
var li = $("<li/>").appendTo(menu);
var a = $("<a/>")
.addClass(getNameColor(r.rank))
.attr("href", "javascript:void(0)")
.text(r.name)
.appendTo(li);
if (r.rank !== entry.rank) {
a.click(function () {
socket.emit("setChannelRank", {
user: entry.name,
rank: r.rank
});
});
} else {
$("<span/>").addClass("glyphicon glyphicon-ok pull-right")
.appendTo(a);
li.addClass("disabled");
}
if (r.rank > CLIENT.rank || (CLIENT.rank < 4 && r.rank === CLIENT.rank)) {
li.addClass("disabled");
}
});
dd.css("margin-right", "10px").prependTo(rankwrap);
rankwrap.appendTo(tr);
tr.appendTo(tbl);
});
}

View File

@ -337,21 +337,21 @@
} }
.userlist_siteadmin { .userlist_siteadmin {
color: #cc0000; color: #cc0000!important;
font-weight: bold; font-weight: bold!important;
} }
.userlist_owner { .userlist_owner {
color: #0000cc; color: #0000cc!important;
font-weight: bold; font-weight: bold!important;
} }
.userlist_op { .userlist_op {
color: #00aa00; color: #00aa00!important;
} }
.userlist_guest { .userlist_guest {
color: #888888; color: #888888!important;
} }
.action { .action {