Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KG - Survey Form Errors Not Appearing #1015

Merged
merged 6 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/assets/javascripts/surveyor/surveys.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ $(document).ready ->
send_update_request = (obj, val) ->
field_data = $(obj).attr('id').split('-')
klass = field_data[0]
attribute = field_data[1]
id = $(obj).parents(".#{klass}").data("#{klass}-id")
id = field_data[1]
attribute = field_data[2]

$.ajax
type: 'put'
Expand All @@ -129,7 +129,7 @@ send_update_request = (obj, val) ->
"#{klass}":
"#{attribute}": val
success: ->
if $.inArray(attribute, ['question_type', 'content'])
if attribute == 'question_type' || attribute == 'content'
build_dependents_selectpicker($('.survey').data('survey-id'))

build_dependents_selectpicker = (survey_id) ->
Expand Down
13 changes: 4 additions & 9 deletions app/controllers/surveyor/surveys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Surveyor::SurveysController < ApplicationController

before_action :authenticate_identity!
before_action :authorize_site_admin
before_action :find_survey, only: [:show, :destroy]

def index
respond_to do |format|
Expand All @@ -35,6 +34,8 @@ def index
end

def show
@survey = Survey.eager_load(sections: { questions: :options }).find(params[:id])

respond_to do |format|
format.js
end
Expand All @@ -53,7 +54,7 @@ def create
end

def destroy
@survey.destroy
Survey.find(params[:id]).destroy

respond_to do |format|
format.js
Expand All @@ -73,16 +74,10 @@ def preview

def update_dependents_list
@survey = Survey.find(params[:survey_id])
@questions = @survey.questions
@questions = @survey.questions.eager_load(section: :survey)

respond_to do |format|
format.js
end
end

private

def find_survey
@survey = Survey.find(params[:id])
end
end
2 changes: 1 addition & 1 deletion app/models/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Question < ActiveRecord::Base
after_update :update_options_based_on_question_type, if: :question_type_changed?

def previous_questions
self.survey.questions.where("questions.id < ?", self.id)
self.survey.questions.eager_load(:options).where("questions.id < ?", self.id)
end

def is_dependent?
Expand Down
10 changes: 5 additions & 5 deletions app/views/surveyor/survey_updater/update.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<% if @errors %>
<% @errors.zip(@errors.full_messages).each do |error, message| %>
if !$("#<%=@klass%>-<%=error[0]%>").parents('.form-group').hasClass('has-error')
$("#<%=@klass%>-<%=error[0]%>").parents('.form-group').addClass('has-error')
$("#<%=@klass%>-<%=error[0]%>").parents('.form-group').children('div:not(.control-label)').append("<span class='help-block'><%=message%></span>")
if !$("#<%=@klass%>-<%=@object.id%>-<%=error[0]%>").parents('.form-group').hasClass('has-error')
$("#<%=@klass%>-<%=@object.id%>-<%=error[0]%>").parents('.form-group').addClass('has-error')
$("#<%=@klass%>-<%=@object.id%>-<%=error[0]%>").after("<span class='help-block'><%=message%></span>")
<% end %>
<% else %>
$("#<%=@klass%>-<%=@field%>").parents('.form-group').removeClass('has-error')
$("#<%=@klass%>-<%=@field%>").parents('.form-group').find('.help-block').remove()
$("#<%=@klass%>-<%=@object.id%>-<%=@field%>").parents('.form-group').removeClass('has-error')
$("#<%=@klass%>-<%=@object.id%>-<%=@field%>").siblings('.help-block').remove()

<% if @klass == 'survey' %>
$('.survey-table').bootstrapTable('refresh')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%select.selectpicker.select-depender#question-depender_id
%select.selectpicker.select-depender{ id: "question-#{question.id}-depender_id" }
%option{ value: "" }
= t(:constants)[:prompts][:none]
- question.previous_questions.each do |q|
Expand Down
4 changes: 2 additions & 2 deletions app/views/surveyor/surveys/form/_survey_content.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
.panel-heading
%h4.panel-title
.form-group.no-margin
= text_field_tag "survey-title", survey.title, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:survey][:title][:placeholder], maxlength: 255
= text_field_tag "survey-#{survey.id}-title", survey.title, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:survey][:title][:placeholder], maxlength: 255
.panel-body
.form-group
.col-lg-12.no-padding
= text_area_tag "survey-description", survey.description, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:survey][:description][:placeholder]
= text_area_tag "survey-#{survey.id}-description", survey.description, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:survey][:description][:placeholder]

