-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from alphagov/report-a-problem-ajax-deal-with…
…-html-for-status-503 Report-a-problem: AJAX deal with html for status 503
- Loading branch information
Showing
5 changed files
with
74 additions
and
54 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
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,68 @@ | ||
var ReportAProblem = { | ||
showErrorMessage: function (jqXHR) { | ||
var response = "<p>Sorry, we're unable to receive your message right now.</p> " + | ||
"<p>We have other ways for you to provide feedback on the " + | ||
"<a href='/feedback'>support page</a>.</p>" | ||
$('.report-a-problem-container').html(response); | ||
}, | ||
|
||
promptUserToEnterValidData: function() { | ||
ReportAProblem.enableSubmitButton(); | ||
$('<p class="error-notification">Please enter details of what you were doing.</p>').insertAfter('.report-a-problem-container p:first-child'); | ||
}, | ||
|
||
disableSubmitButton: function() { | ||
$('.report-a-problem-container .button').attr("disabled", true); | ||
}, | ||
|
||
enableSubmitButton: function() { | ||
$('.report-a-problem-container .button').attr("disabled", false); | ||
}, | ||
|
||
showConfirmation: function(data) { | ||
$('.report-a-problem-container').html(data.message); | ||
}, | ||
|
||
submit: function() { | ||
$('.report-a-problem-container .error-notification').remove(); | ||
|
||
ReportAProblem.disableSubmitButton(); | ||
$.ajax({ | ||
type: "POST", | ||
url: "/feedback", | ||
dataType: "json", | ||
data: $('.report-a-problem-container form').serialize(), | ||
success: ReportAProblem.showConfirmation, | ||
error: function(jqXHR, status) { | ||
if (status === 'error' || !jqXHR.responseText) { | ||
if (jqXHR.status == 422) { | ||
ReportAProblem.promptUserToEnterValidData(); | ||
} | ||
else { | ||
ReportAProblem.showErrorMessage(); | ||
} | ||
} | ||
}, | ||
statusCode: { | ||
500: ReportAProblem.showErrorMessage | ||
} | ||
}); | ||
return false; | ||
} | ||
} | ||
|
||
$(document).ready(function() { | ||
// toggle for reporting a problem (on all content pages) | ||
$('.report-a-problem-toggle a').on('click', function() { | ||
$('.report-a-problem-container').toggle(); | ||
return false; | ||
}); | ||
|
||
// form submission for reporting a problem | ||
var $forms = $('.report-a-problem-container form, .report-a-problem form'); | ||
$forms.append('<input type="hidden" name="javascript_enabled" value="true"/>'); | ||
$forms.append($('<input type="hidden" name="referrer">').val(document.referrer || "unknown")); | ||
|
||
$('.report-a-problem-container form').submit(ReportAProblem.submit); | ||
|
||
}); |
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