{% extends 'view_file_base.html' %}
{% load i18n %}
{% load url from future %}

{% block extra_style %}{{block.super}}
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}codemirror/codemirror.css" />
<style type="text/css">
    {% if fileext == 'txt' or fileext == 'text' %}
.CodeMirror { width:816px; padding:40px 96px; }
    {% endif %}
</style>
{% endblock %}

{% block update_detail %}
{% if last_commit_id %}
  <span class="vam">{% trans "updated this file"%}, <a class="file-diff" href="{% url 'text_diff' repo.id %}?p={{path|urlencode}}&commit={{last_commit_id}}&file_enc={{file_enc}}">{% trans "Detail"%}</a>.</span>
{% endif %}
{% endblock %}

{% block edit_file %}
{% if file_perm == 'rw' and not err%}
<a class="sf-btn-group-btn sf-btn-link op-icon sf2-icon-edit" href="{{ SITE_ROOT }}repo/{{ repo.id }}/file/edit/?p={{ path|urlencode }}&file_enc={{file_enc}}" id="edit" title="{% trans "Edit" %}"></a>
{% endif %}
{% endblock %}

{% block file_view %}
    {% if encoding != None %}
    <div id="file-enc-cont">
        <label for="file-enc">{% trans "Encoding:" %}</label>
        <select id="file-enc">
            {% for enc in file_encoding_list %}
            <option value="{{ enc }}" {% if encoding and encoding == enc %} selected="selected" {% endif %}>{% if enc == 'auto'%}{% trans "auto detect" %}{% else %}{{ enc }}{% endif %}</option>
            {% endfor %}
        </select>
    </div>
    {% endif %}

    {% ifnotequal file_content None %}
    <textarea id="docu-view" class="vh">{{ file_content|escape }}</textarea>
    {% endifnotequal %}
{% endblock %}

{% block extra_script %}{{ block.super }}
{% if not err %}
{% ifnotequal file_content None %}
<script type="text/javascript" src="{{MEDIA_URL}}codemirror/codemirror-2.36.js"></script>
<script type="text/javascript">
    var editor = CodeMirror.fromTextArea($('#docu-view')[0], {
        {% include 'snippets/editor_set_mode.html' %}
        theme: 'default',
        indentUnit: 4,
        {% if fileext != 'txt' and fileext != 'text' %}
        lineNumbers: true,
        {% endif %}
        lineWrapping: true,
        readOnly: true
    });
</script>
{% endifnotequal %}
{% endif %}
<script type="text/javascript">
    // for 'go back'
    var $fileDiff = $('.file-diff');
    $fileDiff.attr('href', $fileDiff.attr('href') + '&referer=' + encodeURIComponent(location.href));
</script>
{% endblock%}
