From d42de93d749b4b0b2ad41fffc1b7ac2b8080da3f Mon Sep 17 00:00:00 2001 From: Xaekai Date: Sun, 4 Jun 2017 22:16:40 -0700 Subject: [PATCH] Round 2. --- src/web/account.js | 1 + templates/account-channels.pug | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/web/account.js b/src/web/account.js index d95582e1..8890ff06 100644 --- a/src/web/account.js +++ b/src/web/account.js @@ -202,6 +202,7 @@ function handleAccountChannelPage(req, res) { db.channels.listUserChannels(req.user.name, function (err, channels) { sendPug(res, "account-channels", { + domain: req.host, channels: channels }); }); diff --git a/templates/account-channels.pug b/templates/account-channels.pug index ab0de34f..0b05e346 100644 --- a/templates/account-channels.pug +++ b/templates/account-channels.pug @@ -56,10 +56,10 @@ html(lang="en") input(type="hidden", name="action", value="new_channel") .form-group label.control-label(for="channelname") Channel URL - span#validation.pull-right + span#validation.text-danger.pull-right .input-group - span.input-group-addon #{baseUrl}/r/ - input#channelname.form-control(type="text", name="name") + span.input-group-addon #{domain}/r/ + input#channelname.form-control(type="text", name="name", maxlength="30", onkeyup="checkChannel()") button#register.btn.btn-primary.btn-block(type="submit") Register include footer @@ -69,11 +69,8 @@ html(lang="en") if(/\s/.test(id)){ return 'Channel URLs may not contain spaces'; } - if(id.length > 30){ - return 'Channel URLs may not be longer than 30 characters'; - } - if(id.length < 1){ - return 'Channel URLs must be at least one character'; + if(id === ''){ + return 'Channel URLs must not be empty'; } if(!/^[\w-]{1,30}$/.test(id)){ return 'Channel URLs may only consist of a-z, A-Z, 0-9, - and _'; @@ -81,8 +78,8 @@ html(lang="en") return false; } - $("#channelname").keyup(function () { - var box = $(this); + function checkChannel(){ + var box = $("#channelname"); var value = box.val(); var lastkey = Date.now(); box.data("lastkey", lastkey); @@ -92,12 +89,15 @@ html(lang="en") return; } if(nameIsInvalid(value)){ - $('#validation').text(nameIsInvalid(value)); + $('#validation').text(nameIsInvalid(value)) + .parent().addClass('has-error').removeClass('has-success'); $('#register').addClass('disabled'); } else { - $('#validation').text(''); + $('#validation').text('') + .parent().addClass('has-success').removeClass('has-error'); $('#register').removeClass('disabled'); } }, 200); - }); + + }