{% extends "site/layout/base_text.html" %}
{% load com %}
{% load i18n %}
{% load local_perms %}
{% block main %}

{% get_local_text_perm request text can_edit_text as can_edit_text %}

<script type="text/javascript">
<!--
tb_conf['current_tab'] = 'history';
-->
</script>

<div id="text_history" class="tab-meta">   

<script type="text/javascript">
<!--
$(function() {
    $(".hidden-text-actions").css('visibility','hidden');   
}) ;
$(function() {
	$("input[name=oldkey]").click(function () {
		hide_show($(this), 'newkey', true, true, -1);
		hide_show($(this), 'newkey', false, false, 0);
	});   
	$("input[name=newkey]").click(function () {
		hide_show($(this), 'oldkey', false, true, 0);
		hide_show($(this), 'oldkey', true, false, +1);
	});   

	$("input[name=newkey]")[0].click();
	$("input[name=oldkey]")[1].click();
}) ;


function hide_show(elem, name, hide, up, plus) {	
	var nb = elem.attr('id').split('-')[1];
	nb = parseInt(nb) + plus;
	
	if (hide)
		var vis = 'hidden';
	else
		var vis = 'visible';
		
	if (up)
		var fu = 'gt';
	else
		var fu = 'lt';
	$("input[name=" + name + "]:" + fu + "(" + nb + ")").css('visibility',vis);
};
-->
</script>

<ul class="sub_list">
    <li class="active_sub">{% blocktrans %}Version list{% endblocktrans %}</li>
    {% if last_last_version %}    
    <li> / </li>
    <li><a href="{% url text-history-compare text.key last_last_version.key last_version.key %}">{% blocktrans %}Compare last two versions{% endblocktrans %}</a></li>
    <li> / </li>
    <li><a href="{% url text-history-version text.key text.last_text_version.key %}">{% blocktrans %}Most recent version{% endblocktrans %}</a></li>
    {% endif %}
</ul>

<form id="compare_form" action="." method="post">

<input name="compare" id="compare_button" type="submit" value="{% blocktrans %}Compare selected versions{% endblocktrans %}"/>

<br />
{% include "site/macros/paginator.html" %}

<div style="clear:both;"></div>

<table summary="text list" class="large_table">
    <thead>
        <tr>
            <th>{% blocktrans %}Version{% endblocktrans %}</th>
            <th colspan="2" width="1%">{% blocktrans %}Selection{% endblocktrans %}</th>
            <th>{% blocktrans %}Title{% endblocktrans %}</th>
            <th>{% blocktrans %}Note{% endblocktrans %}</th>
            <th>{% blocktrans %}Author{% endblocktrans %}</th>
            <th>{% blocktrans %}Created{% endblocktrans %}</th>
            <th>{% blocktrans %}# comments{% endblocktrans %}</th>
        </tr>
    </thead>
    <tbody>
        {% for text_version in object_list %}
        
        {% get_local_text_perm request text can_edit_text as can_edit_text %}
        {% get_local_text_perm request text can_delete_text as can_delete_text %}
        {% get_local_text_perm request text can_manage_text as can_manage_text %}
        
        <tr class="text-{{ text_version.key }} {% cycle 'odd' 'even' %}">
            {% if can_manage_workspace %}<td><input type="checkbox" class="text_check" name="check-{{ text_version.key }}"/></td>{% endif %}
            <td>#{{ forloop.counter0|add:page_obj.start_index|invneg:paginator.count|add:"1" }}</td>
            <td><input id="oldkey-{{ forloop.counter0 }}" type="radio" name="oldkey" value="{{ text_version.key }}"/></td>
            <td><input id="newkey-{{ forloop.counter0 }}" type="radio" name="newkey" value="{{ text_version.key }}"/></td>                        
            <td>
                <a class="main_object_title" href="{% url text-history-version text.key text_version.key %}">{{ text_version.title }}</a>
                
                
                <div class="hidden-text-actions text-actions-{{ text_version.key }}">
                    <a href="{% url text-history-version text.key text_version.key %}">{% blocktrans %}View{% endblocktrans %}</a> 
                    {% if text_version.get_previous_version %}| <a href="{% url text-history-compare text.key text_version.get_previous_version.key text_version.key %}">{% blocktrans %}Compare with previous version{% endblocktrans %}</a>{% endif %}
                    {% if can_edit_text %} | <a href="{% url text-revert text.key text_version.key %}">{% blocktrans %}Revert to this version{% endblocktrans %}</a>{% endif %}
                    {% comment %}{% if can_delete_text %}<a id="text-delete-{{ text_version.key }}" href="#">{% blocktrans %}Delete{% endblocktrans %}</a>
                    <script type="text/javascript">                
                    <!--
                    $(function() {
                        $("#text-delete-{{ text_version.key }}").click(function(){
                            url = '{% url text-version-delete text.key text_version.key %}';
                            question = "{% blocktrans %}Are you sure you want to delete this version?{% endblocktrans %}";
                            if (confirm(question)) {
                                $.post(url, function(data){
                                      window.location = '{% url index %}';
                                    });                        
                            }
                        });
                        
                    }) ;
                    --> 
                    </script>                    
                    {% endif %}
                    {% endcomment %}
                </div>
                <script type="text/javascript">                
                <!--
                $(function() {
                    $(".text-{{ text_version.key }}").mouseover(function(){
                        $(".text-actions-{{ text_version.key }}").css('visibility','visible');
                        $(".text-{{ text_version.key }}").addClass('hover');   
                    });
                    $(".text-{{ text_version.key }}").mouseout(function(){
                        $(".text-actions-{{ text_version.key }}").css('visibility','hidden');   
                        $(".text-{{ text_version.key }}").removeClass('hover');   
                    });
                }) ;
                --> 
                </script>
            </td>
            <td>{{ text_version.note|default_if_none:"" }}</td>
            <td>{{ text_version.get_name }}</td>
            <td>{{ text_version.created|local_date }}</td>
            <td>{{ text_version|nb_comments:request }}</td>

        </tr>
        {% endfor %}
    </tbody>
</table>

</form>

</div>
{% endblock %}
