<commit_before>-# TODO: js for slider
- rg ||= nil
- repeated_template ||= false
- renderer = q.renderer(g ||= nil)
- disabled = defined?(disableFlag) ? disableFlag : false
- question_text = q_text(q, @render_context, I18n.locale)

- pickTypes = Set.new(['one', 'any'])
- selectFields = Set.new([:dropdown, :inline_dropdown, :default_dropdown, :slider, :repeater_dropdown])

- case q.display_type
- when 'hidden' #don't do anything
- when 'label'
  .subsection-label
    %h2.container
      != question_text
      %small= q.help_text

- else
  %div.question.container
    - r = response_for(@response_set, q, nil, rg)
    - a = @response_set.autocomplete_override_message_for(q)

    - explanation_required = (r.autocompletable? && !r.all_autocompleted) || r.error
    - explanation_missing = explanation_required && !a.message?

    - state = 'ok' unless r.new_record?
    - state = 'warning' if r.error || r.any_metadata_missing || explanation_missing
    - state = 'no-response' if q.is_mandatory && (q.pick == "none" ? r.string_value.blank? : !r.answer_id) && !repeated_template

    - status_message = t('surveyor.autocompleted_data')
    - status_message = t('surveyor.autocomplete_override_warning') if explanation_missing
    - status_message = t('surveyor.missing_metadata') if r.any_metadata_missing

    - classes = ['row', 'question-row', "q_#{renderer}"]
    - classes << q.css_class(@response_set)
    - classes << 'choice-boxes' if q.pick == "one" || q.pick == "any"
    - classes << 'mandatory' if q.is_mandatory
    - classes << 'autocompleted' if r.autocompletable? && r.all_autocompleted
    - classes << state if state
    - if pickTypes.include?(q.pick) || selectFields.include?(renderer)
      - classes << ['inline-validation', 'compact-validation']

    - data = {}
    - data['reference-identifier'] = rg ? "#{q.reference_identifier}_#{rg}" : q.reference_identifier
    - data['autocompletable'] = r.autocompletable?
    - data['autocompleted-value'] = r.formatted_auto_value
    - data['metadata-field'] = true if q.metadata_field?

    - id = rg ? "q_#{q.id}_#{rg}" : "q_#{q.id}"
    - attrs = {data: data, id: id, class: classes.join(' ')}

    -# if we are using the default renderer, we will display the question text within that
    = f.inputs (renderer == :default ? '' : question_text), attrs do

      -# for multiple answers, we want to give the question once
      -# at the start of the questions
      - if q.pick == 'one' || q.pick == 'any'
        %label.span8.question_label!= question_text

      .span8
        - i = response_idx

        - case renderer
        - when :image, :label, :default_label, :inline_label, :repeater_label
        - when :dropdown, :inline_dropdown, :default_dropdown, :slider, :repeater_dropdown
          = f.semantic_fields_for i, r do |ff|
            = ff.input :question_id, :as => :quiet
            = ff.input :response_group, :as => :quiet, :value => rg if g && g.display_type == "repeater"
            = ff.input :api_id, :as => :quiet
            = ff.input :autocompleted, :as => :quiet
            = ff.input :answer_id, :as => :select, :collection => q.answers.map{|a| [a.text, a.id, {'data-reference-identifier' => "#{q.reference_identifier}_#{a.reference_identifier}"}]}, :include_blank => (renderer != :slider), :label => q.text, :input_html => { :disabled => disabled }, :status_message => { :message => status_message }
        - else # :default, :inline, :inline_default, :repeater_default
          - if q.pick == "one"
            = f.semantic_fields_for i, r do |ff|
              = ff.input :question_id, :as => :quiet
              = ff.input :response_group, :as => :quiet, :value => rg if g && g.display_type == "repeater"
              = ff.input :api_id, :as => :quiet
              = ff.input :autocompleted, :as => :quiet

          - if q.pick == 'one' || q.pick == 'any'
            %div.status-above
              %div.status-icon
                %i.icon-loading.icon-spin.icon-refresh.icon-large
                %i.icon.icon-variable
              %div.span8.status-message
                %span= status_message
                %i.arrow-border
                %i.arrow
            %div.choice-buttons.status-wrapper
              - q.answers.each do |a|
                - next if disabled and @response_set.responses.where( :question_id => q.id, :answer_id => a.id).empty?
                = render a.custom_renderer || '/partials/answer', q: q, a: a, f: f, rg: rg, g: g, disableFlag: disabled, question_text: question_text, status_message: status_message

          - else
            - q.answers.each do |a|
              = render a.custom_renderer || '/partials/answer', q: q, a: a, f: f, rg: rg, g: g, disableFlag: disabled, question_text: question_text, status_message: status_message, repeated_template: repeated_template

        .autocomplete-override{class: explanation_required ? '' : 'none'}
          - i = (i.to_i + 1).to_s if q.pick == 'any'
          - i = (i.to_i + q.answers.length).to_s if q.pick != 'one' && q.pick != 'any'
          = f.semantic_fields_for i, a, index: 'autocomplete_override_message' do |ff|
            = ff.input :message, as: :additional_text, label: t('surveyor.override_explanation_title'), subtitle: t('surveyor.autocomplete_explanation')

      %aside.span4.question-meta{"data-meta-for"=> rg ? "#{q.reference_identifier}_#{rg}" : q.reference_identifier}
        - unless (q.help_text.blank?)
          %p
            != q.help_text_for(@render_context, I18n.locale)
            - if (q.help_text_more_url)
              %a{:href => q.help_text_more_url} Read more...
        = comment_link "/surveys/questions/#{rg || q.reference_identifier}", t('surveyor.question_comment'), q.text, q.reference_identifier<commit_msg>display link to conversation using discussion_topic<commit_after>-# TODO: js for slider