.survey-sections
- survey.sections.each do |section|
Expand Down
16 changes: 8 additions & 8 deletions app/views/surveyor/surveys/form/_survey_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
= t(:surveyor)[:surveys][:form][:survey_information][:header]
.panel-body
.form-group
= label_tag "survey-access_code", t(:surveyor)[:surveys][:form][:survey_information][:access_code], class: 'col-lg-2 control-label required'
= label_tag "survey-#{survey.id}-access_code", t(:surveyor)[:surveys][:form][:survey_information][:access_code], class: 'col-lg-2 control-label required'
.col-lg-10
= text_field_tag "survey-access_code", survey.access_code, class: 'form-control', maxlength: 255
= text_field_tag "survey-#{survey.id}-access_code", survey.access_code, class: 'form-control', maxlength: 255
.form-group
= label_tag "survey-version", t(:surveyor)[:surveys][:form][:survey_information][:version], class: 'col-lg-2 control-label required'
= label_tag "survey-#{survey.id}-version", t(:surveyor)[:surveys][:form][:survey_information][:version], class: 'col-lg-2 control-label required'
.col-lg-10
= text_field_tag "survey-version", survey.version, class: 'form-control', maxlength: 255
= text_field_tag "survey-#{survey.id}-version", survey.version, class: 'form-control', maxlength: 255
.form-group
= label_tag "survey-display_order", t(:surveyor)[:surveys][:form][:survey_information][:display_order], class: 'col-lg-2 control-label required'
= label_tag "survey-#{survey.id}-display_order", t(:surveyor)[:surveys][:form][:survey_information][:display_order], class: 'col-lg-2 control-label required'
.col-lg-10
= select_tag "survey-display_order", display_order_options, class: 'form-control selectpicker', include_blank: t(:constants)[:prompts][:none]
= select_tag "survey-#{survey.id}-display_order", display_order_options, class: 'form-control selectpicker', include_blank: t(:constants)[:prompts][:none]
.form-group
= label_tag "survey-active", t(:surveyor)[:surveys][:form][:survey_information][:active], class: 'col-lg-2 control-label'
= label_tag "survey-#{survey.id}-active", t(:surveyor)[:surveys][:form][:survey_information][:active], class: 'col-lg-2 control-label'
.col-lg-10
.col-lg-1
= check_box_tag "survey-active", survey.active, survey.active
= check_box_tag "survey-#{survey.id}-active", survey.active, survey.active
16 changes: 8 additions & 8 deletions app/views/surveyor/surveys/form/_survey_question.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
%hr
.col-lg-8.no-padding
.form-group
= text_field_tag "question-content", question.content, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:question][:content][:placeholder], maxlength: 255
= text_field_tag "question-#{question.id}-content", question.content, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:question][:content][:placeholder], maxlength: 255
.col-lg-4.no-padding
.form-group
= select_tag "question-question_type", options_for_select(ADDITIONAL_DETAIL_QUESTION_TYPES, question.question_type), class: 'selectpicker select-question-type pull-right', data: { question_id: question.id }
= select_tag "question-#{question.id}-question_type", options_for_select(ADDITIONAL_DETAIL_QUESTION_TYPES, question.question_type), class: 'selectpicker select-question-type pull-right', data: { question_id: question.id }

.form-group
= text_area_tag "question-description", question.description, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:question][:description][:placeholder]
= text_area_tag "question-#{question.id}-description", question.description, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:question][:description][:placeholder]

