surveyor 0.18.2 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +2 -1
  2. data/CHANGELOG +12 -0
  3. data/Rakefile +1 -0
  4. data/VERSION +1 -1
  5. data/app/helpers/surveyor_helper.rb +40 -22
  6. data/app/views/layouts/surveyor_default.html.erb +0 -1
  7. data/app/views/partials/_answer.html.haml +19 -58
  8. data/app/views/partials/_dependents.html.haml +5 -0
  9. data/app/views/partials/_question.html.haml +24 -72
  10. data/app/views/partials/_question_group.html.haml +30 -39
  11. data/app/views/partials/_section.html.haml +10 -11
  12. data/app/views/partials/_section_menu.html.haml +5 -0
  13. data/app/views/surveyor/edit.html.haml +13 -25
  14. data/app/views/surveyor/new.html.haml +6 -3
  15. data/features/{redcap.feature → redcap_parser.feature} +0 -0
  16. data/features/step_definitions/parser_steps.rb +71 -0
  17. data/features/step_definitions/surveyor_steps.rb +8 -78
  18. data/features/support/paths.rb +2 -0
  19. data/features/surveyor.feature +30 -168
  20. data/features/surveyor_parser.feature +157 -0
  21. data/generators/surveyor/surveyor_generator.rb +2 -1
  22. data/generators/surveyor/templates/assets/images/next.gif +0 -0
  23. data/generators/surveyor/templates/assets/images/prev.gif +0 -0
  24. data/generators/surveyor/templates/assets/javascripts/jquery.surveyor.js +46 -0
  25. data/generators/surveyor/templates/assets/javascripts/jquery.tools.min.js +204 -0
  26. data/generators/surveyor/templates/assets/stylesheets/dateinput.css +149 -0
  27. data/generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass +84 -226
  28. data/generators/surveyor/templates/migrate/add_default_value_to_answers.rb +9 -0
  29. data/lib/formtastic/surveyor_builder.rb +83 -0
  30. data/lib/surveyor.rb +5 -0
  31. data/lib/surveyor/models/answer_methods.rb +8 -3
  32. data/lib/surveyor/models/question_group_methods.rb +1 -1
  33. data/lib/surveyor/models/question_methods.rb +6 -2
  34. data/lib/surveyor/models/response_methods.rb +2 -12
  35. data/lib/surveyor/models/response_set_methods.rb +25 -71
  36. data/lib/surveyor/surveyor_controller_methods.rb +29 -28
  37. data/lib/tasks/surveyor_tasks.rake +1 -15
  38. data/spec/controllers/surveyor_controller_spec.rb +40 -8
  39. data/spec/helpers/surveyor_helper_spec.rb +53 -0
  40. data/spec/models/answer_spec.rb +14 -9
  41. data/spec/models/dependency_condition_spec.rb +56 -61
  42. data/spec/models/question_group_spec.rb +3 -3
  43. data/spec/models/question_spec.rb +10 -0
  44. data/spec/models/response_set_spec.rb +72 -62
  45. data/surveyor.gemspec +21 -58
  46. data/testbed/Gemfile +1 -0
  47. metadata +34 -60
  48. data/app/helpers/survey_form_builder.rb +0 -37
  49. data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_leftright.gif +0 -0
  50. data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_updown.gif +0 -0
  51. data/generators/surveyor/templates/assets/images/222222_11x11_icon_close.gif +0 -0
  52. data/generators/surveyor/templates/assets/images/222222_11x11_icon_doc.gif +0 -0
  53. data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_closed.gif +0 -0
  54. data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_open.gif +0 -0
  55. data/generators/surveyor/templates/assets/images/222222_11x11_icon_minus.gif +0 -0
  56. data/generators/surveyor/templates/assets/images/222222_11x11_icon_plus.gif +0 -0
  57. data/generators/surveyor/templates/assets/images/222222_11x11_icon_resize_se.gif +0 -0
  58. data/generators/surveyor/templates/assets/images/222222_35x9_colorpicker_indicator.gif.gif +0 -0
  59. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_down.gif +0 -0
  60. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_left.gif +0 -0
  61. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_right.gif +0 -0
  62. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_up.gif +0 -0
  63. data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_leftright.gif +0 -0
  64. data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_updown.gif +0 -0
  65. data/generators/surveyor/templates/assets/images/454545_11x11_icon_close.gif +0 -0
  66. data/generators/surveyor/templates/assets/images/454545_11x11_icon_doc.gif +0 -0
  67. data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_closed.gif +0 -0
  68. data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_open.gif +0 -0
  69. data/generators/surveyor/templates/assets/images/454545_11x11_icon_minus.gif +0 -0
  70. data/generators/surveyor/templates/assets/images/454545_11x11_icon_plus.gif +0 -0
  71. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_down.gif +0 -0
  72. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_left.gif +0 -0
  73. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_right.gif +0 -0
  74. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_up.gif +0 -0
  75. data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_leftright.gif +0 -0
  76. data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_updown.gif +0 -0
  77. data/generators/surveyor/templates/assets/images/888888_11x11_icon_close.gif +0 -0
  78. data/generators/surveyor/templates/assets/images/888888_11x11_icon_doc.gif +0 -0
  79. data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_closed.gif +0 -0
  80. data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_open.gif +0 -0
  81. data/generators/surveyor/templates/assets/images/888888_11x11_icon_minus.gif +0 -0
  82. data/generators/surveyor/templates/assets/images/888888_11x11_icon_plus.gif +0 -0
  83. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_down.gif +0 -0
  84. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_left.gif +0 -0
  85. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_right.gif +0 -0
  86. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_up.gif +0 -0
  87. data/generators/surveyor/templates/assets/images/dadada_40x100_textures_02_glass_75.png +0 -0
  88. data/generators/surveyor/templates/assets/images/e6e6e6_40x100_textures_02_glass_75.png +0 -0
  89. data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_01_flat_0.png +0 -0
  90. data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_02_glass_65.png +0 -0
  91. data/generators/surveyor/templates/assets/javascripts/accessibleUISlider.jQuery.js +0 -201
  92. data/generators/surveyor/templates/assets/javascripts/jquery-1.2.6.js +0 -3549
  93. data/generators/surveyor/templates/assets/javascripts/jquery-ui-personalized-1.5.3.js +0 -7616
  94. data/generators/surveyor/templates/assets/javascripts/jquery.form.js +0 -637
  95. data/generators/surveyor/templates/assets/javascripts/surveyor.js +0 -40
  96. data/generators/surveyor/templates/assets/stylesheets/jquery-ui-slider-additions.css +0 -71
  97. data/generators/surveyor/templates/assets/stylesheets/ui.theme.css +0 -851
  98. data/spec/views/surveyor/show.html.haml_spec.rb +0 -32
  99. data/uninstall.rb +0 -1
