surveyor 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGELOG.md +22 -0
  2. data/Gemfile +1 -1
  3. data/README.md +1 -1
  4. data/Rakefile +4 -1
  5. data/app/views/partials/_answer.html.haml +1 -1
  6. data/app/views/partials/_section_menu.html.haml +8 -1
  7. data/app/views/surveyor/edit.html.haml +1 -1
  8. data/app/views/surveyor/new.html.haml +1 -1
  9. data/app/views/surveyor/show.html.haml +17 -20
  10. data/ci-exec.sh +1 -1
  11. data/config/routes.rb +7 -7
  12. data/features/internationalization.feature +68 -2
  13. data/features/show_survey.feature +29 -0
  14. data/features/step_definitions/parser_steps.rb +15 -0
  15. data/features/step_definitions/surveyor_steps.rb +11 -9
  16. data/features/support/paths.rb +5 -2
  17. data/features/z_redcap_parser.feature +4 -1
  18. data/lib/assets/javascripts/surveyor/jquery.surveyor.js +5 -1
  19. data/lib/assets/stylesheets/surveyor.sass +2 -0
  20. data/lib/generators/surveyor/install_generator.rb +4 -0
  21. data/lib/generators/surveyor/templates/app/controllers/surveyor_controller.rb +2 -2
  22. data/lib/generators/surveyor/templates/config/locales/surveyor_en.yml +1 -0
  23. data/lib/generators/surveyor/templates/config/locales/surveyor_es.yml +1 -0
  24. data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +1 -0
  25. data/lib/generators/surveyor/templates/config/locales/surveyor_ko.yml +2 -1
  26. data/lib/generators/surveyor/templates/surveys/languages.rb +9 -5
  27. data/lib/generators/surveyor/templates/surveys/translations/languages.es.yml +4 -0
  28. data/lib/generators/surveyor/templates/surveys/translations/languages.he.yml +4 -0
  29. data/lib/generators/surveyor/templates/surveys/translations/languages.ko.yml +4 -0
  30. data/lib/surveyor/helpers/surveyor_helper_methods.rb +1 -1
  31. data/lib/surveyor/models/answer_methods.rb +2 -2
  32. data/lib/surveyor/models/question_methods.rb +3 -3
  33. data/lib/surveyor/models/response_methods.rb +18 -5
  34. data/lib/surveyor/models/response_set_methods.rb +1 -1
  35. data/lib/surveyor/models/survey_methods.rb +2 -2
  36. data/lib/surveyor/models/survey_section_methods.rb +2 -2
  37. data/lib/surveyor/parser.rb +25 -4
  38. data/lib/surveyor/redcap_parser.rb +13 -13
  39. data/lib/surveyor/surveyor_controller_methods.rb +22 -19
  40. data/lib/surveyor/version.rb +1 -1
  41. data/lib/tasks/surveyor_tasks.rake +1 -1
  42. data/spec/controllers/surveyor_controller_spec.rb +155 -269
  43. data/spec/lib/parser_spec.rb +189 -21
  44. data/spec/models/response_set_spec.rb +7 -5
  45. data/spec/spec_helper.rb +3 -1
  46. data/stacktests.sh +1 -1
  47. data/surveyor.gemspec +3 -1
  48. metadata +271 -275
@@ -14,7 +14,10 @@ Feature: Survey import from REDCap
14
14
  And there should be 233 answers with:
15
15
  ||
16
16
  And there should be 3 resolved dependency_conditions with:
17
- ||
17
+ | rule_key | operator | question_reference | answer_reference |
18
+ | A | == | sex | 0 |
19
+ | A | == | sex | 0 |
20
+ | B | == | given_birth | 1 |
18
21
  And there should be 2 dependencies with:
19
22
  | rule |
20
23
  | A |
