<commit_before><%
  object        = f.object
  klass         = object.class
  value         = object.send attr
  remove        = "remove_#{attr}"
  is_nil_or_new = (value.nil? || object.new_record?)
  is_required   = klass.validates_presence_of? attr
  kind          = klass.crud.find(:fields, attr, :type)
  is_droppable  = klass.crud.find(:fields, attr)[:droppable]
  html_id       = new_uuid
%>

<%- if is_droppable -%>

  <%- 
    max_count   ||= "1"              # TODO: pull this from a setting
    max_size    ||= "5"              # TODO: pull this from a validation
    types       ||= "doc,pdf,docx"   # TODO: pull this from a validation

    html_class  ||= "#{kind.to_s}-upload"
    if resource.send(attr).nil? || resource.new_record?
      existing_image = ""
    else
      existing_image = resource.send(attr).url
    end
  -%>

  <div class="control-group kat-upload <%= attr -%>">
    <%= f.hidden_field "retained_#{attr}" -%>

    <%= f.label(attr) unless klass.crud.find(:fields, attr, :label) === false %>
    <div class="form--file-upload--hint-position">
      <%= f.hint(attr) -%>
    </div>
    <%= f.error(attr) -%>

    <div class="form--file-upload--fallback controls">

      <p class="help-block">
        <%- if max_size -%>
          Max file size: <%= max_size -%>mb<br />
        <%- end -%>
        <%- if types -%>
          File types allowed: <%= types -%><br />
        <%- end -%>
        <%- if max_count.to_i > 1 -%>
          Maximum number of files: <%= max_count -%><br />
        <%- end -%>
      </p>

      <!-- TODO: Create a partial of the regular image uploader below, use that as
           the fallback -->
      <% unless resource.send(attr).nil? || resource.new_record? %>
        <%= image_tag resource.send(attr).thumb('100x').url, :class => 'form--file-upload--fallback-image imgfix left space-r-1' %>
      <% end %>

    </div>

    <div class="form--file-upload">
      <div>
        <%= f.file_field(attr, class: html_class, data: {file_max_count: max_count, file_max_size: max_size, file_types: types, file_existing_image: existing_image, field: "hidden_for_#{attr}" }) %>
      </div>
    </div>

  </div>

<%- else -%>

  <div class="control-group file">
    <%= f.hidden_field "retained_#{attr}" %>
    <%= f.label(attr) unless klass.crud.find(:fields, attr, :label) === false %>
    <%= f.hint attr -%>

    <div class="form--file-upload controls">
      <% unless is_nil_or_new %>
        <%= attachment_image_tag(value, class: "form--file-upload--thumbnail") %>
      <% else %>
        <%= placeholder_image_tag("No File", size: "100x100", class: "form--file-upload--thumbnail") %>
      <% end %>

      <div class="form--file-upload--body">
        <% if value.respond_to?(:name) %>
          <p><%= link_to "View #{kind}", value.url, :target => "_blank" %></p>
        <% end %>
          <div class="controls">
          <% unless is_nil_or_new %>
              <label class="radio"><%= f.radio_button remove, false, checked: !is_nil_or_new %> Keep this <%= kind %></label>
          <% end %>
          <% unless is_required %>
            <label class="radio"><%= f.radio_button remove, true %> No <%= kind %></label>
          <% end %>
          <label class="radio"><%= f.radio_button remove, false, checked: is_nil_or_new, id: html_id %> Upload a new <%= kind %></label>
          <%= f.input_field attr, as: :file, label: false, onclick: "document.getElementById('#{html_id}').click()" %>
        </div>
      </div>
    </div>

    <%= f.error attr -%>
  </div><commit_msg>Updated image field radios being clickable across the page. Now only the text is clickable.<commit_after><%
  object        = f.object
  klass         = object.class
  value         = object.send attr
  remove        = "remove_#{attr}"
  is_nil_or_new = (value.nil? || object.new_record?)
  is_required   = klass.validates_presence_of? attr
  kind          = klass.crud.find(:fields, attr, :type)
  is_droppable  = klass.crud.find(:fields, attr)[:droppable]
  html_id       = new_uuid
