breakpointer-surveyor 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/MIT-LICENSE +20 -0
- data/README.md +20 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/app/controllers/answers_controller.rb +87 -0
- data/app/controllers/dependencies_controller.rb +87 -0
- data/app/controllers/dependency_conditions_controller.rb +87 -0
- data/app/controllers/questions_controller.rb +85 -0
- data/app/controllers/sections_controller.rb +87 -0
- data/app/controllers/surveying_controller.rb +139 -0
- data/app/controllers/surveys_controller.rb +87 -0
- data/app/helpers/answers_helper.rb +2 -0
- data/app/helpers/application_helper.rb +3 -0
- data/app/helpers/questions_helper.rb +2 -0
- data/app/helpers/sections_helper.rb +2 -0
- data/app/helpers/survey_form_builder.rb +38 -0
- data/app/helpers/survey_importer_helper.rb +2 -0
- data/app/helpers/surveying_helper.rb +91 -0
- data/app/helpers/surveys_helper.rb +2 -0
- data/app/models/answer.rb +18 -0
- data/app/models/dependency.rb +43 -0
- data/app/models/dependency_condition.rb +76 -0
- data/app/models/question.rb +44 -0
- data/app/models/question_group.rb +5 -0
- data/app/models/response.rb +58 -0
- data/app/models/response_set.rb +174 -0
- data/app/models/survey.rb +54 -0
- data/app/models/survey_section.rb +19 -0
- data/app/models/user.rb +5 -0
- data/app/views/answer_display_types/_any_answer.html.haml +3 -0
- data/app/views/answer_display_types/_any_other_and_string.html.haml +5 -0
- data/app/views/answer_display_types/_any_string.html.haml +4 -0
- data/app/views/answer_display_types/_date.html.haml +3 -0
- data/app/views/answer_display_types/_datetime.html.haml +2 -0
- data/app/views/answer_display_types/_default.html.haml +1 -0
- data/app/views/answer_display_types/_float.html.haml +5 -0
- data/app/views/answer_display_types/_grid_any_answer.html.haml +2 -0
- data/app/views/answer_display_types/_grid_default.html.haml +2 -0
- data/app/views/answer_display_types/_grid_float.html.haml +2 -0
- data/app/views/answer_display_types/_grid_integer.html.haml +2 -0
- data/app/views/answer_display_types/_grid_one_answer.html.haml +2 -0
- data/app/views/answer_display_types/_grid_string.html.haml +2 -0
- data/app/views/answer_display_types/_integer.html.haml +6 -0
- data/app/views/answer_display_types/_one_answer.html.haml +3 -0
- data/app/views/answer_display_types/_one_string.html.haml +6 -0
- data/app/views/answer_display_types/_repeater_integer.html.haml +6 -0
- data/app/views/answer_display_types/_repeater_string.html.haml +7 -0
- data/app/views/answer_display_types/_string.html.haml +7 -0
- data/app/views/answer_display_types/_text.html.haml +6 -0
- data/app/views/answer_display_types/_time.html.haml +2 -0
- data/app/views/layouts/surveys.html.erb +17 -0
- data/app/views/question_display_types/_default.html.haml +12 -0
- data/app/views/question_display_types/_dropdown.html.haml +12 -0
- data/app/views/question_display_types/_grid_default.html.haml +14 -0
- data/app/views/question_display_types/_grid_dropdown.html.haml +15 -0
- data/app/views/question_display_types/_group_default.html.haml +8 -0
- data/app/views/question_display_types/_group_dropdown.html.haml +6 -0
- data/app/views/question_display_types/_image.html.haml +2 -0
- data/app/views/question_display_types/_inline.html.haml +12 -0
- data/app/views/question_display_types/_label.html.haml +4 -0
- data/app/views/question_display_types/_repeater_default.html.haml +10 -0
- data/app/views/question_display_types/_repeater_dropdown.html.haml +8 -0
- data/app/views/question_display_types/_slider.html.haml +17 -0
- data/app/views/question_group_display_types/_default.html.haml +13 -0
- data/app/views/question_group_display_types/_grid.html.haml +24 -0
- data/app/views/question_group_display_types/_repeater.html.haml +20 -0
- data/app/views/surveying/edit.html.haml +38 -0
- data/app/views/surveying/finish.html.haml +1 -0
- data/app/views/surveying/index.html.erb +19 -0
- data/app/views/surveying/new.html.haml +17 -0
- data/app/views/surveying/show.html.haml +8 -0
- data/config/routes.rb +10 -0
- data/generators/surveyor/surveyor_generator.rb +38 -0
- data/generators/surveyor/templates/README +9 -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 +35 -0
- data/generators/surveyor/templates/assets/stylesheets/jquery-ui-slider-additions.css +71 -0
- data/generators/surveyor/templates/assets/stylesheets/reset.css +46 -0
- data/generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass +321 -0
- data/generators/surveyor/templates/assets/stylesheets/surveyor.css +245 -0
- data/generators/surveyor/templates/assets/stylesheets/ui.theme.css +851 -0
- data/generators/surveyor/templates/migrate/create_answers.rb +46 -0
- data/generators/surveyor/templates/migrate/create_dependencies.rb +21 -0
- data/generators/surveyor/templates/migrate/create_dependency_conditions.rb +29 -0
- data/generators/surveyor/templates/migrate/create_question_groups.rb +18 -0
- data/generators/surveyor/templates/migrate/create_questions.rb +33 -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 +25 -0
- data/generators/surveyor/templates/migrate/create_surveys.rb +25 -0
- data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +201 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/tasks/surveyor_tasks.rake +29 -0
- data/lib/tiny_code.rb +58 -0
- data/lib/user_manager.rb +9 -0
- data/lib/xml_formatter.rb +12 -0
- data/script/surveyor/answer.rb +84 -0
- data/script/surveyor/columnizer.rb +36 -0
- data/script/surveyor/dependency.rb +43 -0
- data/script/surveyor/dependency_condition.rb +74 -0
- data/script/surveyor/dslparse.rb +66 -0
- data/script/surveyor/question.rb +76 -0
- data/script/surveyor/question_group.rb +33 -0
- data/script/surveyor/specs/answer_spec.rb +66 -0
- data/script/surveyor/specs/question_dependency_spec.rb +46 -0
- data/script/surveyor/specs/question_group_spec.rb +9 -0
- data/script/surveyor/specs/question_spec.rb +111 -0
- data/script/surveyor/specs/section_spec.rb +58 -0
- data/script/surveyor/survey.rb +108 -0
- data/script/surveyor/survey_section.rb +153 -0
- data/script/surveyor/whr_dsl.tmproj +244 -0
- data/spec/controllers/answers_controller_spec.rb +64 -0
- data/spec/controllers/dependencies_controller_spec.rb +63 -0
- data/spec/controllers/dependency_conditions_controller_spec.rb +64 -0
- data/spec/controllers/questions_controller_spec.rb +64 -0
- data/spec/controllers/sections_controller_spec.rb +64 -0
- data/spec/controllers/surveying_controller_spec.rb +328 -0
- data/spec/controllers/surveying_routing_spec.rb +45 -0
- data/spec/controllers/surveys_controller_spec.rb +64 -0
- data/spec/fixtures/answers.yml +9 -0
- data/spec/fixtures/dependencies.yml +7 -0
- data/spec/fixtures/dependency_conditions.yml +27 -0
- data/spec/fixtures/question_groups.yml +7 -0
- data/spec/fixtures/questions.yml +15 -0
- data/spec/fixtures/response_sets.yml +13 -0
- data/spec/fixtures/responses.yml +9 -0
- data/spec/fixtures/survey_sections.yml +11 -0
- data/spec/fixtures/surveys.yml +9 -0
- data/spec/fixtures/users.yml +7 -0
- data/spec/helpers/survey_importer_helper_spec.rb +11 -0
- data/spec/helpers/surveying_helper_spec.rb +11 -0
- data/spec/models/answer_spec.rb +62 -0
- data/spec/models/dependency_condition_spec.rb +347 -0
- data/spec/models/dependency_spec.rb +82 -0
- data/spec/models/question_group_spec.rb +11 -0
- data/spec/models/question_spec.rb +70 -0
- data/spec/models/response_set_spec.rb +172 -0
- data/spec/models/response_spec.rb +94 -0
- data/spec/models/survey_section_spec.rb +34 -0
- data/spec/models/survey_spec.rb +72 -0
- data/spec/models/user_spec.rb +11 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +72 -0
- data/spec/views/app/edit.html.erb_spec.rb +20 -0
- data/spec/views/app/index.html.erb_spec.rb +19 -0
- data/spec/views/app/new.html.erb_spec.rb +21 -0
- data/spec/views/app/show.html.erb_spec.rb +17 -0
- data/surveyor.gemspec +258 -0
- data/uninstall.rb +1 -0
- metadata +286 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
class SectionsController < ApplicationController
|
|
2
|
+
|
|
3
|
+
# GET /sections
|
|
4
|
+
# GET /sections.xml
|
|
5
|
+
def index
|
|
6
|
+
@sections = SurveySection.find(:all)
|
|
7
|
+
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.html # index.html.erb
|
|
10
|
+
format.xml { render :xml => @sections }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# GET /sections/1
|
|
15
|
+
# GET /sections/1.xml
|
|
16
|
+
def show
|
|
17
|
+
@section = SurveySection.find(params[:id])
|
|
18
|
+
|
|
19
|
+
respond_to do |format|
|
|
20
|
+
format.html # show.html.erb
|
|
21
|
+
format.xml { render :xml => @section.to_xml(:include => :questions) }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# GET /sections/new
|
|
26
|
+
# GET /sections/new.xml
|
|
27
|
+
def new
|
|
28
|
+
@section = SurveySection.new
|
|
29
|
+
|
|
30
|
+
respond_to do |format|
|
|
31
|
+
format.html # new.html.erb
|
|
32
|
+
format.xml { render :xml => @section }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# GET /sections/1/edit
|
|
37
|
+
def edit
|
|
38
|
+
@section = SurveySection.find(params[:id])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# POST /sections
|
|
42
|
+
# POST /sections.xml
|
|
43
|
+
def create
|
|
44
|
+
@section = SurveySection.new(params[:section])
|
|
45
|
+
|
|
46
|
+
respond_to do |format|
|
|
47
|
+
if @section.save
|
|
48
|
+
flash[:notice] = 'Section was successfully created.'
|
|
49
|
+
format.html { redirect_to(@section) }
|
|
50
|
+
format.xml { render :xml => @section, :status => :created, :location => @section }
|
|
51
|
+
else
|
|
52
|
+
format.html { render :action => "new" }
|
|
53
|
+
format.xml { render :xml => @section.errors, :status => :unprocessable_entity }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# PUT /sections/1
|
|
59
|
+
# PUT /sections/1.xml
|
|
60
|
+
def update
|
|
61
|
+
@section = SurveySection.find(params[:id])
|
|
62
|
+
|
|
63
|
+
respond_to do |format|
|
|
64
|
+
if @section.update_attributes(params[:section])
|
|
65
|
+
flash[:notice] = 'Section was successfully updated.'
|
|
66
|
+
format.html { redirect_to(@section) }
|
|
67
|
+
format.xml { head :ok }
|
|
68
|
+
else
|
|
69
|
+
format.html { render :action => "edit" }
|
|
70
|
+
format.xml { render :xml => @section.errors, :status => :unprocessable_entity }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# DELETE /sections/1
|
|
76
|
+
# DELETE /sections/1.xml
|
|
77
|
+
def destroy
|
|
78
|
+
@section = SurveySection.find(params[:id])
|
|
79
|
+
@section.destroy
|
|
80
|
+
|
|
81
|
+
respond_to do |format|
|
|
82
|
+
format.html { redirect_to(sections_url) }
|
|
83
|
+
format.xml { head :ok }
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
|
|
2
|
+
# The Surveying controller handles the process of a user taking a survey.
|
|
3
|
+
# It is semi-restful since it does not have a concrete representation model.
|
|
4
|
+
# The "resource" could be considered a survey attempt or survey session.
|
|
5
|
+
# It is actually the union of a user filling out a survey and populating a response set.
|
|
6
|
+
|
|
7
|
+
class SurveyingController < ActionController::Base
|
|
8
|
+
layout 'layouts/surveys'
|
|
9
|
+
|
|
10
|
+
include UserManager
|
|
11
|
+
include SurveyingHelper
|
|
12
|
+
before_filter :current_user
|
|
13
|
+
before_filter :get_response_set, :except => [:new, :create]
|
|
14
|
+
|
|
15
|
+
def index
|
|
16
|
+
@surveys = Survey.find(:all)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def new
|
|
20
|
+
@surveys = Survey.find(:all)
|
|
21
|
+
respond_to do |format|
|
|
22
|
+
format.html # new.html.erb
|
|
23
|
+
# format.xml { render :xml => @surveys }
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create
|
|
28
|
+
@survey = Survey.find_by_access_code(params[:survey_code])
|
|
29
|
+
unless @survey
|
|
30
|
+
flash[:notice] = "Unable to find that survey"
|
|
31
|
+
redirect_to(available_surveys_path)
|
|
32
|
+
else
|
|
33
|
+
@response_set = ResponseSet.new(:survey => @survey, :user_id => 123)
|
|
34
|
+
respond_to do |format|
|
|
35
|
+
if @response_set.save!
|
|
36
|
+
flash[:notice] = 'Survey was successfully created.'
|
|
37
|
+
format.html { redirect_to(edit_my_survey_path(:survey_code => @survey.access_code, :response_set_code => @response_set.access_code)) }
|
|
38
|
+
# format.xml { render :xml => @response_set, :status => :created, :location => @response_set }
|
|
39
|
+
else
|
|
40
|
+
format.html { redirect_to(available_surveys_path)}
|
|
41
|
+
# format.xml { render :xml => @response_set.errors, :status => :unprocessable_entity }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def show
|
|
48
|
+
respond_to do |format|
|
|
49
|
+
format.html # show.html.erb
|
|
50
|
+
# format.xml { render :xml => @survey}
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def edit
|
|
55
|
+
# Checking from the questions on the page (which are in the response hash) if there are any dependent questions to show
|
|
56
|
+
dependent_hash = dependents(@response_set)
|
|
57
|
+
@dependents = dependent_hash[:show]
|
|
58
|
+
respond_to do |format|
|
|
59
|
+
format.html do
|
|
60
|
+
render
|
|
61
|
+
end
|
|
62
|
+
format.json do
|
|
63
|
+
render :json => {:show => dependent_hash[:show].map{|q| question_id_helper(q)}, :hide => dependent_hash[:hide].map{|q| question_id_helper(q)} }.to_json
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def update
|
|
69
|
+
if params[:responses] or params[:response_groups]
|
|
70
|
+
saved = @response_set.update_attributes(:response_attributes => (params[:responses] || {}).dup , :response_group_attributes => (params[:response_groups] || {}).dup) #copy (dup) to preserve params because we manipulate params in the response_set methods
|
|
71
|
+
end
|
|
72
|
+
respond_to do |format|
|
|
73
|
+
format.html do
|
|
74
|
+
flash[:notice] = saved ? "Updated survey" : "Unable to update survey" unless saved.nil? # Saved is nil if there are no questions on the page (ie if it only contains a label)
|
|
75
|
+
redirect_to :action => "edit", :anchor => @anchor, :params => {:section => @section.id}
|
|
76
|
+
end
|
|
77
|
+
# No redirect needed if we're talking to the page via json
|
|
78
|
+
format.json do
|
|
79
|
+
dependent_hash = dependents(@response_set)
|
|
80
|
+
@dependents = dependent_hash[:show]
|
|
81
|
+
render :json => {:show => dependent_hash[:show].map{|q| question_id_helper(q)}, :hide => dependent_hash[:hide].map{|q| question_id_helper(q)} }.to_json
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def finish
|
|
89
|
+
respond_to do |format|
|
|
90
|
+
format.html do
|
|
91
|
+
flash[:notice] = @response_set.complete! ? "Completed survey" : "Unable to complete survey"
|
|
92
|
+
render :action => 'edit'
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
# Returns the dependent questions that need to be answered based on the current progress of the response set
|
|
99
|
+
# it also returns the dependent questions that need to be hidden
|
|
100
|
+
def dependents(response_set)
|
|
101
|
+
show = []
|
|
102
|
+
hide = []
|
|
103
|
+
question_ids = response_set.responses.map(&:question_id).uniq # returning a list of all answered questions (only the ids)
|
|
104
|
+
dependencies = DependencyCondition.find_all_by_question_id(question_ids).map(&:dependency).uniq
|
|
105
|
+
dependencies.each do |dep|
|
|
106
|
+
if dep.met?(response_set) and response_set.has_not_answered_question?(dep.question)
|
|
107
|
+
show << dep.question
|
|
108
|
+
else
|
|
109
|
+
hide << dep.question
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
{:show => show, :hide => hide}
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def get_response_set
|
|
118
|
+
@response_set = ResponseSet.find_by_access_code(params[:response_set_code])
|
|
119
|
+
if @response_set
|
|
120
|
+
@survey = @response_set.survey
|
|
121
|
+
found = nil
|
|
122
|
+
@anchor = nil
|
|
123
|
+
unless params[:section].nil?
|
|
124
|
+
# The section to display is passed to us either in the url of a GET request or form params in a POST request
|
|
125
|
+
# Defaulting to look at the posted form params first, then as a url param.
|
|
126
|
+
section_id = (params[:section].respond_to?(:keys))? params[:section].keys.first.split("_").first.to_i : params[:section]
|
|
127
|
+
found = @survey.sections.find_by_id(section_id)
|
|
128
|
+
@anchor = (params[:section].respond_to?(:keys) and params[:section].keys.first.split("_").size > 1)? params[:section].keys.first.split("_").last : nil
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
@section = found || @survey.sections.first
|
|
133
|
+
@dependents = []
|
|
134
|
+
else
|
|
135
|
+
flash[:notice] = "Unable to find your responses to the survey"
|
|
136
|
+
redirect_to(available_surveys_path)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
class SurveysController < ApplicationController
|
|
2
|
+
|
|
3
|
+
# GET /surveys
|
|
4
|
+
# GET /surveys.xml
|
|
5
|
+
def index
|
|
6
|
+
@surveys = Survey.find(:all)
|
|
7
|
+
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.html # index.html.erb
|
|
10
|
+
format.xml { render :xml => @surveys }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# GET /surveys/1
|
|
15
|
+
# GET /surveys/1.xml
|
|
16
|
+
def show
|
|
17
|
+
@survey = Survey.find(params[:id])
|
|
18
|
+
|
|
19
|
+
respond_to do |format|
|
|
20
|
+
format.html # show.html.erb
|
|
21
|
+
format.xml { render :xml => @survey.to_xml(:include => :sections) }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# GET /surveys/new
|
|
26
|
+
# GET /surveys/new.xml
|
|
27
|
+
def new
|
|
28
|
+
@survey = Survey.new
|
|
29
|
+
|
|
30
|
+
respond_to do |format|
|
|
31
|
+
format.html # new.html.haml
|
|
32
|
+
format.xml { render :xml => @survey }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# GET /surveys/1/edit
|
|
37
|
+
def edit
|
|
38
|
+
@survey = Survey.find(params[:id])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# POST /surveys
|
|
42
|
+
# POST /surveys.xml
|
|
43
|
+
def create
|
|
44
|
+
@survey = Survey.new(params[:survey])
|
|
45
|
+
|
|
46
|
+
respond_to do |format|
|
|
47
|
+
if @survey.save
|
|
48
|
+
flash[:notice] = 'Survey was successfully created.'
|
|
49
|
+
format.html { redirect_to(@survey) }
|
|
50
|
+
format.xml { render :xml => @survey, :status => :created, :location => @survey }
|
|
51
|
+
else
|
|
52
|
+
format.html { render :action => "new" }
|
|
53
|
+
format.xml { render :xml => @survey.errors, :status => :unprocessable_entity }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# PUT /surveys/1
|
|
59
|
+
# PUT /surveys/1.xml
|
|
60
|
+
def update
|
|
61
|
+
@survey = Survey.find(params[:id])
|
|
62
|
+
|
|
63
|
+
respond_to do |format|
|
|
64
|
+
if @survey.update_attributes(params[:survey])
|
|
65
|
+
flash[:notice] = 'Survey was successfully updated.'
|
|
66
|
+
format.html { redirect_to(@survey) }
|
|
67
|
+
format.xml { head :ok }
|
|
68
|
+
else
|
|
69
|
+
format.html { render :action => "edit" }
|
|
70
|
+
format.xml { render :xml => @survey.errors, :status => :unprocessable_entity }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# DELETE /surveys/1
|
|
76
|
+
# DELETE /surveys/1.xml
|
|
77
|
+
def destroy
|
|
78
|
+
@survey = Survey.find(params[:id])
|
|
79
|
+
@survey.destroy
|
|
80
|
+
|
|
81
|
+
respond_to do |format|
|
|
82
|
+
format.html { redirect_to(surveys_url) }
|
|
83
|
+
format.xml { head :ok }
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
|
|
22
|
+
def to_survey_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
|
|
23
|
+
options = options.stringify_keys
|
|
24
|
+
options["type"] = "checkbox"
|
|
25
|
+
options["value"] = checked_value
|
|
26
|
+
if options.has_key?("checked")
|
|
27
|
+
cv = options.delete "checked"
|
|
28
|
+
checked = cv == true || cv == "checked"
|
|
29
|
+
else
|
|
30
|
+
checked = self.class.check_box_checked?(value(object), checked_value)
|
|
31
|
+
end
|
|
32
|
+
options["checked"] = "checked" if checked
|
|
33
|
+
add_default_name_and_id(options)
|
|
34
|
+
[tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value), tag("input", options)]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
module SurveyingHelper
|
|
2
|
+
|
|
3
|
+
# Formats the question number the way we want, or not at all if number is nil
|
|
4
|
+
def question_number_helper(number)
|
|
5
|
+
if number
|
|
6
|
+
"#{number}<span style='padding-left:0.1em;'>)</span>"
|
|
7
|
+
else
|
|
8
|
+
""
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# splits the question text using the delimiter
|
|
13
|
+
# parts before the delim. go before the input element, parts after the delim. go after the input element
|
|
14
|
+
def question_text_prefix_helper(question_text = "")
|
|
15
|
+
splits = question_text.split("|")
|
|
16
|
+
unless splits[0].empty?
|
|
17
|
+
splits[0]
|
|
18
|
+
else
|
|
19
|
+
" "
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Parts of the question that go after the input element
|
|
24
|
+
def question_text_postfix_helper(question_text = "")
|
|
25
|
+
splits = question_text.split("|")
|
|
26
|
+
if splits.size > 1
|
|
27
|
+
splits[1]
|
|
28
|
+
else
|
|
29
|
+
" "
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
alias_method :answer_text_prefix_helper, :question_text_prefix_helper
|
|
34
|
+
alias_method :answer_text_postfix_helper, :question_text_postfix_helper
|
|
35
|
+
|
|
36
|
+
def section_id_helper(section)
|
|
37
|
+
"section_#{section.id}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def question_id_helper(question)
|
|
41
|
+
"question_#{question.id}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def answer_id_helper(answer)
|
|
45
|
+
"answer_id_#{answer.id}"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def question_help_helper(question)
|
|
49
|
+
question.help_text.blank? ? "" : %Q(<span class="question-help">#{question.help_text}</span>)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def fields_for_response(response, &block)
|
|
53
|
+
fields_for("responses[#{response.question_id}][#{response.answer_id}]", response, :builder => SurveyFormBuilder, &block)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Changes the response hash to accept response groups for repeater elements
|
|
57
|
+
def fields_for_repeater_response(response, response_group, &block)
|
|
58
|
+
fields_for("response_groups[#{response.question_id}][#{response_group}][#{response.answer_id}]", response, :builder => SurveyFormBuilder, &block)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def fields_for_radio(response, &block)
|
|
62
|
+
fields_for("responses[#{response.question_id}]", response, :builder => SurveyFormBuilder, &block)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def section_submit_helper(section)
|
|
66
|
+
submit_tag(section.title, :name => section_submit_name_helper(section))
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def section_next_helper(section)
|
|
70
|
+
submit_tag("Next section >>", :name => section_submit_name_helper(section))
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def section_previous_helper(section)
|
|
74
|
+
submit_tag("<< Previous section", :name => section_submit_name_helper(section))
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def section_submit_name_helper(section, anchor_id = nil)
|
|
78
|
+
"section[#{section.id}#{(anchor_id)? "_#{anchor_id}" : ""}]"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Attempts to explain why this dependent question needs to be answered by referenced the dependent question and users response
|
|
82
|
+
def dependency_explanation_helper(question,response_set)
|
|
83
|
+
trigger_responses = []
|
|
84
|
+
dependent_questions = Question.find_all_by_id(question.dependency.dependency_conditions.map(&:question_id)).uniq
|
|
85
|
+
response_set.responses.find_all_by_question_id(dependent_questions.map(&:id)).uniq.each do |resp|
|
|
86
|
+
trigger_responses << resp.to_s
|
|
87
|
+
end
|
|
88
|
+
" You answered "#{trigger_responses.join("" and "")}" to the question "#{dependent_questions.map(&:text).join("","")}""
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|