{% load i18n %}

{% if obj.files.all %}
    <form id="object-files-update-form"
          action="{% url lfc_update_portal_files %}"
          method="post">

        <table class="lfs-manage-table full">
            <tr>
                <th class="tiny">
                    <input type="checkbox"
                           class="select-all-2" />
                </th>
                <th>
                    {% trans 'Title' %}
                </th>
                <th class="small right-padding">
                    {% trans 'Position' %}
                </th>
                <th class="middle right-padding">
                    {% trans 'Creation date' %}
                </th>
                <th class="small right-padding">
                    {% trans 'Download' %}
                </th>
            </tr>
            {% for file in obj.files.all %}
                <tr>
                    <td>
                        <input type="checkbox"
                               class="select-2"
                               name="delete-files"
                               value="{{ file.id }}"
                               style="float:left" />
                    </td>
                    <td>
                        <input type="text" name="title-{{ file.id }}" value="{{ file.title }}" />
                    </td>
                    <td class="right">
                        <input class="position" type="text" name="position-{{ file.id }}" value="{{ file.position }}" />
                    </td>
                    <td class="right">
                        {{ file.creation_date|date:"Y-m-d H:i:s" }}
                    </td>
                    <td class="right last">
                        <a href="{{ file.get_absolute_url }}">
                            <image src="{{ MEDIA_URL }}lfc/icons/disk.png" 
                                   alt='{% trans "Download" %}' 
                                   title='{% trans "Download" %}' />
                        </a>
                    </td>
                </tr>
            {% endfor %}
        </table>

        <input class="object-files-update-button"
               type="submit" name="update" value="{% trans 'Update' %}" />
        <input class="object-files-update-button"
               type="submit" name="delete" value="{% trans 'Delete' %}" />

    </form>
{% else %}
    <span>{% trans 'There are no files' %}</span>
{% endif %}

<h2 class="middle-heading">{% trans 'Add files' %}</h2>

<form id="files-form"
      data="{% url lfc_portal_files %}"
      method="post"
      enctype="multipart/form-data">

    {# <span class="legend">{% trans 'Upload Queue' %}</span> #}
    <div class="fieldset flash" id="fsUploadProgressFiles"></div>
    <div id="divStatus"></div>
    <div>
        <span id="spanButtonPlaceHolderFiles"></span>
        <input id="btnUpload"
               type="button"
               value='{% trans "Select Files" %}'
               style="width: 100px; height: 22px; font-size: 8pt;" />

        <input id="btnCancel"
               type="button"
               value="Cancel All Uploads"
               onclick="swfu.cancelQueue();"
               disabled="disabled"
               style="margin-left: 2px; font-size: 8pt; height: 29px;" />
    </div>

</form>

<script>
    var swfu;

    var settings = {
        flash_url : "{{ MEDIA_URL }}lfc/swfupload/swfupload.swf",
        upload_url: "{% url lfc_add_portal_files %}",
        file_size_limit : "100 MB",
        file_types : "*.*",
        file_types_description : "All Files",
        file_upload_limit : 100,
        file_queue_limit : 0,
        custom_settings : {
            progressTarget : "fsUploadProgressFiles",
            cancelButtonId : "btnCancel"
        },
        debug: false,

        // Button settings
        button_width: "100",
        button_height: "22",
        button_placeholder_id: "spanButtonPlaceHolderFiles",
        button_text_left_padding: 0,
        button_text_top_padding: 13,
        button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
        button_cursor : SWFUpload.CURSOR.HAND,

        // The event handler functions are defined in handlers.js
        file_queued_handler : fileQueued,
        file_queue_error_handler : fileQueueError,
        file_dialog_complete_handler : fileDialogComplete,
        upload_start_handler : uploadStart,
        upload_progress_handler : uploadProgress,
        upload_error_handler : uploadError,
        upload_success_handler : uploadSuccess,
        upload_complete_handler : uploadFilesComplete,
        queue_complete_handler : queueComplete  // Queue plugin event
    };

    swfu = new SWFUpload(settings);
</script>