Module: Surveyor::Helpers::SurveyorHelperMethods

Included in:
SurveyorHelper
Defined in:
lib/surveyor/helpers/surveyor_helper_methods.rb

Instance Method Summary collapse

Instance Method Details

#dependency_explanation_helper(question, response_set) ⇒ Object

Section: dependencies, menu, previous and next



14
15
16
17
18
19
20
21
22
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 14

def dependency_explanation_helper(question,response_set)
  # Attempts to explain why this dependent question needs to be answered by referenced the dependent question and users response
  trigger_responses = []
  dependent_questions = Question.find_all_by_id(question.dependency.dependency_conditions.map(&:question_id)).uniq
  response_set.responses.find_all_by_question_id(dependent_questions.map(&:id)).uniq.each do |resp|
    trigger_responses << resp.to_s
  end
  "&nbsp;&nbsp;You answered &quot;#{trigger_responses.join("&quot; and &quot;")}&quot; to the question &quot;#{dependent_questions.map(&:text).join("&quot;,&quot;")}&quot;"
end

#flash_messages(types) ⇒ Object

Helper for displaying warning/notice/error flash messages



10
11
12
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 10

def flash_messages(types)
  types.map{|type| (:div, "#{flash[type]}".html_safe, :class => type.to_s)}.join.html_safe
end

#generate_pick_none_input_html(value, default_value, css_class, response_class, disabled, input_mask, input_mask_placeholder) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 62

def generate_pick_none_input_html(value, default_value, css_class, response_class, disabled, input_mask, input_mask_placeholder)
  html = {}
  html[:class] = [response_class,css_class].reject{ |c| c.blank? }
  html[:value] = value.blank? ? default_value : value
  html[:disabled] = disabled unless disabled.blank?
  if input_mask
    html[:'data-input-mask'] = input_mask
    html[:'data-input-mask-placeholder'] = input_mask_placeholder unless input_mask_placeholder.blank?
  end
  html
end


23
24
25
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 23

def menu_button_for(section)
  submit_tag(section.translation(I18n.locale)[:title], :name => "section[#{section.id}]")
end

#next_question_number(question) ⇒ Object



42
43
44
45
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 42

def next_question_number(question)
  @n ||= 0
  "<span class='qnum'>#{@n += 1}) </span>"
end

#next_sectionObject



31
32
33
34
35
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 31

def next_section
  # use copy in memory instead of making extra db calls
  next_index = [(@sections.index(@section) || @sections.count) + 1, @sections.count].min
  @sections.last == @section ? submit_tag(t('surveyor.click_here_to_finish').html_safe, :name => "finish") : submit_tag(t('surveyor.next_section').html_safe, :name => "section[#{@sections[next_index].id}]")
end

#previous_sectionObject



26
27
28
29
30
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 26

def previous_section
  # use copy in memory instead of making extra db calls
  prev_index = [(@sections.index(@section) || 0) - 1, 0].max
  submit_tag(t('surveyor.previous_section').html_safe, :name => "section[#{@sections[prev_index].id}]") unless @sections[0] == @section
end

#q_text(q, context = nil, locale = nil) ⇒ Object

Questions



38
39
40
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 38

def q_text(q, context=nil, locale=nil)
  "#{next_question_number(q) unless (q.dependent? or q.display_type == "label" or q.display_type == "image" or q.part_of_group?)}#{q.text_for(nil, context, locale)}"
end

#rc_to_as(type_sym) ⇒ Object



55
56
57
58
59
60
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 55

def rc_to_as(type_sym)
  case type_sym.to_s
  when /(integer|float|date|time|datetime)/ then :string
  else type_sym
  end
end

#rc_to_attr(type_sym) ⇒ Object

Responses



48
49
50
51
52
53
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 48

def rc_to_attr(type_sym)
  case type_sym.to_s
  when /^answer$/ then :answer_id
  else "#{type_sym.to_s}_value".to_sym
  end
end

#response_for(response_set, question, answer = nil, response_group = nil) ⇒ Object

Responses



75
76
77
78
79
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 75

def response_for(response_set, question, answer = nil, response_group = nil)
  return nil unless response_set && question && question.id
  result = response_set.responses.detect{|r| (r.question_id == question.id) && (answer.blank? ? true : r.answer_id == answer.id) && (r.response_group.blank? ? true : r.response_group.to_i == response_group.to_i)}
  result.blank? ? response_set.responses.build(:question_id => question.id, :response_group => response_group) : result
end

#response_idx(increment = true) ⇒ Object



80
81
82
83
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 80

def response_idx(increment = true)
  @rc ||= 0
  (increment ? @rc += 1 : @rc).to_s
end

#surveyor_includesObject

Layout: stylsheets and javascripts



6
7
8
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 6

def surveyor_includes
  stylesheet_link_tag('surveyor_all') + javascript_include_tag('surveyor_all')
end