{% load i18n %}
{% if not object.pk %}
    <div class="btn-group">
        <button type="button" class="btn btn-primary dropdown-toggle navbar-btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            {% trans 'Confirm and add a new...' %} <i class="fa fa-caret-down"></i>
        </button>
        <ul class="dropdown-menu">
            {% for question_type in questionnaire.questions_type_and_create_url %}
                <li>
                    <a class="add-another" href="" data-next-url="{{ question_type.create_url }}">{{ question_type.verbose_type }}</a>
                </li>
            {% endfor %}
        </ul>
    </div>
{% endif %}
<script type="text/javascript">
    $(document).ready(function(){
        $('.add-another').click(function(){
            var $form =  $(this).closest('form'),
                submitUrl = $form.attr('action');
            
            // Add the next_url to the form submit url and submit the form
            submitUrl = submitUrl + '?next_url=' + $(this).data('next-url');
            $form.attr('action', submitUrl);
            $form.submit();
            
            return false;
        });
    });
</script>
