spee.ch/views/partials/publishForm-Channel.handlebars

109 lines
5.3 KiB
Handlebars
Raw Normal View History

<!-- select whether to publish anonymously or in a channel -->
2017-09-27 00:12:47 +02:00
<div class="row">
<div class="column column--10">
<form>
2017-10-10 21:10:18 +02:00
<div class="column column--3 column--sml-10">
<input type="radio" name="anonymous-or-channel" id="anonymous-select" class="input-radio" value="anonymous" {{#unless user}}checked {{/unless}} onchange="toggleChannel(event.target.value)"/>
<label class="label label--pointer" for="anonymous-select">Anonymous</label>
</div><div class="column column--7 column--sml-10">
<input type="radio" name="anonymous-or-channel" id="in-a-channel-select" class="input-radio" value="in a channel" {{#if user}}checked {{/if}} onchange="toggleChannel(event.target.value)"/>
<label class="label label--pointer" for="in-a-channel-select">In a channel</label>
</div>
</form>
2017-09-21 01:04:58 +02:00
</div>
2017-09-27 00:12:47 +02:00
</div>
2017-09-21 01:04:58 +02:00
<div id="channel-select-options" {{#unless user}}hidden="true"{{/unless}}>
<!-- select whether to create new or log in to existing channel -->
2017-10-12 18:58:31 +02:00
<div class="row row--no-top">
<div class="column column--3 column--sml-10">
<label class="label" for="channel-name-select">Channel:</label>
</div><div class="column column--7 column--sml-10">
2017-10-12 18:24:03 +02:00
<div class="info-message-placeholder">
<div id="input-error-channel-select" class="info-message info-message--failure"></div>
</div>
<select type="text" id="channel-name-select" class="select select--primary select--arrow" onchange="toggleSelectedChannel(event.target.selectedOptions[0].value)">
{{#if user}}
<option value="{{user.channelName}}" id="publish-channel-select-channel-option">{{user.channelName}}</option>
{{/if}}
<option value="login">Existing</option>
<option value="new" >New</option>
</select>
</div>
</div>
<!-- log into an existing channel -->
<div id="channel-login-details" class="row row--short" {{#if user}}hidden="true"{{/if}}>
{{> channelLoginForm}}
</div>
<!-- create a channel -->
<div id="channel-create-details" class="row row--short" hidden="true">
{{> channelCreationForm}}
</div>
2017-09-27 00:12:47 +02:00
</div>
2017-09-21 01:04:58 +02:00
<script src="/assets/js/authFunctions.js"></script>
<script type="text/javascript">
// show or hide the channel selection tools
function toggleChannel (selectedOption) {
const channelSelectOptions = document.getElementById('channel-select-options');
console.log('toggleChannel event triggered', selectedOption);
// show/hide the login and new channel forms
if (selectedOption === 'anonymous') {
channelSelectOptions.hidden = true;
channelSelectOptions.hidden = true;
2017-10-04 23:31:06 +02:00
// update url
updateUrl(selectedOption);
} else if (selectedOption === 'in a channel') {
channelSelectOptions.hidden = false;
2017-10-04 23:31:06 +02:00
// update url
let selectedChannel = document.getElementById('channel-name-select').selectedOptions[0].value
toggleSelectedChannel(selectedChannel);
} else {
console.log('selected option was not recognized');
}
2017-10-04 23:31:06 +02:00
}
// show or hide the channel create/login tool
function toggleSelectedChannel (selectedChannel) {
2017-09-29 00:47:55 +02:00
const createChannelTool = document.getElementById('channel-create-details');
const loginToChannelTool = document.getElementById('channel-login-details');
console.log('toggleSelectedChannel event triggered', selectedChannel);
// show/hide the login and new channel forms
2017-10-04 23:31:06 +02:00
if (selectedChannel === 'new') {
2017-09-29 00:47:55 +02:00
createChannelTool.hidden = false;
loginToChannelTool.hidden = true;
2017-10-04 23:31:06 +02:00
} else if (selectedChannel === 'login') {
2017-09-29 00:47:55 +02:00
loginToChannelTool.hidden = false;
createChannelTool.hidden = true;
} else {
2017-09-29 00:47:55 +02:00
// hide the login and new channel forms
loginToChannelTool.hidden = true;
createChannelTool.hidden = true;
hideError(document.getElementById('input-error-channel-select'));
}
// update url
2017-10-04 23:31:06 +02:00
updateUrl(selectedChannel);
2017-09-29 00:47:55 +02:00
}
2017-10-06 03:08:44 +02:00
function updateUrl (selectedOption) {
const urlChannel = document.getElementById('url-channel');
const urlNoChannelPlaceholder = document.getElementById('url-no-channel-placeholder');
const urlChannelPlaceholder = document.getElementById('url-channel-placeholder');
if (selectedOption === 'new' || selectedOption === 'login' || selectedOption === ''){
urlChannel.hidden = true;
urlNoChannelPlaceholder.hidden = true;
urlChannelPlaceholder.hidden = false;
} else if (selectedOption === 'anonymous'){
urlChannel.hidden = true;
urlNoChannelPlaceholder.hidden = false;
urlChannelPlaceholder.hidden = true;
} else {
urlChannel.hidden = false;
// show channel and short id
const selectedChannel = getCookie('channel_name');
const shortChannelId = getCookie('short_channel_id');
urlChannel.innerText = `${selectedChannel}:${shortChannelId}`;
2017-10-06 03:08:44 +02:00
urlNoChannelPlaceholder.hidden = true;
urlChannelPlaceholder.hidden = true;
}
}
2017-09-21 01:04:58 +02:00
</script>