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 - Pending Responses / Response Errors #1064

Merged
merged 8 commits into from
Aug 17, 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
2 changes: 0 additions & 2 deletions app/assets/javascripts/surveyor/responses.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ $(document).ready ->
$(".dependent-for-option-#{option_id}").removeClass('hidden')
else
$(".dependent-for-option-#{option_id}").addClass('hidden')


61 changes: 45 additions & 16 deletions app/controllers/surveyor/responses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,72 @@ class Surveyor::ResponsesController < ApplicationController

before_action :authenticate_identity!
before_action :find_survey, only: [:new]
before_action :find_response, only: [:show, :edit, :update]

def show
@response = Response.find(params[:id])
@survey = @response.survey
@survey = @response.survey

respond_to do |format|
format.html
end
end

def new
@response = @survey.responses.new
@review = 'true'
@sub_service_request = nil
@response = @survey.responses.new
@response.question_responses.build

respond_to do |format|
format.html {
@review = 'false'
@sub_service_request = SubServiceRequest.find(params[:sub_service_request_id])
}
format.js {
@review = 'true'
@sub_service_request = nil
}
format.js
end
end

def create
@response = Response.new(response_params)
@review = params[:review] == 'true'

if @response.save && @response.question_responses.none? { |qr| qr.errors.any? }
# Delete responses to questions that didn't show anyways to avoid confusion in the data
@response.question_responses.where(required: true, content: [nil, '']).destroy_all
SurveyNotification.system_satisfaction_survey(@response).deliver_now if @response.survey.access_code == 'system-satisfaction-survey' && @review

flash[:success] = t(:surveyor)[:responses][:create]
SurveyNotification.system_satisfaction_survey(@response).deliver_now if @response.survey.access_code == 'system-satisfaction-survey'
else
@response.destroy
@errors = true
end

respond_to do |format|
format.js
end
end

def edit
redirect_to surveyor_response_complete_path(@response) if @response.completed?

@response.question_responses.build

@review = 'false'
@sub_service_request = @response.sub_service_request

respond_to do |format|
format.html
end
end

def update
if @response.update_attributes(response_params) && @response.question_responses.none? { |qr| qr.errors.any? }
# Delete responses to questions that didn't show anyways to avoid confusion in the data
@response.question_responses.where(required: true, content: [nil, '']).destroy_all

flash[:success] = t(:surveyor)[:responses][:update]
else
@errors = true
end

respond_to do |format|
format.js
end
end

def complete
end

private
Expand All @@ -78,6 +103,10 @@ def find_survey
end
end

def find_response
@response = Response.find(params[:id])
end

def response_params
params.require(:response).permit!
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ class Response < ActiveRecord::Base
has_many :question_responses, dependent: :destroy

accepts_nested_attributes_for :question_responses

def completed?
self.question_responses.any?
end
end
2 changes: 1 addition & 1 deletion app/views/survey_notification/service_survey.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
%ul
- @surveys.each do |survey|
%li
= link_to survey.title, url_for(controller: '/surveyor/responses', action: :new, only_path: false, access_code: survey.access_code, survey_version: survey.version, sub_service_request_id: @ssr.id, format: :html), target: '_blank'
= link_to survey.title, url_for(controller: '/surveyor/responses', action: :edit, only_path: false, id: Response.create(survey: survey, identity: @identity, sub_service_request: @ssr).id, format: :html), target: '_blank'

