spee.ch/views/partials/publishChannel.handlebars

76 lines
3.4 KiB
Handlebars
Raw Normal View History

2017-09-19 17:47:24 +02:00
<div id="claim-channel-input-area">
2017-09-19 21:54:23 +02:00
<p>
2017-09-20 20:36:20 +02:00
<div id="input-error-channel-select" class="info-message info-message--failure"></div>
2017-09-20 00:39:54 +02:00
<label for="channel-name-select">Channel:</label>
2017-09-20 20:36:20 +02:00
<select type="text" id="channel-name-select" name="channel" value="channel" onclick="toggleChannel(event)">
2017-09-19 21:54:23 +02:00
{{#if user}}
<option value="{{user.channelName}}" >{{user.channelName}}</option>
2017-09-19 21:54:23 +02:00
{{/if}}
<option value="@speech" >Anonymous</option>
<option value="new" >New</option>
</select>
</p>
<div id="channel-create-details" hidden="true">
<p>
2017-09-20 20:36:20 +02:00
<form id="publish-channel-form">
<div>
<div id="input-error-channel-name" class="info-message info-message--failure"></div>
<label for="channelName">Channel Name: </label>
@<input type="text" name="channelName" id="new-channel-name" class="input-text input-text--primary" placeholder="exampleChannel" value="" oninput="checkChannelName(event.target.value)">
<span id="input-success-channel-name" class="info-message info-message--success"></span>
</div>
<div>
<div id="input-error-channel-password" class="info-message info-message--failure"></div>
<label for="channelPassword" >Password: </label>
<input type="password" name="channelPassword" id="new-channel-password" placeholder="" value="" class="input-text input-text--primary">
</div>
2017-09-19 21:54:23 +02:00
2017-09-20 20:36:20 +02:00
</form>
2017-09-19 21:54:23 +02:00
</p>
2017-09-20 20:36:20 +02:00
<button onclick="publishNewChannel(event)">Create Channel</button>
2017-09-19 17:47:24 +02:00
</div>
</div>
<script type="text/javascript">
2017-09-20 20:36:20 +02:00
function toggleChannel (event) {
const createChannelTool = document.getElementById('channel-create-details');
2017-09-19 17:47:24 +02:00
const selectedOption = event.target.selectedOptions[0].value;
2017-09-20 00:39:54 +02:00
if (selectedOption != 'new') {
2017-09-19 17:47:24 +02:00
createChannelTool.hidden = true;
2017-09-20 00:39:54 +02:00
hideError(document.getElementById('input-error-channel-select'));
} else {
createChannelTool.hidden = false;
2017-09-19 17:47:24 +02:00
}
}
2017-09-20 20:36:20 +02:00
function publishNewChannel (event) {
const channelName = `@${document.getElementById('new-channel-name').value}`;
const password = document.getElementById('new-channel-password').value;
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
const passwordErrorDisplayElement = document.getElementById('input-error-channel-password');
// prevent default so this script can handle submission
event.preventDefault();
// validate submission
validateNewChannelSubmission(channelName, password)
.then(() => {
return sendSignupRequest(channelName, password) // post the request
})
.then(() => {
console.log('success');
document.getElementById('signup-form').innerHTML = '<p>Your channel has been successfully created! Redirecting you now...</p>';
window.location.href = `/${channelName}`;
})
.catch(error => {
if (error.name === 'ChannelNameError'){
showError(channelNameErrorDisplayElement, error.message);
} else if (error.name === 'ChannelPasswordError'){
showError(passwordErrorDisplayElement, error.message);
} else {
console.log('failure:', error);
}
})
2017-09-19 17:47:24 +02:00
}
</script>