%>

<%- if is_droppable -%>

  <%- 
    max_count   ||= "1"              # TODO: pull this from a setting
    max_size    ||= "5"              # TODO: pull this from a validation
    types       ||= "doc,pdf,docx"   # TODO: pull this from a validation

    html_class  ||= "#{kind.to_s}-upload"
    if resource.send(attr).nil? || resource.new_record?
      existing_image = ""
    else
      existing_image = resource.send(attr).url
    end
  -%>

  <div class="control-group kat-upload <%= attr -%>">
    <%= f.hidden_field "retained_#{attr}" -%>

    <%= f.label(attr) unless klass.crud.find(:fields, attr, :label) === false %>
    <div class="form--file-upload--hint-position">
      <%= f.hint(attr) -%>
    </div>
    <%= f.error(attr) -%>

    <div class="form--file-upload--fallback controls">

      <p class="help-block">
        <%- if max_size -%>
          Max file size: <%= max_size -%>mb<br />
        <%- end -%>
        <%- if types -%>
          File types allowed: <%= types -%><br />
        <%- end -%>
        <%- if max_count.to_i > 1 -%>
          Maximum number of files: <%= max_count -%><br />
        <%- end -%>
      </p>

      <!-- TODO: Create a partial of the regular image uploader below, use that as
           the fallback -->
      <% unless resource.send(attr).nil? || resource.new_record? %>
        <%= image_tag resource.send(attr).thumb('100x').url, :class => 'form--file-upload--fallback-image imgfix left space-r-1' %>
      <% end %>

    </div>

    <div class="form--file-upload">
      <div>
        <%= f.file_field(attr, class: html_class, data: {file_max_count: max_count, file_max_size: max_size, file_types: types, file_existing_image: existing_image, field: "hidden_for_#{attr}" }) %>
      </div>
    </div>

  </div>

<%- else -%>

  <div class="control-group file">
    <%= f.hidden_field "retained_#{attr}" %>
    <%= f.label(attr) unless klass.crud.find(:fields, attr, :label) === false %>
    <%= f.hint attr -%>

    <div class="form--file-upload controls">
      <% unless is_nil_or_new %>
        <%= attachment_image_tag(value, class: "form--file-upload--thumbnail") %>
      <% else %>
        <%= placeholder_image_tag("No File", size: "100x100", class: "form--file-upload--thumbnail") %>
      <% end %>

      <div class="form--file-upload--body">
        <% if value.respond_to?(:name) %>
          <p><%= link_to "View #{kind}", value.url, :target => "_blank" %></p>
        <% end %>
        <div class="control-group radio_buttons">
          <% unless is_nil_or_new %>
            <div class="controls">
              <label class="radio"><%= f.radio_button remove, false, checked: !is_nil_or_new %> Keep this <%= kind %></label>
            </div>
          <% end %>
          <% unless is_required %>
            <div class="controls">
              <label class="radio"><%= f.radio_button remove, true %> No <%= kind %></label>
            </div>
          <% end %>
          <div class="controls">
            <label class="radio"><%= f.radio_button remove, false, checked: is_nil_or_new, id: html_id %> Upload a new <%= kind %></label>
          </div>
        </div>
        <%= f.input_field attr, as: :file, label: false, onclick: "document.getElementById('#{html_id}').click()" %>
      </div>
    </div>

    <%= f.error attr -%>
  </div>
{'fraction_non_alphanumeric': 0.18457150617954637, 'fraction_numerical': 0.0035311693603150888, 'mean_word_length': 2.3007619901389513, 'pattern_counts': {'":': 0, '<': 163, '<?xml version=': 0, '>': 169, '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': '6339375', 'n_tokens_mistral': 2614, 'n_tokens_neox': 2436, 'n_words': 533}