2017-09-27 00:12:47 +02:00
|
|
|
|
|
|
|
<form id="publish-channel-form">
|
2017-09-29 23:11:00 +02:00
|
|
|
<div class="row row--wide">
|
|
|
|
<div class="column column--3">
|
|
|
|
<label class="label" for="new-channel-name">Name:</label>
|
|
|
|
</div><div class="column column--4">
|
2017-09-27 00:12:47 +02:00
|
|
|
<div id="input-error-channel-name" class="info-message info-message--failure"></div>
|
|
|
|
<div class="input-text--primary">
|
|
|
|
<span>@</span>
|
|
|
|
<input type="text" name="new-channel-name" id="new-channel-name" class="input-text" placeholder="exampleChannel" value="" oninput="checkChannelName(event.target.value)">
|
|
|
|
<span id="input-success-channel-name" class="info-message info-message--success"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-09-29 23:11:00 +02:00
|
|
|
<div class="row row--wide">
|
|
|
|
<div class="column column--3">
|
|
|
|
<label class="label" for="new-channel-password">Password:</label>
|
|
|
|
</div><div class="column column--4">
|
|
|
|
<div id="input-error-channel-password" class="info-message info-message--failure"></div>
|
|
|
|
<input type="password" name="new-channel-password" id="new-channel-password" placeholder="" value="" class="input-text input-text--primary">
|
|
|
|
</div>
|
2017-09-27 00:12:47 +02:00
|
|
|
</div>
|
|
|
|
|
2017-09-27 04:06:07 +02:00
|
|
|
<div class="row row--wide">
|
|
|
|
<button onclick="publishNewChannel(event)">Create Channel</button>
|
|
|
|
</div>
|
2017-09-27 00:12:47 +02:00
|
|
|
</form>
|
2017-09-21 01:04:58 +02:00
|
|
|
|
2017-09-27 00:12:47 +02:00
|
|
|
|
2017-09-27 04:06:07 +02:00
|
|
|
<div id="channel-publish-in-progress" hidden="true">
|
|
|
|
<p>Creating your new channel. This may take a few seconds...</p>
|
|
|
|
<div id="create-channel-progress-bar"></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="channel-publish-done" hidden="true">
|
|
|
|
<p>Your channel has been successfully created!</p>
|
|
|
|
</div>
|
2017-09-27 00:12:47 +02:00
|
|
|
|
|
|
|
|
2017-09-21 01:04:58 +02:00
|
|
|
<script type="text/javascript">
|
|
|
|
function publishNewChannel (event) {
|
2017-09-26 07:49:27 +02:00
|
|
|
const channelName = document.getElementById('new-channel-name').value;
|
2017-09-21 01:04:58 +02:00
|
|
|
const password = document.getElementById('new-channel-password').value;
|
|
|
|
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
|
|
|
|
const passwordErrorDisplayElement = document.getElementById('input-error-channel-password');
|
2017-09-27 04:06:07 +02:00
|
|
|
const chanelCreateForm = document.getElementById('publish-channel-form');
|
|
|
|
const inProgress = document.getElementById('channel-publish-in-progress');
|
|
|
|
const done = document.getElementById('channel-publish-done');
|
|
|
|
|
2017-09-21 01:04:58 +02:00
|
|
|
// prevent default so this script can handle submission
|
|
|
|
event.preventDefault();
|
|
|
|
// validate submission
|
|
|
|
validateNewChannelSubmission(channelName, password)
|
|
|
|
.then(() => {
|
2017-09-27 04:06:07 +02:00
|
|
|
console.log('in progress');
|
|
|
|
chanelCreateForm.hidden = true;
|
|
|
|
inProgress.hidden = false;
|
|
|
|
createProgressBar(document.getElementById('create-channel-progress-bar'), 12);
|
2017-09-21 01:04:58 +02:00
|
|
|
return sendAuthRequest(channelName, password, '/signup') // post the request
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
console.log('success');
|
2017-09-27 04:06:07 +02:00
|
|
|
inProgress.hidden=true;
|
|
|
|
done.hidden = false;
|
|
|
|
// refresh window logged in as the channel
|
2017-09-21 01:04:58 +02:00
|
|
|
window.location.href = '/';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (error.name === 'ChannelNameError'){
|
|
|
|
showError(channelNameErrorDisplayElement, error.message);
|
|
|
|
} else if (error.name === 'ChannelPasswordError'){
|
|
|
|
showError(passwordErrorDisplayElement, error.message);
|
|
|
|
} else {
|
|
|
|
console.log('failure:', error);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</script>
|