{% extends "balafon/_bs_section.html" %}
{% load i18n balafon_utils %}

{% block section_title %}{% trans "Contacts" %}{% endblock %}
  
{% block section_data %}
<table class="table table-striped">
  <tr>
    <th colspan="2">&nbsp;</th><th>{% trans "Role" %}</th>
    <th>{% trans "Phone" %}</th><th>{% trans "Email" %}</th><th>{% trans "City" %}</th>
  </tr>
  
  {% for x in contacts %}
  
  {% if x.is_entity %}
    <tr class="{% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}">
      <td rowspan={{x.main_contacts|length}}>
        <a href="{% url "crm_view_entity" x.id %}">{{x}}</a>
      </td>
    {% if x.main_contacts %}
      {% for c in x.main_contacts %}
        {% if not forloop.first %}
          <tr>
        {%endif %}
        <td><a href="{% url "crm_view_contact" c.id %}">{{c.fullname}}</a></td>
        <td>{{c.get_roles|seq_to_dash}}</td>
        <td>{{c.get_phones|seq_to_dash}}</td>
        <td><a href="mailto:{{c.get_email}}">{{c.get_email}}</a></td>
        <td>{{c.get_city|default:"&nbsp;"}}</td>
      </tr>
      {% endfor %}
    {% else %}
      </tr>
    {% endif %}
  {% else %}
    <tr class="{% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}">
    {% with x.entity as e %}
      {% if e.is_single_contact %}
        <td colspan=2>
          <a href="{% url "crm_view_contact" x.id %}">{{x.fullname}}</a>
        </td>
      {% else %}
        <td><a href="{% url "crm_view_entity" e.id %}">{{e}}</a></td>
        <td>
          <a href="{% url "crm_view_contact" x.id %}">{{x.fullname}}</a>
          {%if x.has_left %}<span class="label label-warning ut-has-left">{% trans "has left" %}</span>{% endif %}
        </td>
      {% endif %}
      <td>{{x.get_roles|seq_to_dash}}</td>
      <td>{{x.get_phones|seq_to_dash}}</td>
      <td><a href="mailto:{{x.get_email}}">{{x.get_email}}</a></td>
      <td>{{x.get_city|default:"&nbsp;"}}</td>
    {% endwith %}
  {% endif %}
  
  </tr>
  {% endfor %}
</table>
{% endblock %}