@@ -35,7 +35,7 @@ jQuery(document).ready(function(){
35
35
  jQuery("input[type='text'].datetime").datetimepicker({
36
36
  showSecond: true,
37
37
  showMillisec: false,
38
- timeFormat: 'hh:mm:ss',
38
+ timeFormat: 'HH:mm:ss',
39
39
  dateFormat: 'yy-mm-dd',
40
40
  changeMonth: true,
41
41
  changeYear: true
@@ -147,4 +147,8 @@ jQuery(document).ready(function(){
147
147
  $(e).mask(inputMask, options);
148
148
  });
149
149
 
150
+ // translations selection
151
+ $(".surveyor_language_selection").show();
152
+ $(".surveyor_language_selection select#locale").change(function(){ this.form.submit(); });
153
+
150
154
  });
@@ -47,6 +47,8 @@ body
47
47
  :border-bottom-width 1px
48
48
  li.active, li.active input[type="submit"]
49
49
  :background-color $surveyor_menus_active_color
50
+ .surveyor_language_selection
51
+ :display none
50
52
  //.previous_section
51
53
  .next_section
52
54
  :float right
@@ -69,6 +69,10 @@ module Surveyor
69
69
  end
70
70
  end
71
71
 
72
+ def routes
73
+ route('mount Surveyor::Engine => "/surveys", :as => "surveyor"')
74
+ end
75
+
72
76
  def assets
73
77
  if asset_pipeline_enabled?
74
78
  directory "app/assets"
@@ -27,11 +27,11 @@ module SurveyorControllerCustomMethods
27
27
  # Paths
28
28
  def surveyor_index
29
29
  # most of the above actions redirect to this method
30
- super # available_surveys_path
30
+ super # surveyor.available_surveys_path
31
31
  end
32
32
  def surveyor_finish
33
33
  # the update action redirects to this method if given params[:finish]
34
- super # available_surveys_path
34
+ super # surveyor.available_surveys_path
35
35
  end
36
36
  end
37
37
  class SurveyorController < ApplicationController
@@ -16,3 +16,4 @@ en:
16
16
  next_section: "Next section &raquo;"
17
17
  select_one: "Select one ..."
18
18
  sections: "Sections"
19
+ language: "Language"
@@ -16,3 +16,4 @@ es:
16
16
  next_section: "Sección siguiente &raquo;"
17
17
  select_one: "Seleccione una ..."
18
18
  sections: "Secciones"
19
+ language: "Idioma"
@@ -16,3 +16,4 @@ he:
16
16
  next_section: "&laquo; המשך"
17
17
  select_one: "בחר/י"
18
18
  sections: "סעיפים"
19
+ language: "שפה"
@@ -15,4 +15,5 @@ ko:
15
15
  previous_section: "&laquo; 이전 항목으로"
16
16
  next_section: "다음 항목으로 &raquo;"
17
17
  select_one: "하나를 선택하십시요"
18
- sections: "항목"
18
+ sections: "항목"
19
+ language: "언어"
@@ -1,10 +1,14 @@
1
1
  # encoding: UTF-8
2
2
  survey "One language is never enough" do
3
- translations :es => "translations/languages.es.yml", :he => "translations/languages.he.yml", :ko => "translations/languages.ko.yml"
3
+ translations :en =>:default, :es => "translations/languages.es.yml", :he => "translations/languages.he.yml", :ko => "translations/languages.ko.yml"
4
4
  section_one "One" do
5
5
  g_hello "Hello" do
6
- q_name "What is your name?"
7
- a_name :string, :help_text => "My name is..."
8
- end
6
+ q_name "What is your name?"
7
+ a_name :string, :help_text => "My name is..."
8
+ end
9
9
  end
10
- end
10
+ section_two "Two" do
11
+ q_color "What is your favorite color?"
12
+ a_name :string
13
+ end
14
+ end
@@ -3,6 +3,8 @@ title: "Un idioma nunca es suficiente"
3
3
  survey_sections:
4
4
  one:
5
5
  title: "Uno"
6
+ two:
7
+ title: "Dos"
6
8
  question_groups:
7
9
  hello:
8
10
  text: "¡Hola!"
@@ -12,3 +14,5 @@ questions:
12
14
  answers:
13
15
  name:
14
16
  help_text: "Mi nombre es..."
17
+ color:
18
+ text: "¿Cuál es tu color favorito?"
@@ -3,6 +3,8 @@ title: "ידיעת שפה אחת אינה מספיקה"
3
3
  survey_sections:
4
4
  one:
5
5
  title: "אחת"
6
+ two:
7
+ title: "שנים"
6
8
  question_groups:
7
9
  hello:
8
10
  text: "שלום"
@@ -12,3 +14,5 @@ questions:
12
14
  answers:
13
15
  name:
14
16
  help_text: "שמי..."
17
+ color:
18
+ text: "מהו הצבע האהוב עליך?"
@@ -3,6 +3,8 @@ title: "한가지 언어로는 충분치 않습니다."
3
3
  survey_sections:
4
4
  one:
5
5
  title: "하나"
6
+ two:
7
+ title: "두"
6
8
  question_groups:
7
9
  hello:
8
10
  text: "안녕하십니까"
@@ -12,3 +14,5 @@ questions:
12
14
  answers:
13
15
  name:
14
16
  help_text: "제 이름은 ... 입니다"
17
+ color:
18
+ text: "좋아하는 색은 무엇입니까?"
@@ -79,7 +79,7 @@ module Surveyor
79
79
  def generate_pick_none_input_html(value, default_value, css_class, response_class, disabled, input_mask, input_mask_placeholder)
80
80
  html = {}
81
81
  html[:class] = [response_class,css_class].reject{ |c| c.blank? }
82
- html[:value] = default_value if value.blank?
82
+ html[:value] = value.blank? ? default_value : value
83
83
  html[:disabled] = disabled unless disabled.blank?
84
84
  if input_mask
85
85
  html[:'data-input-mask'] = input_mask
@@ -10,7 +10,7 @@ module Surveyor
10
10
  base.send :has_many, :validations, :dependent => :destroy
11
11
 
12
12
  # Scopes
13
- base.send :default_scope, :order => "display_order ASC"
13
+ base.send :default_scope, :order => "#{base.quoted_table_name}.display_order ASC"
14
14
 
15
15
  # Mustache
16
16
  base.send :include, MustacheContext
@@ -83,4 +83,4 @@ module Surveyor
83
83
  end
84
84
  end
85
85
  end
86
- end
86
+ end
@@ -7,12 +7,12 @@ module Surveyor
7
7
  # Associations
8
8
  base.send :belongs_to, :survey_section
9
9
  base.send :belongs_to, :question_group, :dependent => :destroy
10
- base.send :has_many, :answers, :order => "display_order ASC", :dependent => :destroy # it might not always have answers
10
+ base.send :has_many, :answers, :dependent => :destroy # it might not always have answers
11
11
  base.send :has_one, :dependency, :dependent => :destroy
12
12
  base.send :belongs_to, :correct_answer, :class_name => "Answer", :dependent => :destroy
13
13
 
14
14
  # Scopes
15
- base.send :default_scope, :order => "display_order ASC"
15
+ base.send :default_scope, :order => "#{base.quoted_table_name}.display_order ASC"
16
16
 
17
17
  # Mustache
18
18
  base.send :include, MustacheContext
@@ -112,4 +112,4 @@ module Surveyor
112
112
 
113
113
  end
114
114
  end
115
- end
115
+ end
@@ -7,9 +7,6 @@ module Surveyor
7
7
  base.send :belongs_to, :question
8
8
  base.send :belongs_to, :answer
9
9
 
10
- # Scopes
11
- base.send :default_scope, :order => "created_at ASC"
12
-
13
10
  @@validations_already_included ||= nil
14
11
  unless @@validations_already_included
15
12
  # Validations
@@ -78,7 +75,23 @@ module Surveyor
78
75
  end
79
76
 
80
77
  def datetime_format
81
- '%Y-%m-%d %H:%M'
78
+ '%Y-%m-%d %H:%M:%S'
79
+ end
80
+
81
+ def to_formatted_s
82
+ return "" if answer.nil? || answer.response_class.nil?
83
+ return case t = answer.response_class.to_sym
84
+ when :string, :text, :integer, :float
85
+ send("#{t}_value".to_sym).to_s
86
+ when :date
87
+ date_value
88
+ when :time
89
+ time_value
90
+ when :datetime
91
+ read_attribute(:datetime_value).strftime(datetime_format)
92
+ else
93
+ to_s
94
+ end
82
95
  end
83
96
 
84
97
  def to_s # used in dependency_explanation_helper
@@ -99,7 +112,7 @@ module Surveyor
99
112
  }
100
113
 
101
114
  found = formats[answer.response_class]
102
- found ? datetime_value.try(:strftime, found) : as(answer.response_class)
115
+ found ? datetime_value.try{|d| d.utc.strftime(found)} : as(answer.response_class)
103
116
  end
104
117
  end
105
118
  end
@@ -7,7 +7,7 @@ module Surveyor
7
7
  # Associations
8
8
  base.send :belongs_to, :survey
9
9
  base.send :belongs_to, :user
10
- base.send :has_many, :responses, :dependent => :destroy
10
+ base.send :has_many, :responses, :order => "#{Response.quoted_table_name}.created_at ASC", :dependent => :destroy
11
11
  base.send :accepts_nested_attributes_for, :responses, :allow_destroy => true
12
12
 
13
13
  @@validations_already_included ||= nil
@@ -6,8 +6,8 @@ module Surveyor
6
6
  module SurveyMethods
7
7
  def self.included(base)
8
8
  # Associations
9
- base.send :has_many, :sections, :class_name => "SurveySection", :order => 'display_order', :dependent => :destroy
10
- base.send :has_many, :sections_with_questions, :include => :questions, :class_name => "SurveySection", :order => 'display_order'
9
+ base.send :has_many, :sections, :class_name => "SurveySection", :order => "#{SurveySection.quoted_table_name}.display_order", :dependent => :destroy
10
+ base.send :has_many, :sections_with_questions, :include => :questions, :class_name => "SurveySection", :order => "#{SurveySection.quoted_table_name}.display_order"
11
11
  base.send :has_many, :response_sets
12
12
  base.send :has_many, :translations, :class_name => "SurveyTranslation"
13
13
 
@@ -3,7 +3,7 @@ module Surveyor
3
3
  module SurveySectionMethods
4
4
  def self.included(base)
5
5
  # Associations
6
- base.send :has_many, :questions, :order => "display_order ASC", :dependent => :destroy
6
+ base.send :has_many, :questions, :dependent => :destroy
7
7
  base.send :belongs_to, :survey
8
8
 
9
9
  # Scopes
@@ -53,4 +53,4 @@ module Surveyor
53
53
  end
54
54
  end
55
55
  end
56
- end
56
+ end
@@ -1,4 +1,7 @@
1
1
  %w(survey survey_translation survey_section question_group question dependency dependency_condition answer validation validation_condition).each {|model| require model }
2
+
3
+ require 'yaml'
4
+
2
5
  module Surveyor
3
6
  class ParserError < StandardError; end
4
7
  class Parser
@@ -8,6 +11,9 @@ module Surveyor
8
11
  attr_accessor :context
9
12
 
10
13
  # Class methods
14
+ def self.parse_file(filename, options={})
15
+ self.parse(File.read(filename),{:filename => filename}.merge(options))
16
+ end
11
17
  def self.parse(str, options={})
12
18
  self.ensure_attrs
13
19
  self.options = options
@@ -82,6 +88,7 @@ module Surveyor
82
88
  resolve_dependency_condition_references
83
89
  resolve_question_correct_answers
84
90
  report_lost_and_duplicate_references
91
+ report_missing_default_locale
85
92
  Surveyor::Parser.rake_trace("", -2)
86
93
  if context[:survey].save
87
94
  Surveyor::Parser.rake_trace "Survey saved."
@@ -116,6 +123,11 @@ module Surveyor
116
123
  def block_models
117
124
  %w(survey survey_section question_group)
118
125
  end
126
+ def report_missing_default_locale
127
+ if !self.context[:survey].translations.empty? && self.context[:survey].translations.select{|t|YAML::load(t.translation)=={}}.empty?
128
+ Surveyor::Parser.raise_error("No default locale specified for translations.",true)
129
+ end
130
+ end
119
131
  def report_lost_and_duplicate_references
120
132
  Surveyor::Parser.raise_error("Bad references: #{self.context[:bad_references].join("; ")}", true) unless self.context[:bad_references].empty?
121
133
  Surveyor::Parser.raise_error("Duplicate references: #{self.context[:duplicate_references].join("; ")}", true) unless self.context[:duplicate_references].empty?
@@ -177,9 +189,18 @@ end
177
189
  # SurveySection model
178
190
  module SurveyorParserSurveyTranslationMethods
179
191
  def parse_and_build(context, args, original_method, reference_identifier)
192
+ dir = Surveyor::Parser.options[:filename].nil? ? Dir.pwd : File.dirname(Surveyor::Parser.options[:filename])
180
193
  # build, no change in context
181
194
  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)))
