{% 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 %}
  {{ 'Vous n\'avez selectionne aucun element' | trans }}
{% elseif elements_length == 0 %}
  {{ 'Les elements ne peuvent etre uploades (problemes de type ou de droit)' | trans }}
  {{ 'Le bridge FlickR ne prend en charge que les photos' | trans }}
{% else %}
  {% if elements_length != elements_received_length %}
    {% set n_elements = elements_received_length - elements_length %}
    {% trans with {'%n_elements%' : n_elements} %}%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 with {'%elements_length%' : elements_length} %}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}}'>{{ 'Titre' | trans }}</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 }}'>{{ 'Description' | trans }}
                  <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 }}'>{{ 'Tags' | trans }}</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>
                {{ "2000 caracteres maximum, separe par des espaces" | trans }}
              </td>
            </tr>
          </table>
        </div>
      </div>
    {% endfor %}
    <button class="form_submitter">{{ 'Upload' | trans }}</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 %}
