<div class="modal fade" id="change-photo-modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Change Photo</h4>
      </div>

      <form action="{% url 'change_photo' pk=subject.pk %}" method="POST" enctype="multipart/form-data" id="change-photo-form">{% csrf_token %}
        <div class="modal-body">
          <div class="form-group">
            <label for="{{ form.photo.id_for_label }}" class="sr-only">{{ change_photo_form.photo.label }}</label>
            {{ change_photo_form.photo }}
            {{ change_photo_form.photo.errors }}
          </div>
        </div>

        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>

          <button type="submit" class="btn btn-primary">
            <span class="glyphicon glyphicon-upload"></span> Upload Photo
          </button>
        </div>
      </form>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script type="text/javascript">
$(document).ready(function() {
  $('#change-photo-form').ajaxForm({
    'dataType': 'json',
    'resetForm': true,
    'success': function(data) {
      if(data.success) {
        // Hide Modal
        $('#change-photo-modal').modal('hide');

        $('.user-photo').attr('src', data.photo);
      } else {
        alert("Sorry, an error occored: " + data.error);
      }
    }
  });
});
</script>