195
+ case v
196
+ when Hash
197
+ trans = YAML::dump(v)
198
+ when String
199
+ trans = File.read(File.join(dir,v))
200
+ when :default
201
+ trans = YAML::dump({})
202
+ end
203
+ context[:survey].translations << self.class.new(:locale => k.to_s, :translation => trans)
183
204
  end
184
205
  end
185
206
  end
@@ -337,10 +358,10 @@ module SurveyorParserAnswerMethods
337
358
  self.attributes = ({:display_order => context[:question].answers.size}.merge(attrs))
338
359
  context[:question].answers << context[:answer] = self
339
360
  # keep reference for dependencies
340
- unless context[:question].reference_identifier.blank? or reference_identifier.blank?
361
+ unless context[:question].reference_identifier.blank? or self.reference_identifier.blank?
341
362
  context[:answer_references][context[:question].reference_identifier] ||= {}
342
- context[:duplicate_references].push "q_#{context[:question].reference_identifier}, a_#{reference_identifier}" if context[:answer_references][context[:question].reference_identifier].has_key?(reference_identifier)
343
- context[:answer_references][context[:question].reference_identifier][reference_identifier] = context[:answer]
363
+ context[:duplicate_references].push "q_#{context[:question].reference_identifier}, a_#{self.reference_identifier}" if context[:answer_references][context[:question].reference_identifier].has_key?(self.reference_identifier)
364
+ context[:answer_references][context[:question].reference_identifier][self.reference_identifier] = context[:answer]
344
365
  end
