<%# locals: { plan, research_output, research_output_types } %>
<% research_outputs.each_with_index do |research_output, index|%>
  <% research_output_fragment = research_output.json_fragment %>
  <% research_output_data = research_output_fragment.research_output_description.data if research_output_fragment.present?%>
  <%= form_for research_output, url: plan_research_output_path(:id => research_output.id, :plan_id => plan.id), html: {method: :put, remote: true, id: nil } do |f| %>
    <div class='research-output-element <%= index != 0 ? '' : 'inactive' %>'>
      <%= hidden_field_tag 'research-output-id', research_output.id, class: 'research-output-id' %>
      <div class='research-output-fields'>
        <div class='research-output-field form-group research-output-abbreviation'>
          <%= f.label :abbreviation, d_('dmpopidor', 'Abbreviated Name (20 chars max.)'),  class: 'control-label' %>
          <%= f.text_field :abbreviation, maxlength: 20, class: 'form-control input edit', "aria-required": true,
                      'data-toggle': 'tooltip', title: d_('dmpopidor', 'Research output name (20 chars max.)') %>
          <span class="readonly"><%= research_output.abbreviation %></span>
        </div>
        <div class='research-output-field form-group research-output-fullname'>
          <%= f.label :fullname, d_('dmpopidor', 'Full Title'),  class: 'control-label' %>
          <%= f.text_field :fullname, class: 'form-control input edit', "aria-required": true,
                      'data-toggle': 'tooltip', title: d_('dmpopidor', 'Research output fullname')   %>
          <span class="readonly"><%= research_output_data['title'] %></span>
        </div>
        <div class='research-output-actions pull-right' style="width:25%">
          <%= f.submit _('Save'), class: "btn btn-primary edit" %>
          <button type="button" class="btn btn-secondary cancel"><%= _('Cancel') %></button>
        </div>
      </div>
      <% unless readonly %>
        <div class='research-output-actions'>
            <i class="fa fa-edit edit" aria-hidden="true"
                    title="<%= d_('dmpopidor', 'Edit research output') %>"></i>
          <% if plan.research_outputs.length > 1 && index != 0 %>
            <i class="fa fa-arrows handle" aria-hidden="true" 
                    title="<%= d_('dmpopidor', 'Move research output') %>"></i>
                    
            <%= link_to plan_research_output_url(plan, research_output), 
                        data: {:confirm => d_('dmpopidor', 'Deleting this research output will remove the associated answers. Do you confirm ?')}, 
                        :method => :delete  do %>
              <i class="fa fa-close delete" aria-hidden="true"
                    title="<%= d_('dmpopidor', 'Delete research output') %>" %></i>
            <% end %>
          <% end %>
        </div>
      <% end %>
      <hr/>
    </div>
  <% end %>
<% end %>