{% extends "imagestore/base.html" %}
{% load i18n %}
{% load thumbnail %}


{% block title %}
    {% trans "Upload image" %}
{% endblock %}

{% block head %}
    {{ block.super }}
    <script type="text/javascript">
        function split( val ) {
            return val.split( /,\s*/ );
        }
        function extractLast( term ) {
            return split( term ).pop();
        }
    $().ready(function (){$("#id_tags").autocomplete({
        source: function(request, response){
            $.ajax({
                url: "{% url imagestore-autocomplete-tag 'tag'%}",
                data: {q: extractLast(request.term)},
                success: function(data) {
                    response($.map(data, function(item) {
                        return {
                            label: item[1],
                            value: item[1]
                        };
                    }));
                },
                dataType: "json"
            });
        },
        search: function() {
            // custom minLength
            var term = extractLast( this.value );
            if ( term.length < 2 ) {
                return false;
            }
        },
        focus: function() {
            // prevent value inserted on focus
            return false;
        },
        select: function( event, ui ) {
            var terms = split( this.value );
            // remove the current input
            terms.pop();
            // add the selected item
            terms.push( ui.item.value );
            // add placeholder to get the comma-and-space at the end
            terms.push( "" );
            this.value = terms.join( ", " );
            return false;
        }
        });
    });
    </script>
{% endblock %}

{% block breadcrumb %}
    {{ block.super }} &#187;
    <a href="{% url imagestore-category-list %}">{% trans "Gallery" %}</a>
    &#187; {% trans "Upload image" %}
{% endblock breadcrumb %}

{% block content %}
    <form action="." method="post" enctype="multipart/form-data">
    <table>{{ form.as_table }}</table>
    <input type="submit" value="{% trans "Upload" %}">
    </form>
{% endblock content %}