<!-- layouts/_ref_ten_field.html.erb Start -->
<span id="<%= col_name %>-view">
  <%= select_tag(col_name, options_for_select(options, value)) %>
  <%# filter_link is not used here due to the structure of limited_list %>
  <%= link_to('#',
              :class => "button_filter_data",
              :id => "#{col_name}_filter",
              :title => "Liste filtern",
              :onclick => "FilterModal.show('#{url_for({:action => 'limited_list_json',
                                                        :foreign_table => foreign_table,
                                                        :federal_state_id => federal_state_id,
                                                        :show_all => show_all,
                                                        :rep_code => rep_code})}', '#{col_name}', 'Filter #{human_name}')"


      ) do %>
    <i class="fa fa-search" aria-hidden="true"></i>
  <% end %>


  <br/>
      <button id="<%= col_name %>-button" type="button">
          <%= show_all == 'true' ? 'nur dazugehörige' : 'alle' %> Bundesländer zeigen
      </button>
      <span id="<%= col_name %>-view-loading">
      </span>
  </span>

<script type="text/javascript" language="javascript">

    $("#<%= col_name %>-button").click(function () {

        // change also the modal content if it's visible
        FilterModal.update('<%= url_for({:action => 'limited_list_json',
                                        :foreign_table => foreign_table,
                                        :federal_state_id => federal_state_id,
                                        :show_all => show_all == 'false',
                                        :rep_code => rep_code}) %>', '<%= col_name %>');

        $.ajax({
            url: '<%= url_for :action => 'limited_list_update' %>',
            type: "get",
            dataType: "html",
            data: {
                "col_name": "<%= col_name %>",
                <% if value != nil %>
                "value": "<%= value %>",
                <% end %>
                <% if federal_state_id != nil %>
                "federal_state_id": "<%= federal_state_id %>",
                <% end %>
                "human_name": "<%= human_name %>",
                "foreign_table": "<%= foreign_table %>",
                "rep_code": "<%= rep_code %>",
                "show_all": <%= show_all == 'false' %>,
                "authenticity_token": encodeURIComponent('<%= form_authenticity_token %>'),
            },
            success: function (msg) {
                // console.log($(msg));
                // console.log($(msg).find('select').children().length);
                $('#<%= col_name %>-view').html(msg);

            },
            error: function (e) {
                console.error(e)
            }
        });
    });
</script>
<!-- layouts/_ref_ten_field.html.erb Ende -->
