Module: SurveyorHelper

Includes:
SurveyorHelperExtensions
Defined in:
app/helpers/surveyor_helper.rb

Instance Method Summary collapse

Instance Method Details

#dependency_explanation_helper(question, response_set) ⇒ Object

Section: dependencies, menu, previous and next



23
24
25
26
27
28
29
30
31
# File 'app/helpers/surveyor_helper.rb', line 23

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

#fields_for_radio(response, &block) ⇒ Object



63
64
65
# File 'app/helpers/surveyor_helper.rb', line 63

def fields_for_radio(response, &block)
  fields_for("responses[#{response.question_id}]", response, :builder => SurveyFormBuilder, &block)
end

#fields_for_response(response, response_group = nil, &block) ⇒ Object

Answers



59
60
61
62
# File 'app/helpers/surveyor_helper.rb', line 59

def fields_for_response(response, response_group = nil, &block)
  name = response_group.nil? ? "responses[#{response.question_id}][#{response.answer_id}]" : "response_groups[#{response.question_id}][#{response_group}][#{response.answer_id}]"
  fields_for(name, response, :builder => SurveyFormBuilder, &block)
end


32
33
34
# File 'app/helpers/surveyor_helper.rb', line 32

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

#next_numberObject

Questions



47
48
49
50
# File 'app/helpers/surveyor_helper.rb', line 47

def next_number
  @n ||= 0
  "#{@n += 1}<span style='padding-left:0.1em;'>)</span>"
end

#next_sectionObject



40
41
42
43
44
# File 'app/helpers/surveyor_helper.rb', line 40

def next_section
  # @section.next.nil? ? submit_tag("Click here to finish", :name => "finish") : submit_tag("Next section &raquo;", :name => "section[#{@section.next.id}]")
  # refactored to use copy in memory instead of making extra db calls
  @sections.last == @section ? submit_tag("Click here to finish", :name => "finish") : submit_tag("Next section &raquo;", :name => "section[#{@sections[@sections.index(@section)+1].id}]")
end

#previous_sectionObject



35
36
37
38
39
# File 'app/helpers/surveyor_helper.rb', line 35

def previous_section
  # submit_tag("&laquo; Previous section", :name => "section[#{@section.previous.id}]") unless @section.previous.nil?
  # refactored to use copy in memory instead of making extra db calls
  submit_tag("&laquo; Previous section", :name => "section[#{@sections[@sections.index(@section)-1].id}]") unless @sections.first == @section
end

#question_help_helper(question) ⇒ Object



54
55
56
# File 'app/helpers/surveyor_helper.rb', line 54

def question_help_helper(question)
  question.help_text.blank? ? "" : %Q(<span class="question-help">#{question.help_text}</span>)
end

#split_text(text = "") ⇒ Object

Split text into with “|” delimiter - parts to go before/after input element



51
52
53
# File 'app/helpers/surveyor_helper.rb', line 51

def split_text(text = "") # Split text into with "|" delimiter - parts to go before/after input element
  {:prefix => text.split("|")[0].blank? ? "&nbsp;" : text.split("|")[0], :postfix => text.split("|")[1] || "&nbsp;"}
end

#surveyor_configObject

Configuration



7
8
9
# File 'app/helpers/surveyor_helper.rb', line 7

def surveyor_config
  Surveyor::Config
end

#surveyor_includesObject

Layout: stylsheets and javascripts



12
13
14
# File 'app/helpers/surveyor_helper.rb', line 12

def surveyor_includes
  surveyor_stylsheets + surveyor_javascripts    
end

#surveyor_javascriptsObject



18
19
20
# File 'app/helpers/surveyor_helper.rb', line 18

def surveyor_javascripts
  javascript_include_tag 'surveyor/jquery-1.2.6.js', 'surveyor/jquery-ui-personalized-1.5.3.js', 'surveyor/accessibleUISlider.jQuery.js','surveyor/jquery.form.js', 'surveyor/surveyor.js'
end

#surveyor_stylsheetsObject



15
16
17
# File 'app/helpers/surveyor_helper.rb', line 15

def surveyor_stylsheets
  stylesheet_link_tag 'surveyor/reset', 'surveyor/surveyor', 'surveyor/ui.theme.css','surveyor/jquery-ui-slider-additions'
end