From 8aa92f73eca2d5d0f4f39e4a8161d2517253e89b Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 15 Jan 2014 00:16:29 -0600 Subject: [PATCH] Work on channel settings --- templates/channeloptions.jade | 32 +++++++++--------- www/assets/js/ui.js | 27 +++++++++++++++ www/assets/js/util.js | 62 +++++++++++++++++++---------------- www/css/cytube.css | 4 +++ 4 files changed, 80 insertions(+), 45 deletions(-) diff --git a/templates/channeloptions.jade b/templates/channeloptions.jade index 708df4e3..149e6d95 100644 --- a/templates/channeloptions.jade +++ b/templates/channeloptions.jade @@ -10,26 +10,26 @@ mixin rcheckbox(id, label) .col-sm-8.col-sm-offset-4 .checkbox label.control-label(for=id)= label - input(type="checkbox", id=id) + input.cs-checkbox(type="checkbox", id=id) mixin textbox(id, label, placeholder) .form-group label.control-label.col-sm-4(for=id)= label .col-sm-8 if placeholder - input.form-control(id=id, type="text", placeholder=placeholder) + input.form-control.cs-textbox(id=id, type="text", placeholder=placeholder) else - input.form-control(id=id, type="text") + input.form-control.cs-textbox(id=id, type="text") mixin miscoptions #cs-miscoptions.tab-pane h4 General Settings form.form-horizontal(action="javascript:void(0)") - mixin rcheckbox("opt_enable_link_regex", "Convert URLs in chat to links") - mixin rcheckbox("opt_allow_voteskip", "Allow voteskip") - mixin textbox("opt_voteskip_ratio", "Voteskip ratio", "0.5") - mixin textbox("opt_maxlength", "Max video length", "HH:MM:SS") - mixin textbox("opt_afktimeout", "Auto-AFK Delay", "0 (disabled)") + mixin rcheckbox("cs-enable_link_regex", "Convert URLs in chat to links") + mixin rcheckbox("cs-allow_voteskip", "Allow voteskip") + mixin textbox("cs-voteskip_ratio", "Voteskip ratio", "0.5") + mixin textbox("cs-maxlength", "Max video length", "HH:MM:SS") + mixin textbox("cs-afk_timeout", "Auto-AFK Delay", "0 (disabled)") .form-group .col-sm-8.col-sm-offset-4 button.btn.btn-default#cs-miscoptionssubmit Save @@ -39,11 +39,11 @@ mixin adminoptions h4 Admin-Only Settings form.form-horizontal(action="javascript:void(0)") - var defname = "CyTube - /r/" + channelName - mixin textbox("opt_pagetitle", "Page title", defname) - mixin textbox("opt_password", "Password", "leave blank to disable") - mixin textbox("opt_externalcss", "External CSS", "Stylesheet URL") - mixin textbox("opt_externaljs", "External Javascript", "Script URL") - mixin rcheckbox("opt_show_public", "List channel publicly") + mixin textbox("cs-pagetitle", "Page title", defname) + mixin textbox("cs-password", "Password", "leave blank to disable") + mixin textbox("cs-externalcss", "External CSS", "Stylesheet URL") + mixin textbox("cs-externaljs", "External Javascript", "Script URL") + mixin rcheckbox("cs-show_public", "List channel publicly") .form-group .col-sm-8.col-sm-offset-4 button.btn.btn-default#cs-adminoptionssubmit Save @@ -53,21 +53,21 @@ mixin motdeditor h4 MOTD editor p The MOTD can be formatted using a subset of HTML. Tags which attempt to execute Javascript will be removed. textarea.form-control#cs-motdtext(rows="10") - button.btn.btn-default#cs-motdsubmit Save MOTD + button.btn.btn-primary.pull-right#cs-motdsubmit Save MOTD mixin csseditor #cs-csseditor.tab-pane h4 CSS editor p Maximum size 20KB. If more space is required, use the External CSS option under General Settings to link to an externally hosted stylesheet. textarea.form-control#cs-csstext(rows="10") - button.btn.btn-default#cs-csssubmit Save CSS + button.btn.btn-primary.pull-right#cs-csssubmit Save CSS mixin jseditor #cs-jseditor.tab-pane h4 JS editor p Maximum size 20KB. If more space is required, use the External JS option under General Settings to link to an externally hosted stylesheet. textarea.form-control#cs-jstext(rows="10") - button.btn.btn-default#cs-jssubmit Save JS + button.btn.btn-primary.pull-right#cs-jssubmit Save JS mixin banlist #cs-banlist.tab-pane diff --git a/www/assets/js/ui.js b/www/assets/js/ui.js index 6f3ff4f3..35f228ee 100644 --- a/www/assets/js/ui.js +++ b/www/assets/js/ui.js @@ -470,3 +470,30 @@ $("#cs-chanranks-owner").click(chanrankSubmit.bind(this, 4)); }); $(".plcontrol-collapse").collapse(); $(".plcontrol-collapse").collapse("hide"); + +$(".cs-checkbox").change(function () { + var box = $(this); + var key = box.attr("id").replace("cs-", ""); + var value = box.prop("checked"); + var data = {}; + data[key] = value; + socket.emit("setOptions", data); +}); + +$(".cs-textbox").keyup(function () { + var box = $(this); + var key = box.attr("id").replace("cs-", ""); + var value = box.val(); + var lastkey = Date.now(); + box.data("lastkey", lastkey); + + setTimeout(function () { + if (box.data("lastkey") !== lastkey || box.val() !== value) { + return; + } + + var data = {}; + data[key] = value; + socket.emit("setOptions", data); + }, 1000); +}); diff --git a/www/assets/js/util.js b/www/assets/js/util.js index 30f968ae..9abefa27 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -724,32 +724,38 @@ function setVisible(selector, bool) { $(selector).css("display", disp); } +function setParentVisible(selector, bool) { + var disp = bool ? "" : "none"; + $(selector).parent().css("display", disp); +} + 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); - $("#opt_externalcss").val(CHANNEL.opts.externalcss); - $("#opt_externalcss").attr("disabled", CLIENT.rank < 3); - $("#opt_externaljs").val(CHANNEL.opts.externaljs); - $("#opt_externaljs").attr("disabled", CLIENT.rank < 3); + $("#cs-pagetitle").val(CHANNEL.opts.pagetitle); + $("#cs-pagetitle").attr("disabled", CLIENT.rank < 3); + $("#cs-externalcss").val(CHANNEL.opts.externalcss); + $("#cs-externalcss").attr("disabled", CLIENT.rank < 3); + $("#cs-externaljs").val(CHANNEL.opts.externaljs); + $("#cs-externaljs").attr("disabled", CLIENT.rank < 3); + /* TODO FIX */ $("#opt_chat_antiflood").prop("checked", CHANNEL.opts.chat_antiflood); if ("chat_antiflood_params" in CHANNEL.opts) { $("#opt_chat_antiflood_burst").val(CHANNEL.opts.chat_antiflood_params.burst); $("#opt_chat_antiflood_sustained").val(CHANNEL.opts.chat_antiflood_params.sustained); } - $("#opt_show_public").prop("checked", CHANNEL.opts.show_public); - $("#opt_show_public").attr("disabled", CLIENT.rank < 3); - $("#opt_password").val(CHANNEL.opts.password || ""); - $("#opt_password").attr("disabled", CLIENT.rank < 3); - $("#opt_enable_link_regex").prop("checked", CHANNEL.opts.enable_link_regex); - $("#opt_afktimeout").val(CHANNEL.opts.afk_timeout); - $("#opt_allow_voteskip").prop("checked", CHANNEL.opts.allow_voteskip); - $("#opt_voteskip_ratio").val(CHANNEL.opts.voteskip_ratio); + $("#cs-show_public").prop("checked", CHANNEL.opts.show_public); + $("#cs-show_public").attr("disabled", CLIENT.rank < 3); + $("#cs-password").val(CHANNEL.opts.password || ""); + $("#cs-password").attr("disabled", CLIENT.rank < 3); + $("#cs-enable_link_regex").prop("checked", CHANNEL.opts.enable_link_regex); + $("#cs-afk_timeout").val(CHANNEL.opts.afk_timeout); + $("#cs-allow_voteskip").prop("checked", CHANNEL.opts.allow_voteskip); + $("#cs-voteskip_ratio").val(CHANNEL.opts.voteskip_ratio); (function() { if(typeof CHANNEL.opts.maxlength != "number") { - $("#opt_maxlength").val(""); + $("#cs-maxlength").val(""); return; } var h = parseInt(CHANNEL.opts.maxlength / 3600); @@ -761,21 +767,19 @@ function handleModPermissions() { var s = parseInt(CHANNEL.opts.maxlength % 60); s = ""+s; if(s.length < 2) s = "0" + s; - $("#opt_maxlength").val(h + ":" + m + ":" + s); + $("#cs-maxlength").val(h + ":" + m + ":" + s); })(); - $("#csstext").val(CHANNEL.css); - $("#jstext").val(CHANNEL.js); - $("#motdtext").val(CHANNEL.motd_text); - setVisible("#editmotd", hasPermission("motdedit")); - setVisible("#permedit_tab", CLIENT.rank >= 3); - setVisible("#banlist_tab", hasPermission("ban")); - setVisible("#motdedit_tab", hasPermission("motdedit")); - setVisible("#cssedit_tab", CLIENT.rank >= 3); - setVisible("#jsedit_tab", CLIENT.rank >= 3); - setVisible("#filteredit_tab", hasPermission("filteredit")); - setVisible("#channelranks_tab", CLIENT.rank >= 3); - setVisible("#chanlog_tab", CLIENT.rank >= 3); - setVisible("#chanopts_unregister_wrap", CLIENT.rank >= 10); + $("#cs-csstext").val(CHANNEL.css); + $("#cs-jstext").val(CHANNEL.js); + $("#cs-motdtext").val(CHANNEL.motd_text); + setParentVisible("a[href='#cs-motdeditor']", hasPermission("motdedit")); + setParentVisible("a[href='#cs-permissions']", CLIENT.rank >= 3); + setParentVisible("a[href='#cs-banlist']", hasPermission("ban")); + setParentVisible("a[href='#cs-csseditor']", CLIENT.rank >= 3); + setParentVisible("a[href='#cs-jseditor']", CLIENT.rank >= 3); + setParentVisible("a[href='#cs-filtereditor']", CLIENT.rank >= 3); + setParentVisible("a[href='#cs-chanranks']", CLIENT.rank >= 3); + setParentVisible("a[href='#cs-chanlog']", CLIENT.rank >= 3); } function handlePermissionChange() { diff --git a/www/css/cytube.css b/www/css/cytube.css index b9f7da86..e0901490 100644 --- a/www/css/cytube.css +++ b/www/css/cytube.css @@ -483,3 +483,7 @@ #customembed-content { font-family: Monospace; } + +#cs-csssubmit, #cs-motdsubmit, #cs-jssubmit { + margin: 10px 0; +}