{% extends "userprofile/base.html" %}
{% load i18n %}
{% load pagination_tags %}
{% load txcommontags %}

{% block title %}{{ block.super }} | {% trans "Notifications" %}{% endblock %}
{% block breadcrumb %}{{ block.super }} &raquo; {% trans "Notifications" %}{% endblock %}
{% block content_title %}<h2 class="pagetitle">{% trans "Notification settings" %}</h2>{% endblock %}

{% block extra_head %}
    <link rel="alternate" type="application/atom+xml" title="Notices Feed" href="{% url notification_feed_for_user %}" />
{% endblock %}

{% block content %}

    <h1>{% trans "Notices" %}</h1>
    
    {% autopaginate notices %}
    
    {% if notices %}
        <a href="{% url notification_mark_all_seen %}">{% trans "Mark all unseen notices seen" %}</a>
        
        {# TODO: get timezone support working with regroup #}
        {% regroup notices by added.date as notices_by_date %}
        
        {% for date in notices_by_date %}
            <h2 class="notice_date">{{ date.grouper }}</h2>
            
            {% for notice in date.list %}
                {% if notice.is_unseen %}
                    <div class="unseen_notice">
                {% else %}
                    <div class="notice">
                {% endif %}
                    <span class="notice_type">[{% trans notice.notice_type.display %}]</span>
                    <span class="notice_message">{{ notice.message|safe }}</span>
                    <span class="notice_time">{{ notice.added }}</span>
                </div>
            {% endfor %}
        {% endfor %}
        
        {% paginate %}
        
    {% else %}
        <p>{% trans "No notices." %}</p>
    {% endif %}

<p>-------------------------------------------------------------</p>

    <div class="notice_settings">
       
        {% with user.email as user_email %}
        {% if user_email %}
            <p>{% blocktrans %}You can receive notifications whenever an event occurs in Transifex. Check the notifications available for you on the list below and choose which events you would like to be notified by email.{% endblocktrans %}</p>
            <p>{% trans "Primary email" %}: <strong>{{ user_email }}</strong>
            <br />({% trans "change under" %} <a href="{% url email_validation %}">{% trans "Account" %}</a>)
        {% else %}
            <p><span class="warning">{% trans "Note" %}</span>:
              {% trans "You do not have a verified email address to which notices can be sent. You can add one by going to" %} <a href="{% url email_validation %}">{% trans "Account" %}</a>.
            </p>
        {% endif %}
        {% endwith %}
        
        <form method="POST" action="">
            <table class="notice_settings">
                <tr>
                    <th>{% trans "Notification Type" %}</th>
                    {% for header in notice_settings.column_headers %}
                        <th>{{ header }}</th>
                    {% endfor %}
                </tr>
                {% for row in notice_settings.rows|notice_type_user_filter %}
                    <tr>
                        <td>{% trans row.notice_type.display %}<br/>
                            <span class="notice_type_description">{% trans row.notice_type.description %}</span>
                        </td>
                        {% for cell in row.cells %}
                            <td>
                                <input type="checkbox" name="{{ cell.0 }}" {% if cell.1 %}checked="yes"{% endif %}/>
                            </td>
                        {% endfor %}
                    </tr>
                {% endfor %}
                <tr>
                    <td><input type="submit" class="i16 submit" value="{% trans "Change" %}" /></td>
                </tr>
            </table>
        </form>
    </div>

{% endblock %}
