$("#user-setup-modal-window").html("<%= escape_javascript(render partial: 'setup_popup') %>");
// disable the submit button on load
var $input = $('input:text'),
$register = $('#register');
var email_disabled = document.forms["setup_form"]["email"].disabled;
var email_value = document.forms["setup_form"]["email"].value;
var prefix_value = document.forms["setup_form"]["openid_prefix"].value;
if ((email_disabled == false) && (email_value == null || email_value == "" ||
prefix_value == null || prefix_value == "")) {
$register.prop('disabled', true);
}
// capture events to enable submit button when applicable
$input.on('keyup paste mouseleave', function() {
var trigger = false;
var email_disabled = document.forms["setup_form"]["email"].disabled;
var email_value = document.forms["setup_form"]["email"].value;
var prefix_value = document.forms["setup_form"]["openid_prefix"].value;
var emailRegExp = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var validEmail = false;
if (emailRegExp.test(email_value )) {
validEmail = true;
}
if ((email_disabled == false) && (!validEmail || email_value == null ||
email_value == "" || prefix_value == null || prefix_value == "")){
trigger = true;
}
$register.prop('disabled', trigger);
});
// reset form input fields, for the next time around
function reset_form() {
$('#email').val("");
$('#openid_prefix').val("");
$('#repo_name').val("");
$('select').val('')
}