{% load yacon_tags %}

{% block scripts %}
    <script type="text/JavaScript">
        $(document).ready(function(){
            $('#folder_toolbar').show();
        });

        function remove_file(filename) {
            var action = confirm('Remove \"' + filename + '"?  This cannot be '
                + 'undone.');
            if( action ) {
                var node = encodeURIComponent('{{node}}/' + filename);
                $.ajax({
                    url: "/yacon/nexus/uploads/remove_file/" + node + "/",
                    dataType: "json",
                    success: function(data) {
                        var tree = $('#tree').dynatree("getTree");
                        tree.reactivate();
                    }
                });
            }
        }
    </script>
{% endblock scripts %}

<div class="node">
    <h2> Folder: {{spec.relative_dir}}/ </h2>
    <p>
        Click the button to choose one or more files to upload to this
        directory.  If your browser supports drag-and-drop you can also
        simply drag files to the button.  Files with the same name will be
        overwritten.
    </p>
    {% upload_widget node %}

    <h2> Files in: {{spec.relative_dir}}/ </h2>

    {% for file in files %}
        {% if forloop.first %}
        <table>
            <tbody>
        {% endif %}
            <tr class="{% cycle 'odd' 'even' %}">
                <td width="1%">
                    <a href="#" onclick="remove_file('{{file.name}}');"
                        style="color:#FF0000; background-color:#FFFFFF;">X</a> 
                </td>
                <td>
                    <a target="_blank" href="{{file.url}}">{{file.name}}</a>
                </td>
            </tr>
        {% if forloop.last %}
            </tbody>
        </table>
        {% endif %}
    {% empty %}
        <p>There were no files.</p>
    {% endfor %}

</div>
