{% extends "prod/actions/Bridge/wrapper.html.twig"%}
{% import "common/thumbnail.html.twig" as thumb %}
{% import "prod/actions/Bridge/macro_error_form.html.twig" as error_form %}

{% block menu %}
  {% trans %}
  Upload
  {% endtrans %}
{% endblock %}

{% block response %}
{% set elements_length = route.get_elements()|length %}
{% set elements_received_length = route.get_count_element_received() %}

{% if elements_received_length == 0 %}
  {% trans 'Vous n\'avez selectionne aucun element' %}
{% elseif elements_length == 0 %}
  {% trans 'Les elements ne peuvent etre uploades (problemes de type ou de droit)' %}
  {% trans 'Le bridge FlickR ne prend en charge que les photos' %}
{% else %}
  {% if elements_length != elements_received_length %}
    {% set n_elements = elements_received_length - elements_length %}
    {% trans %}
      {{n_elements}} elements ne peuvent etre uploades
    {% endtrans %}
  {% endif %}

  <form class='bridge_form' name="upload_form" action="{{ path('prod_bridge_do_upload') }}" method="post">
    {% trans %}
      Upload sur Flickr de {{ elements_length }} elements
    {% endtrans %}
    <input type="hidden" name="lst" value="{{ route.get_serialize_list() }}" />
    <input type="hidden" name="account_id" value="{{ account.get_id() }}" />
    {% for record in route.get_elements() %}
      {% set caption = record.get_caption() %}
      <div style="border:2px solid #414141;margin:10px" class="ui-corner-all">
        <div style="margin:10px;">
          <table style="width:100%;">
            <tr>
              <td rowspan="3" style="width:120px;text-align:center;">
                {{thumb.format(record.get_thumbnail, 100, 100, "", true, false)}}
              </td>
              <td style="width:100px;">
                {% set name = "title_" ~ record.get_serialize_key() %}
                <label for='{{name}}'>{% trans 'Titre' %}</label>
              </td>
              <td style="width:180px;">
                <input class="required_field" style="width:150px;" type='text' name='{{name}}' value="{{ caption.get_dc_field('Title') is not none ? caption.get_dc_field('Title').get_serialized_values()|default(record.get_title()) : record.get_title()  }}"/>
                <br />
                {{ error_form.display_errors(name, constraint_errors) }}
              </td>
              <td>
              </td>
            </tr>
            <tr>
              <td>
                {% set name = "description_" ~ record.get_serialize_key() %}
                <label for='{{ name }}'>{% trans 'Description' %}
                  <br>
                  <span class='form_error'>&nbsp;</span>
                </label>
              </td>
              <td class='column_right'>
                <textarea class="required_field" name="{{ name }}" rows="5" style="width:150px;">{{ caption.get_dc_field('Description') is not none ? caption.get_dc_field('Description').get_serialized_values() : "" }}</textarea>
                <br />
                {{ error_form.display_errors(name, constraint_errors) }}
              </td>
              <td>
              </td>
            </tr>
            <tr>
              <td>
                {% set name = "tags_" ~ record.get_serialize_key() %}
                <label for='{{ name }}'>{% trans 'Tags' %}</label>
              </td>
              <td>
                <input class='required_field' type='text' style="width:150px;" name='{{ name }}' value="{{ caption.get_dc_field('Subject') is not none ? caption.get_dc_field('Subject').get_serialized_values(' ') : '' }}"/>
                <br />
                  {{ error_form.display_errors(name, constraint_errors) }}
              </td>
              <td>
                {% trans "2000 caracteres maximum, separe par des espaces" %}
              </td>
            </tr>
          </table>
        </div>
      </div>
    {% endfor %}
    <button class="form_submitter">{% trans 'Upload' %}</button>
  </form>
  <script type="text/javascript">
    $(document).ready(function(){
      var box = $('#dialog-confirm');
      $(".the_upload_form .back_link", box).bind("click", function(){
        $(".the_upload_selection").show();
        $(".the_upload_form").hide();

        return false;
      }).button();
    });
  </script>
{% endif %}
{% endblock %}