345
366
  end
346
367
  end
@@ -62,16 +62,15 @@ module Surveyor
62
62
  end
63
63
  def resolve_references
64
64
  context[:dependency_conditions].each do |dc|
65
- return unless dc.lookup_reference
66
65
  Surveyor::RedcapParser.rake_trace "resolve(#{dc.question_reference},#{dc.answer_reference})"
67
- if dc.answer_reference.blank? and (row = dc.lookup_reference.find{|r| r[0] == dc.question_reference and r[1] == nil}) and row[2].answers.size == 1
66
+ if dc.answer_reference.blank? and (context[:question_references][dc.question_reference].answers.size == 1)
68
67
  Surveyor::RedcapParser.rake_trace "...found "
69
- dc.question = row[2]
68
+ dc.question = context[:question_references][dc.question_reference]
70
69
  dc.answer = dc.question.answers.first
71
- elsif row = dc.lookup_reference.find{|r| r[0] == dc.question_reference and r[1] == dc.answer_reference}
70
+ elsif answer = context[:answer_references][dc.question_reference][dc.answer_reference]
72
71
  Surveyor::RedcapParser.rake_trace "...found "
73
- dc.answer = row[2]
74
- dc.question = dc.answer.question
72
+ dc.answer = answer
73
+ dc.question = context[:question_references][dc.question_reference]
75
74
  else
