Added tabs between PUT and PATCH forms and better PATCH form handing

This commit is contained in:
Michael Elovskikh 2013-01-25 15:18:22 +06:00
parent a1c322c346
commit e53b66bed8
2 changed files with 61 additions and 46 deletions

View File

@ -3,3 +3,11 @@ prettyPrint();
$('.js-tooltip').tooltip({ $('.js-tooltip').tooltip({
delay: 1000 delay: 1000
}); });
$('#patch-form').find('.field-switcher').on('change', function() {
var $this = $(this);
$('#patch-form').find('#'+$this.attr('data-field-id'))
.prop('disabled', !$this.prop('checked'));
});
$('#form-method-switcher a:first').tab('show');

View File

@ -147,56 +147,63 @@
</div> </div>
{% endif %} {% endif %}
{% if put_form %} {% if put_form or patch_form %}
<div class="well"> <div class="well">
<form action="{{ request.get_full_path }}" method="POST" {% if put_form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal"> <ul class="nav nav-pills" id="form-method-switcher">
<fieldset> {% if put_form %}<li><a href="#put-form" data-toggle="pill">PUT Form</a></li>{% endif %}
<input type="hidden" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PUT" /> {% if patch_form %}<li><a href="#patch-form" data-toggle="pill">PATCH Form</a></li>{% endif %}
{% csrf_token %} </ul>
{{ put_form.non_field_errors }} <div class="tab-content">
{% for field in put_form %} {% if put_form %}
<div class="control-group"> <!--{% if field.errors %}error{% endif %}--> <div class="tab-pane" id="put-form">
{{ field.label_tag|add_class:"control-label" }} <form action="{{ request.get_full_path }}" method="POST" {% if put_form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal">
<div class="controls"> <fieldset>
{{ field }} <input type="hidden" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PUT" />
<span class='help-inline'>{{ field.help_text }}</span> {% csrf_token %}
<!--{{ field.errors|add_class:"help-block" }}--> {{ put_form.non_field_errors }}
</div> {% for field in put_form %}
</div> <div class="control-group"> <!--{% if field.errors %}error{% endif %}-->
{% endfor %} {{ field.label_tag|add_class:"control-label" }}
<div class="form-actions"> <div class="controls">
<button class="btn btn-primary js-tooltip" title="Make a PUT request on the {{ name }} resource">PUT</button> {{ field }}
</div> <span class='help-inline'>{{ field.help_text }}</span>
<!--{{ field.errors|add_class:"help-block" }}-->
</fieldset> </div>
</form>
</div>
{% endif %}
{% if patch_form %}
<div class="well">
<form action="{{ request.get_full_path }}" method="POST" {% if patch_form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal">
<fieldset>
<input type="hidden" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PATCH" />
{% csrf_token %}
{{ patch_form.non_field_errors }}
{% for field in patch_form %}
<div class="control-group"> <!--{% if field.errors %}error{% endif %}-->
{{ field.label_tag|add_class:"control-label" }}
<div class="controls">
{{ field }}
<span class='help-inline'>{{ field.help_text }}</span>
<!--{{ field.errors|add_class:"help-block" }}-->
</div> </div>
{% endfor %}
<div class="form-actions">
<button class="btn btn-primary js-tooltip" title="Make a PUT request on the {{ name }} resource">PUT</button>
</div> </div>
{% endfor %} </fieldset>
<div class="form-actions"> </form>
<button class="btn btn-primary js-tooltip" title="Make a PATCH request on the {{ name }} resource">PATCH</button> </div>
</div> {% endif %}
{% if patch_form %}
</fieldset> <div class="tab-pane" id="patch-form">
</form> <form action="{{ request.get_full_path }}" method="POST" {% if patch_form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal">
<fieldset>
<input type="hidden" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PATCH" />
{% csrf_token %}
{{ patch_form.non_field_errors }}
{% for field in patch_form %}
<div class="control-group"> <!--{% if field.errors %}error{% endif %}-->
{{ field.label_tag|add_class:"control-label" }}
<div class="controls">
{{ field }}&nbsp;<input checked="checked" type="checkbox" id="{{ field.html_name }}_field_sent" class="field-switcher" data-field-id="{{ field.auto_id }}">
<span class='help-inline'>{{ field.help_text }}</span>
<!--{{ field.errors|add_class:"help-block" }}-->
</div>
</div>
{% endfor %}
<div class="form-actions">
<button class="btn btn-primary js-tooltip" title="Make a PATCH request on the {{ name }} resource">PATCH</button>
</div>
</fieldset>
</form>
</div>
{% endif %}
</div> </div>
</div>
{% endif %} {% endif %}
{% endif %} {% endif %}