data/.gitignore CHANGED
@@ -22,4 +22,5 @@ pkg
22
22
  testbed/log/*.log
23
23
  testbed/db/*
24
24
  testbed/.bundle
25
- surveys/fixtures/*.yml
25
+ testbed/*
26
+ surveys/fixtures/*.yml
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
1
+ 0.19.0
2
+
3
+ * reload to correctly calculate dependencies
4
+ * date picker. closes #58
5
+ * hide section menu for fewer than three sections
6
+ * cleaning up features from merge
7
+ * correcing spec to reject blank radio responses. fixing response set spec
8
+ * modifications for repeaters and response groups
9
+ * merge formtastic
10
+ * default value for pick none answers. closes #103.
11
+ * view changes and updates.
12
+
1
13
  0.18.2
2
14
 
3
15
  * redcap text and string answers. closes #99
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.authors = ["Brian Chamberlain", "Mark Yoon"]
12
12
  gem.add_dependency 'haml'
13
13
  gem.add_dependency 'fastercsv'
14
+ gem.add_dependency 'formtastic'
14
15
  gem.add_development_dependency "yard", ">= 0"
15
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.18.2
1
+ 0.19.0
@@ -1,16 +1,18 @@
1
1
  module SurveyorHelper
2
-
3
2
  # Layout: stylsheets and javascripts
4
3
  def surveyor_includes
5
4
  surveyor_stylsheets + surveyor_javascripts
6
5
  end
7
6
  def surveyor_stylsheets
8
- stylesheet_link_tag 'surveyor/reset', 'surveyor', 'surveyor/ui.theme.css','surveyor/jquery-ui-slider-additions'
7
+ stylesheet_link_tag 'surveyor/reset', 'surveyor/dateinput', 'surveyor'
9
8
  end
10
9
  def surveyor_javascripts
11
- 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'
10
+ javascript_include_tag 'surveyor/jquery.tools.min', 'surveyor/jquery.surveyor'
11
+ end
12
+ # Helper for displaying warning/notice/error flash messages
13
+ def flash_messages(types)
14
+ types.map{|type| content_tag(:div, "#{flash[type]}".html_safe, :class => type.to_s)}.join.html_safe
12
15
  end
13
-
14
16
  # Section: dependencies, menu, previous and next
15
17
  def dependency_explanation_helper(question,response_set)
16
18
  # Attempts to explain why this dependent question needs to be answered by referenced the dependent question and users response
@@ -25,35 +27,51 @@ module SurveyorHelper
25
27
  submit_tag(section.title, :name => "section[#{section.id}]")
26
28
  end
27
29
  def previous_section
28
- # submit_tag("#{t ('surveyor.previous_section')} »", :name => "section[#{@section.previous.id}]") unless @section.previous.nil?
29
- # refactored to use copy in memory instead of making extra db calls
30
+ # use copy in memory instead of making extra db calls
30
31
  submit_tag(t('surveyor.previous_section'), :name => "section[#{@sections[@sections.index(@section)-1].id}]") unless @sections.first == @section
31
32
  end
32
33
  def next_section
33
- # @section.next.nil? ? submit_tag(t ('surveyor.click_here_to_finish'), :name => "finish") : submit_tag("Next section «", :name => "section[#{@section.next.id}]")
34
- # refactored to use copy in memory instead of making extra db calls
34
+ # use copy in memory instead of making extra db calls
35
35
  @sections.last == @section ? submit_tag(t('surveyor.click_here_to_finish'), :name => "finish") : submit_tag(t('surveyor.next_section'), :name => "section[#{@sections[@sections.index(@section)+1].id}]")
36
36
  end
37
37
 
38
38
  # Questions
39
- def next_number
39
+ def q_text(obj)
40
40
  @n ||= 0
41
- "#{@n += 1}<span style='padding-left:0.1em;'>)</span>"
42
- end
43
- def split_text(text = "") # Split text into with "|" delimiter - parts to go before/after input element
44
- {:prefix => text.split("|")[0].blank? ? "&nbsp;" : text.split("|")[0], :postfix => text.split("|")[1] || "&nbsp;"}
45
- end
46
- def question_help_helper(question)
47
- question.help_text.blank? ? "" : %Q(<span class="question-help">#{question.help_text}</span>)
41
+ return image_tag(obj.text) if obj.is_a?(Question) and obj.display_type == "image"
42
+ return obj.text if obj.is_a?(Question) and (obj.dependent? or obj.display_type == "label" or obj.part_of_group?)
43
+ "#{@n += 1}) #{obj.text}"
48
44
  end
49
-
45
+ # def split_text(text = "") # Split text into with "|" delimiter - parts to go before/after input element
46
+ # {:prefix => text.split("|")[0].blank? ? "&nbsp;" : text.split("|")[0], :postfix => text.split("|")[1] || "&nbsp;"}
47
+ # end
48
+ # def question_help_helper(question)
49
+ # question.help_text.blank? ? "" : %Q(<span class="question-help">#{question.help_text}</span>)
50
+ # end
51
+
50
52
  # Answers
51
- def fields_for_response(response, response_group = nil, &block)
52
- name = response_group.nil? ? "responses[#{response.question_id}][#{response.answer_id}]" : "response_groups[#{response.question_id}][#{response_group}][#{response.answer_id}]"
53
- fields_for(name, response, :builder => SurveyFormBuilder, &block)
53
+ def rc_to_attr(type_sym)
54
+ case type_sym.to_s
55
+ when /^date|time$/ then :datetime_value
56
+ when /(string|text|integer|float|datetime)/ then "#{type_sym.to_s}_value".to_sym
57
+ else :answer_id
58
+ end
54
59
  end
55
- def fields_for_radio(response, &block)
56
- fields_for("responses[#{response.question_id}]", response, :builder => SurveyFormBuilder, &block)
60
+ def rc_to_as(type_sym)
61
+ case type_sym.to_s
62
+ when /(integer|float)/ then :string
63
+ else type_sym
64
+ end
57
65
  end
58
66
 
67
+ # Responses
68
+ def response_for(response_set, question, answer = nil, response_group = nil)
69
+ return nil unless response_set && question && question.id
70
+ 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)}
71
+ result.blank? ? response_set.responses.build(:question_id => question.id, :response_group => response_group) : result
72
+ end
73
+ def response_idx(increment = true)
74
+ @rc ||= 0
75
+ (increment ? @rc += 1 : @rc).to_s
76
+ end
59
77
  end
@@ -7,7 +7,6 @@
7
7
  <%= surveyor_includes %>
8
8
  </head>
9
9
  <body>
10
- <div id="flash"><%= flash[:notice] %></div>
11
10
  <%= yield %>
12
11
  </body>
13
12
  </html>
@@ -1,58 +1,19 @@
1
- - renderer = answer.renderer(question)
2
- - response_group ||= nil
3
- - hide_label ||= false
4
- - disabled ||= false
5
- - fields_for_response(response_obj, response_group) do |response_form|
6
- - case renderer
7
- - when :any_answer
8
- = response_form.survey_check_box(:selected, :class => (answer.is_exclusive? ? "exclusive" : ""))
9
- = response_form.label("selected", answer.text) unless hide_label # This is a temp fix til I figure out why the id of the checkbox is all jacked up
10
- - when :any_other_and_string
11
- = response_form.survey_check_box(:selected, :class => (answer.is_exclusive? ? "exclusive" : ""))
12
- %label Other
13
- = response_form.text_field(:other_value)
14
- = response_form.text_field(:string_value)
15
- - when :any_string
16
- = response_form.survey_check_box(:selected, :class => (answer.is_exclusive? ? "exclusive" : ""))
17
- = response_form.label(:answer_id, answer.text)
18
- = response_form.text_field(:string_value, :size => 25, :maxlength => 250)
19
- - when :one_answer, :one_string, :one_integer
20
- - fields_for_radio(response_obj) do |radio_form|
21
- = radio_form.radio_button(:answer_id, answer.id, :checked => response_obj.selected?, :title => answer.text)
22
- = radio_form.label("answer_id_#{answer.id}", split_text(answer.text)[:prefix]) unless hide_label
23
- - if renderer == :one_string
24
- = response_form.text_field(:string_value, :size => 25, :maxlength => 250, :autocomplete => "off")
25
- - if renderer == :one_integer
26
- = response_form.text_field(:integer_value, :size => 5, :maxlength => 10, :autocomplete => "off")
27
- = radio_form.label("answer_id_#{answer.id}", split_text(answer.text)[:postfix]) unless hide_label
28
- - when :none_date
29
- = response_form.label(:datetime_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
30
- = response_form.text_field(:datetime_value)
31
- = response_form.label(:datetime_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
32
- - when :none_datetime
33
- = response_form.label(:datetime_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
34
- = response_form.datetime_select(:datetime_value, {:include_blank => true})
35
- = response_form.label(:datetime_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
36
- - when :none_float
37
- = response_form.label(:float_value, split_text(answer.text)[:prefix]) unless hide_label
38
- = response_form.text_field(:float_value, :size => 5, :maxlength => 10, :autocomplete => "off")
39
- = response_form.label(:float_value, split_text(answer.text)[:postfix]) unless hide_label
40
- - when :none_integer
41
- = response_form.label(:integer_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
42
- = response_form.text_field(:integer_value, :size => 5, :maxlength => 10, :autocomplete => "off", :disabled => disabled)
43
- = response_form.label(:integer_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
44
- - when :none_string
45
- = response_form.label(:string_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
46
- = response_form.text_field(:string_value, :size => 25, :maxlength => 250, :autocomplete => "off", :disabled => disabled)
47
- = response_form.label(:string_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
48
- - when :none_text
49
- = response_form.label(:text_value, split_text(answer.text)[:prefix]) unless hide_label
50
- = response_form.text_area(:text_value, :cols => 80, :rows => 10)
51
- = response_form.label(:text_value, split_text(answer.text)[:postfix]) unless hide_label
52
- - when :none_time
53
- = response_form.label(:datetime_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
54
- = response_form.time_select(:datetime_value,{ :include_blank => true })
55
- = response_form.label(:datetime_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
56
- - else
57
- = answer.text
58
-
1
+ -# TODO: disabled
2
+ - rg ||= nil
3
+ - r = response_for(@response_set, q, a, rg)
4
+ - i = response_idx(q.pick != "one") # argument will be false (don't increment i) if we're on radio buttons
5
+ - f.semantic_fields_for i, r do |ff|
6
+ = ff.quiet_input :question_id unless q.pick == "one" # don't repeat question_id if we're on radio buttons
7
+ = ff.quiet_input :id unless q.pick == "one" or r.new_record?
8
+ = ff.quiet_input :response_group, :value => rg if q.pick != "one" && g && g.display_type == "repeater"
9
+ - case q.pick
10
+ - when "one"
11
+ = ff.input :answer_id, :as => :surveyor_radio, :collection => [[a.text, a.id]], :label => false, :input_html => {:class => a.css_class}, :response_class => a.response_class
12
+ - when "any"
13
+ = ff.input :answer_id, :as => :surveyor_check_boxes, :collection => [[a.text, a.id]], :label => false, :input_html => {:class => a.css_class}, :response_class => a.response_class
14
+ - when "none"
15
+ - if %w(date datetime time float integer string text).include? a.response_class
16
+ = ff.quiet_input :answer_id, :input_html => {:class => a.css_class, :value => a.id}
17
+ = ff.input rc_to_attr(a.response_class), :as => rc_to_as(a.response_class), :label => a.split_or_hidden_text(:pre).blank? ? false : a.split_or_hidden_text(:pre), :hint => a.split_or_hidden_text(:post), :input_html => {:value => a.default_value}
18
+ - else
19
+ = a.text
@@ -0,0 +1,5 @@
1
+ #dependents
2
+ .title Follow-up questions from your answers on the previous page
3
+ -# @dependents.each_with_index do |question, index|
4
+ = dependency_explanation_helper(question, @response_set)
5
+ = render question.custom_renderer || "/partials/question", :question => question, :response_set => @response_set, :number => "D#{index+1}"
@@ -1,72 +1,24 @@
1
- - renderer = question.renderer(question_group ||= nil)
2
- - case renderer
3
- - when :label
4
- - div_for question, :class => "label #{question.css_class(response_set)}" do
5
- %span.text= question.text
6
- %span.help= question.help_text
7
- - when :image
8
- .image= image_tag(question.text)
9
- - when :dropdown, :slider
10
- - if renderer == :slider
11
- %script{:type => "text/javascript"}= "$(function(){$('#slider_#{question.id}').accessibleUISlider({width: 400, labels:#{question.answers.size} }).hide();});"
12
- - div_for question, :class => question.css_class(response_set) do
13
- .number= next_number unless question.dependent?
14
- %fieldset
15
- %legend{:style => "display:inline;"}
16
- %span.text= question.text
17
- %span.help= question.help_text
18
- = hidden_field_tag("responses[#{question.id}][question_id]", question.id)
19
- %ol.answers
20
- %li.answer
21
- - options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
22
- = renderer == :slider ? select_tag("responses[#{question.id}][answer_id]", options, {:id => "slider_#{question.id}"}) : select_tag("responses[#{question.id}][answer_id]", ["<option value=''>#{t('surveyor.Select_one')}</option>"].concat(options))
23
- - when :grid_default
24
- - reset_cycle("col")
25
- - content_tag_for :tr, question, :class => question.css_class(response_set) do
26
- %th.question_prefix
27
- %span.text= split_text(question.text)[:prefix]
28
- %span.help= question.help_text
29
- = hidden_field_tag("responses[#{question.id}][question_id]", question.id)
30
- - question.answers.each do |answer|
31
- %td{:class => "#{cycle("column_highlight", "", :name => "col")}"}
32
- .answer{:class => answer.custom_class}= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => true})
33
- %th.question_postfix
34
- %span.text= split_text(question.text)[:postfix]
35
- - when :repeater_default, :repeater_dropdown
36
- - disabled ||= false
37
- - div_for question, :class => "#{disabled ? 'dis' : 'en'}abled #{question.css_class(response_set)}" do
38
- %span.text= question.text
39
- %span.help= question.help_text
40
- = hidden_field_tag("response_groups[#{question.id}][#{response_group}][response_group]", response_group)
41
- = hidden_field_tag("response_groups[#{question.id}][#{response_group}][question_id]", question.id)
42
- %br
43
- %ol.answers
44
- - if renderer == :repeater_default
45
- - question.answers.each do |answer|
46
- - content_tag_for :li, answer, :class => answer.custom_class do
47
- = render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id, response_group), :response_group => response_group, :hide_label => true, :disabled => disabled})
48
- - else
49
- %li.answer
50
- - options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id, response_group).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
51
- = select_tag("response_groups[#{question.id}][#{response_group}][answer_id]", ["<option value=''>Select one...</option>"].concat(options), :disabled => disabled)
52
- - when :inline_default, :inline_dropdown
53
- - div_for question, :class => "inline #{question.css_class(response_set)}" do
54
- = hidden_field_tag("responses[#{question.id}][question_id]", question.id)
55
- - if renderer == :inline_default
56
- - question.answers.each do |answer|
57
- .answer{:class => answer.custom_class}= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
58
- - else
59
- - options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
60
- = select_tag("responses[#{question.id}][answer_id]", ["<option value=''>Select one...</option>"].concat(options))
61
- - else # :default, :inline
62
- - div_for question, :class => question.css_class(response_set) do
63
- .number= next_number unless question.dependent?
64
- %fieldset
65
- %legend
66
- %span.text= question.text
67
- %span.help= question.help_text
68
- = hidden_field_tag("responses[#{question.id}][question_id]", question.id)
69
- %ol.answers{:class => renderer == :inline ? "inline" : nil}
70
- - question.answers.each do |answer|
71
- - content_tag_for :li, answer, :class => answer.custom_class do
72
- = render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
1
+ -# TODO: js for slider
2
+ - rg ||= nil
3
+ - renderer = q.renderer(g ||= nil)
4
+ - f.inputs q_text(q), :id => rg ? "q_#{q.id}_#{rg.id}" : "q_#{q.id}", :class => "q_#{renderer} #{q.css_class(@response_set)}" do
5
+ %span.help= q.help_text
6
+ - case renderer
7
+ - when :image, :label
8
+ - when :dropdown, :inline_dropdown, :slider
9
+ - r = response_for(@response_set, q, nil, rg)
10
+ - i = response_idx
11
+ - f.semantic_fields_for i, r do |ff|
12
+ = ff.quiet_input :question_id
13
+ = ff.quiet_input :response_group, :value => rg if g && g.display_type == "repeater"
14
+ = ff.input :answer_id, :as => :select, :collection => q.answers.map{|a| [a.text, a.id]}, :label => false
15
+ - else # :default, :inline, :inline_default
16
+ - if q.pick == "one"
17
+ - r = response_for(@response_set, q, nil, rg)
18
+ - i = response_idx # increment the response index since the answer partial skips for q.pick == one
19
+ - f.semantic_fields_for i, r do |ff|
20
+ = ff.quiet_input :question_id
21
+ = ff.quiet_input :response_group, :value => rg if g && g.display_type == "repeater"
22
+ = ff.quiet_input :id unless r.new_record?
23
+ - q.answers.each do |a|
24
+ = render a.custom_renderer || '/partials/answer', :q => q, :a => a, :f => f, :rg => rg, :g => g
@@ -1,39 +1,30 @@
1
- - renderer = question_group.renderer
2
- - locals = {:question_group => question_group, :response_set => response_set, :hide_label => true}
3
- - div_for question_group, :class => question_group.css_class(response_set) do
4
- .head
5
- .number= next_number
6
- %span.text= question_group.text
7
- %span.help= question_group.help_text
8
-
9
- - case question_group.renderer
10
- - when :grid
11
- %table.grid
12
- %thead
13
- %tr
14
- %th= "&nbsp;"
15
- - reset_cycle("column_highlight")
16
- - group_questions.first.answers.each do |answer|
17
- %th{:class => "#{cycle("column_highlight", "", :name => "column_highlight")}"}= answer.text
18
- %tbody
19
- - group_questions.each_with_index do |question, i|
20
- = render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question}))
21
- - if i%10 == 9
22
- %th= "&nbsp;"
23
- - reset_cycle("column_highlight")
24
- - group_questions.first.answers.each do |answer|
25
- %th{:class => "#{cycle("column_highlight", "", :name => "column_highlight")}"}= answer.text
26
- - when :repeater
27
- %ul.repeater
28
- - (response_set.count_group_responses(group_questions) + 1).times do |group_number|
29
- %li.repeater
30
- - group_questions.each do |question|
31
- = render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question, :response_group => group_number, :disabled => false}))
32
- %li.repeater
33
- - group_questions.each do |question|
34
- = render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question, :response_group => 9999, :disabled => true}))
35
- = submit_tag("&lt;= add row", :name => "section[#{group_questions.first.survey_section_id}]question_group_#{question_group.id}", :class => "add_row")
36
- - else # :inline
37
- %ul
38
- - group_questions.each do |question|
39
- %li{:class => question_group.renderer == :inline ? "inline" : nil}= render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question}))
1
+ - renderer = g.renderer
2
+ - f.inputs q_text(g), :id => "g_#{g.id}", :class => "g_#{renderer} #{g.css_class(@response_set)}" do
3
+ %li.help= g.help_text
4
+ - case renderer
5
+ - when :grid
6
+ %li
7
+ %table
8
+ %tbody
9
+ - qs.each_slice(10) do |ten_questions| # header row every 10
10
+ %tr
11
+ %th &nbsp;
12
+ - ten_questions.first.answers.each do |a|
13
+ %th= a.text
14
+ %th &nbsp;
15
+ - ten_questions.each_with_index do |q, i|
16
+ %tr{:id => "q_#{q.id}", :class => "q_#{renderer} #{q.css_class(@response_set)}"}
17
+ %th= q.split_text(:pre)
18
+ - response_idx if q.pick == "one" # increment the response index since the answer partial skips for q.pick == one
19
+ - q.answers.each do |a|
20
+ %td= render a.custom_renderer || '/partials/answer', :g => g, :q => q, :a => a, :f => f
21
+ %th= q.split_text(:post)
22
+ - when :repeater
23
+ - (@response_set.count_group_responses(qs) + 1).times do |rg|
24
+ %li
25
+ - qs.each do |q|
26
+ = render q.custom_renderer || "/partials/question", :g => g, :rg => rg, :q => q, :f => f
27
+ = submit_tag("+ add row", :name => "section[#{@section.id}][g_#{g.id}]", :class => "add_row")
28
+ - else # :inline
29
+ - qs.each do |q|
30
+ = render q.custom_renderer || "/partials/question", :g => g, :q => q, :f => f
@@ -1,13 +1,12 @@
1
1
  - div_for @section, :class => @section.custom_class do
2
2
  %span.title= @section.title
3
- .questions
4
- - group_questions ||= []
5
- - @questions.each_with_index do |question, index|
6
- - unless question.part_of_group?
7
- = render(:partial => question.custom_renderer || "/partials/question", :locals => {:question => question, :response_set => @response_set})
8
- - else # gather up the group questions
9
- - group_questions << question
10
- - if (index + 1 >= @questions.size) or (question.question_group_id != @questions[index + 1].question_group_id)
11
- - # this is the last question of the section, or the group
12
- = render(:partial => question.question_group.custom_renderer || "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set, :group_questions => group_questions})
13
- - group_questions = []
3
+ - qs ||= []
4
+ - (questions = @section.questions).each_with_index do |q, i|
5
+ - if q.part_of_group?
6
+ - qs << q # gather up the group questions
7
+ - if (i+1 >= questions.size) or (q.question_group_id != questions[i+1].question_group_id)
8
+ - # this is the last question of the section, or the group
9
+ = render q.question_group.custom_renderer || "/partials/question_group", :g => q.question_group, :qs => qs, :f => f
10
+ - qs = []
11
+ - else # gather up the group questions
12
+ = render q.custom_renderer || "/partials/question", :q => q, :f => f
@@ -0,0 +1,5 @@
1
+ .surveyor_menu
2
+ = t('surveyor.sections')
3
+ %ul
4
+ - @sections.each do |s|
5
+ %li{:class => ("active" if s == @section)}= menu_button_for(s)
@@ -1,28 +1,16 @@
1
1
  #surveyor
2
- - form_tag(update_my_survey_path, :method => :put, :id => "survey_form", :class => @survey.custom_class) do
3
- = hidden_field_tag :current_section_id, @section.id
4
- - unless @sections.size < 3
5
- #menu
6
- = t('surveyor.sections')
7
- %ul
8
- - @sections.each do |s|
9
- %li{:class => ("active" if s == @section)}= menu_button_for(s)
10
- #header
11
- .title= @survey.title
2
+ - unless (types = flash.keys.select{|k| [:notice, :error, :warning].include?(k)}).blank?
3
+ .surveyor_flash
4
+ = flash_messages(types)
5
+ .close
6
+ - semantic_form_for(:r, @response_set, :url => update_my_survey_path, :html => {:method => :put, :id => "survey_form", :class => @survey.custom_class}) do |f|
7
+ = render 'partials/section_menu' unless @sections.size < 3
8
+ .survey_title= @survey.title
12
9
  .previous_section= previous_section
13
- - unless @dependents.empty?
14
- #dependents
15
- .title Follow-up questions from your answers on the previous page
16
- -# @dependents.each_with_index do |question, index|
17
- = dependency_explanation_helper(question, @response_set)
18
- = render(:partial => question.custom_renderer || "/partials/question", :locals => {:question => question, :response_set => @response_set, :number => "D#{index+1}"})
19
- -# cache section if there are no responses for that section in th current response_set
20
- - if @response_set.no_responses_for_section?(@section)
21
- - cache("section_#{@section.id}") do
22
- -# cache
23
- = render(:partial => "/partials/section", :locals => {:section => @section, :questions => @questions, :response_set => @response_set})
24
- - else
25
- -# no cache
26
- = render(:partial => "/partials/section", :locals => {:section => @section, :questions => @questions, :response_set => @response_set})
10
+ = render 'partials/dependents' unless @dependents.empty?
11
+ - if @response_set.no_responses_for_section?(@section) # cache if response_set has no responses for current section
12
+ = cache("section_#{@section.id}"){ render "/partials/section", :f => f }
13
+ - else # no cache
14
+ = render "/partials/section", :f => f
27
15
  .next_section= next_section
28
-
16
+ %br