76
75
  Surveyor::RedcapParser.rake_trace "\n!!! failed lookup for dependency_condition q: #{question_reference} a: #{question_reference}"
77
76
  end
@@ -118,8 +117,8 @@ module SurveyorRedcapParserQuestionMethods
118
117
  })
119
118
  context[:survey_section].questions << context[:question] = self
120
119
  unless context[:question].reference_identifier.blank?
121
- context[:lookup] ||= []
122
- context[:lookup] << [context[:question].reference_identifier, nil, context[:question]]
120
+ context[:question_references] ||= {}
121
+ context[:question_references][context[:question].reference_identifier] = context[:question]
123
122
  end
124
123
  Surveyor::RedcapParser.rake_trace "question_#{context[:question].reference_identifier} "
125
124
  end
@@ -141,7 +140,7 @@ module SurveyorRedcapParserDependencyMethods
141
140
  self.attributes = {:rule => hash[:rule]}
142
141
  context[:question].dependency = context[:dependency] = self
143
142
  hash[:components].each do |component|
144
- dc = context[:dependency].dependency_conditions.build(decompose_component(component).merge(:lookup_reference => context[:lookup], :rule_key => letters.shift))
143
+ dc = context[:dependency].dependency_conditions.build(decompose_component(component).merge({ :rule_key => letters.shift } ))
145
144
  context[:dependency_conditions] << dc
