2017-10-11 02:46:26 +02:00
|
|
|
function showChannelCreateInProgressDisplay () {
|
|
|
|
const publishChannelForm = document.getElementById('publish-channel-form');
|
|
|
|
publishChannelForm.hidden = true;
|
|
|
|
const inProgress = document.getElementById('channel-publish-in-progress');
|
|
|
|
inProgress.hidden = false;
|
|
|
|
createProgressBar(document.getElementById('create-channel-progress-bar'), 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
function showChannelCreateDoneDisplay() {
|
|
|
|
const inProgress = document.getElementById('channel-publish-in-progress');
|
|
|
|
inProgress.hidden=true;
|
|
|
|
const done = document.getElementById('channel-publish-done');
|
|
|
|
done.hidden = false;
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:01:46 +02:00
|
|
|
function showChannelCreationError(msg) {
|
|
|
|
const inProgress = document.getElementById('channel-publish-in-progress');
|
|
|
|
inProgress.innerText = msg;
|
|
|
|
}
|
|
|
|
|
2017-10-11 02:46:26 +02:00
|
|
|
function publishNewChannel (event) {
|
|
|
|
const userName = document.getElementById('new-channel-name').value;
|
|
|
|
const password = document.getElementById('new-channel-password').value;
|
|
|
|
// prevent default so this script can handle submission
|
|
|
|
event.preventDefault();
|
|
|
|
// validate submission
|
|
|
|
validateNewChannelSubmission(userName, password)
|
|
|
|
.then(() => {
|
|
|
|
showChannelCreateInProgressDisplay();
|
|
|
|
return sendAuthRequest(userName, password, '/signup') // post the request
|
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
showChannelCreateDoneDisplay();
|
|
|
|
// refresh window logged in as the channel
|
|
|
|
setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId); // set cookies
|
|
|
|
})
|
|
|
|
.then(() => {
|
2017-10-11 03:05:47 +02:00
|
|
|
if (window.location.pathname === '/') {
|
|
|
|
// remove old channel and replace with new one & select it
|
|
|
|
replaceChannelOptionInPublishChannelSelect();
|
|
|
|
// remove old channel and replace with new one & select it
|
|
|
|
replaceChannelOptionInNavBarChannelSelect();
|
|
|
|
} else {
|
|
|
|
window.location = '/';
|
|
|
|
}
|
2017-10-11 02:46:26 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-10-12 19:07:18 +02:00
|
|
|
if (error.name === 'ChannelNameError' || error.name === 'ChannelPasswordError'){
|
2017-10-11 02:46:26 +02:00
|
|
|
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
|
|
|
|
showError(channelNameErrorDisplayElement, error.message);
|
|
|
|
} else {
|
|
|
|
console.log('signup failure:', error);
|
2017-10-17 17:47:00 +02:00
|
|
|
showChannelCreationError('Unfortunately, Spee.ch encountered an error while creating your channel. Please let us know in slack!');
|
2017-10-11 02:46:26 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|