.form-group
= label_tag "question-required", t(:surveyor)[:surveys][:form][:content][:question][:required], class: 'col-sm-1 control-label no-padding-x text-left'
= label_tag "question-#{question.id}-required", t(:surveyor)[:surveys][:form][:content][:question][:required], class: 'col-sm-1 control-label no-padding-x text-left'
.col-sm-1
= check_box_tag "question-required", question.required, question.required
= label_tag "question-is_dependent", t(:surveyor)[:surveys][:form][:content][:question][:dependent][:label], class: 'col-sm-2 control-label no-padding-x text-right'
= check_box_tag "question-#{question.id}-required", question.required, question.required
= label_tag "question-#{question.id}-is_dependent", t(:surveyor)[:surveys][:form][:content][:question][:dependent][:label], class: 'col-sm-2 control-label no-padding-x text-right'
.col-sm-1
= check_box_tag "question-is_dependent", question.is_dependent, question.is_dependent, class: 'is-dependent', disabled: question.previous_questions.empty?
= check_box_tag "question-#{question.id}-is_dependent", question.is_dependent, question.is_dependent, class: 'is-dependent', disabled: question.previous_questions.empty?
.dependent-dropdown-container{ class: question.is_dependent ? '' : 'hidden' }
= label_tag "question-depender_id", t(:surveyor)[:surveys][:form][:content][:question][:dependent][:dropdown][:label], class: 'col-sm-2 control-label no-padding-x'
= label_tag "question-#{question.id}-depender_id", t(:surveyor)[:surveys][:form][:content][:question][:dependent][:dropdown][:label], class: 'col-sm-2 control-label no-padding-x'
.col-sm-4.no-padding
.col-sm-4
= render 'surveyor/surveys/form/dependent_dropdown', survey: survey, question: question
Expand Down
4 changes: 2 additions & 2 deletions app/views/surveyor/surveys/form/_survey_section.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
.clearfix
.form-group.no-margin
.col-sm-11.no-padding
= text_field_tag "section-title", section.title, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:section][:title][:placeholder], maxlength: 255
= text_field_tag "section-#{section.id}-title", section.title, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:section][:title][:placeholder], maxlength: 255
.col-sm-1.no-padding
%button.btn.btn-sm.btn-danger.pull-right.delete-section{ title: t(:surveyor)[:surveys][:form][:content][:section][:delete], data: { toggle: 'tooltip', animation: 'false' } }
%span.glyphicon.glyphicon-trash
.panel-body
.form-group
.col-lg-12.no-padding
= text_area_tag "section-description", section.description, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:section][:description][:placeholder]
= text_area_tag "section-#{section.id}-description", section.description, class: 'form-control', placeholder: t(:surveyor)[:surveys][:form][:content][:section][:description][:placeholder]

.section-questions{ class: "section-#{section.id}-questions" }
- section.questions.each do |question|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
.col-lg-1.text-center
= check_box_tag :response_example, '', false, class: 'checkbox-example', disabled: true
.col-lg-10.no-padding
= text_field_tag "option-content", option.content, class: 'form-control option-content', placeholder: t(:surveyor)[:surveys][:form][:content][:option][:content][:placeholder], maxlength: 255
= text_field_tag "option-#{option.id}-content", option.content, class: 'form-control option-content', placeholder: t(:surveyor)[:surveys][:form][:content][:option][:content][:placeholder], maxlength: 255
.col-lg-1.no-padding
= render 'surveyor/surveys/form/form_partials/delete_option_button'
= render 'surveyor/surveys/form/form_partials/add_option_button', question: question
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- question.options.each do |option|
.form-group.option{ data: {option_id: option.id } }
.col-lg-11.no-padding
= text_field_tag "option-content", option.content, class: 'form-control option-content', placeholder: t(:surveyor)[:surveys][:form][:content][:option][:content][:placeholder], maxlength: 255
= text_field_tag "option-#{option.id}-content", option.content, class: 'form-control option-content', placeholder: t(:surveyor)[:surveys][:form][:content][:option][:content][:placeholder], maxlength: 255
.col-lg-1.no-padding
= render 'surveyor/surveys/form/form_partials/delete_option_button'
= render 'surveyor/surveys/form/form_partials/add_option_button', question: question
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.col-lg-1.text-center
= radio_button_tag :response_example, '', false, class: 'radio-example', disabled: true
.col-lg-10.no-padding
= text_field_tag "option-content", option.content, class: 'form-control option-content', placeholder: t(:surveyor)[:surveys][:form][:content][:option][:content][:placeholder], maxlength: 255
= text_field_tag "option-#{option.id}-content", option.content, class: 'form-control option-content', placeholder: t(:surveyor)[:surveys][:form][:content][:option][:content][:placeholder], maxlength: 255
.col-lg-1.no-padding
= render 'surveyor/surveys/form/form_partials/delete_option_button'
= render 'surveyor/surveys/form/form_partials/add_option_button'
10 changes: 0 additions & 10 deletions spec/controllers/surveyor/surveys/delete_destroy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@
expect(before_filters.include?(:authorize_site_admin)).to eq(true)
end

it 'should assign @survey to the survey' do
survey = create(:survey_without_validations)

delete :destroy, params: {
id: survey.id
}, xhr: true

expect(assigns(:survey)).to eq(survey)
end

it 'should delete the survey' do
survey = create(:survey_without_validations)

