{% load seahub_tags i18n staticfiles %}

<!DOCTYPE html>
<html>
<head>
<title>{{doc_title}}</title>
<link rel="icon" href="{{ MEDIA_URL }}{{ favicon_path }}" />
<style type="text/css">
html, body { padding:0; margin:0; height:100%; }
</style>
</head>

<body>

<div id="placeholder"></div>

{% get_current_language as LANGUAGE_CODE %}
<script type="text/javascript">
var SEAFILE_GLOBAL = {
    csrfCookieName: '{{ CSRF_COOKIE_NAME }}'
};
</script>
<script type="text/javascript" src="{% static "scripts/lib/jquery.min.js" %}"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/jq.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/base.js?t=1536127546642"></script>
<script type="text/javascript" src="{{ ONLYOFFICE_APIJS_URL }}"></script>
<script type="text/javascript">
    var config = {
        "type": window.screen.width < 992 ? 'mobile' : 'desktop',
        "document": {
            "fileType": "{{ file_type }}",
            "key": "{{ doc_key }}",
            "title": "{{ doc_title|escapejs }}",
            "url": "{{ doc_url }}",
            "permissions": {
                "download": {% if can_download %}true{% else %}false{% endif %},
                "edit": {% if can_edit %}true{% else %}false{% endif %},
                "print": {% if can_download %}true{% else %}false{% endif %},
                "review": true
            }
        },
        "documentType": "{{ document_type }}", // 'text' | 'spreadsheet' | 'presentation',
        "editorConfig": {
            "callbackUrl": "{{ callback_url }}",
            "lang": "{{ LANGUAGE_CODE }}",
            "mode": {% if can_edit %}"edit"{% else %}"view"{% endif %},
            "customization": {
                "forcesave": {% if onlyoffice_force_save %}true{% else %}false{% endif %},
            },
            "user": {
                "name": "{{ username|email2nickname|escapejs }}"
            }
        }
    };
    var docEditor = new DocsAPI.DocEditor("placeholder", config);

    {% if can_edit %}
    var interval;
    var refreshLock = function() {
        $.ajax({
            url: '{% url "api-v2.1-file-view" repo_id %}' + '?p={{path|urlencode}}',
            type: 'PUT',
            dataType: 'json',
            data: {
                'operation': 'refresh-lock'
            },
            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);
            }
        });
    };
    interval = setInterval(refreshLock, 60 * 1000);
    {% endif %}
</script>
{% if enable_watermark %}
<script type="text/javascript" src="{{ MEDIA_URL }}js/watermark.js"></script>
<script type="text/javascript">{% include "snippets/add_watermark.html" %}</script>
{% endif %}
</body>
</html>
