wo-bisch-web/static/js/wo-bisch-web.js

71 lines
2.6 KiB
JavaScript

$(document).ready(function() {
$("#email").focus();
// Check for click events on the navbar burger icon
$(".navbar-burger").click(function() {
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
$(".navbar-burger").toggleClass("is-active");
$(".navbar-menu").toggleClass("is-active");
});
// Login Button
$("#login-button").click(function(e){
//alert(true);
$("#login-form").submit();
});
// Login Form
$("#login-form-blabla").submit(function(e){
e.preventDefault();
var formData = {
next: $("#email").val(),
email: $("#email").val(),
password: $("#password").val(),
csrf_token: $("#csrf_token").val(),
next: $("#next").val()
};
//console.log(formData);
// send ajax
$.ajax({
url: '/login', // url where to submit the request
type : "POST", // type of action POST || GET
dataType : 'json', // data type
contentType: 'application/json',
data : JSON.stringify(formData), // post data || get data
success : function(result) {
// you can see the result from the console
// tab of the developer tools
console.log('SUCCESS');
console.log(result);
window.location.replace("/");
},
error: function(result) {
//console.log(xhr, resp, text);
console.log('ERROR');
console.log(result);
var errortext = '<ul style="list-style-type:disc">';
a = result.responseJSON.response.errors.email;
if (a != undefined) {
for (i=0; i < a.length; ++i) {
errortext = errortext + "<li>" + a[i] + "</li>";
}
}
a = result.responseJSON.response.errors.password;
if (a != undefined) {
for (i=0; i < a.length; ++i) {
errortext = errortext + "<li>" + a[i] + "</li>";
}
}
errortext = errortext + "</ul>";
$('#errorbox').html(errortext);
$('#errorbox').show();
}
})
});
});