{% extends "html/notebook/base.html" %}
{#
INPUT:
- worksheet - an instance of Worksheet
- notebook - an instance of Notebook which contains worksheet
- username - a string containing a username
#}

{% block javascript %}
{{ super() }}
<script src="/javascript/sage/js/published_worksheet.js"></script>
{% endblock %}

{% block page_id %}guest-worksheet-page{% endblock %}
{% block body_classes %}{% if conf['pub_interact'] %}active-worksheet{% endif %}{% endblock %}

{% set original_worksheet = worksheet.worksheet_that_was_published() %}
{% if original_worksheet.is_collaborator(username) or original_worksheet.is_owner(username) %}
    {% set edit_text = "Edit this." %}
    {% set edit_text = gettext('Edit this.') %}
    {% set url           = original_worksheet.worksheet_command('') %}
{% elif notebook.user_manager().user_is_guest(username) %}
    {% set edit_text = gettext('Log in to edit a copy.') %}
    {% set url       = "/" %}
{% else %}
    {% set edit_text = gettext('Edit a copy.') %}
    {% set url       = "edit_published_page" %}
{% endif %}

{% set download_name = worksheet.download_name() %}

{% block published_link_rel %}
<link rel="alternate" type="application/sage" title="{{ render_title() }}" href="download/{{ download_name }}.sws" />
{% endblock %}

{% block body %}
<ul class="controls">
    <li><a href="{{ url }}">{{ edit_text }}</a></li>
    <li><a href="download/{{ download_name }}.sws">{{ gettext('Download.') }}</a></li>
    {% if worksheet.rating() != -1 or
       not (notebook.user_manager().user_is_guest(username) or worksheet.is_publisher(username)) %}
    <li>
        {% if worksheet.rating() != -1 %}
            <a class="usercontrol" href="rating_info">
                {{ gettext('This page is rated %(wr).1f.', wr=worksheet.rating()) }}
            </a>
        {% endif %}
        {% if not (notebook.user_manager().user_is_guest(username) or worksheet.is_publisher(username)) %}
            <span>
            </span>
            {% for i in range(5) %}
            <input type="radio" name="rating" value={{ i }} > {{ i }}
            {% endfor %}
            &nbsp;&nbsp; <input name="rating_comment" id="rating_comment" value="{{ gettext('leave a comment') }}"/>
            <input type="button" id="rate_button" name="rating" value= {{ gettext("Rerate") if worksheet.is_rater(username) else gettext("Rate") }} > 
        {% endif %}
    </li>
    {% endif %}
    <li><a href="/pub/">{{ gettext('Other published documents...') }}</a></li>
</ul>
<hr class="usercontrol" />
<h1 class="title">{{ worksheet.name() }}</h1>
<h2 class="lastedit">{{ worksheet.html_time_since_last_edited() | safe }}</h2>
{{ worksheet.html(do_print=false, publish=true, username=username) | safe }}
<script>
{%- if conf['pub_interact'] %}
    cell_id_list = {{ worksheet.cell_id_list() }};
    onload_id_list = {{ worksheet.onload_id_list() }};
    ignore_all_jumps = true;
{%- else %}
    MathJax.Hub.Process();
{%- endif %}
</script>


<hr class="usercontrol" />
{%- for i in range(10) %}
&nbsp;
{%- endfor %}
{% endblock %}