146
145
  end
147
146
  Surveyor::RedcapParser.rake_trace "dependency(#{hash[:rule]}) "
@@ -193,8 +192,8 @@ end
193
192
  # DependencyCondition model
194
193
  module SurveyorRedcapParserDependencyConditionMethods
195
194
  DependencyCondition.instance_eval do
196
- attr_accessor :question_reference, :answer_reference, :lookup_reference
197
- attr_accessible :question_reference, :answer_reference, :lookup_reference
195
+ attr_accessor :question_reference, :answer_reference
196
+ attr_accessible :question_reference, :answer_reference
198
197
  end
199
198
  end
200
199
 
@@ -228,8 +227,9 @@ module SurveyorRedcapParserAnswerMethods
228
227
  :display_order => context[:question].answers.size })
229
228
  context[:question].answers << context[:answer] = a
230
229
  unless context[:question].reference_identifier.blank? or aref.blank? or !context[:answer].valid?
231
- context[:lookup] ||= []
232
- context[:lookup] << [context[:question].reference_identifier, aref, context[:answer]]
230
+ context[:answer_references] ||= {}
231
+ context[:answer_references][context[:question].reference_identifier] ||= {}
232
+ context[:answer_references][context[:question].reference_identifier][aref] = context[:answer]
233
233
  end
234
234
  Surveyor::RedcapParser.rake_trace "#{context[:answer].errors.full_messages}, #{context[:answer].inspect}" unless context[:answer].valid?
235
235
  Surveyor::RedcapParser.rake_trace "answer_#{context[:answer].reference_identifier} "
@@ -15,7 +15,7 @@ module Surveyor
15
15
  # Actions
16
16
  def new
17
17
  @surveys_by_access_code = Survey.order("created_at DESC, survey_version DESC").all.group_by(&:access_code)
