{% extends "layout.html" %}

{% comment %}
Oh yeah, I know, this template code is horrible, and actually there are three
templates in one (news page for: project, language and translation project). In
the future we have to take a different approach for this.
{% endcomment %}

{% load i18n cleanhtml assets %}

{% get_current_language as LANGUAGE_CODE %}

{% block title %}
  {% trans "News" %} |
  {% if directory.is_language %}
    {{ directory.language.name }}
  {% elif directory.is_project %}
    {{ directory.project.fullname }} | {% trans "Projects" %}
  {% else %}
    {{ directory.translation_project.project.fullname }} | {{ directory.translation_project.language.fullname }}
  {% endif %}
  | {{ block.super }}
{% endblock %}

{% block extra_head %}
  <link rel="alternate" type="application/rss+xml" title="{{ title }}" href="{{ notification_url }}" />
{% endblock %}

{% block breadcrumbs %}
  {% if directory.is_language %}
    {% include 'core/_breadcrumbs.html' with nav='languages/_nav.html' %}
  {% elif directory.is_project %}
    {% include 'core/_breadcrumbs.html' with nav='projects/_nav.html' %}
  {% else %}
    {% include 'core/_breadcrumbs.html' with nav='translation_projects/_nav.html' %}
  {% endif %}
{% endblock %}

{% block content %}
  <div class="settings-container" lang="{{ LANGUAGE_CODE }}">
    {% if form %}
      <div class="form news">
        <h2>{% trans "Publish News" %}</h2>

        {% if notices_published %}
          <h3>{% trans "Successfully published the following news" %}</h3>
          <div name="publishednotice">
            {% for np in notices_published %}
              <p>{{ np }}</p>
            {% endfor %}
          </div>
          <hr />
        {% endif %}

        <form method="post" action="">
          {% csrf_token %}
          {{ form.as_p }}
          <p class="buttons">
            <input type="submit" class="btn" value="{% trans 'Publish' %}" />
          </p>
        </form>
      </div>
    {% endif %}

    <div class="news-feed{% if form %}-with-form{% endif %}">
      <h2>{% trans "Latest News" %}</h2>
      {% for notice in notices %}
        <div class="datetime"><small>{{ notice.get_date }}</small></div>
        <div class="newsitem">{{ notice.message|safe|linebreaks|clean }}</div>
        <div class="newsitem-sep"></div>
      {% empty %}
        <p>{% trans "No news yet." %}</p>
      {% endfor %}
    </div>
  </div>
{% endblock %}

{% block scripts_extra %}
  {% if user.is_superuser or request.permissions.administrate %}
    {% assets "js_admin" %}
      <script type="text/javascript" src="{{ ASSET_URL }}"></script>
    {% endassets %}
  {% endif %}
  <script type="text/javascript">
  $(function() {
    $(".newsitem address, .newsitem blockcode, .newsitem blockquote, .newsitem :header, .newsitem p, .newsitem pre, .newsitem li, .newsitem dt, .newsitem dd, .newsitem ul, .newsitem ol, .newsitem dl").filter(":not([dir])").bidi();
  {% if user.is_superuser or request.permissions.administrate %}
    noticeFormInit();
  {% endif %}
  });
  </script>
{% endblock %}