- if @surveys.map(&:access_code).include?("sctr-customer-satisfaction-survey")
#sctr-grant-citation
Expand Down
16 changes: 6 additions & 10 deletions app/views/surveyor/responses/create.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@
<% if @errors %>
<% @response.question_responses.each do |qr| %>
<% if qr.errors.any? %>
if !$(".question-<%=qr.question_id%>").hasClass('has-error')
$(".question-<%=qr.question_id%>").addClass('has-error')
if !$(".question-<%=qr.question_id%> .question-label").hasClass('has-error')
$(".question-<%=qr.question_id%> .question-label").addClass('has-error')
<% qr.errors.full_messages.each do |message| %>
$(".question-<%=qr.question_id%>").append("<span class='help-block'><%= message %></span>")
$(".question-<%=qr.question_id%> .question-label").append("<span class='help-block'><%= message %></span>")
<% end %>
<% else %>
$(".question-<%=qr.question_id%>").removeClass('has-error')
$(".question-<%=qr.question_id%> .help-block").remove()
$(".question-<%=qr.question_id%> .question-label").removeClass('has-error')
$(".question-<%=qr.question_id%> .question-label .help-block").remove()
<% end %>
<% end %>
<% @response.question_responses.destroy_all %>
<% @response.destroy %>
<% else %>
<% if @review %>
$('#modal_place').modal('hide')
<% else %>
window.location = "/surveyor/responses/<%=@response.id%>/complete"
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
.panel.panel-default#survey-panel
.panel-heading.text-center
%h4.panel-title
= @survey.title
= form_for @response, url: surveyor_responses_path(@response, review: @review), remote: true do |f|
= @response.survey.title
= form_for @response, url: surveyor_response_path(@response, review: @review), remote: true do |f|
.panel-body
= render 'surveyor/responses/form/response_content', f: f, survey: @survey, sub_service_request: @sub_service_request
= render 'surveyor/responses/form/response_content', f: f, survey: @response.survey, sub_service_request: @sub_service_request
.panel-footer
.clearfix
= f.submit t(:actions)[:submit], class: 'btn btn-primary pull-right'
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
%hr
= qr.hidden_field :required, value: question.required?
= qr.hidden_field :question_id, value: question.id
.form-group
= qr.label :content, raw(question.content), class: question.required? ? "required" : ""
.form-group.question-label
= qr.label :content, raw(question.content), class: ['control-label text-left', question.required? ? "required" : ""]
- unless question.description.blank?
.form-group
%p.question-description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
-# 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.
- question.options.each do |option|
.form-group.option{ data: { question_id: question.id, option_id: option.id } }
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
.col-lg-1.text-center
= qr.check_box :content, { multiple: true }, option.content, nil
= option.content
- else
.col-lg-1.text-center
= check_box_tag :content_checkbox, '', multiple_select_formatter(qr.content).include?(option.content), disabled: true, multiple: true
= check_box_tag :content_checkbox, '', multiple_select_formatter(qr.object.content).include?(option.content), disabled: true, multiple: true
= option.content
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.country_select :content, { priority_countries: ['US'], include_blank: true }, { class: 'form-control selectpicker option' }
- else
= country_select :content, :country, { priority_countries: ['US'], include_blank: true, selected: qr.content }, { class: 'form-control selectpicker option', disabled: true }
= country_select :content, :country, { priority_countries: ['US'], include_blank: true, selected: qr.object.content }, { class: 'form-control selectpicker option', disabled: true }
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
-# 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.
.form-group
.input-group.datetimepicker.date.option
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.text_field :content, class: 'form-control', maxlength: 255
- else
= text_field_tag :content, qr.content, class: 'form-control', disabled: true
= text_field_tag :content, qr.object.content, class: 'form-control', disabled: true
%span.input-group-addon
%span.glyphicon.glyphicon-calendar
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.select :content, options_from_collection_for_select(question.options, 'content', 'content'), { include_blank: true }, { class: 'form-control selectpicker option' }
- else
= select_tag :content, options_from_collection_for_select(qr.question.options, 'content', 'content', qr.content), include_blank: true, class: 'form-control selectpicker option', disabled: true
= select_tag :content, options_from_collection_for_select(qr.question.options, 'content', 'content', qr.object.content), include_blank: true, class: 'form-control selectpicker option', disabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.email_field :content, class: 'form-control option'
- else
= email_field_tag :content, qr.content, class: 'form-control option', disabled: true
= email_field_tag :content, qr.object.content, class: 'form-control option', disabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
.col-sm-12.text-center.no-padding
= index+1
.col-sm-12.text-center.no-padding.likert
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.radio_button :content, option.content
- else
= radio_button_tag :content_likert, '', qr.content == option.content, disabled: true
= radio_button_tag :content_likert, '', qr.object.content == option.content, disabled: true
.col-sm-12.text-center.no-padding
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.label :content, option.content, class: "radio-inline option no-padding", data: { question_id: question.id, option_id: option.id }
- else
%label.radio-inline.option.no-padding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.select :content, options_from_collection_for_select(question.options, 'content', 'content'), { include_blank: true }, { class: 'form-control selectpicker option', multiple: true }
- else
= select_tag :content, options_from_collection_for_select(qr.question.options, 'content', 'content', multiple_select_formatter(qr.content)), include_blank: true, class: 'form-control selectpicker option', disabled: true, multiple: true
= select_tag :content, options_from_collection_for_select(qr.question.options, 'content', 'content', multiple_select_formatter(qr.object.content)), include_blank: true, class: 'form-control selectpicker option', disabled: true, multiple: true
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.number_field :content, class: 'form-control option'
- else
= number_field_tag :content, qr.content, class: 'form-control option', disabled: true
= number_field_tag :content, qr.object.content, class: 'form-control option', disabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.telephone_field :content, class: 'form-control option'
- else
= telephone_field_tag :content, qr.content, class: 'form-control option', disabled: true
= telephone_field_tag :content, qr.object.content, class: 'form-control option', disabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
-# 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.
- question.options.each do |option|
.form-group.option{ data: { question_id: question.id, option_id: option.id } }
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
.col-lg-1.text-center
= qr.radio_button :content, option.content
= option.content
- else
.col-lg-1.text-center
= radio_button_tag :content_radio, '', qr.content == option.content, disabled: true
= radio_button_tag :content_radio, '', qr.object.content == option.content, disabled: true
= option.content
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.select :content, options_for_select(us_states), { include_blank: true }, { class: 'form-control selectpicker option' }
- else
= select_tag :content, options_for_select(us_states, qr.content), include_blank: true, class: 'form-control selectpicker option', disabled: true
= select_tag :content, options_for_select(us_states, qr.object.content), include_blank: true, class: 'form-control selectpicker option', disabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.text_field :content, class: 'form-control option', maxlength: 255
- else
= text_field_tag :content, qr.content, class: 'form-control option', disabled: true
= text_field_tag :content, qr.object.content, class: 'form-control option', disabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.text_area :content, class: 'form-control option', maxlength: 255
- else
= text_area_tag :content, qr.content, class: 'form-control option', disabled: true
= text_area_tag :content, qr.object.content, class: 'form-control option', disabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
-# 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.
.form-group
.input-group.datetimepicker.time.option
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.text_field :content, class: 'form-control', maxlength: 255
- else
= text_field_tag :content, qr.content, class: 'form-control', disabled: true
= text_field_tag :content, qr.object.content, class: 'form-control', disabled: true
%span.input-group-addon
%span.glyphicon.glyphicon-time
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
.form-group
- question.options.each do |option|
.col-lg-2.no-padding
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
.col-lg-6.no-padding.text-center.option{ data: { question_id: question.id, option_id: option.id } }
= qr.radio_button :content, option.content.downcase
= option.content
- else
.col-lg-6.no-padding.text-center.option{ data: { question_id: question.id, option_id: option.id } }
= radio_button_tag :content_yes_no, option.content.downcase, qr.content == option.content.downcase, disabled: true
= radio_button_tag :content_yes_no, option.content.downcase, qr.object.content == option.content.downcase, disabled: true
= option.content
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-# 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.
.form-group
- if ['new', 'preview'].include?(action_name)
- if ['new', 'edit', 'preview'].include?(action_name)
= qr.text_field :content, class: 'form-control option', maxlength: 255
- else
= text_field_tag :content, qr.content, class: 'form-control option', disabled: true
= text_field_tag :content, qr.object.content, class: 'form-control option', disabled: true
2 changes: 1 addition & 1 deletion app/views/surveyor/responses/new.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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.
$('#modal_place').html("<%= j render 'surveyor/responses/new_form_modal', survey: @survey, response: @response, review: @review, sub_service_request: @sub_service_request %>")
$('#modal_place').html("<%= j render 'surveyor/responses/form_modal', survey: @survey, response: @response, review: @review, sub_service_request: @sub_service_request %>")
$('#modal_place').modal('show')
$('.datetimepicker.date').datetimepicker(format: 'MM/DD/YYYY', allowInputToggle: true)
$('.datetimepicker.time').datetimepicker(format: 'hh:mm A', allowInputToggle: true)
Expand Down