affectiva-surveyor 1.5.0.pre.disco.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.rspec +1 -0
  4. data/CHANGELOG.md +198 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.rails_version +27 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +166 -0
  9. data/Rakefile +106 -0
  10. data/app/controllers/surveyor_controller.rb +5 -0
  11. data/app/helpers/results_helper.rb +20 -0
  12. data/app/helpers/survey_form_builder.rb +37 -0
  13. data/app/helpers/surveyor_helper.rb +3 -0
  14. data/app/inputs/quiet_input.rb +5 -0
  15. data/app/inputs/surveyor_check_boxes_input.rb +35 -0
  16. data/app/inputs/surveyor_radio_input.rb +18 -0
  17. data/app/models/answer.rb +3 -0
  18. data/app/models/dependency.rb +3 -0
  19. data/app/models/dependency_condition.rb +3 -0
  20. data/app/models/question.rb +3 -0
  21. data/app/models/question_group.rb +4 -0
  22. data/app/models/response.rb +4 -0
  23. data/app/models/response_set.rb +3 -0
  24. data/app/models/survey.rb +3 -0
  25. data/app/models/survey_section.rb +4 -0
  26. data/app/models/survey_section_sweeper.rb +15 -0
  27. data/app/models/survey_translation.rb +4 -0
  28. data/app/models/validation.rb +3 -0
  29. data/app/models/validation_condition.rb +3 -0
  30. data/app/views/layouts/results.html.erb +13 -0
  31. data/app/views/layouts/surveyor_default.html.erb +12 -0
  32. data/app/views/partials/_answer.html.haml +25 -0
  33. data/app/views/partials/_dependents.html.haml +5 -0
  34. data/app/views/partials/_question.html.haml +28 -0
  35. data/app/views/partials/_question_group.html.haml +44 -0
  36. data/app/views/partials/_section.html.haml +12 -0
  37. data/app/views/partials/_section_menu.html.haml +12 -0
  38. data/app/views/surveyor/edit.html.haml +24 -0
  39. data/app/views/surveyor/export.json.rabl +85 -0
  40. data/app/views/surveyor/new.html.haml +24 -0
  41. data/app/views/surveyor/show.html.haml +74 -0
  42. data/app/views/surveyor/show.json.rabl +15 -0
  43. data/ci-exec.sh +56 -0
  44. data/config/routes.rb +8 -0
  45. data/cucumber.yml +10 -0
  46. data/doc/REPRESENTATIONS.md +34 -0
  47. data/doc/api_id_schema.json +7 -0
  48. data/doc/question types.png +0 -0
  49. data/doc/response_set_schema.json +54 -0
  50. data/doc/surveyor question combinations.png +0 -0
  51. data/doc/surveyor reject or delete decision matrix.png +0 -0
  52. data/doc/surveyor_models.png +0 -0
  53. data/doc/surveyor_models2.png +0 -0
  54. data/doc/surveyor_timestamp_schema.json +9 -0
  55. data/features/ajax_submissions.feature +140 -0
  56. data/features/export_to_json.feature +344 -0
  57. data/features/internationalization.feature +121 -0
  58. data/features/no_duplicates.feature +110 -0
  59. data/features/show_survey.feature +71 -0
  60. data/features/step_definitions/parser_steps.rb +145 -0
  61. data/features/step_definitions/surveyor_steps.rb +325 -0
  62. data/features/step_definitions/ui_steps.rb +25 -0
  63. data/features/step_definitions/web_steps.rb +225 -0
  64. data/features/support/REDCapDemoDatabase_DataDictionary.csv +127 -0
  65. data/features/support/database_cleaner.rb +16 -0
  66. data/features/support/env.rb +56 -0
  67. data/features/support/hooks.rb +4 -0
  68. data/features/support/paths.rb +39 -0
  69. data/features/support/redcap_new_headers.csv +1 -0
  70. data/features/support/redcap_siblings.csv +1 -0
  71. data/features/support/redcap_whitespace.csv +1 -0
  72. data/features/support/selectors.rb +39 -0
  73. data/features/support/simultaneous_ajax.rb +101 -0
  74. data/features/support/single_quit_selenium_driver.rb +23 -0
  75. data/features/support/slow_updates.rb +18 -0
  76. data/features/surveyor.feature +895 -0
  77. data/features/surveyor_dependencies.feature +476 -0
  78. data/features/surveyor_parser.feature +504 -0
  79. data/features/z_redcap_parser.feature +62 -0
  80. data/lib/assets/images/surveyor/next.gif +0 -0
  81. data/lib/assets/images/surveyor/prev.gif +0 -0
  82. data/lib/assets/images/surveyor/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  83. data/lib/assets/images/surveyor/ui-bg_flat_75_ffffff_40x100.png +0 -0
  84. data/lib/assets/images/surveyor/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  85. data/lib/assets/images/surveyor/ui-bg_glass_65_ffffff_1x400.png +0 -0
  86. data/lib/assets/images/surveyor/ui-bg_glass_75_dadada_1x400.png +0 -0
  87. data/lib/assets/images/surveyor/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  88. data/lib/assets/images/surveyor/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  89. data/lib/assets/images/surveyor/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  90. data/lib/assets/images/surveyor/ui-icons_222222_256x240.png +0 -0
  91. data/lib/assets/images/surveyor/ui-icons_2e83ff_256x240.png +0 -0
  92. data/lib/assets/images/surveyor/ui-icons_454545_256x240.png +0 -0
  93. data/lib/assets/images/surveyor/ui-icons_888888_256x240.png +0 -0
  94. data/lib/assets/images/surveyor/ui-icons_cd0a0a_256x240.png +0 -0
  95. data/lib/assets/javascripts/surveyor/jquery-1.9.0.js +9555 -0
  96. data/lib/assets/javascripts/surveyor/jquery-ui-1.10.0.custom.js +14850 -0
  97. data/lib/assets/javascripts/surveyor/jquery-ui-timepicker-addon.js +1919 -0
  98. data/lib/assets/javascripts/surveyor/jquery.maskedinput.js +338 -0
  99. data/lib/assets/javascripts/surveyor/jquery.selectToUISlider.js +240 -0
  100. data/lib/assets/javascripts/surveyor/jquery.surveyor.js +154 -0
  101. data/lib/assets/stylesheets/surveyor.sass +132 -0
  102. data/lib/assets/stylesheets/surveyor/jquery-ui-1.10.0.custom.css +1174 -0
  103. data/lib/assets/stylesheets/surveyor/jquery-ui-timepicker-addon.css +11 -0
  104. data/lib/assets/stylesheets/surveyor/reset.css +48 -0
  105. data/lib/assets/stylesheets/surveyor/results.css +125 -0
  106. data/lib/assets/stylesheets/surveyor/ui.slider.extras.css +110 -0
  107. data/lib/generators/surveyor/custom_generator.rb +18 -0
  108. data/lib/generators/surveyor/install_generator.rb +101 -0
  109. data/lib/generators/surveyor/templates/app/assets/javascripts/surveyor_all.js +6 -0
  110. data/lib/generators/surveyor/templates/app/assets/stylesheets/surveyor_all.css +9 -0
  111. data/lib/generators/surveyor/templates/app/controllers/surveyor_controller.rb +40 -0
  112. data/lib/generators/surveyor/templates/app/views/layouts/surveyor_custom.html.erb +13 -0
  113. data/lib/generators/surveyor/templates/config/locales/surveyor_en.yml +19 -0
  114. data/lib/generators/surveyor/templates/config/locales/surveyor_es.yml +19 -0
  115. data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +19 -0
  116. data/lib/generators/surveyor/templates/config/locales/surveyor_ko.yml +19 -0
  117. data/lib/generators/surveyor/templates/db/migrate/add_api_id_to_question_groups.rb +10 -0
  118. data/lib/generators/surveyor/templates/db/migrate/add_api_ids.rb +14 -0
  119. data/lib/generators/surveyor/templates/db/migrate/add_api_ids_to_response_sets_and_responses.rb +12 -0
  120. data/lib/generators/surveyor/templates/db/migrate/add_correct_answer_id_to_questions.rb +10 -0
  121. data/lib/generators/surveyor/templates/db/migrate/add_default_value_to_answers.rb +10 -0
  122. data/lib/generators/surveyor/templates/db/migrate/add_display_order_to_surveys.rb +10 -0
  123. data/lib/generators/surveyor/templates/db/migrate/add_display_type_to_answers.rb +14 -0
  124. data/lib/generators/surveyor/templates/db/migrate/add_index_to_response_sets.rb +10 -0
  125. data/lib/generators/surveyor/templates/db/migrate/add_index_to_surveys.rb +10 -0
  126. data/lib/generators/surveyor/templates/db/migrate/add_input_mask_attributes_to_answer.rb +12 -0
  127. data/lib/generators/surveyor/templates/db/migrate/add_section_id_to_responses.rb +12 -0
  128. data/lib/generators/surveyor/templates/db/migrate/add_unique_index_on_access_code_and_version_in_surveys.rb +10 -0
  129. data/lib/generators/surveyor/templates/db/migrate/add_unique_indicies.rb +18 -0
  130. data/lib/generators/surveyor/templates/db/migrate/add_version_to_surveys.rb +10 -0
  131. data/lib/generators/surveyor/templates/db/migrate/api_ids_must_be_unique.rb +23 -0
  132. data/lib/generators/surveyor/templates/db/migrate/create_answers.rb +38 -0
  133. data/lib/generators/surveyor/templates/db/migrate/create_dependencies.rb +23 -0
  134. data/lib/generators/surveyor/templates/db/migrate/create_dependency_conditions.rb +30 -0
  135. data/lib/generators/surveyor/templates/db/migrate/create_question_groups.rb +28 -0
  136. data/lib/generators/surveyor/templates/db/migrate/create_questions.rb +37 -0
  137. data/lib/generators/surveyor/templates/db/migrate/create_response_sets.rb +23 -0
  138. data/lib/generators/surveyor/templates/db/migrate/create_responses.rb +34 -0
  139. data/lib/generators/surveyor/templates/db/migrate/create_survey_sections.rb +30 -0
  140. data/lib/generators/surveyor/templates/db/migrate/create_survey_translations.rb +19 -0
  141. data/lib/generators/surveyor/templates/db/migrate/create_surveys.rb +32 -0
  142. data/lib/generators/surveyor/templates/db/migrate/create_validation_conditions.rb +33 -0
  143. data/lib/generators/surveyor/templates/db/migrate/create_validations.rb +21 -0
  144. data/lib/generators/surveyor/templates/db/migrate/drop_unique_index_on_access_code_in_surveys.rb +10 -0
  145. data/lib/generators/surveyor/templates/db/migrate/update_blank_api_ids_on_question_group.rb +22 -0
  146. data/lib/generators/surveyor/templates/db/migrate/update_blank_versions_on_surveys.rb +13 -0
  147. data/lib/generators/surveyor/templates/surveys/EXTENDING_SURVEYOR.md +52 -0
  148. data/lib/generators/surveyor/templates/surveys/MODIFYING_SURVEYOR.md +91 -0
  149. data/lib/generators/surveyor/templates/surveys/date_survey.rb +16 -0
  150. data/lib/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +280 -0
  151. data/lib/generators/surveyor/templates/surveys/languages.rb +14 -0
  152. data/lib/generators/surveyor/templates/surveys/quiz.rb +11 -0
  153. data/lib/generators/surveyor/templates/surveys/translations/languages.es.yml +18 -0
  154. data/lib/generators/surveyor/templates/surveys/translations/languages.he.yml +18 -0
  155. data/lib/generators/surveyor/templates/surveys/translations/languages.ko.yml +18 -0
  156. data/lib/generators/surveyor/templates/vendor/assets/stylesheets/custom.sass +5 -0
  157. data/lib/surveyor.rb +13 -0
  158. data/lib/surveyor/acts_as_response.rb +17 -0
  159. data/lib/surveyor/common.rb +59 -0
  160. data/lib/surveyor/engine.rb +10 -0
  161. data/lib/surveyor/helpers/asset_pipeline.rb +18 -0
  162. data/lib/surveyor/helpers/formtastic_custom_input.rb +13 -0
  163. data/lib/surveyor/helpers/surveyor_helper_methods.rb +103 -0
  164. data/lib/surveyor/models/answer_methods.rb +83 -0
  165. data/lib/surveyor/models/dependency_condition_methods.rb +69 -0
  166. data/lib/surveyor/models/dependency_methods.rb +57 -0
  167. data/lib/surveyor/models/question_group_methods.rb +58 -0
  168. data/lib/surveyor/models/question_methods.rb +112 -0
  169. data/lib/surveyor/models/response_methods.rb +126 -0
  170. data/lib/surveyor/models/response_set_methods.rb +188 -0
  171. data/lib/surveyor/models/survey_methods.rb +100 -0
  172. data/lib/surveyor/models/survey_section_methods.rb +53 -0
  173. data/lib/surveyor/models/survey_translation_methods.rb +30 -0
  174. data/lib/surveyor/models/validation_condition_methods.rb +54 -0
  175. data/lib/surveyor/models/validation_methods.rb +45 -0
  176. data/lib/surveyor/mustache_context.rb +11 -0
  177. data/lib/surveyor/parser.rb +427 -0
  178. data/lib/surveyor/redcap_parser.rb +288 -0
  179. data/lib/surveyor/surveyor_controller_methods.rb +236 -0
  180. data/lib/surveyor/unparser.rb +147 -0
  181. data/lib/surveyor/version.rb +3 -0
  182. data/lib/tasks/surveyor_tasks.rake +88 -0
  183. data/rails/init.rb +1 -0
  184. data/spec/controllers/surveyor_controller_spec.rb +311 -0
  185. data/spec/factories.rb +166 -0
  186. data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
  187. data/spec/helpers/surveyor_helper_spec.rb +117 -0
  188. data/spec/lib/benchmark_spec.rb +22 -0
  189. data/spec/lib/chinese_survey.rb +14 -0
  190. data/spec/lib/common_spec.rb +34 -0
  191. data/spec/lib/parser_spec.rb +204 -0
  192. data/spec/lib/rake_kitchen_sink.rb +40 -0
  193. data/spec/lib/redcap_parser_spec.rb +75 -0
  194. data/spec/lib/tasks_spec.rake +26 -0
  195. data/spec/lib/unparser_spec.rb +126 -0
  196. data/spec/models/answer_spec.rb +174 -0
  197. data/spec/models/dependency_condition_spec.rb +439 -0
  198. data/spec/models/dependency_spec.rb +101 -0
  199. data/spec/models/question_group_spec.rb +93 -0
  200. data/spec/models/question_spec.rb +206 -0
  201. data/spec/models/response_set_spec.rb +477 -0
  202. data/spec/models/response_spec.rb +218 -0
  203. data/spec/models/survey_section_spec.rb +85 -0
  204. data/spec/models/survey_spec.rb +191 -0
  205. data/spec/models/validation_condition_spec.rb +113 -0
  206. data/spec/models/validation_spec.rb +74 -0
  207. data/spec/rcov.opts +2 -0
  208. data/spec/spec.opts +4 -0
  209. data/spec/spec_helper.rb +56 -0
  210. data/stacktests.sh +65 -0
  211. data/surveyor.gemspec +53 -0
  212. metadata +601 -0
