mirror of https://github.com/calzoneman/sync.git
Finish channel ranks / moderator list
This commit is contained in:
parent
2fadd70297
commit
8554c38c7d
|
@ -419,6 +419,11 @@ module.exports = {
|
|||
callback = blackHole;
|
||||
}
|
||||
|
||||
if (rank < 2) {
|
||||
module.exports.deleteRank(chan, name, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!valid(chan)) {
|
||||
callback("Invalid channel name", null);
|
||||
return;
|
||||
|
|
|
@ -92,12 +92,14 @@ mixin recentjoins
|
|||
|
||||
mixin chanranks
|
||||
#cs-chanranks.tab-pane
|
||||
h4 Moderator List
|
||||
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
|
||||
button#cs-chanranks-owner.btn.btn-info +Owner
|
||||
table.table.table-striped
|
||||
thead
|
||||
tr
|
||||
|
|
|
@ -493,85 +493,12 @@ Callbacks = {
|
|||
|
||||
channelRanks: function(entries) {
|
||||
var tbl = $("#cs-chanranks table");
|
||||
tbl.find("tbody").remove();
|
||||
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 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);
|
||||
});
|
||||
tbl.data("entries", entries);
|
||||
formatCSModList();
|
||||
},
|
||||
|
||||
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)
|
||||
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")
|
||||
);
|
||||
makeAlert("Error", data.msg, "alert-danger").insertAfter($("#cs-chanranks h4"));
|
||||
},
|
||||
|
||||
readChanLog: function (data) {
|
||||
|
@ -757,10 +684,21 @@ 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 entries = $("#cs-chanranks table").data("entries");
|
||||
var found = false;
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
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);
|
||||
if (user === null) {
|
||||
|
|
|
@ -492,20 +492,13 @@ if (location.protocol === "https:") {
|
|||
}
|
||||
|
||||
/* channel ranks stuff */
|
||||
$("#cs-chanranks-mod").click(function () {
|
||||
function chanrankSubmit(rank) {
|
||||
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
|
||||
});
|
||||
});
|
||||
}
|
||||
$("#cs-chanranks-mod").click(chanrankSubmit.bind(this, 2));
|
||||
$("#cs-chanranks-adm").click(chanrankSubmit.bind(this, 3));
|
||||
$("#cs-chanranks-owner").click(chanrankSubmit.bind(this, 4));
|
||||
|
|
|
@ -754,6 +754,8 @@ function setVisible(selector, bool) {
|
|||
}
|
||||
|
||||
function handleModPermissions() {
|
||||
$("#cs-chanranks-adm").attr("disabled", CLIENT.rank < 4);
|
||||
$("#cs-chanranks-owner").attr("disabled", CLIENT.rank < 4);
|
||||
/* update channel controls */
|
||||
$("#opt_pagetitle").val(CHANNEL.opts.pagetitle);
|
||||
$("#opt_pagetitle").attr("disabled", CLIENT.rank < 3);
|
||||
|
@ -1689,3 +1691,75 @@ function makeModal() {
|
|||
});
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -337,21 +337,21 @@
|
|||
}
|
||||
|
||||
.userlist_siteadmin {
|
||||
color: #cc0000;
|
||||
font-weight: bold;
|
||||
color: #cc0000!important;
|
||||
font-weight: bold!important;
|
||||
}
|
||||
|
||||
.userlist_owner {
|
||||
color: #0000cc;
|
||||
font-weight: bold;
|
||||
color: #0000cc!important;
|
||||
font-weight: bold!important;
|
||||
}
|
||||
|
||||
.userlist_op {
|
||||
color: #00aa00;
|
||||
color: #00aa00!important;
|
||||
}
|
||||
|
||||
.userlist_guest {
|
||||
color: #888888;
|
||||
color: #888888!important;
|
||||
}
|
||||
|
||||
.action {
|
||||
|
|
Loading…
Reference in New Issue