jakewendt-surveyor 0.11.3
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +285 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/app/controllers/surveyor_controller.rb +142 -0
- data/app/helpers/survey_form_builder.rb +37 -0
- data/app/helpers/surveyor_helper.rb +67 -0
- data/app/models/answer.rb +23 -0
- data/app/models/dependency.rb +50 -0
- data/app/models/dependency_condition.rb +47 -0
- data/app/models/question.rb +54 -0
- data/app/models/question_group.rb +33 -0
- data/app/models/response.rb +94 -0
- data/app/models/response_set.rb +316 -0
- data/app/models/survey.rb +172 -0
- data/app/models/survey_section.rb +18 -0
- data/app/models/validation.rb +38 -0
- data/app/models/validation_condition.rb +47 -0
- data/app/views/layouts/surveyor_default.html.erb +13 -0
- data/app/views/partials/_answer.html.haml +58 -0
- data/app/views/partials/_question.html.haml +80 -0
- data/app/views/partials/_question_group.html.haml +39 -0
- data/app/views/surveyor/edit.html.haml +38 -0
- data/app/views/surveyor/new.html.haml +16 -0
- data/app/views/surveyor/show.html.haml +12 -0
- data/config/routes.rb +11 -0
- data/features/step_definitions/surveyor_steps.rb +7 -0
- data/features/step_definitions/web_steps.rb +273 -0
- data/features/support/env.rb +57 -0
- data/features/support/paths.rb +25 -0
- data/features/surveyor.feature +11 -0
- data/generators/extend_surveyor/extend_surveyor_generator.rb +22 -0
- data/generators/extend_surveyor/templates/EXTENDING_SURVEYOR +17 -0
- data/generators/extend_surveyor/templates/extensions/survey_extensions.rb +24 -0
- data/generators/extend_surveyor/templates/extensions/surveyor_controller_extensions.rb +28 -0
- data/generators/extend_surveyor/templates/extensions/surveyor_custom.html.erb +13 -0
- data/generators/extend_surveyor/templates/extensions/surveyor_helper_extensions.rb +17 -0
- data/generators/surveyor/surveyor_generator.rb +67 -0
- data/generators/surveyor/templates/README +10 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_resize_se.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_35x9_colorpicker_indicator.gif.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/dadada_40x100_textures_02_glass_75.png +0 -0
- data/generators/surveyor/templates/assets/images/e6e6e6_40x100_textures_02_glass_75.png +0 -0
- data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_01_flat_0.png +0 -0
- data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_02_glass_65.png +0 -0
- data/generators/surveyor/templates/assets/javascripts/accessibleUISlider.jQuery.js +201 -0
- data/generators/surveyor/templates/assets/javascripts/jquery-1.2.6.js +3549 -0
- data/generators/surveyor/templates/assets/javascripts/jquery-ui-personalized-1.5.3.js +7616 -0
- data/generators/surveyor/templates/assets/javascripts/jquery.form.js +637 -0
- data/generators/surveyor/templates/assets/javascripts/surveyor.js +47 -0
- data/generators/surveyor/templates/assets/stylesheets/jquery-ui-slider-additions.css +71 -0
- data/generators/surveyor/templates/assets/stylesheets/reset.css +50 -0
- data/generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass +243 -0
- data/generators/surveyor/templates/assets/stylesheets/surveyor.css +235 -0
- data/generators/surveyor/templates/assets/stylesheets/ui.theme.css +851 -0
- data/generators/surveyor/templates/initializers/haml.rb +8 -0
- data/generators/surveyor/templates/initializers/surveyor.rb +10 -0
- data/generators/surveyor/templates/migrate/add_correct_answer_id_to_questions.rb +9 -0
- data/generators/surveyor/templates/migrate/add_display_order_to_surveys.rb +9 -0
- data/generators/surveyor/templates/migrate/add_index_to_response_sets.rb +9 -0
- data/generators/surveyor/templates/migrate/add_index_to_surveys.rb +9 -0
- data/generators/surveyor/templates/migrate/add_manual_numbering.rb +11 -0
- data/generators/surveyor/templates/migrate/add_unique_indicies.rb +17 -0
- data/generators/surveyor/templates/migrate/create_answers.rb +37 -0
- data/generators/surveyor/templates/migrate/create_dependencies.rb +22 -0
- data/generators/surveyor/templates/migrate/create_dependency_conditions.rb +29 -0
- data/generators/surveyor/templates/migrate/create_question_groups.rb +27 -0
- data/generators/surveyor/templates/migrate/create_questions.rb +36 -0
- data/generators/surveyor/templates/migrate/create_response_sets.rb +22 -0
- data/generators/surveyor/templates/migrate/create_responses.rb +33 -0
- data/generators/surveyor/templates/migrate/create_survey_sections.rb +29 -0
- data/generators/surveyor/templates/migrate/create_surveys.rb +31 -0
- data/generators/surveyor/templates/migrate/create_validation_conditions.rb +32 -0
- data/generators/surveyor/templates/migrate/create_validations.rb +20 -0
- data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +218 -0
- data/generators/surveyor/templates/tasks/surveyor.rb +4 -0
- data/generators/test_surveyor/templates/TESTING_SURVEYOR +0 -0
- data/generators/test_surveyor/templates/environments/cucumber.rb +21 -0
- data/generators/test_surveyor/test_surveyor_generator.rb +15 -0
- data/jakewendt-surveyor.gemspec +212 -0
- data/lib/fixtures_extensions.rb +6 -0
- data/lib/jakewendt-surveyor.rb +1 -0
- data/lib/surveyor.rb +44 -0
- data/lib/surveyor/acts_as_response.rb +33 -0
- data/lib/surveyor/config.rb +45 -0
- data/lib/tasks/surveyor_tasks.rake +33 -0
- data/lib/xml_formatter.rb +12 -0
- data/rails/init.rb +1 -0
- data/script/surveyor/answer.rb +54 -0
- data/script/surveyor/base.rb +77 -0
- data/script/surveyor/dependency.rb +13 -0
- data/script/surveyor/dependency_condition.rb +40 -0
- data/script/surveyor/parser.rb +207 -0
- data/script/surveyor/question.rb +37 -0
- data/script/surveyor/question_group.rb +26 -0
- data/script/surveyor/specs/answer_spec.rb +29 -0
- data/script/surveyor/specs/question_spec.rb +63 -0
- data/script/surveyor/specs/spec_helper.rb +7 -0
- data/script/surveyor/specs/survey_section_spec.rb +23 -0
- data/script/surveyor/specs/validation_condition_spec.rb +20 -0
- data/script/surveyor/specs/validation_spec.rb +20 -0
- data/script/surveyor/survey.rb +35 -0
- data/script/surveyor/survey_section.rb +21 -0
- data/script/surveyor/validation.rb +21 -0
- data/script/surveyor/validation_condition.rb +21 -0
- data/script/surveyor/whr_dsl.tmproj +244 -0
- data/spec/controllers/surveyor_controller_spec.rb +193 -0
- data/spec/factories.rb +145 -0
- data/spec/lib/surveyor_spec.rb +44 -0
- data/spec/models/answer_spec.rb +29 -0
- data/spec/models/dependency_condition_spec.rb +321 -0
- data/spec/models/dependency_spec.rb +81 -0
- data/spec/models/question_group_spec.rb +35 -0
- data/spec/models/question_spec.rb +75 -0
- data/spec/models/response_set_spec.rb +245 -0
- data/spec/models/response_spec.rb +76 -0
- data/spec/models/survey_section_spec.rb +32 -0
- data/spec/models/survey_spec.rb +71 -0
- data/spec/models/validation_condition_spec.rb +105 -0
- data/spec/models/validation_spec.rb +59 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +12 -0
- metadata +254 -0
@@ -0,0 +1,172 @@
|
|
1
|
+
class Survey < ActiveRecord::Base
|
2
|
+
|
3
|
+
# Extending surveyor
|
4
|
+
include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
|
5
|
+
|
6
|
+
# Associations
|
7
|
+
has_many :sections, :class_name => "SurveySection", :order => 'display_order'
|
8
|
+
has_many :sections_with_questions, :include => :questions, :class_name => "SurveySection", :order => 'display_order'
|
9
|
+
has_many :response_sets
|
10
|
+
has_many :questions, :through => :sections
|
11
|
+
|
12
|
+
# Scopes
|
13
|
+
named_scope :with_sections, {:include => :sections}
|
14
|
+
|
15
|
+
# Validations
|
16
|
+
validates_presence_of :title
|
17
|
+
validates_uniqueness_of :access_code
|
18
|
+
|
19
|
+
# Class methods
|
20
|
+
def self.to_normalized_string(value)
|
21
|
+
# replace non-alphanumeric with "-". remove repeat "-"s. don't start or end with "-"
|
22
|
+
value.to_s.downcase.gsub(/[^a-z0-9]/,"-").gsub(/-+/,"-").gsub(/-$|^-/,"")
|
23
|
+
end
|
24
|
+
|
25
|
+
# Instance methods
|
26
|
+
def initialize(*args)
|
27
|
+
super(*args)
|
28
|
+
default_args
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_args
|
32
|
+
self.inactive_at ||= DateTime.now
|
33
|
+
end
|
34
|
+
|
35
|
+
def title=(value)
|
36
|
+
self.access_code = Survey.to_normalized_string(value)
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
def active?
|
41
|
+
self.active_as_of?(DateTime.now)
|
42
|
+
end
|
43
|
+
def active_as_of?(datetime)
|
44
|
+
(self.active_at.nil? or self.active_at < datetime) and (self.inactive_at.nil? or self.inactive_at > datetime)
|
45
|
+
end
|
46
|
+
def activate!
|
47
|
+
self.active_at = DateTime.now
|
48
|
+
end
|
49
|
+
def deactivate!
|
50
|
+
self.inactive_at = DateTime.now
|
51
|
+
end
|
52
|
+
def active_at=(datetime)
|
53
|
+
self.inactive_at = nil if !datetime.nil? and !self.inactive_at.nil? and self.inactive_at < datetime
|
54
|
+
super(datetime)
|
55
|
+
end
|
56
|
+
def inactive_at=(datetime)
|
57
|
+
self.active_at = nil if !datetime.nil? and !self.active_at.nil? and self.active_at > datetime
|
58
|
+
super(datetime)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
# Survey access_code not guaranteed to be unique
|
64
|
+
#
|
65
|
+
# As there is no model validation or unique index in the
|
66
|
+
# database, there is no guarantee that your survey access_code
|
67
|
+
# will be unique. It is just a normalized version of your
|
68
|
+
# survey title.
|
69
|
+
#
|
70
|
+
# Running ...
|
71
|
+
#
|
72
|
+
# rake surveyor FILE=surveys/kitchen_sink_survey.rb APPEND=true
|
73
|
+
# rake surveyor FILE=surveys/kitchen_sink_survey.rb APPEND=true
|
74
|
+
# script/console
|
75
|
+
# Survey.all.collect(&:access_code)
|
76
|
+
#
|
77
|
+
# should show this to be true.
|
78
|
+
#
|
79
|
+
# This will show both surveys as able to be taken, but will
|
80
|
+
# only allow the first one when the attempt is made as the
|
81
|
+
# survey is found by
|
82
|
+
#
|
83
|
+
#
|
84
|
+
# @survey = Survey.find_by_access_code(params[:survey_code])
|
85
|
+
#
|
86
|
+
#
|
87
|
+
# In addition, adding a unique index to the db and model will
|
88
|
+
# make a mess when running
|
89
|
+
#
|
90
|
+
# rake surveyor FILE=surveys/kitchen_sink_survey.rb APPEND=true
|
91
|
+
# rake surveyor FILE=surveys/kitchen_sink_survey.rb APPEND=true
|
92
|
+
#
|
93
|
+
# as the access_code is not unique and the survey fixtures are
|
94
|
+
# loaded last, leaving the associations with an invalid survey_id.
|
95
|
+
# To avoid this, the survey fixture should probably be attempted first.
|
96
|
+
#
|
97
|
+
#
|
98
|
+
# Update...
|
99
|
+
#
|
100
|
+
# Adding something like ...
|
101
|
+
#
|
102
|
+
# def access_code=(value)
|
103
|
+
# counter = 2
|
104
|
+
# original_value = value
|
105
|
+
# while( ( survey = Survey.find_by_access_code(value) ) &&
|
106
|
+
# ( self.id != survey.id ) )
|
107
|
+
# value = [original_value,"_",counter].join
|
108
|
+
# counter += 1
|
109
|
+
# end
|
110
|
+
# super
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# ... to Survey seems to provide a "fix" for this "problem",
|
114
|
+
# although I don't know how kosher it is.
|
115
|
+
#
|
116
|
+
# It works in my test environment, but does not actually work
|
117
|
+
# in the "rake surveyor" task as the survey is built from a
|
118
|
+
# different Survey model completely and then loaded into the
|
119
|
+
# database and not created though the application.
|
120
|
+
#
|
121
|
+
# My final "fix" was to add
|
122
|
+
#
|
123
|
+
# require 'lib/surveyor/survey_extensions'
|
124
|
+
#
|
125
|
+
# to my Rakefile and create the file
|
126
|
+
#
|
127
|
+
# > cat lib/surveyor/survey_extensions.rb
|
128
|
+
# if surveyor_gem = Gem.searcher.find('surveyor')
|
129
|
+
# require surveyor_gem.full_gem_path + '/script/surveyor/parser'
|
130
|
+
# require surveyor_gem.full_gem_path + '/script/surveyor/survey'
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# module SurveyParser
|
134
|
+
# module SurveyExtensions
|
135
|
+
# def self.included(base)
|
136
|
+
# base.class_eval do
|
137
|
+
# def initialize_with_unique_access_code(obj, args, opts)
|
138
|
+
# initialize_without_unique_access_code(obj, args, opts)
|
139
|
+
# counter = 2
|
140
|
+
# ac = self.access_code
|
141
|
+
# original_ac = self.access_code
|
142
|
+
# while( survey = ::Survey.find_by_access_code(ac) )
|
143
|
+
# ac = [original_ac,"_",counter].join
|
144
|
+
# counter += 1
|
145
|
+
# end
|
146
|
+
# self.access_code = ac
|
147
|
+
# end
|
148
|
+
# alias_method_chain :initialize, :unique_access_code
|
149
|
+
# end
|
150
|
+
# end
|
151
|
+
# end
|
152
|
+
# end
|
153
|
+
# SurveyParser::Survey.send(:include, SurveyParser::SurveyExtensions)
|
154
|
+
#
|
155
|
+
# It is not as clean as I would've liked, but works.
|
156
|
+
# Override the setting of the access_code to ensure its uniqueness
|
157
|
+
#
|
158
|
+
# While uniqueness was added after 0.10.0, this method
|
159
|
+
# was not deemed important or likely to be needed enough.
|
160
|
+
# It is true that this really isn't NEEDed.
|
161
|
+
def access_code=(value)
|
162
|
+
counter = 2
|
163
|
+
original_value = value
|
164
|
+
while( ( survey = Survey.find_by_access_code(value) ) &&
|
165
|
+
( self.id != survey.id ) )
|
166
|
+
value = [original_value,"_",counter].join
|
167
|
+
counter += 1
|
168
|
+
end
|
169
|
+
super #(value)
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class SurveySection < ActiveRecord::Base
|
2
|
+
|
3
|
+
# Extending surveyor
|
4
|
+
include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
|
5
|
+
|
6
|
+
# Associations
|
7
|
+
has_many :questions, :order => "display_order ASC"
|
8
|
+
belongs_to :survey
|
9
|
+
|
10
|
+
# Scopes
|
11
|
+
default_scope :order => "display_order ASC"
|
12
|
+
named_scope :with_includes, { :include => {:questions => [:answers, :question_group, {:dependency => :dependency_conditions}]}}
|
13
|
+
|
14
|
+
# Validations
|
15
|
+
validates_presence_of :title, :survey, :display_order
|
16
|
+
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Validation < ActiveRecord::Base
|
2
|
+
|
3
|
+
# Extending surveyor
|
4
|
+
include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
|
5
|
+
|
6
|
+
|
7
|
+
# Associations
|
8
|
+
belongs_to :answer
|
9
|
+
has_many :validation_conditions
|
10
|
+
|
11
|
+
# Scopes
|
12
|
+
|
13
|
+
# Validations
|
14
|
+
validates_presence_of :rule
|
15
|
+
validates_format_of :rule, :with => /^(?:and|or|\)|\(|[A-Z]|\s)+$/
|
16
|
+
validates_numericality_of :answer_id
|
17
|
+
|
18
|
+
# Instance Methods
|
19
|
+
def is_valid?(response_set)
|
20
|
+
ch = conditions_hash(response_set)
|
21
|
+
rgx = Regexp.new(self.validation_conditions.map{|vc| ["a","o"].include?(vc.rule_key) ? "#{vc.rule_key}(?!nd|r)" : vc.rule_key}.join("|")) # exclude and, or
|
22
|
+
# logger.debug "v: #{self.inspect}"
|
23
|
+
# logger.debug "rule: #{self.rule.inspect}"
|
24
|
+
# logger.debug "rexp: #{rgx.inspect}"
|
25
|
+
# logger.debug "keyp: #{ch.inspect}"
|
26
|
+
# logger.debug "subd: #{self.rule.gsub(rgx){|m| ch[m.to_sym]}}"
|
27
|
+
eval(self.rule.gsub(rgx){|m| ch[m.to_sym]})
|
28
|
+
end
|
29
|
+
|
30
|
+
# A hash of the conditions (keyed by rule_key) and their evaluation (boolean) in the context of response_set
|
31
|
+
def conditions_hash(response_set)
|
32
|
+
hash = {}
|
33
|
+
response = response_set.responses.detect{|r| r.answer_id.to_i == self.answer_id.to_i}
|
34
|
+
# logger.debug "r: #{response.inspect}"
|
35
|
+
self.validation_conditions.each{|vc| hash.merge!(vc.to_hash(response))}
|
36
|
+
return hash
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class ValidationCondition < ActiveRecord::Base
|
2
|
+
|
3
|
+
# Extending surveyor
|
4
|
+
include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
|
5
|
+
|
6
|
+
# Constants
|
7
|
+
OPERATORS = %w(== != < > <= >= =~)
|
8
|
+
|
9
|
+
# Associations
|
10
|
+
belongs_to :validation
|
11
|
+
|
12
|
+
# Scopes
|
13
|
+
|
14
|
+
# Validations
|
15
|
+
validates_numericality_of :validation_id #, :question_id, :answer_id
|
16
|
+
validates_presence_of :operator, :rule_key
|
17
|
+
validates_inclusion_of :operator, :in => OPERATORS
|
18
|
+
validates_uniqueness_of :rule_key, :scope => :validation_id
|
19
|
+
|
20
|
+
acts_as_response # includes "as" instance method
|
21
|
+
|
22
|
+
# Class methods
|
23
|
+
def self.operators
|
24
|
+
OPERATORS
|
25
|
+
end
|
26
|
+
|
27
|
+
# Instance Methods
|
28
|
+
def to_hash(response)
|
29
|
+
{rule_key.to_sym => (response.nil? ? false : self.is_valid?(response))}
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_valid?(response)
|
33
|
+
klass = response.answer.response_class
|
34
|
+
compare_to = Response.find_by_question_id_and_answer_id(self.question_id, self.answer_id) || self
|
35
|
+
case self.operator
|
36
|
+
when "==", "<", ">", "<=", ">="
|
37
|
+
response.as(klass).send(self.operator, compare_to.as(klass))
|
38
|
+
when "!="
|
39
|
+
!(response.as(klass) == compare_to.as(klass))
|
40
|
+
when "=~"
|
41
|
+
return false if compare_to != self
|
42
|
+
!(response.as(klass).to_s =~ Regexp.new(self.regexp || "")).nil?
|
43
|
+
else
|
44
|
+
false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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: <%= controller.action_name %></title>
|
7
|
+
<%= surveyor_includes %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<div id="flash"><%= flash[:notice] %></div>
|
11
|
+
<%= yield %>
|
12
|
+
</body>
|
13
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
- renderer = answer.renderer(question)
|
2
|
+
- response_group ||= nil
|
3
|
+
- hide_label ||= false
|
4
|
+
- disabled ||= false
|
5
|
+
- fields_for_response(response_obj, response_group) do |response_form|
|
6
|
+
- case renderer
|
7
|
+
- when :any_answer
|
8
|
+
= response_form.survey_check_box(:selected, :class => (answer.is_exclusive? ? "exclusive" : ""))
|
9
|
+
= response_form.label("selected", answer.text) unless hide_label # This is a temp fix til I figure out why the id of the checkbox is all jacked up
|
10
|
+
- when :any_other_and_string
|
11
|
+
= response_form.survey_check_box(:selected, :class => (answer.is_exclusive? ? "exclusive" : ""))
|
12
|
+
%label Other
|
13
|
+
= response_form.text_field(:other_value)
|
14
|
+
= response_form.text_field(:string_value)
|
15
|
+
- when :any_string
|
16
|
+
= response_form.survey_check_box(:selected, :class => (answer.is_exclusive? ? "exclusive" : ""))
|
17
|
+
= response_form.label(:answer_id, answer.text)
|
18
|
+
= response_form.text_field(:string_value, :size => 25, :maxlength => 250)
|
19
|
+
- when :one_answer, :one_string, :one_integer
|
20
|
+
- fields_for_radio(response_obj) do |radio_form|
|
21
|
+
= radio_form.radio_button(:answer_id, answer.id, :checked => response_obj.selected?, :title => answer.text)
|
22
|
+
= radio_form.label("answer_id_#{answer.id}", split_text(answer.text)[:prefix]) unless hide_label
|
23
|
+
- if renderer == :one_string
|
24
|
+
= response_form.text_field(:string_value, :size => 25, :maxlength => 250, :autocomplete => "off")
|
25
|
+
- if renderer == :one_integer
|
26
|
+
= response_form.text_field(:integer_value, :size => 5, :maxlength => 10, :autocomplete => "off")
|
27
|
+
= radio_form.label("answer_id_#{answer.id}", split_text(answer.text)[:postfix]) unless hide_label
|
28
|
+
- when :none_date
|
29
|
+
= response_form.label(:datetime_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
30
|
+
= response_form.text_field(:datetime_value)
|
31
|
+
= response_form.label(:datetime_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
32
|
+
- when :none_datetime
|
33
|
+
= response_form.label(:datetime_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
34
|
+
= response_form.datetime_select(:datetime_value, {:include_blank => true})
|
35
|
+
= response_form.label(:datetime_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
36
|
+
- when :none_float
|
37
|
+
= response_form.label(:float_value, split_text(answer.text)[:prefix]) unless hide_label
|
38
|
+
= response_form.text_field(:float_value, :size => 5, :maxlength => 10, :autocomplete => "off")
|
39
|
+
= response_form.label(:float_value, split_text(answer.text)[:postfix]) unless hide_label
|
40
|
+
- when :none_integer
|
41
|
+
= response_form.label(:integer_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
42
|
+
= response_form.text_field(:integer_value, :size => 5, :maxlength => 10, :autocomplete => "off", :disabled => disabled)
|
43
|
+
= response_form.label(:integer_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
44
|
+
- when :none_string
|
45
|
+
= response_form.label(:string_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
46
|
+
= response_form.text_field(:string_value, :size => 25, :maxlength => 250, :autocomplete => "off", :disabled => disabled)
|
47
|
+
= response_form.label(:string_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
48
|
+
- when :none_text
|
49
|
+
= response_form.label(:text_value, split_text(answer.text)[:prefix]) unless hide_label
|
50
|
+
= response_form.text_area(:text_value, :cols => 80, :rows => 10)
|
51
|
+
= response_form.label(:text_value, split_text(answer.text)[:postfix]) unless hide_label
|
52
|
+
- when :none_time
|
53
|
+
= response_form.label(:datetime_value, split_text(answer.text)[:prefix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
54
|
+
= response_form.time_select(:datetime_value,{ :include_blank => true })
|
55
|
+
= response_form.label(:datetime_value, split_text(answer.text)[:postfix], :class => "#{(disabled)? 'disabled' : 'enabled'}") unless hide_label
|
56
|
+
- else
|
57
|
+
= answer.text
|
58
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
- renderer = question.renderer(question_group ||= nil)
|
2
|
+
- case renderer
|
3
|
+
- when :label
|
4
|
+
- div_for question, :class => "label #{question.css_class(response_set)}" do
|
5
|
+
- if question.survey_section.survey.manual_numbering && question.number
|
6
|
+
.number= question.number #||' '
|
7
|
+
%span.text= question.text
|
8
|
+
%span.help= question.help_text
|
9
|
+
- when :image
|
10
|
+
.image= image_tag(question.text)
|
11
|
+
- when :dropdown, :slider
|
12
|
+
- if renderer == :slider
|
13
|
+
%script{:type => "text/javascript"}= "$(function(){$('#slider_#{question.id}').accessibleUISlider({width: 400, labels:#{question.answers.size} }).hide();});"
|
14
|
+
- div_for question, :class => question.css_class(response_set) do
|
15
|
+
- if question.survey_section.survey.manual_numbering
|
16
|
+
.number= question.number||' '
|
17
|
+
- else
|
18
|
+
.number= next_number unless question.dependent?
|
19
|
+
%fieldset
|
20
|
+
%legend{:style => "display:inline;"}
|
21
|
+
%span.text= question.text
|
22
|
+
%span.help= question.help_text
|
23
|
+
= hidden_field_tag("responses[#{question.id}][question_id]", question.id)
|
24
|
+
%ol.answers
|
25
|
+
%li.answer
|
26
|
+
- options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
|
27
|
+
= renderer == :slider ? select_tag("responses[#{question.id}][answer_id]", options, {:id => "slider_#{question.id}"}) : select_tag("responses[#{question.id}][answer_id]", ["<option value=''>Select one...</option>"].concat(options))
|
28
|
+
- when :grid_default
|
29
|
+
- reset_cycle("col")
|
30
|
+
- content_tag_for :tr, question, :class => question.css_class(response_set) do
|
31
|
+
%th.question_prefix
|
32
|
+
%span.text= split_text(question.text)[:prefix]
|
33
|
+
%span.help= question.help_text
|
34
|
+
= hidden_field_tag("responses[#{question.id}][question_id]", question.id)
|
35
|
+
- question.answers.each do |answer|
|
36
|
+
%td{:class => "#{cycle("column_highlight", "", :name => "col")}"}
|
37
|
+
.answer{:class => answer.custom_class}= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => true})
|
38
|
+
%th.question_postfix
|
39
|
+
%span.text= split_text(question.text)[:postfix]
|
40
|
+
- when :repeater_default, :repeater_dropdown
|
41
|
+
- disabled ||= false
|
42
|
+
- div_for question, :class => "#{disabled ? 'dis' : 'en'}abled #{question.css_class(response_set)}" do
|
43
|
+
%span.text= question.text
|
44
|
+
%span.help= question.help_text
|
45
|
+
= hidden_field_tag("response_groups[#{question.id}][#{response_group}][response_group]", response_group)
|
46
|
+
= hidden_field_tag("response_groups[#{question.id}][#{response_group}][question_id]", question.id)
|
47
|
+
%br
|
48
|
+
%ol.answers
|
49
|
+
- if renderer == :repeater_default
|
50
|
+
- question.answers.each do |answer|
|
51
|
+
- content_tag_for :li, answer, :class => answer.custom_class do
|
52
|
+
= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id, response_group), :response_group => response_group, :hide_label => true, :disabled => disabled})
|
53
|
+
- else
|
54
|
+
%li.answer
|
55
|
+
- options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id, response_group).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
|
56
|
+
= select_tag("response_groups[#{question.id}][#{response_group}][answer_id]", ["<option value=''>Select one...</option>"].concat(options), :disabled => disabled)
|
57
|
+
- when :inline_default, :inline_dropdown
|
58
|
+
- div_for question, :class => "inline #{question.css_class(response_set)}" do
|
59
|
+
= hidden_field_tag("responses[#{question.id}][question_id]", question.id)
|
60
|
+
- if renderer == :inline_default
|
61
|
+
- question.answers.each do |answer|
|
62
|
+
.answer{:class => answer.custom_class}= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
|
63
|
+
- else
|
64
|
+
- options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
|
65
|
+
= select_tag("responses[#{question.id}][answer_id]", ["<option value=''>Select one...</option>"].concat(options))
|
66
|
+
- else # :default, :inline
|
67
|
+
- div_for question, :class => question.css_class(response_set) do
|
68
|
+
- if question.survey_section.survey.manual_numbering
|
69
|
+
.number= question.number||' '
|
70
|
+
- else
|
71
|
+
.number= next_number unless question.dependent?
|
72
|
+
%fieldset
|
73
|
+
%legend
|
74
|
+
%span.text= question.text
|
75
|
+
%span.help= question.help_text
|
76
|
+
= hidden_field_tag("responses[#{question.id}][question_id]", question.id)
|
77
|
+
%ol.answers{:class => renderer == :inline ? "inline" : nil}
|
78
|
+
- question.answers.each do |answer|
|
79
|
+
- content_tag_for :li, answer, :class => answer.custom_class do
|
80
|
+
= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
|
@@ -0,0 +1,39 @@
|
|
1
|
+
- renderer = question_group.renderer
|
2
|
+
- locals = {:question_group => question_group, :response_set => response_set, :hide_label => true}
|
3
|
+
- div_for question_group, :class => question_group.css_class(response_set) do
|
4
|
+
.head
|
5
|
+
.number= next_number
|
6
|
+
%span.text= question_group.text
|
7
|
+
%span.help= question_group.help_text
|
8
|
+
|
9
|
+
- case question_group.renderer
|
10
|
+
- when :grid
|
11
|
+
%table.grid
|
12
|
+
%thead
|
13
|
+
%tr
|
14
|
+
%th= " "
|
15
|
+
- reset_cycle("column_highlight")
|
16
|
+
- group_questions.first.answers.each do |answer|
|
17
|
+
%th{:class => "#{cycle("column_highlight", "", :name => "column_highlight")}"}= answer.text
|
18
|
+
%tbody
|
19
|
+
- group_questions.each_with_index do |question, i|
|
20
|
+
= render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question}))
|
21
|
+
- if i%10 == 9
|
22
|
+
%th= " "
|
23
|
+
- reset_cycle("column_highlight")
|
24
|
+
- group_questions.first.answers.each do |answer|
|
25
|
+
%th{:class => "#{cycle("column_highlight", "", :name => "column_highlight")}"}= answer.text
|
26
|
+
- when :repeater
|
27
|
+
%ul.repeater
|
28
|
+
- (response_set.count_group_responses(group_questions) + 1).times do |group_number|
|
29
|
+
%li.repeater
|
30
|
+
- group_questions.each do |question|
|
31
|
+
= render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question, :response_group => group_number, :disabled => false}))
|
32
|
+
%li.repeater
|
33
|
+
- group_questions.each do |question|
|
34
|
+
= render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question, :response_group => 9999, :disabled => true}))
|
35
|
+
= submit_tag("<= add row", :name => "section[#{group_questions.first.survey_section_id}]question_group_#{question_group.id}", :class => "add_row")
|
36
|
+
- else # :inline
|
37
|
+
%ul
|
38
|
+
- group_questions.each do |question|
|
39
|
+
%li{:class => question_group.renderer == :inline ? "inline" : nil}= render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question}))
|