{% load i18n thumbnail balafon_utils %}

<div class="custom-field-list">
  <div class="custom-field-list-header">
    <span class="custom-field-list-title">{% trans "Fields" %}</span>
    {% if contact %}
      <a class="btn btn-xs pull-right colorbox-form" href="{% url "crm_edit_custom_fields" "contact" contact.id %}">
        <span class="glyphicon glyphicon-pencil"></span> {% trans "Edit" %}
      </a>
    {% else %}
      <a class="btn btn-xs pull-right colorbox-form" href="{% url "crm_edit_custom_fields" "entity" entity.id %}">
        <span class="glyphicon glyphicon-pencil"></span> {% trans "Edit" %}
      </a>
      {% endif %}    
  </div>
  <div class="row">
    <div class="col-md-12">
      <div class="data-groups">
      {% for field in custom_fields %}
        {% with instance|custom_field:field.name as field_value %}
        {% if field_value %}
        <span class="custom-field">
          <span class="custom-field-label">{% if field.label %}{{field.label}}{% else %}{{ field.name }}{% endif %}:</span>
          <span class="custom-field-value">
            {% if field.is_link %}
              <a href="{{field_value}}" target="_blank">{% trans "Open" %}</a>
            {% else %}
              {{field_value}}
            {% endif %}
          </span>
        </span>
        {% endif %}
        {% endwith %}
      {% endfor %}
      </div>
    </div>
  </div>
</div>