{% extends 'cv/forms/_publication_base.html' %}

{% load widget_tweaks %}
{% load staticfiles %}

{% block userstyles %}
{{block.super}}
<link rel="stylesheet" type="text/css" href="{% static 'cv/cv-forms.css' %}" />  
{% endblock userstyles %}
{% block centerbar %}
<div class="alert alert-primary small">
<h2 class="display-4">{{method}} {{model|title}}</h2>    
    <form method="POST" id="{{model}}Form" class="post-form" action="{{action_url}}" >{% csrf_token %}
    <div class="form-group row align-items-start ">
        <div class="col-12 col-lg-6 form-row">
            <span class="col-12">
                {% with form.title as field %}
                    {% include "cv/forms/_publication_field.html" %}
                {% endwith %}
            </span>
            <span class="col-12">
                {% with form.short_title as field %}
                    {% include "cv/forms/_publication_field.html" %}
                {% endwith %}
            </span>
            <span class="col-12">
                {% with form.slug as field %}
                    {% include "cv/forms/_publication_field.html" %}
                {% endwith %}
            </span>
        </div>
        <div class="col-12 col-lg-6 form-row">
            <span class="col-12">
                {% with form.role as field %}
                    {% include "cv/forms/_publication_field.html" %}
                {% endwith %}
            </span>
            <span class="col-6">
                {% with form.start_date as field %}
                    {% include "cv/forms/_publication_field.html" %}
                {% endwith %}
            </span>                
            <span class="col-6">
                {% with form.end_date as field %}
                    {% include "cv/forms/_publication_field.html" %}
                {% endwith %}
            </span>
            <span class="col-12">
                {% with form.source as field %}
                    {% include "cv/forms/_publication_field.html" %}
                {% endwith %}
            </span>
            <span class="col-12 pt-2 form-row">
                {% with form.display as field %}
                    {% with labelwidth="col-2" inputwidth="col-1" %}
                        {% include "cv/forms/_publication_field.html" %}
                    {% endwith %}
                {% endwith %}
            </span>
            <span class="col-12 pt-2 form-row">
                {% with form.is_current as field %}
                    {% with labelwidth="col-2" inputwidth="col-1" %}
                        {% include "cv/forms/_publication_field.html" %}
                    {% endwith %}
                {% endwith %}
            </span>
        </div>

        <!-- ABSTRACT -->
        <div class="col-12 col-lg-6 mt-3 form-row">
            <h5 class="col-12">Abstract</h5>
            <span class="col-12">
                {% with form.abstract as field %}
                    {% include "cv/forms/_publication_field.html" %}
                {% endwith %}
                <span class="form-text text-muted">Use <a href="https://daringfireball.net/projects/markdown/syntax" alt="Markdown syntax">Markdown syntax</a>: e.g., **<b>bold</b>**, *<i>italics</i>*, `<code>code</code>`, [link text]&lt;url&gt;</span>
            </span>
        </div>

        <!-- FUNDING INFORMATION -->
        <div class="col-12 col-lg-6 mt-3 form-row align-content-start">
            <h5 class="col-12">Funding Information</h5>
            <span class="col-12 row">
                <span class="col-12 col-lg-8">
                    {% with form.agency as field %}
                        {% include "cv/forms/_publication_field.html" %}
                    {% endwith %}
                </span>
                <span class="col-12 col-lg-4">
                    {% with form.agency_acronym as field %}
                        {% include "cv/forms/_publication_field.html" %}
                    {% endwith %}
                </span>
                <span class="col-12 col-lg-8">
                    {% with form.division as field %}
                        {% include "cv/forms/_publication_field.html" %}
                    {% endwith %}
                </span>
                <span class="col-12 col-lg-4">
                    {% with form.division_acronym as field %}
                        {% include "cv/forms/_publication_field.html" %}
                    {% endwith %}
                </span>
                <span class="col-12">
                    {% with form.grant_number as field %}
                        {% include "cv/forms/_publication_field.html" %}
                    {% endwith %}
                </span>
                <span class="col-12 col-lg-4">
                    {% with form.amount as field %}
                        {% include "cv/forms/_publication_field.html" %}
                    {% endwith %}
                </span>
            </span>
        </div>


        <!-- AUTHORSHIP INFORMATION -->
         <div class="col-12 row mt-3">
            <h5 class="col-12">Collaborators</h5>
            <div class="col-12 row">
                {{grant_collaboration_formset.management_form}}
                {% for collaborator_form in grant_collaboration_formset %}
                <span class="col-12 d-flex flex-row flex-wrap justify-content-left ml-3 mr-3 mt-2 mb-2 author">
                {% for field in collaborator_form.visible_fields %}
                    {% spaceless %}
                    <span class="d-flex flex-row justify-content-left align-items-center 

                    {% if forloop.first %}
                        col-12 col-lg-4
                    {% else %}
                        col-12 col-lg-2
                        {% if forloop.last %}
                            col-lg-1
                        {% endif %}
                    {% endif %}
                    ">
                    {% endspaceless %}
                        <label for="{{field.id_for_label}}" class="p-0  mt-0 align-self-center 
                            {% if field.field.required %}font-weight-bold{% endif %}">
                        {{field.label}}</label>
                        {{field}}
                        {% if field.error %}
                            <span class="invalid-feedback">{{field.error}}</span>
                        {% endif %}
                    </span>                       
                    {% endfor %}
                </span>
                {% endfor %}
            </div>
                <div class="save-group btn-group col-12" role="group" aria-label="{{method}} {{model}}">
                    <button id="{{model}}FormSubmit" type="submit" class="btn btn-light">Save</button>
                    <a id="cancel" class="btn btn-light" href="{% url 'cv:cv_list' %}#{{model}}s">Cancel</a>
{% if method == "Edit" %}
                    <button href="{% url 'cv:cv_delete' model_name=model pk=form.instance.pk%}" class="btn btn-detail alert-danger cv-delete">Delete</button>
{% endif %}
                </div>


    </div>
    </form>
</div>
{% endblock centerbar %}