{% extends "admin/base_site.html" %}
{% load i18n admin_static admin_list admin_urls %}
{% load fb_tags %}
{% load url from future %}

{% block extrastyle %}
    {{ block.super }}
    <link rel="stylesheet" type="text/css" href="{{ settings_var.URL_FILEBROWSER_MEDIA }}uploadify/uploadify.css" />
    <link rel="stylesheet" type="text/css" href="{{ settings_var.URL_FILEBROWSER_MEDIA }}css/suit-filebrowser.css" />
{% endblock %}

{% block extrahead %}
    {{ block.super }}
    <script type="text/javascript" src="../../jsi18n/"></script>
    <script type="text/javascript" src="{% static "admin/js/core.js" %}"></script>

    <script type="text/javascript" src="{{ settings_var.URL_FILEBROWSER_MEDIA }}uploadify/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="{{ settings_var.URL_FILEBROWSER_MEDIA }}uploadify/jquery.uploadify.v2.1.0.js"></script>
    <script type="text/javascript" src="{{ settings_var.URL_FILEBROWSER_MEDIA }}uploadify/swfobject.js"></script>

    <script type="text/javascript">
        (function($){
            $(document).ready(function() {
                $('#id_file').uploadify({
                    'uploader'          : '{{ settings_var.URL_FILEBROWSER_MEDIA }}uploadify/uploadify.swf',
                    'script'            : '{% url "fb_do_upload" %}',
                    'scriptData'        : {'session_key': '{{session_key}}'},
                    'checkScript'       : '{% url "fb_check" %}',
                    'cancelImg'         : '{{ settings_var.URL_FILEBROWSER_MEDIA }}uploadify/cancel.png',
                    'auto'              : false,
                    'folder'            : '{{ query.dir }}',
                    'multi'             : true,
                    'fileDesc'          : '{% for extension in settings_var.EXTENSIONS.items %}{% ifnotequal extension.0 'Folder' %}{% for item in extension.1 %}*{{ item|safe }};{% endfor %}{% endifnotequal %}{% endfor %}',
                    'fileExt'           : '{% for extension in settings_var.EXTENSIONS.items %}{% ifnotequal extension.0 'Folder' %}{% for item in extension.1 %}*{{ item|safe }};{% endfor %}{% endifnotequal %}{% endfor %}',
                    'sizeLimit'         : {{ settings_var.MAX_UPLOAD_SIZE }},
                    'scriptAccess'      : 'sameDomain',
                    'queueSizeLimit'    : 50,
                    'simUploadLimit'    : 1,
                    'width'             : 300,
                    'height'            : 30,
                    'hideButton'        : false,
                    'wmode'             : 'transparent',
                    'onAllComplete'     : function(){var newpath='../browse/{% query_string %}';window.location=newpath;},
                    translations        : {
                        browseButton: '{% trans "BROWSE" %}',
                        error: '{% trans "An Error occured" %}',
                        completed: '{% trans "Completed" %}',
                        replaceFile: '{% trans "Do you want to replace the file" %}',
                        unitKb: '{% trans "KB" %}',
                        unitMb: '{% trans "MB" %}'
                    }
                });
                $('input:submit').click(function(evt){
                    $('#id_file').uploadifyUpload();
                    return false;
                });
                $('input[name="clear"]').click(function(evt){
                    $('#id_file').uploadifyClearQueue();
                    return false;
                });
            });
        })(jQuery.noConflict());
    </script>
{% endblock %}

{% block coltype %}colM{% endblock %}

{% block bodyclass %}change-form{% endblock %}

{% block breadcrumbs %}
    {% include "suit/include/breadcrumbs.html" %}
{% endblock %}

{% block content %}
    <div id="content-main" class="inner-two-columns">
        <form class="form-horizontal">
            <div class="inner-right-column">
                <div class="box save-box">
                    <div class="submit-row clearfix">
                        <input type="submit" value="{% trans 'Submit' %}" class="btn btn-high btn-info" />
                        <input type="button" value="{% trans "Clear Queue" %}" class="btn btn-high btn-info" name="clear"/>
                    </div>
                </div>
            </div>
            <div class="inner-center-column">
                <div class="tab-content tab-content-main">
                    <fieldset class="module aligned">
                        <div class="control-group">
                            <div class="control-label">
                                <label class="required" for="id_file">{% trans "Select a file." %}</label>
                            </div>
                            <div class="controls">
                                <input type="File" id="id_file" class="btn btn-info"/>
                                {% for extension in settings_var.EXTENSIONS.items %}
                                <span class="help-block">

                                        {% ifnotequal extension.0 'Folder' %}
                                            <strong>{% if forloop.first %}{% trans "Allowed" %}:{% else %}&nbsp;{% endif %}</strong>
                                            <p>{{ extension.0|safe }} ({{ extension.1|join:", "|safe }})</p>
                                        {% endifnotequal %}

                                </span>
                                {% endfor %}
                                <br>
                                <span class="help-block">
                                    <strong>{% trans "Max. Filesize" %}:</strong>
                                    <p>{{ settings_var.MAX_UPLOAD_SIZE|filesizeformat }}</p>
                                </span>
                                {% if settings_var.CONVERT_FILENAME %}
                                    <br>
                                    <span class="help-block">
                                        <strong>{% trans "The Name will be converted to lowercase. Spaces will be replaced with underscores." %}</strong>
                                    </span>
                                {% endif %}
                            </div>
                        </div>
                    </fieldset>
                </div>
            </div>
        </form>
    </div>
{% endblock %}