Expand Down
2 changes: 1 addition & 1 deletion spec/features/surveyor/user_edits_option_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
find('.edit-survey').click
wait_for_javascript_to_finish

fill_in('option-content', with: 'This is a Terrible Option')
fill_in("option-#{@option.id}-content", with: 'This is a Terrible Option')
find('.modal-title').click
wait_for_javascript_to_finish

Expand Down
26 changes: 13 additions & 13 deletions spec/features/surveyor/user_edits_question_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
find('.edit-survey').click
wait_for_javascript_to_finish

fill_in('question-content', with: 'This is a Terrible Question')
fill_in("question-#{@question.id}-content", with: 'This is a Terrible Question')
find('.modal-title').click
wait_for_javascript_to_finish

Expand All @@ -54,7 +54,7 @@
find('.edit-survey').click
wait_for_javascript_to_finish

fill_in('question-description', with: 'How can I describe such a terrible question?')
fill_in("question-#{@question.id}-description", with: 'How can I describe such a terrible question?')
find('.modal-title').click
wait_for_javascript_to_finish

Expand All @@ -68,7 +68,7 @@
find('.edit-survey').click
wait_for_javascript_to_finish

bootstrap_select '#question-question_type', 'Text Area'
bootstrap_select "#question-#{@question.id}-question_type", 'Text Area'
wait_for_javascript_to_finish

expect(@question.reload.question_type).to eq('textarea')
Expand All @@ -81,7 +81,7 @@
find('.edit-survey').click
wait_for_javascript_to_finish

find('#question-required').click
find("#question-#{@question.id}-required").click
wait_for_javascript_to_finish

expect(@question.reload.required).to eq(true)
Expand All @@ -96,8 +96,8 @@
find('.edit-survey').click
wait_for_javascript_to_finish

expect(page).to have_selector('#question-is_dependent:disabled')
expect(page).to_not have_selector('#question-is_dependent:not(:disabled)')
expect(page).to have_selector("#question-#{@question.id}-is_dependent:disabled")
expect(page).to_not have_selector("#question-#{@question.id}-is_dependent:not(:disabled)")
end
end

Expand All @@ -111,7 +111,7 @@
find('.edit-survey').click
wait_for_javascript_to_finish

all('#question-is_dependent')[1].click
find("#question-#{@question2.id}-is_dependent").click
wait_for_javascript_to_finish

expect(@question2.reload.is_dependent).to eq(true)
Expand All @@ -129,10 +129,10 @@
find('.edit-survey').click
wait_for_javascript_to_finish

all('#question-is_dependent')[1].click
find("#question-#{@question2.id}-is_dependent").click
wait_for_javascript_to_finish

find("button[data-id='question-depender_id']").click
find("button[data-id='question-#{@question2.id}-depender_id']").click

expect(page).to have_selector('.text', text: @option.content)
end
Expand All @@ -148,10 +148,10 @@
find('.edit-survey').click
wait_for_javascript_to_finish

all('#question-is_dependent')[1].click
find("#question-#{@question2.id}-is_dependent").click
wait_for_javascript_to_finish

find("button[data-id='question-depender_id']").click
find("button[data-id='question-#{@question2.id}-depender_id']").click

expect(page).to_not have_selector('.text', text: @option.content)
end
Expand All @@ -166,10 +166,10 @@
find('.edit-survey').click
wait_for_javascript_to_finish

all('#question-is_dependent')[1].click
find("#question-#{@question2.id}-is_dependent").click
wait_for_javascript_to_finish

bootstrap_select '#question-depender_id', 'What is the meaning of life?'
bootstrap_select "#question-#{@question2.id}-depender_id", 'What is the meaning of life?'
wait_for_javascript_to_finish

expect(@question2.reload.depender_id).to eq(@option.id)
Expand Down
4 changes: 2 additions & 2 deletions spec/features/surveyor/user_edits_section_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
find('.edit-survey').click
wait_for_javascript_to_finish

fill_in('section-title', with: 'This is a Terrible Section')
fill_in("section-#{@section.id}-title", with: 'This is a Terrible Section')
find('.modal-title').click
wait_for_javascript_to_finish

Expand All @@ -53,7 +53,7 @@
find('.edit-survey').click
wait_for_javascript_to_finish

fill_in('section-description', with: 'How can I describe such a terrible section?')
fill_in("section-#{@section.id}-description", with: 'How can I describe such a terrible section?')
find('.modal-title').click
wait_for_javascript_to_finish

Expand Down