Module: Surveyor::Helpers::SurveyorHelperMethods

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

Instance Method Summary collapse

Methods included from AssetPipeline

#asset_pipeline_enabled?

Instance Method Details

#dependency_explanation_helper(question, response_set) ⇒ Object

Section: dependencies, menu, previous and next



33
34
35
36
37
38
39
40
41
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 33

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



29
30
31
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 29

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



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 79

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


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

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

#next_question_number(question) ⇒ Object



59
60
61
62
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 59

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

#next_sectionObject



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

def next_section
  # use copy in memory instead of making extra db calls
  @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[@sections.index(@section)+1].id}]")
end

#previous_sectionObject



45
46
47
48
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 45

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

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

Questions



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

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



72
73
74
75
76
77
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 72

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



65
66
67
68
69
70
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 65

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



92
93
94
95
96
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 92

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



97
98
99
100
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 97

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

#surveyor_includesObject

Layout: stylsheets and javascripts



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/surveyor/helpers/surveyor_helper_methods.rb', line 9

def surveyor_includes
  if asset_pipeline_enabled?
    stylesheet_link_tag('surveyor_all') + javascript_include_tag('surveyor_all')
  else
    stylesheet_link_tag('surveyor/reset',
                        'surveyor/jquery-ui-1.10.0.custom',
                        'surveyor/jquery-ui-timepicker-addon',
                        'surveyor/ui.slider.extras',
                        'surveyor/results',
                        'surveyor',
                        'custom') +
    javascript_include_tag('surveyor/jquery-1.9.0',
                            'surveyor/jquery-ui-1.10.0.custom',
                            'surveyor/jquery-ui-timepicker-addon',
                            'surveyor/jquery.selectToUISlider',
                            'surveyor/jquery.surveyor',
                            'surveyor/jquery.maskedinput')
  end
end