Disable OPTIONS if method isn't allowed

This commit is contained in:
Alec Perkins 2012-09-08 00:40:11 -04:00
parent 94029acd28
commit 4cc3dd3b23
2 changed files with 19 additions and 3 deletions

View File

@ -30,4 +30,17 @@ h2, h3 {
.format-option {
font-family: Menlo, Consolas, "Andale Mono", "Lucida Console", monospace;
}
#options-form {
position: relative;
}
/* To allow tooltips to work on disabled elements */
.disabled-tooltip-shield {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}

View File

@ -64,11 +64,14 @@
<!-- Content -->
<div id="content">
{% if 'OPTIONS' in allowed_methods and api_settings.FORM_METHOD_OVERRIDE %}
<form action="{{ request.get_full_path }}" method="post" class="pull-right">
{% if api_settings.FORM_METHOD_OVERRIDE %}
<form id="options-form" action="{{ request.get_full_path }}" method="post" class="pull-right">
{% csrf_token %}
<input type="hidden" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="OPTIONS" />
<button class="btn">OPTIONS</button>
<button class="btn js-tooltip" {% if 'OPTIONS' in allowed_methods %} title="Do an OPTIONS request on the {{ name }} resource"{% else %} disabled{% endif %}>OPTIONS</button>
{% if not 'OPTIONS' in allowed_methods %}
<div class="js-tooltip disabled-tooltip-shield" title="OPTIONS request not allowed for resource {{ name }}"></div>
{% endif %}
</form>
{% endif %}