18
- redirect_to surveyor_index unless surveyor_index == available_surveys_path
18
+ redirect_to surveyor_index unless surveyor_index == surveyor.available_surveys_path
19
19
  end
20
20
 
21
21
  def create
@@ -29,7 +29,7 @@ module Surveyor
29
29
  create(:survey => @survey, :user_id => (@current_user.nil? ? @current_user : @current_user.id))
30
30
  if (@survey && @response_set)
31
31
  flash[:notice] = t('surveyor.survey_started_success')
32
- redirect_to(edit_my_survey_path(
32
+ redirect_to(surveyor.edit_my_survey_path(
33
33
  :survey_code => @survey.access_code, :response_set_code => @response_set.access_code))
34
34
  else
35
35
  flash[:notice] = t('surveyor.Unable_to_find_that_survey')
@@ -60,11 +60,7 @@ module Surveyor
60
60
  if @response_set
61
61
  @survey = Survey.with_sections.find_by_id(@response_set.survey_id)
62
62
  @sections = @survey.sections
63
- if params[:section]
64
- @section = @sections.with_includes.find(section_id_from(params[:section])) || @sections.with_includes.first
65
- else
66
- @section = @sections.with_includes.first
67
- end
63
+ @section = @sections.with_includes.find(section_id_from(params) || :first) || @sections.with_includes.first
68
64
  set_dependents
69
65
  else
70
66
  flash[:notice] = t('surveyor.unable_to_find_your_responses')
@@ -81,11 +77,10 @@ module Surveyor
81
77
  respond_to do |format|
82
78
  format.html do
83
79
  if @response_set.nil?
84
- return redirect_with_message(available_surveys_path, :notice, t('surveyor.unable_to_find_your_responses'))
80
+ return redirect_with_message(surveyor.available_surveys_path, :notice, t('surveyor.unable_to_find_your_responses'))
85
81
  else
86
82
  flash[:notice] = t('surveyor.unable_to_update_survey') unless saved
87
- redirect_to edit_my_survey_path(
88
- :anchor => anchor_from(params[:section]), :section => section_id_from(params[:section]))
83
+ redirect_to surveyor.edit_my_survey_path(:anchor => anchor_from(params[:section]), :section => section_id_from(params))
89
84
  end
90
85
  end
91
86
  format.js do
@@ -167,18 +162,26 @@ module Surveyor
167
162
  end
168
163
 
169
164
  def set_locale
170
- if params[:locale]
171
- I18n.locale = params[:locale]
172
- else
173
- I18n.locale = I18n.default_locale
174
- end
165
+ if params[:new_locale]
166
+ I18n.locale = params[:new_locale]
167
+ elsif params[:locale]
168
+ I18n.locale = params[:locale]
169
+ else
170
+ I18n.locale = I18n.default_locale
171
+ end
175
172
  end
176
173
 
177
174
  # Params: the name of some submit buttons store the section we'd like to go
178
175
  # to. for repeater questions, an anchor to the repeater group is also stored
179
176
  # e.g. params[:section] = {"1"=>{"question_group_1"=>"<= add row"}}
180
- def section_id_from(p)
181
- p.respond_to?(:keys) ? p.keys.first : p
177
+ def section_id_from(p = {})
178
+ if p[:section] && p[:section].respond_to?(:keys)
179
+ p[:section].keys.first
180
+ elsif p[:section]
181
+ p[:section]
182
+ elsif p[:current_section]
183
+ p[:current_section]
184
+ end
182
185
  end
183
186
 
184
187
  def anchor_from(p)
@@ -186,10 +189,10 @@ module Surveyor
186
189
  end
187
190
 
188
191
  def surveyor_index
189
- available_surveys_path
192
+ surveyor.available_surveys_path
190
193
  end
191
194
  def surveyor_finish
192
- available_surveys_path
195
+ surveyor.available_surveys_path
193
196
  end
194
197
 
195
198
  def redirect_with_message(path, message_type, message)