@@ -0,0 +1,106 @@
1
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'cucumber/rake/task'
6
+ require 'ci/reporter/rake/rspec'
7
+
8
+ ###### RSPEC
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
13
+ spec.rcov = true
14
+ end
15
+
16
+ task :default => :spec
17
+
18
+ ###### CUCUMBER
19
+
20
+ namespace :cucumber do
21
+ Cucumber::Rake::Task.new(:ok, 'Run features that should pass') do |t|
22
+ t.profile = 'default'
23
+ end
24
+
25
+ Cucumber::Rake::Task.new(:wip, 'Run features that are being worked on') do |t|
26
+ t.profile = 'wip'
27
+ end
28
+
29
+ desc 'Run all features'
30
+ task :all => [:ok, :wip]
31
+ end
32
+ desc 'Alias for cucumber:ok'
33
+ task :cucumber => 'cucumber:ok'
34
+
35
+ ###### TESTBED
36
+
37
+ desc 'Set up the rails app that the specs and features use'
38
+ task :testbed => 'testbed:rebuild'
39
+
40
+ namespace :testbed do
41
+ desc 'Generate a minimal surveyor-using rails app'
42
+ task :generate do
43
+ Tempfile.open('surveyor_Rakefile') do |f|
44
+ f.write("application \"config.time_zone='Rome'\"\n")
45
+ f.flush
46
+ sh "bundle exec rails new testbed --skip-bundle -m #{f.path}" # don't run bundle install until the Gemfile modifications
47
+ end
48
+ chdir('testbed') do
49
+ gem_file_contents = File.read('Gemfile')
50
+ gem_file_contents.sub!(/^(gem 'rails'.*)$/, %Q{# \\1\nplugin_root = File.expand_path('../..', __FILE__)\neval(File.read File.join(plugin_root, 'Gemfile.rails_version'))\ngem 'surveyor', :path => plugin_root})
51
+ File.open('Gemfile', 'w'){|f| f.write(gem_file_contents) }
52
+
53
+ Bundler.with_clean_env do
54
+ sh 'bundle install' # run bundle install after Gemfile modifications
55
+ end
56
+ end
57
+ end
58
+
59
+ desc 'Prepare the databases for the testbed'
60
+ task :migrate do
61
+ chdir('testbed') do
62
+ Bundler.with_clean_env do
63
+ sh 'bundle exec rails generate surveyor:install'
64
+ sh 'bundle exec rake db:migrate db:test:prepare'
65
+ end
66
+ end
67
+ end
68
+
69
+ desc 'Remove the testbed entirely'
70
+ task :remove do
71
+ rm_rf 'testbed'
72
+ end
73
+
74
+ task :rebuild => [:remove, :generate, :migrate]
75
+
76
+ desc 'Load all the sample surveys into the testbed instance'
77
+ task :surveys do
78
+ cd('testbed') do
79
+ Dir[File.join('surveys', '*.rb')].each do |fn|
80
+ puts "Installing #{fn} into the testbed"
81
+ system("rake surveyor FILE='#{fn}'")
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ ###### CI
88
+
89
+ namespace :ci do
90
+ task :all => ['rake:testbed', :spec, :cucumber, 'cucumber:wip']
91
+
92
+ task :env do
93
+ ENV['CI_REPORTS'] = 'reports/spec-xml'
94
+ ENV['SPEC_OPTS'] = "#{ENV['SPEC_OPTS']} --format nested"
95
+ end
96
+
97
+ Cucumber::Rake::Task.new(:cucumber, 'Run features using the CI profile') do |t|
98
+ t.profile = 'ci'
99
+ end
100
+
101
+ Cucumber::Rake::Task.new('cucumber:wip', 'Run WIP features using the CI profile') do |t|
102
+ t.profile = 'ci_wip'
103
+ end
104
+
105
+ task :spec => [:env, 'ci:setup:rspecbase', 'rake:spec']
106
+ end
@@ -0,0 +1,5 @@
1
+ # Surveyor Controller allows a user to take a survey. It is semi-RESTful since it does not have a concrete representation model.
2
+ # The "resource" is a survey attempt/session populating a response set.
3
+ class SurveyorController < ApplicationController
4
+ include Surveyor::SurveyorControllerMethods
5
+ end
@@ -0,0 +1,20 @@
1
+ module ResultsHelper
2
+ def display_response(r_set,question)
3
+ sets = r_set.responses.select{|r| r.question.display_order == question.display_order}
4
+ if sets.size == 0
5
+ return "-"
6
+ elsif sets.size == 1
7
+ return (sets.first.string_value || sets.first.text_value || show_answer(sets.first))
8
+ else
9
+ txt = ""
10
+ sets.each do |set|
11
+ txt << show_answer(set) + "<br/>"
12
+ end
13
+ return txt
14
+ end
15
+ end
16
+
17
+ def show_answer(set)
18
+ set.answer.text
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ class SurveyFormBuilder < ActionView::Helpers::FormBuilder
2
+ def survey_check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
3
+ fields = @template.survey_check_box(@object_name, method, options.merge(:object => @object), checked_value, unchecked_value)
4
+ fields[1]
5
+ end
6
+ end
7
+
8
+ module ActionView
9
+ module Helpers
10
+ module FormHelper
11
+ def survey_check_box(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
12
+ if (Rails::VERSION::STRING.to_f > 2.1)
13
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_survey_check_box_tag(options, checked_value, unchecked_value)
14
+ else
15
+ InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_survey_check_box_tag(options, checked_value, unchecked_value)
16
+ end
17
+ end
18
+ end
19
+
20
+ class InstanceTag
21
+ def to_survey_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
22
+ options = options.stringify_keys
23
+ options["type"] = "checkbox"
24
+ options["value"] = checked_value
25
+ if options.has_key?("checked")
26
+ cv = options.delete "checked"
27
+ checked = cv == true || cv == "checked"
28
+ else
29
+ checked = self.class.check_box_checked?(value(object), checked_value)
30
+ end
31
+ options["checked"] = "checked" if checked
32
+ add_default_name_and_id(options)
33
+ [tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value), tag("input", options)]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module SurveyorHelper
2
+ include Surveyor::Helpers::SurveyorHelperMethods
3
+ end
@@ -0,0 +1,5 @@
1
+ class QuietInput < Formtastic::Inputs::HiddenInput
2
+ def to_html
3
+ super
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+ class SurveyorCheckBoxesInput < Formtastic::Inputs::CheckBoxesInput
2
+ include Surveyor::Helpers::FormtasticCustomInput
3
+ def to_html
4
+ super
5
+ end
6
+ def choice_html(choice)
7
+ output = ""
8
+ output << template.content_tag(:label,
9
+ hidden_fields? ?
10
+ check_box_with_hidden_input(choice) :
11
+ check_box_without_hidden_input(choice) <<
12
+ choice_label(choice),
13
+ label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
14
+ )
15
+ output << builder.text_field(:response_other, input_html_options_with(choice, :response_other)) if options[:response_class] == "other_and_string"
16
+ output << builder.text_field(response_class_to_method(options[:response_class]), input_html_options_with(choice, options[:response_class])) if %w(date datetime time float integer string other_and_string).include? options[:response_class]
17
+ output << builder.text_area(:text_value, input_html_options_with(choice, :text_value)) if options[:response_class] == "text"
18
+ output.html_safe
19
+ end
20
+ def checked?(value)
21
+ selected_values.include?(value.to_s)
22
+ end
23
+ def disabled?(value)
24
+ disabled_values.include?(value) || input_html_options[:disabled] == true
25
+ end
26
+ def make_selected_values
27
+ if object.respond_to?(method)
28
+ selected_items = [object.send(method)].compact.flatten.map(&:to_s)
29
+
30
+ [*selected_items.map { |o| send_or_call_or_object(value_method, o) }].compact
31
+ else
32
+ []
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ class SurveyorRadioInput < Formtastic::Inputs::RadioInput
2
+ include Surveyor::Helpers::FormtasticCustomInput
3
+ def to_html
4
+ super
5
+ end
6
+ def choice_html(choice)
7
+ output = ""
8
+ output << template.content_tag(:label,
9
+ builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<
10
+ choice_label(choice),
11
+ label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
12
+ )
13
+ output << builder.text_field(:response_other, input_html_options_with(choice, :response_other)) if options[:response_class] == "other_and_string"
14
+ output << builder.text_field(response_class_to_method(options[:response_class]), input_html_options_with(choice, options[:response_class])) if %w(date datetime time float integer string other_and_string).include? options[:response_class]
15
+ output << builder.text_area(:text_value, input_html_options_with(choice, :text_value)) if options[:response_class] == "text"
16
+ output.html_safe
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class Answer < ActiveRecord::Base
2
+ include Surveyor::Models::AnswerMethods
3
+ end
@@ -0,0 +1,3 @@
1
+ class Dependency < ActiveRecord::Base
2
+ include Surveyor::Models::DependencyMethods
3
+ end
@@ -0,0 +1,3 @@
1
+ class DependencyCondition < ActiveRecord::Base
2
+ include Surveyor::Models::DependencyConditionMethods
3
+ end
@@ -0,0 +1,3 @@
1
+ class Question < ActiveRecord::Base
2
+ include Surveyor::Models::QuestionMethods
3
+ end
@@ -0,0 +1,4 @@
1
+ class QuestionGroup < ActiveRecord::Base
2
+ include Surveyor::Models::QuestionGroupMethods
3
+
4
+ end
@@ -0,0 +1,4 @@
1
+ class Response < ActiveRecord::Base
2
+ include ActionView::Helpers::SanitizeHelper
3
+ include Surveyor::Models::ResponseMethods
4
+ end
@@ -0,0 +1,3 @@
1
+ class ResponseSet < ActiveRecord::Base
2
+ include Surveyor::Models::ResponseSetMethods
3
+ end
@@ -0,0 +1,3 @@
1
+ class Survey < ActiveRecord::Base
2
+ include Surveyor::Models::SurveyMethods
3
+ end
@@ -0,0 +1,4 @@
1
+ class SurveySection < ActiveRecord::Base
2
+ include Surveyor::Models::SurveySectionMethods
3
+ end
4
+
@@ -0,0 +1,15 @@
1
+ class SurveySectionSweeper < ActionController::Caching::Sweeper
2
+ observe :survey_section
3
+
4
+ def after_save(section)
5
+ expire_cache(section)
6
+ end
7
+
8
+ def after_destroy(section)
9
+ expire_cache(section)
10
+ end
11
+
12
+ def expire_cache(section)
13
+ expire_fregment "section_#{section.id}"
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ class SurveyTranslation < ActiveRecord::Base
2
+ include Surveyor::Models::SurveyTranslationMethods
3
+ end
4
+
@@ -0,0 +1,3 @@
1
+ class Validation < ActiveRecord::Base
2
+ include Surveyor::Models::ValidationMethods
3
+ end
@@ -0,0 +1,3 @@
1
+ class ValidationCondition < ActiveRecord::Base
2
+ include Surveyor::Models::ValidationConditionMethods
3
+ end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
6
+ <title>Survey: Result Sets</title>
7
+ <%= surveyor_includes %>
8
+ </head>
9
+ <body>
10
+ <div id="flash"><%= flash[:notice] %></div>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
6
+ <title>Survey: <%= controller.action_name %></title>
7
+ <%= surveyor_includes %>
8
+ </head>
9
+ <body>
10
+ <%= yield %>
11
+ </body>
12
+ </html>
@@ -0,0 +1,25 @@
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
+ - disabled = defined?(disableFlag) ? disableFlag : false
6
+ = f.semantic_fields_for i, r do |ff|
7
+ = ff.input :question_id, :as => :quiet unless q.pick == "one" # don't repeat question_id if we're on radio buttons
8
+ = ff.input :api_id, :as => :quiet unless q.pick == "one"
9
+ = ff.input :response_group, :value => rg, :as => :quiet if q.pick != "one" && g && g.display_type == "repeater"
10
+ - case q.pick
11
+ - when "one"
12
+ = ff.input :answer_id, :as => :surveyor_radio, :collection => [[a.text_for(nil, @render_context, I18n.locale), a.id]], :label => false, :input_html => {:class => a.css_class, :disabled => disabled}, :response_class => a.response_class
13
+ - when "any"
14
+ = ff.input :answer_id, :as => :surveyor_check_boxes, :collection => [[a.text_for(nil, @render_context, I18n.locale), a.id]], :label => false, :input_html => {:class => a.css_class, :disabled => disabled}, :response_class => a.response_class
15
+ - when "none"
16
+ - if %w(date datetime time float integer string text).include? a.response_class
17
+ = ff.input :answer_id, :as => :quiet, :input_html => {:class => a.css_class, :value => a.id}
18
+ = ff.input rc_to_attr(a.response_class),
19
+ :as => rc_to_as(a.response_class),
20
+ :label => a.text_for(:pre, @render_context, I18n.locale).blank? ? false : a.text_for(:pre, @render_context, I18n.locale),
21
+ :hint => a.text_for(:post, @render_context, I18n.locale),
22
+ :input_html => generate_pick_none_input_html(r.to_formatted_s, a.default_value_for(@render_context, I18n.locale), a.css_class, a.response_class, disabled, a.input_mask, a.input_mask_placeholder)
23
+ - else
24
+ = a.text_for(nil, @render_context, I18n.locale)
25
+ %span.help= a.help_text_for(@render_context, I18n.locale) unless g && g.display_type == "grid"
@@ -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}"
@@ -0,0 +1,28 @@
1
+ -# TODO: js for slider
2
+ - rg ||= nil
3
+ - renderer = q.renderer(g ||= nil)
4
+ - disabled = defined?(disableFlag) ? disableFlag : false
5
+ - unless q.display_type == "hidden"
6
+ = f.inputs q_text(q, @render_context, I18n.locale), :id => rg ? "q_#{q.id}_#{rg}" : "q_#{q.id}", :class => "q_#{renderer} #{q.css_class(@response_set)}" do
7
+ %span.help= q.help_text_for(@render_context, I18n.locale)
8
+ - case renderer
9
+ - when :image, :label, :default_label, :inline_label, :repeater_label
10
+ - when :dropdown, :inline_dropdown, :default_dropdown, :slider, :repeater_dropdown
11
+ - r = response_for(@response_set, q, nil, rg)
12
+ - i = response_idx
13
+ = f.semantic_fields_for i, r do |ff|
14
+ = ff.input :question_id, :as => :quiet
15
+ = ff.input :response_group, :as => :quiet, :value => rg if g && g.display_type == "repeater"
16
+ = ff.input :api_id, :as => :quiet
17
+ = ff.input :answer_id, :as => :select, :collection => q.answers.map{|a| [a.text, a.id]}, :include_blank => (renderer != :slider), :label => q.text, :input_html => { :disabled => disabled }
18
+ - else # :default, :inline, :inline_default
19
+ - if q.pick == "one"
20
+ - r = response_for(@response_set, q, nil, rg)
21
+ - i = response_idx # increment the response index since the answer partial skips for q.pick == one
22
+ = f.semantic_fields_for i, r do |ff|
23
+ = ff.input :question_id, :as => :quiet
24
+ = ff.input :response_group, :as => :quiet, :value => rg if g && g.display_type == "repeater"
25
+ = ff.input :api_id, :as => :quiet
26
+ - q.answers.each do |a|
27
+ - next if (q.pick == "one" or q.pick == "any") and disabled and @response_set.responses.where( :question_id => q.id, :answer_id => a.id).empty?
28
+ = render a.custom_renderer || '/partials/answer', :q => q, :a => a, :f => f, :rg => rg, :g => g, :disableFlag => disabled
@@ -0,0 +1,44 @@
1
+ - renderer = g.renderer
2
+ - unless g.display_type == "hidden"
3
+ = f.inputs "#{next_question_number(g)}#{g.text_for(@render_context, I18n.locale)}", :id => "g_#{g.id}", :class => "g_#{renderer} #{g.css_class(@response_set)}" do
4
+ %li.help= g.help_text_for(@render_context, I18n.locale)
5
+ - case renderer
6
+ - when :grid
7
+ %li
8
+ %table
9
+ %col.pre
10
+ - qs.first.answers.each do |a|
11
+ %col{:class => cycle("odd", "even")}
12
+ %col.post
13
+ %tbody
14
+ - qs.each_slice(10) do |ten_questions| # header row every 10
15
+ %tr
16
+ %th &nbsp;
17
+ - ten_questions.first.answers.each do |a|
18
+ %th
19
+ = a.text_for(nil, @render_context, I18n.locale)
20
+ %span.help= a.help_text_for(@render_context, I18n.locale)
21
+ %th &nbsp;
22
+ - ten_questions.each_with_index do |q, i|
23
+ %tr{:id => "q_#{q.id}", :class => "q_#{renderer} #{q.css_class(@response_set)}"}
24
+ %th
25
+ = q.text_for(:pre, @render_context, I18n.locale)
26
+ = q.help_text_for(@render_context, I18n.locale)
27
+ - if q.pick == "one"
28
+ - r = response_for(@response_set, q, nil, g)
29
+ - i = response_idx # increment the response index since the answer partial skips for q.pick == one
30
+ = f.semantic_fields_for i, r do |ff|
31
+ = ff.input :question_id, :as => :quiet
32
+ = ff.input :api_id, :as => :quiet
33
+ - q.answers.each do |a|
34
+ %td= render(a.custom_renderer || '/partials/answer', :g => g, :q => q, :a => a, :f => f) unless q.display_type == "label"
35
+ %th= q.text_for(:post, @render_context, I18n.locale)
36
+ - when :repeater
37
+ - (@response_set.count_group_responses(qs) + 1).times do |rg|
38
+ %li
39
+ - qs.each do |q|
40
+ = render q.custom_renderer || "/partials/question", :g => g, :rg => rg, :q => q, :f => f
41
+ = submit_tag("+ add row", :name => "section[#{@section.id}][g_#{g.id}]", :class => "add_row")
42
+ - else # :inline
43
+ - qs.each do |q|
44
+ = render q.custom_renderer || "/partials/question", :g => g, :q => q, :f => f