diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb index 2ee2c43..83e13c7 100644 --- a/app/controllers/surveys_controller.rb +++ b/app/controllers/surveys_controller.rb @@ -102,6 +102,7 @@ class SurveysController < ApplicationController @survey = QuestionnaireSurvey.find_by(:uid=>uid) total = 0 + individual_total = [] answer = params[:answer] @answer_model = @survey.survey_answers.new @answer_model.user = current_user.id if !current_user.nil? @@ -120,11 +121,13 @@ class SurveysController < ApplicationController @answer_model[qid] = opt.name p = (opt.points == nil ? 0 : opt.points) rescue 0 total = total + p + individual_total << p end end when SurveyQuestion::Check @answer_model[qid] = [] if answer[qid] + t = 0 answer[qid].each do |oid, value| if value.to_i != 0 if question.custom_option && oid == 'custom_option' @@ -134,33 +137,40 @@ class SurveysController < ApplicationController @answer_model[qid].push opt.name p = (opt.points == nil ? 0 : opt.points) rescue 0 total = total + p + t = t + p end end end + individual_total << p end when SurveyQuestion::Radiogroup @answer_model[qid] = {} options = Hash[question.survey_question_options.collect{|o| [ o.id.to_s, (o.points.nil? ? 0 : o.points) ] }] radiogroups = Hash[question.survey_question_radiogroups.collect{|rg| [ rg.id.to_s, rg.name] }] if answer[qid] + t = 0 answer[qid].each do |oid, value| unless value.blank? @answer_model[qid][oid] = radiogroups[value] total = total + options[oid] + t = t + options[oid] else if question.is_required @answer_model.errors.add question.title, t('survey_question.required_error') end end end + individual_total << t end when SurveyQuestion::Oneline, SurveyQuestion::Multiline @answer_model[qid] = answer[qid] + individual_total << 0 end end end if @answer_model.errors.empty? @answer_model.scored_points = total + @answer_model.individual_total = individual_total @answer_model.save! redirect_to OrbitHelper.url_to_show(@survey.to_param) + "?method=answer_success&ans=#{@answer_model.id.to_s}" else diff --git a/app/models/survey_answer.rb b/app/models/survey_answer.rb index f44dd96..245a85b 100644 --- a/app/models/survey_answer.rb +++ b/app/models/survey_answer.rb @@ -4,6 +4,7 @@ class SurveyAnswer field :user, type: BSON::ObjectId field :scored_points, type: Integer, :default => 0 + field :individual_total, type: Array, :default => [] belongs_to :questionnaire_survey diff --git a/app/views/admin/surveys/set_answers.html.erb b/app/views/admin/surveys/set_answers.html.erb index cab3619..7fb68fc 100644 --- a/app/views/admin/surveys/set_answers.html.erb +++ b/app/views/admin/surveys/set_answers.html.erb @@ -2,6 +2,14 @@ <%= stylesheet_link_tag "lib/main-forms" %> <%= stylesheet_link_tag "lib/wrap-nav" %> <%= stylesheet_link_tag "lib/main-list" %> + <% end %> <% content_for :page_specific_javascript do %> <%= javascript_include_tag "jquery-ui-custom.js" %> @@ -67,23 +75,37 @@