55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
$(document).ready( function () {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
|
}
|
|
});
|
|
|
|
$('#sendInviteUserFrm').submit(function(e) {
|
|
e.preventDefault();
|
|
var action = $(this).attr('action');
|
|
var button = $(this).find('button[type="submit"]');
|
|
var buttonHtml = button.html();
|
|
|
|
if (!button.is(':disabled') && action) {
|
|
button.attr('disabled', 'disabled');
|
|
button.html('<i class="fa fa-spinner fa-spin" style="font-size:24px"></i>');
|
|
|
|
$.ajax({
|
|
url: action,
|
|
type: "post",
|
|
data: $(this).serialize(),
|
|
dataType: 'json',
|
|
success:function(data) {
|
|
button.removeAttr('disabled');
|
|
button.html(buttonHtml);
|
|
|
|
if (data.success) {
|
|
$('#validationModal').modal('show');
|
|
$('#validationModal .error-message').html(data.message);
|
|
|
|
$('#sendInviteUserFrm').trigger("reset");
|
|
}
|
|
else {
|
|
$('#validationModal .error-message').html(data.message);
|
|
$('#validationModal').modal('show');
|
|
}
|
|
},
|
|
error: function(data) {
|
|
var errors = data.responseJSON.errors;
|
|
var errorMessage = '<ul>';
|
|
$.each(errors, function(index, error) {
|
|
console.log(error);
|
|
errorMessage += '<li>' + error[0] + '</li>';
|
|
});
|
|
errorMessage += '</ul>';
|
|
|
|
$('#validationModal .error-message').html(errorMessage);
|
|
$('#validationModal').modal('show');
|
|
button.removeAttr('disabled');
|
|
button.html(buttonHtml);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
} ); |