Add permissions editor

This commit is contained in:
calzoneman 2014-01-20 12:16:30 -06:00
parent 8c47221a22
commit fd6b95920a
5 changed files with 40 additions and 20 deletions

View File

@ -2329,7 +2329,7 @@ Channel.prototype.handleMoveFilter = function (user, data) {
/** /**
* Handles a user message to change the channel permissions * Handles a user message to change the channel permissions
*/ */
Channel.prototype.handleUpdatePermissions = function (user, perms) { Channel.prototype.handleSetPermissions = function (user, perms) {
if (user.rank < 3) { if (user.rank < 3) {
user.kick("Attempted setPermissions as a non-admin"); user.kick("Attempted setPermissions as a non-admin");
return; return;

View File

@ -177,6 +177,7 @@ html(lang="en")
li: a(href="#cs-motdeditor", data-toggle="tab", tabindex="-1") Edit MOTD 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-csseditor", data-toggle="tab", tabindex="-1") Edit CSS
li: a(href="#cs-jseditor", data-toggle="tab", tabindex="-1") Edit Javascript li: a(href="#cs-jseditor", data-toggle="tab", tabindex="-1") Edit Javascript
li: a(href="#cs-permedit", data-toggle="tab", tabindex="-1") Edit Permissions
li: a(href="#cs-chanranks", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestChannelRanks')") Edit moderators 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 li: a(href="#cs-banlist", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestBanlist')") Ban list
.modal-body .modal-body
@ -192,6 +193,7 @@ html(lang="en")
mixin chanranks() mixin chanranks()
mixin chatfilters() mixin chatfilters()
mixin chanlog() mixin chanlog()
mixin permeditor()
.modal-footer .modal-footer
button.btn.btn-default(type="button", data-dismiss="modal") Close button.btn.btn-default(type="button", data-dismiss="modal") Close
include footer include footer

View File

@ -162,3 +162,6 @@ mixin chanlog
input#filter_joinquit(type="checkbox") input#filter_joinquit(type="checkbox")
pre#chanlog_contents(style="max-height: 400px; overflow-y: scroll") pre#chanlog_contents(style="max-height: 400px; overflow-y: scroll")
button.btn.btn-default#chanlog_refresh Refresh button.btn.btn-default#chanlog_refresh Refresh
mixin permeditor
#cs-permedit.tab-pane

View File

@ -300,8 +300,7 @@ Callbacks = {
setPermissions: function(perms) { setPermissions: function(perms) {
CHANNEL.perms = perms; CHANNEL.perms = perms;
if(CLIENT.rank >= Rank.Admin) genPermissionsEditor();
genPermissionsEditor();
handlePermissionChange(); handlePermissionChange();
}, },

View File

@ -1370,33 +1370,36 @@ function chatOnly() {
// TODO fix // TODO fix
function genPermissionsEditor() { function genPermissionsEditor() {
$("#permedit").html(""); $("#cs-permedit").html("");
var form = $("<form/>").addClass("form-horizontal") var form = $("<form/>").addClass("form-horizontal")
.attr("action", "javascript:void(0)") .attr("action", "javascript:void(0)")
.appendTo($("#permedit")); .appendTo($("#cs-permedit"));
var fs = $("<fieldset/>").appendTo(form);
function makeOption(text, key, permset, defval) { function makeOption(text, key, permset, defval) {
var group = $("<div/>").addClass("control-group") var group = $("<div/>").addClass("form-group")
.appendTo(fs); .appendTo(form);
$("<label/>").addClass("control-label") $("<label/>").addClass("control-label col-sm-4")
.text(text) .text(text)
.appendTo(group); .appendTo(group);
var controls = $("<div/>").addClass("controls") var controls = $("<div/>").addClass("col-sm-8")
.appendTo(group); .appendTo(group);
var select = $("<select/>").appendTo(controls); var select = $("<select/>").addClass("form-control")
select.data("key", key); .appendTo(controls)
for(var i = 0; i < permset.length; i++) { .data("key", key);
for (var i = 0; i < permset.length; i++) {
$("<option/>").attr("value", permset[i][1]) $("<option/>").attr("value", permset[i][1])
.text(permset[i][0]) .text(permset[i][0])
.attr("selected", defval == permset[i][1]) .attr("selected", defval === permset[i][1])
.appendTo(select); .appendTo(select);
} }
} }
function addDivider(text) { function addDivider(text, nonewline) {
$("<hr/>").appendTo(fs); $("<hr/>").appendTo(form);
$("<h3/>").text(text).appendTo(fs); if (!nonewline) {
$("<h3/>").text(text).appendTo(form);
}
} }
var standard = [ var standard = [
@ -1431,7 +1434,7 @@ function genPermissionsEditor() {
["Nobody" , "1000000"] ["Nobody" , "1000000"]
]; ];
$("<h3/>").text("Open playlist permissions").appendTo(fs); $("<h3/>").text("Open playlist permissions").appendTo(form);
makeOption("Add to playlist", "oplaylistadd", standard, CHANNEL.perms.oplaylistadd+""); makeOption("Add to playlist", "oplaylistadd", standard, CHANNEL.perms.oplaylistadd+"");
makeOption("Add/move to next", "oplaylistnext", standard, CHANNEL.perms.oplaylistnext+""); makeOption("Add/move to next", "oplaylistnext", standard, CHANNEL.perms.oplaylistnext+"");
makeOption("Move playlist items", "oplaylistmove", standard, CHANNEL.perms.oplaylistmove+""); makeOption("Move playlist items", "oplaylistmove", standard, CHANNEL.perms.oplaylistmove+"");
@ -1471,15 +1474,28 @@ function genPermissionsEditor() {
makeOption("Drink calls", "drink", modleader, CHANNEL.perms.drink+""); makeOption("Drink calls", "drink", modleader, CHANNEL.perms.drink+"");
makeOption("Chat", "chat", noanon, CHANNEL.perms.chat+""); makeOption("Chat", "chat", noanon, CHANNEL.perms.chat+"");
var submit = $("<button/>").addClass("btn btn-primary").appendTo(fs); var sgroup = $("<div/>").addClass("form-group").appendTo(form);
var sgroupinner = $("<div/>").addClass("col-sm-8 col-sm-offset-4").appendTo(sgroup);
var submit = $("<button/>").addClass("btn btn-primary").appendTo(sgroupinner);
submit.text("Save"); submit.text("Save");
submit.click(function() { submit.click(function() {
var perms = {}; var perms = {};
fs.find("select").each(function() { form.find("select").each(function() {
perms[$(this).data("key")] = parseFloat($(this).val()); perms[$(this).data("key")] = parseFloat($(this).val());
}); });
socket.emit("setPermissions", perms); socket.emit("setPermissions", perms);
}); });
var msggroup = $("<div/>").addClass("form-group").insertAfter(sgroup);
var msginner = $("<div/>").addClass("col-sm-8 col-sm-offset-4").appendTo(msggroup);
var text = $("<span/>").addClass("text-info").text("Permissions updated")
.appendTo(msginner);
setTimeout(function () {
msggroup.hide("fade", function () {
msggroup.remove();
});
}, 5000);
} }
function waitUntilDefined(obj, key, fn) { function waitUntilDefined(obj, key, fn) {