2017-11-10 02:46:50 +01:00
|
|
|
// display the content that shows channel creation has started
|
2017-10-11 02:46:26 +02:00
|
|
|
function showChannelCreateInProgressDisplay () {
|
|
|
|
const publishChannelForm = document.getElementById('publish-channel-form');
|
|
|
|
const inProgress = document.getElementById('channel-publish-in-progress');
|
2017-11-10 02:46:50 +01:00
|
|
|
const channelProgressBar = document.getElementById('create-channel-progress-bar');
|
|
|
|
publishChannelForm.hidden = true;
|
2017-10-11 02:46:26 +02:00
|
|
|
inProgress.hidden = false;
|
2017-11-10 02:46:50 +01:00
|
|
|
createProgressBar(channelProgressBar, 12);
|
2017-10-11 02:46:26 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 02:46:50 +01:00
|
|
|
// display the content that shows channle creation is done
|
2017-10-11 02:46:26 +02:00
|
|
|
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
|
2017-11-02 23:47:55 +01:00
|
|
|
validationFunctions.validateNewChannelSubmission(userName, password)
|
2017-10-11 02:46:26 +02:00
|
|
|
.then(() => {
|
|
|
|
showChannelCreateInProgressDisplay();
|
|
|
|
return sendAuthRequest(userName, password, '/signup') // post the request
|
|
|
|
})
|
|
|
|
.then(result => {
|
2017-12-01 03:23:27 +01:00
|
|
|
setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId);
|
2017-10-11 02:46:26 +02:00
|
|
|
showChannelCreateDoneDisplay();
|
2017-12-01 03:23:27 +01:00
|
|
|
// if user is on the home page, update the needed elements without reloading
|
2017-10-11 03:05:47 +02:00
|
|
|
if (window.location.pathname === '/') {
|
2017-12-01 03:23:27 +01:00
|
|
|
replaceChannelOptionInPublishChannelSelect(result.channelName);
|
|
|
|
replaceChannelOptionInNavBarChannelSelect(result.channelName);
|
|
|
|
// if user is not on home page, redirect to home page
|
2017-10-11 03:05:47 +02:00
|
|
|
} 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');
|
2017-11-10 02:46:50 +01:00
|
|
|
validationFunctions.showError(channelNameErrorDisplayElement, error.message);
|
2017-10-11 02:46:26 +02:00
|
|
|
} else {
|
|
|
|
console.log('signup failure:', error);
|
2017-12-14 21:32:20 +01:00
|
|
|
showChannelCreationError('Unfortunately, we encountered an error while creating your channel. Please let us know in slack!');
|
2017-10-11 02:46:26 +02:00
|
|
|
}
|
|
|
|
})
|
2017-12-14 21:32:20 +01:00
|
|
|
}
|