- rg ||= nil
- repeated_template ||= false
- renderer = q.renderer(g ||= nil)
- disabled = defined?(disableFlag) ? disableFlag : false
- question_text = q_text(q, @render_context, I18n.locale)

- pickTypes = Set.new(['one', 'any'])
- selectFields = Set.new([:dropdown, :inline_dropdown, :default_dropdown, :slider, :repeater_dropdown])

- case q.display_type
- when 'hidden' #don't do anything
- when 'label'
  .subsection-label
    %h2.container
      != question_text
      %small= q.help_text

- else
  %div.question.container
    - r = response_for(@response_set, q, nil, rg)
    - a = @response_set.autocomplete_override_message_for(q)

    - explanation_required = (r.autocompletable? && !r.all_autocompleted) || r.error
    - explanation_missing = explanation_required && !a.message?

    - state = 'ok' unless r.new_record?
    - state = 'warning' if r.error || r.any_metadata_missing || explanation_missing
    - state = 'no-response' if q.is_mandatory && (q.pick == "none" ? r.string_value.blank? : !r.answer_id) && !repeated_template

    - status_message = t('surveyor.autocompleted_data')
    - status_message = t('surveyor.autocomplete_override_warning') if explanation_missing
    - status_message = t('surveyor.missing_metadata') if r.any_metadata_missing

    - classes = ['row', 'question-row', "q_#{renderer}"]
    - classes << q.css_class(@response_set)
    - classes << 'choice-boxes' if q.pick == "one" || q.pick == "any"
    - classes << 'mandatory' if q.is_mandatory
    - classes << 'autocompleted' if r.autocompletable? && r.all_autocompleted
    - classes << state if state
    - if pickTypes.include?(q.pick) || selectFields.include?(renderer)
      - classes << ['inline-validation', 'compact-validation']

    - data = {}
    - data['reference-identifier'] = rg ? "#{q.reference_identifier}_#{rg}" : q.reference_identifier
    - data['autocompletable'] = r.autocompletable?
    - data['autocompleted-value'] = r.formatted_auto_value
    - data['metadata-field'] = true if q.metadata_field?

    - id = rg ? "q_#{q.id}_#{rg}" : "q_#{q.id}"
    - attrs = {data: data, id: id, class: classes.join(' ')}

    -# if we are using the default renderer, we will display the question text within that
    = f.inputs (renderer == :default ? '' : question_text), attrs do

      -# for multiple answers, we want to give the question once
      -# at the start of the questions
      - if q.pick == 'one' || q.pick == 'any'
        %label.span8.question_label!= question_text

      .span8
        - i = response_idx

        - case renderer
        - when :image, :label, :default_label, :inline_label, :repeater_label
        - when :dropdown, :inline_dropdown, :default_dropdown, :slider, :repeater_dropdown
          = f.semantic_fields_for i, r do |ff|
            = ff.input :question_id, :as => :quiet
            = ff.input :response_group, :as => :quiet, :value => rg if g && g.display_type == "repeater"
            = ff.input :api_id, :as => :quiet
            = ff.input :autocompleted, :as => :quiet
            = ff.input :answer_id, :as => :select, :collection => q.answers.map{|a| [a.text, a.id, {'data-reference-identifier' => "#{q.reference_identifier}_#{a.reference_identifier}"}]}, :include_blank => (renderer != :slider), :label => q.text, :input_html => { :disabled => disabled }, :status_message => { :message => status_message }
        - else # :default, :inline, :inline_default, :repeater_default
          - if q.pick == "one"
            = f.semantic_fields_for i, r do |ff|
              = ff.input :question_id, :as => :quiet
              = ff.input :response_group, :as => :quiet, :value => rg if g && g.display_type == "repeater"
              = ff.input :api_id, :as => :quiet
              = ff.input :autocompleted, :as => :quiet

          - if q.pick == 'one' || q.pick == 'any'
            %div.status-above
              %div.status-icon
                %i.icon-loading.icon-spin.icon-refresh.icon-large
                %i.icon.icon-variable
              %div.span8.status-message
                %span= status_message
                %i.arrow-border
                %i.arrow
            %div.choice-buttons.status-wrapper
              - q.answers.each do |a|
                - next if disabled and @response_set.responses.where( :question_id => q.id, :answer_id => a.id).empty?
                = render a.custom_renderer || '/partials/answer', q: q, a: a, f: f, rg: rg, g: g, disableFlag: disabled, question_text: question_text, status_message: status_message

          - else
            - q.answers.each do |a|
              = render a.custom_renderer || '/partials/answer', q: q, a: a, f: f, rg: rg, g: g, disableFlag: disabled, question_text: question_text, status_message: status_message, repeated_template: repeated_template

        .autocomplete-override{class: explanation_required ? '' : 'none'}
          - i = (i.to_i + 1).to_s if q.pick == 'any'
          - i = (i.to_i + q.answers.length).to_s if q.pick != 'one' && q.pick != 'any'
          = f.semantic_fields_for i, a, index: 'autocomplete_override_message' do |ff|
            = ff.input :message, as: :additional_text, label: t('surveyor.override_explanation_title'), subtitle: t('surveyor.autocomplete_explanation')

      %aside.span4.question-meta{"data-meta-for"=> rg ? "#{q.reference_identifier}_#{rg}" : q.reference_identifier}
        - unless (q.help_text.blank?)
          %p
            != q.help_text_for(@render_context, I18n.locale)
            - if (q.help_text_more_url)
              %a{:href => q.help_text_more_url} Read more...
        - if q.discussion_topic
          = comment_link q.discussion_topic, t('surveyor.question_comment'), q.text
{'fraction_non_alphanumeric': 0.14995670995670995, 'fraction_numerical': 0.0017316017316017316, 'mean_word_length': 2.7600911458333335, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 49, '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': '656715', 'n_tokens_mistral': 3828, 'n_tokens_neox': 3722, 'n_words': 828}