<commit_before><div class="tab-pane fade in active" id="CatalogConfig">
  <hr/>
  <table id="existing-plans-for-tenants" class="table table-condensed">
    <thead>
    <tr>
      <th>Plan Id</th>
      <th>Product</th>
      <th>Billing Period</th>
      <th>
        <select id="select_currencies" class="selectpicker show-menu-arrow">
          <% @currencies.each_with_index do |c, i| %>
              <option><%= c %></option>
          <% end %>
        </select>
      </th>
      <th>Trial</th>
    </tr>
    </thead>
    <tbody>
    <% @existing_simple_plans.each do |p| %>
        <tr>
          <td><%= p.plan_id %></td>
          <td><%= p.product_name %></td>
          <td><%= p.billing_period %></td>
          <td>
            <% @currencies.each do |c| %>
                <span class="plan_currency_<%= c %>"><%= p.prices[c] %></span>
            <% end %>
          </td>
          <td><%= p.trial_length != 0 ? "#{p.trial_length} #{p.trial_time_unit}" : "#{p.trial_time_unit}" %></td>
        </tr>
    <% end %>
    </tbody>
  </table>
  <hr/>
  <%= render :partial => 'form_simple_plan' %>
  <hr/>
  <%= form_tag({:action => :upload_catalog}, :method => 'post', :multipart => true, :class => 'form-horizontal') do %>
      <%= hidden_field_tag(:id, @tenant.id) %>

      <div class="form-group">
        <div class="col-sm-10">
          <%= file_field_tag 'catalog', :class => 'form-control' %>
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-10">
          <%= submit_tag 'Upload', :class => 'btn btn-default' %>
        </div>
      </div>
  <% end %>
</div>

<%= javascript_tag do %>

function hideCurrency(currency) {
    var class_name = ".plan_currency_" + currency;
    $(class_name).hide();
}

function showCurrency(currency) {
    var class_name = ".plan_currency_" + currency;
    $(class_name).show();
}

function selectCurrency() {
    var currencies_opt = $("#select_currencies option");
    res= [];
    for (var i = 0; i < currencies_opt.length; i++) {
        if (currencies_opt[i].selected) {
            showCurrency(currencies_opt[i].value);
        } else {
            hideCurrency(currencies_opt[i].value);
        }
    }
    return res;
}

$(document).ready(function() {
    selectCurrency();
    $("#select_currencies").change(function() {
        selectCurrency();
    });
});
<% end %>
<commit_msg>Shorten (simplify?) javascript to display plan amount based on currency selector<commit_after><div class="tab-pane fade in active" id="CatalogConfig">
  <hr/>
  <table id="existing-plans-for-tenants" class="table table-condensed">
    <thead>
    <tr>
      <th>Plan Id</th>
      <th>Product</th>
      <th>Billing Period</th>
      <th>
        <select id="select_currencies" class="selectpicker show-menu-arrow">
          <% @currencies.each_with_index do |c, i| %>
              <option><%= c %></option>
          <% end %>
        </select>
      </th>
      <th>Trial</th>
    </tr>
    </thead>
    <tbody>
    <% @existing_simple_plans.each do |p| %>
        <tr>
          <td><%= p.plan_id %></td>
          <td><%= p.product_name %></td>
          <td><%= p.billing_period %></td>
          <td>
            <% @currencies.each do |c| %>
                <span class="plan_currency_<%= c %>"><%= p.prices[c] %></span>
            <% end %>
          </td>
          <td><%= p.trial_length != 0 ? "#{p.trial_length} #{p.trial_time_unit}" : "#{p.trial_time_unit}" %></td>
        </tr>
    <% end %>
    </tbody>
  </table>
  <hr/>
  <%= render :partial => 'form_simple_plan' %>
  <hr/>
  <%= form_tag({:action => :upload_catalog}, :method => 'post', :multipart => true, :class => 'form-horizontal') do %>
      <%= hidden_field_tag(:id, @tenant.id) %>

      <div class="form-group">
        <div class="col-sm-10">
          <%= file_field_tag 'catalog', :class => 'form-control' %>
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-10">
          <%= submit_tag 'Upload', :class => 'btn btn-default' %>
        </div>
      </div>
  <% end %>
</div>

<%= javascript_tag do %>


function displayAmountsForCurrency() {
    $('[class^="plan_currency_"]').hide();
    $("[class^=plan_currency_" + $("#select_currencies option").filter(function(idx, value) { return value.selected; })[0].value + "]").show();
}

$(document).ready(function() {
    displayAmountsForCurrency();
    $("#select_currencies").change(function() {
        displayAmountsForCurrency();
    });
});
<% end %>

{'fraction_non_alphanumeric': 0.20638439370427844, 'fraction_numerical': 0.002660164043449346, 'mean_word_length': 2.377245508982036, 'pattern_counts': {'":': 0, '<': 144, '<?xml version=': 0, '>': 157, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2881690', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1535, 'n_words': 292}