fix: Re-enable button and add disable styles

This commit is contained in:
Mrugesh Mohapatra
2018-01-05 12:53:26 +05:30
parent 07ca7c4376
commit 7d2e9bc15e

View File

@ -10,16 +10,15 @@ block content
#flash-content
.row
.text-center
h2 Sign in or Sign Up with an Email
h2 Sign in or Sign Up with an Email here:
.button-spacer
div#sign-in-form
.col-sm-6.col-sm-offset-3
form(method='POST', action='/passwordless-auth')
input(type='hidden', name='_csrf', value=_csrf)
.form-group
input.input-lg.form-control(type='email', name='email', id='email', placeholder='Email', autofocus=true, required)
.button-spacer
button.btn.btn-primary.btn-lg.btn-block(type='submit')
button#magic-btn.btn.btn-primary.btn-lg.btn-block(type='submit')
span.fa.fa-envelope
| Get a magic link to sign in.
.row
@ -36,12 +35,16 @@ block content
script.
$(document).ready(function() {
function disableMagicButton () {
var userEmail = $("input[name=email]").val();
$('#sign-in-form')
.empty()
.html('<h3 class="text-center"> OK - we are sending a magic link to ' + userEmail + ' </h3>')
.fadeIn(100);
function disableMagicButton (isDisabled) {
if (isDisabled) {
$('#magic-btn')
.prop('disabled', true)
.html('<span style="color:#E0E0E0;"><i class="fa fa-circle-o-notch fa-spin fa-fw"></i>Ok - We will attempt sending to the email above.</span>');
} else {
$('#magic-btn')
.prop('disabled', true)
.html('<span style="color:#E0E0E0;">Did not get a link? Reload the page and resend again.</span>');
}
}
$('form').submit(function(event){
@ -60,7 +63,7 @@ block content
.fail(error => {
if (error.responseText){
var data = JSON.parse(error.responseText);
if(data.error && data.error.message)
if(data.error && data.error.message) {
$('#flash-content').html(data.error.message);
$('#flash-board')
.removeClass('alert-success')
@ -68,9 +71,11 @@ block content
.slideDown(400)
.delay(800)
.fadeIn();
disableMagicButton(false);
}
}
})
.done(data =>{
.done(data => {
if(data && data.message) {
var alertType = 'alert-';
switch (data.type) {
@ -93,6 +98,7 @@ block content
.slideDown(400)
.delay(800)
.fadeIn();
disableMagicButton(false);
}
});
});