-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
164 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
webapp/home/templates/home/subdomains/components/feedback-modal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<!-- A modal for collecting user feedback --> | ||
|
||
{% load static %} | ||
|
||
<div class="modal fade" id="feedbackModal" tabindex="-1"> | ||
<div class="modal-dialog modal-lg"> | ||
<div class="modal-content"> | ||
<form id="feedbackForm"> | ||
|
||
{% csrf_token %} | ||
|
||
<div class="modal-header"> | ||
<h5 class="modal-title">Feedback</h5> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" | ||
onclick="clearFeedbackForm()"></button> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="default-content"> | ||
<p> | ||
We'd love to hear your feedback on the Galaxy {{ site_name }} {{ lab_name }}. Please let us know what | ||
you think! | ||
</p> | ||
<div class="mb-3"> | ||
<label for="nameInput" class="form-label">Name</label> | ||
|
||
<input type="text" class="form-control" id="nameInput" required> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="emailInput" class="form-label">Email address</label> | ||
<input type="email" class="form-control" id="emailInput" aria-describedby="emailHelp" required> | ||
<div id="emailHelp" class="form-text">In case we'd like to contact you for more information.</div> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="messageInput" class="form-label">Your feedback</label> | ||
<textarea class="form-control" id="messageInput" rows="8" required></textarea> | ||
</div> | ||
</div> | ||
|
||
<div class="success-content" style="display: none;"> | ||
<p class="alert alert-success">Thanks for your feedback!</p> | ||
</div> | ||
|
||
<div class="loading m-5 text-center" style="display: none;"> | ||
<img src="{% static '/home/img/spinner.svg' %}" alt="Loading animation" width="150px"> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="clearFeedbackForm();">Close</button> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
function clearFeedbackForm() { | ||
setTimeout(() => { | ||
document.getElementById('feedbackForm').reset(); | ||
$('#feedbackForm .default-content').show(); | ||
$('#feedbackForm .success-content').hide(); | ||
$('#feedbackForm .loading').hide(); | ||
$('button[type="submit"]').show(); | ||
}, 500); | ||
} | ||
|
||
function submitFeedbackForm(event) { | ||
event.preventDefault(); | ||
$('#feedbackForm .loading').show(); | ||
$('#feedbackForm .default-content').hide(); | ||
$('button[type="submit"]').hide(); | ||
|
||
// Clear any previous errors | ||
$('#feedbackForm .error-message').remove(); | ||
$('#feedbackForm .invalid').removeClass('invalid'); | ||
|
||
let formData = new FormData(); | ||
formData.append('name', $('#nameInput').val()); | ||
formData.append('email', $('#emailInput').val()); | ||
formData.append('message', $('#messageInput').val()); | ||
formData.append('to_address', '{{ feedback_email }}'); | ||
|
||
fetch('/lab/feedback/{{ subdomain }}', { | ||
method: 'POST', | ||
headers: { | ||
'X-CSRFToken': getCsrfToken(), | ||
}, | ||
body: formData, | ||
}).then(r => r.json()) | ||
.then(data => { | ||
if (data.success) { | ||
showFeedbackSuccess(); | ||
} else { | ||
try { | ||
showErrors(JSON.parse(data.errors_json)); | ||
} catch (e) { | ||
console.error(e); | ||
alert('An error occurred. Please try again later.'); | ||
} | ||
} | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
alert('An error occurred. Please try again later.'); | ||
}); | ||
} | ||
|
||
function getCsrfToken() { | ||
return document.querySelector('[name=csrfmiddlewaretoken]').value; | ||
} | ||
|
||
function showFeedbackSuccess() { | ||
console.log("Form success"); | ||
$('#feedbackForm .loading').hide(); | ||
$('#feedbackForm .default-content').hide(); | ||
$('#feedbackForm .success-content').show(); | ||
} | ||
|
||
function showErrors(errors) { | ||
Object.keys(errors).forEach( (field) => { | ||
errors[field].forEach( err => { | ||
const msg = err.message; | ||
$(`#${field}Input`) | ||
.addClass('invalid') | ||
.parent().append(`<small class="text-danger error-message">${msg}</small>`); | ||
}) | ||
}); | ||
$('#feedbackForm .loading').hide(); | ||
$('#feedbackForm .default-content').show(); | ||
$('button[type="submit"]').show(); | ||
} | ||
|
||
$('#feedbackForm').submit(submitFeedbackForm); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.