{% extends "common-content.html" %}

{% block content_js_media %}
    <script type="text/javascript">
        $(function () {
            $('.leave-organization').click(function () {
                return confirm('{{ _('Are you sure you want to leave this organization?') }}\n' +
                    {% if organization.is_open %}
                        '{{ _('You will have to rejoin to show up on the organization leaderboard.') }}'
                    {% else %}
                        '{{ _('You will have to request membership in order to join again.') }}'
                    {% endif %}
                );
            });
        });
    </script>
{% endblock %}

{% block info_float %}
    {% if request.user.is_authenticated %}
        {% if request.profile in organization %}
            <form method="post" action="{{ url('leave_organization', organization.id, organization.slug) }}">
                {% csrf_token %}
                <input type="submit" class="unselectable button full leave-organization" value="{{ _('Leave organization') }}">
            </form>
        {% elif organization.is_open %}
            <form method="post" action="{{ url('join_organization', organization.id, organization.slug) }}">
                {% csrf_token %}
                <input type="submit" class="unselectable button full" value="{{ _('Join organization') }}">
            </form>
        {% else %}
            <a href="{{ url('request_organization', organization.id, organization.slug) }}"
               class="unselectable button full">{{ _('Request membership') }}</a>
        {% endif %}
        <hr>
    {% endif %}

    {% if can_edit %}
        <div><a href="{{ url('edit_organization', organization.id, organization.slug) }}">{{ _('Edit organization') }}</a></div>

        {% if not organization.is_open %}
            <div>
                <a href="{{ url('organization_requests_pending', organization.id, organization.slug) }}">{{ _('View requests') }}</a>
            </div>
        {% endif %}
    {% endif %}

    {% if perms.judge.change_organization %}
        <div>
            <a href="{{ url('admin:judge_organization_change', organization.id) }}">{{ _('Admin organization') }}</a>
        </div>
    {% endif %}

    <div>
        <a href="{{ organization.get_users_url() }}">{{ _('View members') }}</a>
    </div>
{% endblock %}

{% block description %}
    {% cache 3600 'organization_html' organization.id MATH_ENGINE %}
        {{ organization.about|markdown('organization-about', MATH_ENGINE)|reference|str|safe }}
    {% endcache %}
{% endblock %}