diff --git a/channel.js b/channel.js index 67a2601c..65c25fb8 100644 --- a/channel.js +++ b/channel.js @@ -74,8 +74,8 @@ var Channel = function(name) { allow_voteskip: true, voteskip_ratio: 0.5, pagetitle: this.name, - customcss: "", - customjs: "", + externalcss: "", + externaljs: "", chat_antiflood: false, show_public: false, enable_link_regex: true @@ -170,7 +170,14 @@ Channel.prototype.loadDump = function() { this.media.currentTime = data.currentTime; } for(var key in data.opts) { - this.opts[key] = data.opts[key]; + // Gotta love backwards compatibility + if(key == "customcss" || key == "customjs") { + var k = key.substring(6); + this.opts[k] = data.opts[key]; + } + else { + this.opts[key] = data.opts[key]; + } } for(var key in data.permissions) { this.permissions[key] = data.permissions[key]; diff --git a/user.js b/user.js index 3fbadbf2..c3d18702 100644 --- a/user.js +++ b/user.js @@ -343,7 +343,7 @@ User.prototype.initCallbacks = function() { } }.bind(this)); - this.socket.on("channelOpts", function(data) { + this.socket.on("setOptions", function(data) { if(this.channel != null) { this.channel.tryUpdateOptions(this, data); } diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 100c285a..4369933a 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -194,28 +194,19 @@ Callbacks = { }, channelOpts: function(opts) { - // TODO update if necessary when HTML admin stuff added - $("#opt_pagetitle").attr("placeholder", opts.pagetitle); document.title = opts.pagetitle; PAGETITLE = opts.pagetitle; - $("#opt_customcss").val(opts.customcss); - $("#opt_customjs").val(opts.customjs); - $("#opt_chat_antiflood").prop("checked", opts.chat_antiflood); - $("#opt_show_public").prop("checked", opts.show_public); - $("#opt_enable_link_regex").prop("checked", opts.enable_link_regex); - $("#customCss").remove(); - if(opts.customcss.trim() != "") { + $("#chanexternalcss").remove(); + if(opts.externalcss.trim() != "") { $("") .attr("rel", "stylesheet") - .attr("href", opts.customcss) - .attr("id", "customCss") + .attr("href", opts.externalcss) + .attr("id", "chanexternalcss") .appendTo($("head")); } - $("#opt_allow_voteskip").prop("checked", opts.allow_voteskip); - $("#opt_voteskip_ratio").val(opts.voteskip_ratio); - if(opts.customjs.trim() != "") { - if(opts.customjs != CHANNEL.opts.customjs) { - $.getScript(opts.customjs); + if(opts.externaljs.trim() != "") { + if(opts.externaljs != CHANNEL.opts.externaljs) { + $.getScript(opts.externaljs); } } @@ -231,8 +222,7 @@ Callbacks = { setPermissions: function(perms) { CHANNEL.perms = perms; if(CLIENT.rank >= Rank.Admin) - 1; - //genPermissionsEditor(); + genPermissionsEditor(); handlePermissionChange(); }, @@ -466,7 +456,6 @@ Callbacks = { }, drinkCount: function(count) { - console.log(count); if(count != 0) { var text = count + " drink"; if(count != 1) { diff --git a/www/assets/js/channelsettings.js b/www/assets/js/channelsettings.js index 958de6f5..566cf59a 100644 --- a/www/assets/js/channelsettings.js +++ b/www/assets/js/channelsettings.js @@ -20,4 +20,50 @@ clickHandler("#show_filteredit", "#filteredit"); clickHandler("#show_cssedit", "#cssedit"); clickHandler("#show_jsedit", "#jsedit"); + + genPermissionsEditor(); + + $("#chanopts_submit").click(function() { + socket.emit("setOptions", { + allow_voteskip: $("#opt_allow_voteskip").prop("checked"), + voteskip_ratio: parseFloat($("#opt_voteskip_ratio").val()), + pagetitle: $("#opt_pagetitle").val() || CHANNEL.name, + externalcss: $("#opt_externalcss").val(), + externaljs: $("#opt_externaljs").val(), + chat_antiflood: $("#opt_chat_antiflood").prop("checked"), + show_public: $("#opt_show_public").prop("checked"), + /* TODO Deprecate this in favour of per-filter toggle */ + enable_link_regex: $("#opt_enable_link_regex").prop("checked") + }); + }); + + $("#save_motd").click(function() { + socket.emit("setMotd", { + motd: $("#motdtext").val() + }); + }); + $("#csstext").keydown(function(ev) { + if(ev.keyCode == 9) { + $("#csstext").text($("#csstext").val() + " "); + ev.preventDefault(); + return false; + } + }); + $("#save_css").click(function() { + socket.emit("setChannelCSS", { + css: $("#csstext").val() + }); + }); + $("#jstext").keydown(function(ev) { + if(ev.keyCode == 9) { + $("#jstext").text($("#jstext").val() + " "); + ev.preventDefault(); + return false; + } + }); + $("#save_js").click(function() { + socket.emit("setChannelJS", { + js: $("#jstext").val() + }); + }); })(); diff --git a/www/assets/js/util.js b/www/assets/js/util.js index 353a5ff9..66bbda4a 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -647,7 +647,17 @@ function handlePermissionChange() { } if(CLIENT.rank >= 2) { - $("#channelsettingswrap").load("channeloptions.html"); + if($("#channelsettingswrap").html() == "") + $("#channelsettingswrap").load("channeloptions.html"); + /* update channel controls */ + $("#opt_pagetitle").val(CHANNEL.opts.pagetitle); + $("#opt_externalcss").val(CHANNEL.opts.externalcss); + $("#opt_externaljs").val(CHANNEL.opts.externaljs); + $("#opt_chat_antiflood").prop("checked", CHANNEL.opts.chat_antiflood); + $("#opt_show_public").prop("checked", CHANNEL.opts.show_public); + $("#opt_enable_link_regex").prop("checked", CHANNEL.opts.enable_link_regex); + $("#opt_allow_voteskip").prop("checked", CHANNEL.opts.allow_voteskip); + $("#opt_voteskip_ratio").val(CHANNEL.opts.voteskip_ratio); } else { $("#channelsettingswrap").html(""); @@ -1043,3 +1053,101 @@ function chatOnly() { $("#videowrap").remove(); $("#chatwrap").removeClass("span5").addClass("span12"); } + +/* channel administration stuff */ + +function genPermissionsEditor() { + $("#permedit").html(""); + var form = $("
").addClass("form-horizontal") + .attr("action", "javascript:void(0)") + .appendTo($("#permedit")); + var fs = $("
").appendTo(form); + + function makeOption(text, key, permset, defval) { + var group = $("
").addClass("control-group") + .appendTo(fs); + $("