surveyor 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +26 -0
- data/README.md +67 -168
- data/app/models/survey_translation.rb +5 -0
- data/app/views/partials/_answer.html.haml +9 -5
- data/app/views/partials/_question.html.haml +3 -3
- data/app/views/partials/_question_group.html.haml +9 -8
- data/app/views/partials/_section.html.haml +1 -1
- data/app/views/surveyor/edit.html.haml +3 -3
- data/app/views/surveyor/export.json.rabl +12 -8
- data/app/views/surveyor/new.html.haml +9 -14
- data/app/views/surveyor/show.html.haml +2 -2
- data/doc/surveyor_models.png +0 -0
- data/doc/surveyor_models2.png +0 -0
- data/features/export_to_json.feature +97 -1
- data/features/internationalization.feature +55 -0
- data/features/step_definitions/parser_steps.rb +7 -0
- data/features/step_definitions/surveyor_steps.rb +43 -6
- data/features/step_definitions/ui_steps.rb +22 -0
- data/features/support/env.rb +2 -0
- data/features/support/hooks.rb +4 -0
- data/features/surveyor.feature +117 -1
- data/features/surveyor_dependencies.feature +56 -2
- data/features/surveyor_parser.feature +10 -10
- data/lib/assets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/assets/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/assets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/assets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/assets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/assets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/assets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/assets/images/{ui-icons_ef8c08_256x240.png → ui-icons_222222_256x240.png} +0 -0
- data/lib/assets/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/assets/images/{ui-icons_ffffff_256x240.png → ui-icons_454545_256x240.png} +0 -0
- data/lib/assets/images/ui-icons_888888_256x240.png +0 -0
- data/lib/assets/images/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 +1795 -1153
- data/lib/assets/javascripts/surveyor/jquery.maskedinput.js +338 -0
- data/lib/assets/javascripts/surveyor/jquery.surveyor.js +8 -0
- data/lib/assets/stylesheets/surveyor.sass +2 -2
- data/lib/assets/stylesheets/surveyor/jquery-ui-1.10.0.custom.css +1174 -0
- data/lib/assets/stylesheets/surveyor/jquery-ui-timepicker-addon.css +7 -2
- data/lib/assets/stylesheets/surveyor/reset.css +24 -26
- data/lib/generators/surveyor/install_generator.rb +4 -0
- data/lib/generators/surveyor/templates/app/assets/javascripts/surveyor_all.js +4 -3
- data/lib/generators/surveyor/templates/app/assets/stylesheets/surveyor_all.css +2 -2
- data/lib/generators/surveyor/templates/config/locales/surveyor_en.yml +1 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +1 -1
- data/lib/generators/surveyor/templates/config/locales/surveyor_ko.yml +18 -0
- data/lib/generators/surveyor/templates/db/migrate/add_input_mask_attributes_to_answer.rb +12 -0
- data/lib/generators/surveyor/templates/db/migrate/create_survey_translations.rb +19 -0
- data/lib/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +5 -0
- data/lib/generators/surveyor/templates/surveys/languages.rb +10 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.es.yml +14 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.he.yml +14 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.ko.yml +14 -0
- data/lib/surveyor/helpers/formtastic_custom_input.rb +4 -8
- data/lib/surveyor/helpers/surveyor_helper_methods.rb +22 -26
- data/lib/surveyor/models/answer_methods.rb +41 -10
- data/lib/surveyor/models/question_group_methods.rb +17 -3
- data/lib/surveyor/models/question_methods.rb +32 -5
- data/lib/surveyor/models/response_methods.rb +7 -7
- data/lib/surveyor/models/survey_methods.rb +20 -4
- data/lib/surveyor/models/survey_section_methods.rb +10 -5
- data/lib/surveyor/models/survey_translation_methods.rb +33 -0
- data/lib/surveyor/mustache_context.rb +11 -0
- data/lib/surveyor/parser.rb +15 -2
- data/lib/surveyor/surveyor_controller_methods.rb +19 -17
- data/lib/surveyor/version.rb +1 -1
- data/spec/controllers/surveyor_controller_spec.rb +3 -3
- data/spec/factories.rb +21 -7
- data/spec/helpers/formtastic_custom_input_spec.rb +2 -3
- data/spec/helpers/surveyor_helper_spec.rb +64 -100
- data/spec/models/answer_spec.rb +166 -58
- data/spec/models/question_group_spec.rb +84 -38
- data/spec/models/question_spec.rb +188 -116
- data/spec/models/survey_section_spec.rb +77 -40
- data/spec/models/survey_spec.rb +176 -145
- data/spec/spec_helper.rb +3 -0
- data/stacktests.sh +52 -0
- metadata +36 -18
- data/lib/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/lib/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/lib/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/lib/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/lib/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/lib/assets/javascripts/surveyor/jquery-ui.js +0 -11729
- data/lib/assets/javascripts/surveyor/jquery.tools.min.js +0 -204
- data/lib/assets/stylesheets/surveyor/dateinput.css +0 -149
- data/lib/assets/stylesheets/surveyor/jquery-ui.custom.css +0 -572
- data/lib/surveyor/render_text.rb +0 -23
- data/lib/surveyor/surveyor_admin_controller_methods.rb +0 -55
@@ -7,13 +7,13 @@ module Surveyor
|
|
7
7
|
# Associations
|
8
8
|
base.send :has_many, :questions
|
9
9
|
base.send :has_one, :dependency
|
10
|
-
|
10
|
+
|
11
11
|
# Whitelisting attributes
|
12
12
|
base.send :attr_accessible, :text, :help_text, :reference_identifier, :data_export_identifier, :common_namespace, :common_identifier, :display_type, :custom_class, :custom_renderer
|
13
13
|
end
|
14
14
|
|
15
|
-
include
|
16
|
-
|
15
|
+
include MustacheContext
|
16
|
+
|
17
17
|
# Instance Methods
|
18
18
|
def initialize(*args)
|
19
19
|
super(*args)
|
@@ -42,6 +42,20 @@ module Surveyor
|
|
42
42
|
def css_class(response_set)
|
43
43
|
[(dependent? ? "g_dependent" : nil), (triggered?(response_set) ? nil : "g_hidden"), custom_class].compact.join(" ")
|
44
44
|
end
|
45
|
+
|
46
|
+
def text_for(context = nil, locale = nil)
|
47
|
+
return "" if display_type == "hidden_label"
|
48
|
+
in_context(translation(locale)[:text], context)
|
49
|
+
end
|
50
|
+
def help_text_for(context = nil, locale = nil)
|
51
|
+
in_context(translation(locale)[:help_text], context)
|
52
|
+
end
|
53
|
+
|
54
|
+
def translation(locale)
|
55
|
+
{:text => self.text, :help_text => self.help_text}.with_indifferent_access.merge(
|
56
|
+
(self.questions.first.survey_section.survey.translation(locale)[:question_groups] || {})[self.reference_identifier] || {}
|
57
|
+
)
|
58
|
+
end
|
45
59
|
end
|
46
60
|
end
|
47
61
|
end
|
@@ -14,6 +14,9 @@ module Surveyor
|
|
14
14
|
# Scopes
|
15
15
|
base.send :default_scope, :order => "display_order ASC"
|
16
16
|
|
17
|
+
# Mustache
|
18
|
+
base.send :include, MustacheContext
|
19
|
+
|
17
20
|
@@validations_already_included ||= nil
|
18
21
|
unless @@validations_already_included
|
19
22
|
# Validations
|
@@ -30,8 +33,6 @@ module Surveyor
|
|
30
33
|
base.send :attr_accessible, :survey_section, :question_group, :survey_section_id, :question_group_id, :text, :short_text, :help_text, :pick, :reference_identifier, :data_export_identifier, :common_namespace, :common_identifier, :display_order, :display_type, :is_mandatory, :display_width, :custom_class, :custom_renderer, :correct_answer_id
|
31
34
|
end
|
32
35
|
|
33
|
-
include RenderText
|
34
|
-
|
35
36
|
# Instance Methods
|
36
37
|
def initialize(*args)
|
37
38
|
super(*args)
|
@@ -75,14 +76,40 @@ module Surveyor
|
|
75
76
|
self.question_group.nil?
|
76
77
|
end
|
77
78
|
|
78
|
-
def
|
79
|
-
|
79
|
+
def text_for(position = nil, context = nil, locale = nil)
|
80
|
+
return "" if display_type == "hidden_label"
|
81
|
+
imaged(split(in_context(translation(locale)[:text], context), position))
|
82
|
+
end
|
83
|
+
def help_text_for(context = nil, locale = nil)
|
84
|
+
in_context(translation(locale)[:help_text], context)
|
85
|
+
end
|
86
|
+
def split(text, position=nil)
|
87
|
+
case position
|
88
|
+
when :pre
|
89
|
+
text.split("|",2)[0]
|
90
|
+
when :post
|
91
|
+
text.split("|",2)[1]
|
92
|
+
else
|
93
|
+
text
|
94
|
+
end.to_s
|
80
95
|
end
|
81
|
-
|
82
96
|
def renderer(g = question_group)
|
83
97
|
r = [g ? g.renderer.to_s : nil, display_type].compact.join("_")
|
84
98
|
r.blank? ? :default : r.to_sym
|
85
99
|
end
|
100
|
+
def translation(locale)
|
101
|
+
{:text => self.text, :help_text => self.help_text}.with_indifferent_access.merge(
|
102
|
+
(self.survey_section.survey.translation(locale)[:questions] || {})[self.reference_identifier] || {}
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
|
109
|
+
def imaged(text)
|
110
|
+
self.display_type == "image" && !text.blank? ? ActionController::Base.helpers.image_tag(text) : text
|
111
|
+
end
|
112
|
+
|
86
113
|
end
|
87
114
|
end
|
88
115
|
end
|
@@ -6,10 +6,10 @@ module Surveyor
|
|
6
6
|
base.send :belongs_to, :response_set
|
7
7
|
base.send :belongs_to, :question
|
8
8
|
base.send :belongs_to, :answer
|
9
|
-
|
9
|
+
|
10
10
|
# Scopes
|
11
11
|
base.send :default_scope, :order => "created_at ASC"
|
12
|
-
|
12
|
+
|
13
13
|
@@validations_already_included ||= nil
|
14
14
|
unless @@validations_already_included
|
15
15
|
# Validations
|
@@ -21,7 +21,7 @@ module Surveyor
|
|
21
21
|
|
22
22
|
# Whitelisting attributes
|
23
23
|
base.send :attr_accessible, :response_set, :question, :answer, :date_value, :time_value, :response_set_id, :question_id, :answer_id, :datetime_value, :integer_value, :float_value, :unit, :text_value, :string_value, :response_other, :response_group, :survey_section_id
|
24
|
-
|
24
|
+
|
25
25
|
# Class methods
|
26
26
|
base.instance_eval do
|
27
27
|
def applicable_attributes(attrs)
|
@@ -45,7 +45,7 @@ module Surveyor
|
|
45
45
|
def default_args
|
46
46
|
self.api_id ||= Surveyor::Common.generate_api_id
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def answer_id=(val)
|
50
50
|
write_attribute :answer_id, (val.is_a?(Array) ? val.detect{|x| !x.to_s.blank?} : val)
|
51
51
|
end
|
@@ -58,7 +58,7 @@ module Surveyor
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def time_value=(val)
|
61
|
-
self.datetime_value = Time.zone.parse("#{Date.today.to_s} #{val}").to_datetime
|
61
|
+
self.datetime_value = Time.zone.parse("#{Date.today.to_s} #{val}") ? Time.zone.parse("#{Date.today.to_s} #{val}").to_datetime : nil
|
62
62
|
end
|
63
63
|
|
64
64
|
def date_value
|
@@ -66,7 +66,7 @@ module Surveyor
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def date_value=(val)
|
69
|
-
self.datetime_value = Time.zone.parse(val).to_datetime
|
69
|
+
self.datetime_value = Time.zone.parse(val) ? Time.zone.parse(val).to_datetime : nil
|
70
70
|
end
|
71
71
|
|
72
72
|
def time_format
|
@@ -99,7 +99,7 @@ module Surveyor
|
|
99
99
|
}
|
100
100
|
|
101
101
|
found = formats[answer.response_class]
|
102
|
-
found ? datetime_value.strftime
|
102
|
+
found ? datetime_value.try(:strftime, found) : as(answer.response_class)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -9,19 +9,20 @@ module Surveyor
|
|
9
9
|
base.send :has_many, :sections, :class_name => "SurveySection", :order => 'display_order', :dependent => :destroy
|
10
10
|
base.send :has_many, :sections_with_questions, :include => :questions, :class_name => "SurveySection", :order => 'display_order'
|
11
11
|
base.send :has_many, :response_sets
|
12
|
+
base.send :has_many, :translations, :class_name => "SurveyTranslation"
|
12
13
|
|
13
14
|
# Scopes
|
14
15
|
base.send :scope, :with_sections, {:include => :sections}
|
15
|
-
|
16
|
+
|
16
17
|
@@validations_already_included ||= nil
|
17
18
|
unless @@validations_already_included
|
18
19
|
# Validations
|
19
20
|
base.send :validates_presence_of, :title
|
20
21
|
base.send :validates_uniqueness_of, :survey_version, :scope => :access_code, :message => "survey with matching access code and version already exists"
|
21
|
-
|
22
|
+
|
22
23
|
@@validations_already_included = true
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
# Whitelisting attributes
|
26
27
|
base.send :attr_accessible, :title, :description, :reference_identifier, :data_export_identifier, :common_namespace, :common_identifier, :css_url, :custom_class, :display_order
|
27
28
|
|
@@ -63,9 +64,17 @@ module Surveyor
|
|
63
64
|
self.inactive_at = DateTime.now
|
64
65
|
self.active_at = nil
|
65
66
|
end
|
67
|
+
|
66
68
|
def as_json(options = nil)
|
67
69
|
template_paths = ActionController::Base.view_paths.collect(&:to_path)
|
68
|
-
Rabl.render(
|
70
|
+
Rabl.render(filtered_for_json, 'surveyor/export.json', :view_path => template_paths, :format => "hash")
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# A hook that allows the survey object to be modified before it is
|
75
|
+
# serialized by the #as_json method.
|
76
|
+
def filtered_for_json
|
77
|
+
self
|
69
78
|
end
|
70
79
|
|
71
80
|
def default_access_code
|
@@ -82,6 +91,13 @@ module Surveyor
|
|
82
91
|
|
83
92
|
self.survey_version = next_version
|
84
93
|
end
|
94
|
+
|
95
|
+
def translation(locale_symbol)
|
96
|
+
t = self.translations.where(:locale => locale_symbol.to_s).first
|
97
|
+
{:title => self.title, :description => self.description}.with_indifferent_access.merge(
|
98
|
+
t ? YAML.load(t.translation || "{}").with_indifferent_access : {}
|
99
|
+
)
|
100
|
+
end
|
85
101
|
end
|
86
102
|
end
|
87
103
|
end
|
@@ -7,19 +7,18 @@ module Surveyor
|
|
7
7
|
base.send :belongs_to, :survey
|
8
8
|
|
9
9
|
# Scopes
|
10
|
-
base.send :default_scope, :order => "display_order ASC"
|
11
10
|
base.send :scope, :with_includes, { :include => {:questions => [:answers, :question_group, {:dependency => :dependency_conditions}]}}
|
12
|
-
|
11
|
+
|
13
12
|
@@validations_already_included ||= nil
|
14
13
|
unless @@validations_already_included
|
15
14
|
# Validations
|
16
15
|
base.send :validates_presence_of, :title, :display_order
|
17
16
|
# this causes issues with building and saving
|
18
17
|
#, :survey
|
19
|
-
|
18
|
+
|
20
19
|
@@validations_already_included = true
|
21
20
|
end
|
22
|
-
|
21
|
+
|
23
22
|
# Whitelisting attributes
|
24
23
|
base.send :attr_accessible, :survey, :survey_id, :title, :description, :reference_identifier, :data_export_identifier, :common_namespace, :common_identifier, :display_order, :custom_class
|
25
24
|
end
|
@@ -33,7 +32,7 @@ module Surveyor
|
|
33
32
|
def default_args
|
34
33
|
self.data_export_identifier ||= Surveyor::Common.normalize(title)
|
35
34
|
end
|
36
|
-
|
35
|
+
|
37
36
|
def questions_and_groups
|
38
37
|
qs = []
|
39
38
|
questions.each_with_index.map do |q,i|
|
@@ -46,6 +45,12 @@ module Surveyor
|
|
46
45
|
end
|
47
46
|
end.compact
|
48
47
|
end
|
48
|
+
|
49
|
+
def translation(locale)
|
50
|
+
{:title => self.title, :description => self.description}.with_indifferent_access.merge(
|
51
|
+
(self.survey.translation(locale)[:survey_sections] || {})[self.reference_identifier] || {}
|
52
|
+
)
|
53
|
+
end
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Surveyor
|
2
|
+
module Models
|
3
|
+
module SurveyTranslationMethods
|
4
|
+
def self.included(base)
|
5
|
+
# Associations
|
6
|
+
base.send :belongs_to, :survey
|
7
|
+
|
8
|
+
@@validations_already_included ||= nil
|
9
|
+
unless @@validations_already_included
|
10
|
+
# Validations
|
11
|
+
base.send :validates_presence_of, :locale, :translation
|
12
|
+
base.send :validates_uniqueness_of, :locale, :scope => :survey_id
|
13
|
+
# this causes issues with building and saving
|
14
|
+
#, :survey
|
15
|
+
|
16
|
+
@@validations_already_included = true
|
17
|
+
end
|
18
|
+
|
19
|
+
# Whitelisting attributes
|
20
|
+
base.send :attr_accessible, :survey, :survey_id, :locale, :translation
|
21
|
+
end
|
22
|
+
|
23
|
+
# Instance Methods
|
24
|
+
def initialize(*args)
|
25
|
+
super(*args)
|
26
|
+
default_args
|
27
|
+
end
|
28
|
+
|
29
|
+
def default_args
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/surveyor/parser.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
%w(survey survey_section question_group question dependency dependency_condition answer validation validation_condition).each {|model| require model }
|
1
|
+
%w(survey survey_translation survey_section question_group question dependency dependency_condition answer validation validation_condition).each {|model| require model }
|
2
2
|
module Surveyor
|
3
3
|
class ParserError < StandardError; end
|
4
4
|
class Parser
|
@@ -63,7 +63,7 @@ module Surveyor
|
|
63
63
|
def method_missing(missing_method, *args, &block)
|
64
64
|
method_name, reference_identifier = missing_method.to_s.split("_", 2)
|
65
65
|
type = full(method_name)
|
66
|
-
Surveyor::Parser.raise_error( "\"#{type}\" is not a surveyor method." )if !%w(survey survey_section question_group question dependency dependency_condition answer validation validation_condition).include?(type)
|
66
|
+
Surveyor::Parser.raise_error( "\"#{type}\" is not a surveyor method." )if !%w(survey survey_translation survey_section question_group question dependency dependency_condition answer validation validation_condition).include?(type)
|
67
67
|
|
68
68
|
Surveyor::Parser.rake_trace(reference_identifier.blank? ? "#{type} #{args.map(&:inspect).join ', '}" : "#{type}_#{reference_identifier} #{args.map(&:inspect).join ', '}",
|
69
69
|
block_models.include?(type) ? 2 : 0)
|
@@ -100,6 +100,7 @@ module Surveyor
|
|
100
100
|
|
101
101
|
def full(method_name)
|
102
102
|
case method_name.to_s
|
103
|
+
when /^translations$/; "survey_translation"
|
103
104
|
when /^section$/; "survey_section"
|
104
105
|
when /^g$|^grid$|^group$|^repeater$/; "question_group"
|
105
106
|
when /^q$|^label$|^image$/; "question"
|
@@ -173,6 +174,16 @@ module SurveyorParserSurveyMethods
|
|
173
174
|
end
|
174
175
|
end
|
175
176
|
|
177
|
+
# SurveySection model
|
178
|
+
module SurveyorParserSurveyTranslationMethods
|
179
|
+
def parse_and_build(context, args, original_method, reference_identifier)
|
180
|
+
# build, no change in context
|
181
|
+
args[0].each do |k,v|
|
182
|
+
context[:survey].translations << self.class.new(:locale => k.to_s, :translation => File.read(Rails.root.join("surveys", v)))
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
176
187
|
# SurveySection model
|
177
188
|
module SurveyorParserSurveySectionMethods
|
178
189
|
def parse_and_build(context, args, original_method, reference_identifier)
|
@@ -183,6 +194,7 @@ module SurveyorParserSurveySectionMethods
|
|
183
194
|
title = args[0]
|
184
195
|
self.attributes = ({
|
185
196
|
:title => title,
|
197
|
+
:reference_identifier => reference_identifier,
|
186
198
|
:display_order => context[:survey].sections.size }.merge(args[1] || {}))
|
187
199
|
context[:survey].sections << context[:survey_section] = self
|
188
200
|
end
|
@@ -208,6 +220,7 @@ module SurveyorParserQuestionGroupMethods
|
|
208
220
|
# build and set context
|
209
221
|
self.attributes = ({
|
210
222
|
:text => args[0] || "Question Group",
|
223
|
+
:reference_identifier => reference_identifier,
|
211
224
|
:display_type => (original_method =~ /grid|repeater/ ? original_method : "default")}.merge(args[1] || {}))
|
212
225
|
context[:question_group] = self
|
213
226
|
end
|
@@ -9,19 +9,12 @@ module Surveyor
|
|
9
9
|
base.send :before_filter, :determine_if_javascript_is_enabled, :only => [:create, :update]
|
10
10
|
base.send :before_filter, :set_response_set_and_render_context, :only => [:edit, :show]
|
11
11
|
base.send :layout, 'surveyor_default'
|
12
|
+
base.send :before_filter, :set_locale
|
12
13
|
end
|
13
14
|
|
14
15
|
# Actions
|
15
16
|
def new
|
16
|
-
@
|
17
|
-
@codes = @surveys.inject({}) do |codes,s|
|
18
|
-
codes[s.access_code] ||= {}
|
19
|
-
codes[s.access_code][:title] = s.title
|
20
|
-
codes[s.access_code][:survey_versions] ||= []
|
21
|
-
codes[s.access_code][:survey_versions] << s.survey_version
|
22
|
-
codes
|
23
|
-
end
|
24
|
-
@title = "You can take these surveys"
|
17
|
+
@surveys_by_access_code = Survey.order("created_at DESC, survey_version DESC").all.group_by(&:access_code)
|
25
18
|
redirect_to surveyor_index unless surveyor_index == available_surveys_path
|
26
19
|
end
|
27
20
|
|
@@ -80,6 +73,7 @@ module Surveyor
|
|
80
73
|
end
|
81
74
|
|
82
75
|
def update
|
76
|
+
question_ids_for_dependencies = (params[:r] || []).map{|k,v| v["question_id"] }.compact.uniq
|
83
77
|
saved = load_and_update_response_set_with_retries
|
84
78
|
|
85
79
|
return redirect_with_message(surveyor_finish, :notice, t('surveyor.completed_survey')) if saved && params[:finish]
|
@@ -96,7 +90,7 @@ module Surveyor
|
|
96
90
|
end
|
97
91
|
format.js do
|
98
92
|
if @response_set
|
99
|
-
render :json => @response_set.reload.all_dependencies
|
93
|
+
render :json => @response_set.reload.all_dependencies(question_ids_for_dependencies)
|
100
94
|
else
|
101
95
|
render :text => "No response set #{params[:response_set_code]}",
|
102
96
|
:status => 404
|
@@ -140,12 +134,9 @@ module Surveyor
|
|
140
134
|
|
141
135
|
def export
|
142
136
|
surveys = Survey.where(:access_code => params[:survey_code]).order("survey_version DESC")
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
@survey = surveys.where(:survey_version => params[:survey_version]).first
|
147
|
-
end
|
148
|
-
render_404 and return if @survey.blank?
|
137
|
+
s = params[:survey_version].blank? ? surveys.first : surveys.where(:survey_version => params[:survey_version]).first
|
138
|
+
render_404 and return if s.blank?
|
139
|
+
@survey = s.filtered_for_json
|
149
140
|
end
|
150
141
|
|
151
142
|
def render_404
|
@@ -153,6 +144,10 @@ module Surveyor
|
|
153
144
|
true
|
154
145
|
end
|
155
146
|
|
147
|
+
def url_options
|
148
|
+
((I18n.locale == I18n.default_locale) ? {} : {:locale => I18n.locale}).merge(super)
|
149
|
+
end
|
150
|
+
|
156
151
|
private
|
157
152
|
|
158
153
|
# This is a hook method for surveyor-using applications to override and provide the context object
|
@@ -171,6 +166,14 @@ module Surveyor
|
|
171
166
|
@render_context = render_context
|
172
167
|
end
|
173
168
|
|
169
|
+
def set_locale
|
170
|
+
if params[:locale]
|
171
|
+
I18n.locale = params[:locale]
|
172
|
+
else
|
173
|
+
I18n.locale = I18n.default_locale
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
174
177
|
# Params: the name of some submit buttons store the section we'd like to go
|
175
178
|
# to. for repeater questions, an anchor to the repeater group is also stored
|
176
179
|
# e.g. params[:section] = {"1"=>{"question_group_1"=>"<= add row"}}
|
@@ -227,6 +230,5 @@ module Surveyor
|
|
227
230
|
session[:surveyor_javascript] = "not_enabled"
|
228
231
|
end
|
229
232
|
end
|
230
|
-
|
231
233
|
end
|
232
234
|
end
|
data/lib/surveyor/version.rb
CHANGED