{% extends 'detail.html.j2' %}

{% load json %}
{% load markdown %}


{% block tabs %}
<form action="" method="post">
  {% csrf_token %}

<div id="details" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.details %}

</div>


<div id="child_groups" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.child_groups %}

    <input type="button" value="Add Child Group" onclick="window.location='{% url 'Config Management:_group_add_child' group.id %}';">

    <table class="data">
        <tr>
            <th>Name</th>
            <th>Sub-Groups</th>
            <th>&nbsp;</th>
        </tr>
        {% if child_groups %}
        {% for group in child_groups %}
        <tr>
            <td><a href="{% url 'Config Management:_group_view' pk=group.id %}">{{ group.name }}</a></td>
            <td>{{ group.count_children }}</td>
            <td>&nbsp;</td>
        </tr>
        {% endfor %}
        {% else %}
        <tr>
            <td colspan="4">Nothing Found</td>
        </tr>
        {% endif %}
    </table>
</div>


<div id="hosts" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.hosts %}

    <table class="data">
        <tr>
            <th>Name</th>
            <th>Organization</th>
            <th>&nbsp;</th>
        </tr>
        {% if group.hosts %}
        {% for host in group.hosts.all %}
        <tr>
            <td><a href="{% url 'ITAM:_device_view' pk=host.id %}">{{ host }}</a></td>
            <td>{{ host.organization }}</td>
            <td>&nbsp;</td>
        </tr>
        {% endfor %}
        {% else %}
        <tr>
            <td colspan="3">Nothing Found</td>
        </tr>
        {% endif %}
    </table>
</div>


<div id="software" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.software %}

    <input type="button" value="Add Software Action" onclick="window.location='{% url 'Config Management:_group_software_add' model_pk %}';">

    <table>
        <thead>
            <th>Name</th>
            <th>Category</th>
            <th>Action</th>
            <th>Desired Version</th>
            <th>&nbsp;</th>
        </thead>
        {% if softwares %}
        {% for software in softwares %}
        <tr>
            <td><a href="{% url 'ITAM:_software_view' pk=software.software_id %}">{{ software.software }}</a></td>
            <td>{{ software.software.category }}</td>
            <td>
            {% url 'Config Management:_group_software_change' group_id=group.id pk=software.id as icon_link %}
            {% if software.get_action_display == 'Install' %}
                {% include 'icons/success_text.html.j2' with icon_text=software.get_action_display icon_link=icon_link %}
            {% elif software.get_action_display == 'Remove'%}
                {% include 'icons/cross_text.html.j2' with icon_text=software.get_action_display %}
            {% else %}
                {% include 'icons/add_link.html.j2' with icon_text='Add' %}
            {% endif %}
            </td>
            <td>
            {% if software.version %}
                {{ software.version }}
            {% else %}
                -
            {% endif %}
            </td>
            <td>&nbsp;</td>
        </tr>
        {% endfor %}
        {% else %}
        <td colspan="5">Nothing Found</td>
        {% endif %}
    </table>

</div>


<div id="configuration" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.configuration %}

    <div>
        <textarea cols="90" rows="30" readonly>{{ config }}</textarea>
    </div>
</div>


<div id="tickets" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.tickets %}

    <table>
        <thead>
          <th>Name</th>
          <th>Status</th>
          <th>&nbsp</th>
        </thead>
        {% if tickets %}
        {% for ticket in tickets %}
        <tr>
          <td>{% concat_strings "#" ticket.ticket.id as ticket_ref %}{{ ticket_ref | markdown | safe}}</td>
          <td>{% include 'core/ticket/badge_ticket_status.html.j2' with ticket_status_text=ticket.ticket.get_status_display ticket_status=ticket.ticket.get_status_display|ticket_status %}</td>
          <td>&nbsp;</td>
        </tr>
        {% endfor %}
        {% else %}
        <tr>
            <td colspan="3">No related tickets exist</td>
        </tr>
        {% endif %}
    </table>

</div>


<div id="notes" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.notes %}

    {{ notes_form }}
    <input type="submit" name="{{notes_form.prefix}}" value="Submit" />
    <div class="comments">
      {% if notes %}
      {% for note in notes%}
      {% include 'note.html.j2' %}
      {% endfor %}
      {% endif %}
    </div>

</div>


</form>
{% endblock %}























{% block contents %}


<form method="post">
    <div id="Details" class="tabcontent">
        <h3>Details</h3>

        {% csrf_token %}
        {{ form }}
        <br>
        <input type="submit" value="Submit">

        <script>
            document.getElementById("defaultOpen").click();
        </script>

    </div>

    <div id="Children" class="tabcontent">
        <h3>Child Groups</h3>


    </div>

    <div id="Hosts" class="tabcontent">
        <h3>
            Hosts
        </h3>


    </div>

    <div id="Software" class="tabcontent">
        <h3>
            Software
        </h3>

    </div>

    <div id="Configuration" class="tabcontent">
        <h3>Configuration</h3>
        
    </div>

    <div id="Notes" class="tabcontent">
        <h3>
            Notes
        </h3>
        {{ notes_form }}
        <input type="submit" name="{{notes_form.prefix}}" value="Submit" />
        <div class="comments">
            {% if notes %}
            {% for note in notes %}
            {% include 'note.html.j2' %}
            {% endfor %}
            {% endif %}
        </div>

    </div>

</form>

{% endblock %}