{% extends "base.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 url from future %}
{% load i18n cleanhtml assets cache common_tags %}

{% get_current_language as LANGUAGE_CODE %}

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

{% block breadcrumbs %}
{{ block.super }}{% include 'common/_breadcrumbs.html' %}
{% endblock %}

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

{% block body_id %}{% if directory.is_language %}languagenews{% else %}tpnews{% endif %}{% endblock %}

{% block tabs %}
  {% if directory.is_language %}
    {% include "language_menu.html" %}
  {% else %}
    {% if directory.is_project %}
      {% include "project_menu.html" %}
    {% else %}
      {% include "tp_menu.html" %}
    {% endif %}
  {% 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="news-publish" 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 %}
