{% extends "_layout.html" %}

{% block content %}
<div class="panel panel-default">
    <div class="panel-heading">
        <h1>
            {{ item.meta['filename'] }}
            <div class="btn-group pull-right">
                {% if not item.meta['locked'] or may(ADMIN) %}
                    <button id="dl-btn" type="button" class="btn btn-info">
                        <span class="glyphicon glyphicon-download-alt"></span> Download
                    </button>
                    <button id="inline-btn" type="button" class="btn btn-info">
                        <span class="glyphicon glyphicon-asterisk"></span> Inline
                    </button>
                {% endif %}
                {% if may(DELETE) %}
                <button id="del-btn" type="button" class="btn btn-danger">
                    <span class="glyphicon glyphicon-remove"></span> Delete
                </button>
                {% endif %}
                {% if may(ADMIN) %}
                {% if not item.meta['locked'] %}
                    <button id="lock-btn" type="button" class="btn btn-danger">
                        <span class="glyphicon glyphicon-lock"></span> Lock
                    </button>
                {% else %}
                    <button id="unlock-btn" type="button" class="btn btn-info">
                        <span class="glyphicon glyphicon-heart"></span> Unlock
                    </button>
                {% endif %}
                {% endif %}
            </div>
        </h1>
    </div>
    <div class="panel-body">
        <p>
        Type {{ item.meta.get('type') or 'undefined' }}, Size {{ item.meta['size'] }} bytes, uploaded {{ item.meta['timestamp-upload'] | datetime }}.
        <br/>
        SHA256-Hash: {{ item.meta.get('hash')}}
        </p>
        <div class="data">
            {{ rendered_content }}
        </div>
    </div>
</div>
{% endblock content %}

{% block extra_script %}
<script src="{{ url_for('static', filename='bootbox/bootbox.min.js') }}" type="text/javascript"></script>
<script type="text/javascript">
$("#del-btn").click(function(){
    bootbox.confirm("Are you sure you want to delete this file?", function(result) {
        if (result == true){
            window.location.replace("{{ url_for('bepasty.delete', name=name) }}");
        }
    }); 
});
{% if not item.meta['locked'] or may(ADMIN) %}
$("#dl-btn").click(function(){
    window.location.replace("{{ url_for('bepasty.download', name=name) }}");
});
$("#inline-btn").click(function(){
    window.location.replace("{{ url_for('bepasty.inline', name=name) }}");
});
{% endif %}
{% if may(ADMIN) %}
$("#lock-btn").click(function(){
    window.location.replace("{{ url_for('bepasty.lock', name=name) }}");
});
$("#unlock-btn").click(function(){
    window.location.replace("{{ url_for('bepasty.unlock', name=name) }}");
});
{% endif %}
</script>
{% endblock extra_script %}
