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.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +198 -0
- data/Gemfile +5 -0
- data/Gemfile.rails_version +27 -0
- data/MIT-LICENSE +20 -0
- data/README.md +166 -0
- data/Rakefile +106 -0
- data/app/controllers/surveyor_controller.rb +5 -0
- data/app/helpers/results_helper.rb +20 -0
- data/app/helpers/survey_form_builder.rb +37 -0
- data/app/helpers/surveyor_helper.rb +3 -0
- data/app/inputs/quiet_input.rb +5 -0
- data/app/inputs/surveyor_check_boxes_input.rb +35 -0
- data/app/inputs/surveyor_radio_input.rb +18 -0
- data/app/models/answer.rb +3 -0
- data/app/models/dependency.rb +3 -0
- data/app/models/dependency_condition.rb +3 -0
- data/app/models/question.rb +3 -0
- data/app/models/question_group.rb +4 -0
- data/app/models/response.rb +4 -0
- data/app/models/response_set.rb +3 -0
- data/app/models/survey.rb +3 -0
- data/app/models/survey_section.rb +4 -0
- data/app/models/survey_section_sweeper.rb +15 -0
- data/app/models/survey_translation.rb +4 -0
- data/app/models/validation.rb +3 -0
- data/app/models/validation_condition.rb +3 -0
- data/app/views/layouts/results.html.erb +13 -0
- data/app/views/layouts/surveyor_default.html.erb +12 -0
- data/app/views/partials/_answer.html.haml +25 -0
- data/app/views/partials/_dependents.html.haml +5 -0
- data/app/views/partials/_question.html.haml +28 -0
- data/app/views/partials/_question_group.html.haml +44 -0
- data/app/views/partials/_section.html.haml +12 -0
- data/app/views/partials/_section_menu.html.haml +12 -0
- data/app/views/surveyor/edit.html.haml +24 -0
- data/app/views/surveyor/export.json.rabl +85 -0
- data/app/views/surveyor/new.html.haml +24 -0
- data/app/views/surveyor/show.html.haml +74 -0
- data/app/views/surveyor/show.json.rabl +15 -0
- data/ci-exec.sh +56 -0
- data/config/routes.rb +8 -0
- data/cucumber.yml +10 -0
- data/doc/REPRESENTATIONS.md +34 -0
- data/doc/api_id_schema.json +7 -0
- data/doc/question types.png +0 -0
- data/doc/response_set_schema.json +54 -0
- data/doc/surveyor question combinations.png +0 -0
- data/doc/surveyor reject or delete decision matrix.png +0 -0
- data/doc/surveyor_models.png +0 -0
- data/doc/surveyor_models2.png +0 -0
- data/doc/surveyor_timestamp_schema.json +9 -0
- data/features/ajax_submissions.feature +140 -0
- data/features/export_to_json.feature +344 -0
- data/features/internationalization.feature +121 -0
- data/features/no_duplicates.feature +110 -0
- data/features/show_survey.feature +71 -0
- data/features/step_definitions/parser_steps.rb +145 -0
- data/features/step_definitions/surveyor_steps.rb +325 -0
- data/features/step_definitions/ui_steps.rb +25 -0
- data/features/step_definitions/web_steps.rb +225 -0
- data/features/support/REDCapDemoDatabase_DataDictionary.csv +127 -0
- data/features/support/database_cleaner.rb +16 -0
- data/features/support/env.rb +56 -0
- data/features/support/hooks.rb +4 -0
- data/features/support/paths.rb +39 -0
- data/features/support/redcap_new_headers.csv +1 -0
- data/features/support/redcap_siblings.csv +1 -0
- data/features/support/redcap_whitespace.csv +1 -0
- data/features/support/selectors.rb +39 -0
- data/features/support/simultaneous_ajax.rb +101 -0
- data/features/support/single_quit_selenium_driver.rb +23 -0
- data/features/support/slow_updates.rb +18 -0
- data/features/surveyor.feature +895 -0
- data/features/surveyor_dependencies.feature +476 -0
- data/features/surveyor_parser.feature +504 -0
- data/features/z_redcap_parser.feature +62 -0
- data/lib/assets/images/surveyor/next.gif +0 -0
- data/lib/assets/images/surveyor/prev.gif +0 -0
- data/lib/assets/images/surveyor/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_222222_256x240.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_454545_256x240.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_888888_256x240.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/assets/javascripts/surveyor/jquery-1.9.0.js +9555 -0
- data/lib/assets/javascripts/surveyor/jquery-ui-1.10.0.custom.js +14850 -0
- data/lib/assets/javascripts/surveyor/jquery-ui-timepicker-addon.js +1919 -0
- data/lib/assets/javascripts/surveyor/jquery.maskedinput.js +338 -0
- data/lib/assets/javascripts/surveyor/jquery.selectToUISlider.js +240 -0
- data/lib/assets/javascripts/surveyor/jquery.surveyor.js +154 -0
- data/lib/assets/stylesheets/surveyor.sass +132 -0
- data/lib/assets/stylesheets/surveyor/jquery-ui-1.10.0.custom.css +1174 -0
- data/lib/assets/stylesheets/surveyor/jquery-ui-timepicker-addon.css +11 -0
- data/lib/assets/stylesheets/surveyor/reset.css +48 -0
- data/lib/assets/stylesheets/surveyor/results.css +125 -0
- data/lib/assets/stylesheets/surveyor/ui.slider.extras.css +110 -0
- data/lib/generators/surveyor/custom_generator.rb +18 -0
- data/lib/generators/surveyor/install_generator.rb +101 -0
- data/lib/generators/surveyor/templates/app/assets/javascripts/surveyor_all.js +6 -0
- data/lib/generators/surveyor/templates/app/assets/stylesheets/surveyor_all.css +9 -0
- data/lib/generators/surveyor/templates/app/controllers/surveyor_controller.rb +40 -0
- data/lib/generators/surveyor/templates/app/views/layouts/surveyor_custom.html.erb +13 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_en.yml +19 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_es.yml +19 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +19 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_ko.yml +19 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_id_to_question_groups.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_ids.rb +14 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_ids_to_response_sets_and_responses.rb +12 -0
- data/lib/generators/surveyor/templates/db/migrate/add_correct_answer_id_to_questions.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_default_value_to_answers.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_display_order_to_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_display_type_to_answers.rb +14 -0
- data/lib/generators/surveyor/templates/db/migrate/add_index_to_response_sets.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_index_to_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_input_mask_attributes_to_answer.rb +12 -0
- data/lib/generators/surveyor/templates/db/migrate/add_section_id_to_responses.rb +12 -0
- data/lib/generators/surveyor/templates/db/migrate/add_unique_index_on_access_code_and_version_in_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_unique_indicies.rb +18 -0
- data/lib/generators/surveyor/templates/db/migrate/add_version_to_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/api_ids_must_be_unique.rb +23 -0
- data/lib/generators/surveyor/templates/db/migrate/create_answers.rb +38 -0
- data/lib/generators/surveyor/templates/db/migrate/create_dependencies.rb +23 -0
- data/lib/generators/surveyor/templates/db/migrate/create_dependency_conditions.rb +30 -0
- data/lib/generators/surveyor/templates/db/migrate/create_question_groups.rb +28 -0
- data/lib/generators/surveyor/templates/db/migrate/create_questions.rb +37 -0
- data/lib/generators/surveyor/templates/db/migrate/create_response_sets.rb +23 -0
- data/lib/generators/surveyor/templates/db/migrate/create_responses.rb +34 -0
- data/lib/generators/surveyor/templates/db/migrate/create_survey_sections.rb +30 -0
- data/lib/generators/surveyor/templates/db/migrate/create_survey_translations.rb +19 -0
- data/lib/generators/surveyor/templates/db/migrate/create_surveys.rb +32 -0
- data/lib/generators/surveyor/templates/db/migrate/create_validation_conditions.rb +33 -0
- data/lib/generators/surveyor/templates/db/migrate/create_validations.rb +21 -0
- data/lib/generators/surveyor/templates/db/migrate/drop_unique_index_on_access_code_in_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/update_blank_api_ids_on_question_group.rb +22 -0
- data/lib/generators/surveyor/templates/db/migrate/update_blank_versions_on_surveys.rb +13 -0
- data/lib/generators/surveyor/templates/surveys/EXTENDING_SURVEYOR.md +52 -0
- data/lib/generators/surveyor/templates/surveys/MODIFYING_SURVEYOR.md +91 -0
- data/lib/generators/surveyor/templates/surveys/date_survey.rb +16 -0
- data/lib/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +280 -0
- data/lib/generators/surveyor/templates/surveys/languages.rb +14 -0
- data/lib/generators/surveyor/templates/surveys/quiz.rb +11 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.es.yml +18 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.he.yml +18 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.ko.yml +18 -0
- data/lib/generators/surveyor/templates/vendor/assets/stylesheets/custom.sass +5 -0
- data/lib/surveyor.rb +13 -0
- data/lib/surveyor/acts_as_response.rb +17 -0
- data/lib/surveyor/common.rb +59 -0
- data/lib/surveyor/engine.rb +10 -0
- data/lib/surveyor/helpers/asset_pipeline.rb +18 -0
- data/lib/surveyor/helpers/formtastic_custom_input.rb +13 -0
- data/lib/surveyor/helpers/surveyor_helper_methods.rb +103 -0
- data/lib/surveyor/models/answer_methods.rb +83 -0
- data/lib/surveyor/models/dependency_condition_methods.rb +69 -0
- data/lib/surveyor/models/dependency_methods.rb +57 -0
- data/lib/surveyor/models/question_group_methods.rb +58 -0
- data/lib/surveyor/models/question_methods.rb +112 -0
- data/lib/surveyor/models/response_methods.rb +126 -0
- data/lib/surveyor/models/response_set_methods.rb +188 -0
- data/lib/surveyor/models/survey_methods.rb +100 -0
- data/lib/surveyor/models/survey_section_methods.rb +53 -0
- data/lib/surveyor/models/survey_translation_methods.rb +30 -0
- data/lib/surveyor/models/validation_condition_methods.rb +54 -0
- data/lib/surveyor/models/validation_methods.rb +45 -0
- data/lib/surveyor/mustache_context.rb +11 -0
- data/lib/surveyor/parser.rb +427 -0
- data/lib/surveyor/redcap_parser.rb +288 -0
- data/lib/surveyor/surveyor_controller_methods.rb +236 -0
- data/lib/surveyor/unparser.rb +147 -0
- data/lib/surveyor/version.rb +3 -0
- data/lib/tasks/surveyor_tasks.rake +88 -0
- data/rails/init.rb +1 -0
- data/spec/controllers/surveyor_controller_spec.rb +311 -0
- data/spec/factories.rb +166 -0
- data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
- data/spec/helpers/surveyor_helper_spec.rb +117 -0
- data/spec/lib/benchmark_spec.rb +22 -0
- data/spec/lib/chinese_survey.rb +14 -0
- data/spec/lib/common_spec.rb +34 -0
- data/spec/lib/parser_spec.rb +204 -0
- data/spec/lib/rake_kitchen_sink.rb +40 -0
- data/spec/lib/redcap_parser_spec.rb +75 -0
- data/spec/lib/tasks_spec.rake +26 -0
- data/spec/lib/unparser_spec.rb +126 -0
- data/spec/models/answer_spec.rb +174 -0
- data/spec/models/dependency_condition_spec.rb +439 -0
- data/spec/models/dependency_spec.rb +101 -0
- data/spec/models/question_group_spec.rb +93 -0
- data/spec/models/question_spec.rb +206 -0
- data/spec/models/response_set_spec.rb +477 -0
- data/spec/models/response_spec.rb +218 -0
- data/spec/models/survey_section_spec.rb +85 -0
- data/spec/models/survey_spec.rb +191 -0
- data/spec/models/validation_condition_spec.rb +113 -0
- data/spec/models/validation_spec.rb +74 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +56 -0
- data/stacktests.sh +65 -0
- data/surveyor.gemspec +53 -0
- metadata +601 -0
data/Rakefile
ADDED
@@ -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,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,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,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
|
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
|
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
|