<h5><%=t "experiments.canvas.modal_manage_tags.subtitle", module: @my_module.name %></h5>
<% if @my_module_tags.size == 0 then %>
  <div class="row"><div class="col-xs-4"><em><%= t 'experiments.canvas.modal_manage_tags.no_tags' %></em></div></div>
<% else %>
  <ul class="list-group">
    <% @my_module_tags.each_with_index do |mmt, i| tag = mmt.tag %>
      <li class="list-group-item" style="background-color: <%= tag.color %>" data-color="<%= tag.color %>" data-tag-id="<%= tag.id %>" data-name="<%= tag.name %>">

        <div class="row tag-show">
          <div class="col-xs-6 col-lg-8">
            <h4><%= tag.name %></h4>
          </div>
            <div class="pull-right" data-view-mode="active">
              <%= link_to "", remote: true, class: 'btn btn-link edit-tag-link', title: t("experiments.canvas.modal_manage_tags.edit_tag") do %>
                <span class="fas fa-pencil-alt"></span>
              <% end %>
              <%= link_to my_module_my_module_tag_path(@my_module, mmt, format: :json), method: :delete, remote: true, class: 'btn btn-link remove-tag-link', title: t("experiments.canvas.modal_manage_tags.remove_tag", module: @my_module.name), data: {tag_id: tag.id} do %>
                <span class="fas fa-times"></span>
              <% end %>
              <%= bootstrap_form_for tag, remote: true, url: project_tag_path(@my_module.experiment.project, tag, format: :json), data: {tag_id: tag.id}, method: :delete, html: { class: "delete-tag-form"} do |f| %>
                <%= hidden_field_tag :my_module_id, @my_module.id %>
                <%= f.button class: 'btn btn-link delete-tag-link', title: t("experiments.canvas.modal_manage_tags.delete_tag") do %>
                  <span class="fas fa-trash-alt"></span>
                <% end %>
              <% end %>
            </div>
        </div>

        <div class="row tag-edit" style="display: none;">
          <%= bootstrap_form_for tag, remote: true, url: project_tag_path(@my_module.experiment.project, tag, format: :json), method: :put, html: { class: "edit-tag-form" }, data: {tag_id: tag.id} do |f| %>
            <%= hidden_field_tag :my_module_id, @my_module.id %>
            <div class="col-xs-7">
              <%= f.text_field :name, hide_label: true %>
            </div>
            <div class="pull-right">
              <%= f.color_picker_select :color, Constants::TAG_COLORS, class: "edit-tag-color" %>
              <%= f.button class: "btn btn-link save-tag-link", title: t("experiments.canvas.modal_manage_tags.save_tag") do %>
                <span class="fas fa-check"></span>
              <% end %>
              <%= link_to "", remote: true, class: 'btn btn-link cancel-tag-link', title: t("experiments.canvas.modal_manage_tags.cancel_tag") do %>
                <span class="fas fa-times"></span>
              <% end %>
            </div>
          <% end %>
        </div>

      </li>
    <% end %>
  </ul>
<% end %>

<hr data-view-mode="active">
<div class="row" data-view-mode="active">
    <%= bootstrap_form_for [@my_module, @new_mmt], remote: true, format: :json, html: { class: 'add-tag-form' } do |f| %>
      <div>
        <div class="well well-sm">
          <%= collection_select(:my_module_tag,
                                :tag_id,
                                @unassigned_tags.collect{ |t| t.name = t.name.truncate(Constants::DROPDOWN_TEXT_MAX_LENGTH, omission: '...'); t },
                                :id,
                                :name,
                                {},
                                { class: 'selectpicker' }) %>
          <%= f.button class: 'btn btn-primary' do %>
            <span><%= t("experiments.canvas.modal_manage_tags.create") %></span>
          <% end %>
        </div>
      </div>
    <% end %>
    <div class="pull-right create-new-tag-btn">
      <%= bootstrap_form_for [@my_module.experiment.project, @new_tag], remote: true, format: :json, html: { class: 'add-tag-form' } do |f| %>
        <%= hidden_field_tag :my_module_id, @my_module.id %>
        <%= f.hidden_field :project_id, :value => @my_module.experiment.project.id %>
        <%= f.hidden_field :name, :value => t("tags.create.new_name") %>
        <%= f.hidden_field :color, :value => Constants::TAG_COLORS[0] %>
        <%= f.button class: "btn btn-primary" do %>
          <span class="fas fa-plus"></span>
          <span class="hidden-xs"><%=t "experiments.canvas.modal_manage_tags.create_new" %></span>
        <% end %>
      <% end %>
    </div>
</div>
