Handles 401 errors for OAuth users following the 'code flow' (redirects) and notifies the user if there is a fatal error. You wouldn't want the server giving your users 401s outright though -- only when the request is AJAX (X-Requested-With: XMLHttpRequest
.)
Uses jQuery (obviously) as well as Bootstrap modals. I'm not using PJAX just yet but I will include it when I do.
In the following example, I've placed the following elements as the last children of the <body>
element. Note the addition of the empty data-remote
attribute on #dynamic-modal
-- this prevents Bootstrap from performing a redundant load the first time the modal is used.
<div class="modal fade special" id="error-modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Error</h4>
</div>
<div class="modal-body">
An error has occurred while trying to perform the requested action.
Please try again or reload the page.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link" data-dismiss="modal">
Close
</button>
<button type="button" class="btn btn-primary" onclick="window.location.reload()">
Reload page
</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="dynamic-modal" tabindex="-1" role="dialog" data-remote="">
<div class="modal-dialog" role="document">
<div class="modal-content">
</div>
</div>
</div>
Here's an example 'edit-in-place comment' as it would appear in a full page load:
<div data-ajax="component">
<div class="author">Bob</div>
<div class="comment">Hello</div>
<a href="edit" data-ajax>Edit</a>
</div>
...and once you click 'edit', it is replaced with:
<form method="post" action="/new-comment" data-ajax="component">
<div class="author">Bob</div>
<div class="comment">
<textarea name="comments" rows="5">Hello</textarea>
</div>
<button type="submit">Save</button> or
<a href="display" data-ajax>Cancel</a>
</form>
And a small example for the #dynamic-modal
(it's exactly the same as the Bootstrap docs):
<a href="/some/resource" data-toggle="modal" data-target="#dynamic-modal">Some link</a>