gurix/helena

View on GitHub
app/views/helena/questions/_bipolar_radio_matrix.html.slim

Summary

Maintainability
Test Coverage
- label_width = "#{60 / question.labels.count}%"
.radio_matrix class="#{'helena-error' if errors.present?}"
  = question_label(question, dummy: true)

  table
    thead
      tr
        td
        - question.labels.each do |label|
          th width="#{label_width}"
            = label.text
        td

    tbody
      - question.sub_questions.each do |sub_question|
        tr class="#{'error' if errors[sub_question.code]}" id="question_#{sub_question.code}"
          td
            = sub_question.parts.first
            - if errors[sub_question.code]
              .error= errors[sub_question.code]
          - question.labels.each_with_index do |label, index|
            - checked = answers[sub_question.code].to_s == label.value.to_s if answers[sub_question.code].present?
            - checked ||= (label.preselected? ? true : false)
            th width="#{label_width}"
              label
                = form.simple_fields_for :answers do |answer_form|
                  = answer_form.radio_button sub_question.code, label.value, checked: checked
                span.label-text
                  - if index < (question.labels.size / 2)
                    = "#{label.text} #{sub_question.parts.first}"
                  - elsif index > (question.labels.size / 2)
                    = "#{label.text} #{sub_question.parts.last}"
                  - else
                    = label.text
          td
            = sub_question.parts.last if sub_question.splitted?