{% extends 'file_view_react.html' %}
{% load render_bundle from webpack_loader %}
{% load seahub_tags i18n static %}

{% block extra_style %}
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}sdoc-editor/sdoc-editor-font.css" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}seafile-editor/seafile-editor-font.css" />
{% render_bundle 'viewFileSdoc' 'css' %}
{% endblock %}

{% block extra_data %}
isPro: '{{ is_pro }}',
docPath: '{{ path|escapejs }}',
docName: '{{ filename|escapejs }}',
docUuid: '{{ file_uuid }}',
assetsUrl: '{{ assets_url }}',
seadocAccessToken: '{{ seadoc_access_token }}',
seadocServerUrl: '{{ seadoc_server_url }}',
isSdocRevision: {% if is_sdoc_revision %}true{% else %}false{% endif %},
revisionId: '{{ revision_id }}',
originDocUuid: '{{ origin_doc_uuid }}',
originParentPath: '{{ origin_parent_path }}',
originFilename: '{{ origin_filename }}',
originFilePath: '{{ origin_file_path }}',
originFileVersion: '{{ origin_file_version }}',
publishFileVersion: '{{ publish_file_version }}',
publisher: '{{ publisher }}',
publisherNickname: '{{ publisher_nickname }}',
isPublished: {% if is_published %}true{% else %}false{% endif %},
revisionCreatedAt: '{{ revision_created_at }}',
revisionUpdatedAt: '{{ revision_updated_at }}',
isFreezed: {% if is_freezed %}true{% else %}false{% endif %},
lang: '{{ LANGUAGE_CODE }}',
enableSeafileAI: {% if enable_seafile_ai %} true {% else %} false {% endif %},
{% endblock %}

{% block render_bundle %}
<script type="text/javascript" src="{% static "scripts/lib/jquery.min.js" %}"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/base.js?t=1536127546642"></script>
<script src="{{ MEDIA_URL }}js/init-scroll-bar.js" ></script>
<script type="text/javascript">
    var SEAFILE_GLOBAL = {
        csrfCookieName: '{{ CSRF_COOKIE_NAME }}'
    };
    {% if can_edit_file %}
    var interval;
    {% if not share_link_token %}
    var refreshLock = function() {
        $.ajax({
            url: '{% url "api-v2.1-file-view" repo.id %}' + '?p={{path|urlencode}}',
            type: 'PUT',
            dataType: 'json',
            data: {
                'operation': 'refresh-lock',
                'expire': 2400
            },
            cache: false,
            beforeSend: prepareCSRFToken,
            success: function(data) {
            },
            error: function(xhr) {
                if (xhr.responseText) {
                    feedback(JSON.parse(xhr.responseText).error_msg, 'error');
                } else {
                    feedback("{% trans "Failed. Please check the network." %}", 'error');
                }
                clearInterval(interval);
            }
        });
    };
    {% else %}
    var refreshLock = function() {
        $.ajax({
            url: '{% url "api-v2.1-share-link-online-office-lock" share_link_token %}',
            type: 'PUT',
            dataType: 'json',
            data: {
                'expire': 2400
            },
            cache: false,
            beforeSend: prepareCSRFToken,
            success: function(data) {
            },
            error: function(xhr) {
                if (xhr.responseText) {
                    feedback(JSON.parse(xhr.responseText).error_msg, 'error');
                } else {
                    feedback("{% trans "Failed. Please check the network." %}", 'error');
                }
                clearInterval(interval);
            }
        });
    };
    {% endif %}
    interval = setInterval(refreshLock, 30 * 60 * 1000);
    {% endif %}
</script>
{% render_bundle 'viewFileSdoc' 'js' %}
{% endblock %}
