From 783e919daefd5169022de00d4ff3dca9977ada17 Mon Sep 17 00:00:00 2001 From: Bohung Date: Thu, 4 Nov 2021 17:52:57 +0800 Subject: [PATCH] Fix bug. Add consent feature. --- app/controllers/surveys_controller.rb | 1 + app/models/questionnaire_survey.rb | 4 ++- app/models/survey_answer.rb | 1 + app/views/admin/surveys/_form.html.erb | 30 ++++++++++++++++++++- app/views/admin/surveys/answer_set.html.erb | 5 ++++ app/views/surveys/show.html.erb | 16 ++++++++++- config/locales/en.yml | 4 +++ config/locales/zh_tw.yml | 4 +++ 8 files changed, 62 insertions(+), 3 deletions(-) diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb index efc8b8c..a8e1939 100644 --- a/app/controllers/surveys_controller.rb +++ b/app/controllers/surveys_controller.rb @@ -256,6 +256,7 @@ class SurveysController < ApplicationController if @answer_model.errors.empty? @answer_model.scored_points = total @answer_model.individual_total = individual_total + @answer_model.consent_used = answer[:consent_used] @answer_model.save! params[:url] = params[:show_page_url] OrbitHelper.set_params(params,current_user) diff --git a/app/models/questionnaire_survey.rb b/app/models/questionnaire_survey.rb index 86cdca5..5ae7dc2 100644 --- a/app/models/questionnaire_survey.rb +++ b/app/models/questionnaire_survey.rb @@ -12,6 +12,8 @@ class QuestionnaireSurvey include OrbitCategory::Categorizable scope :can_display, ->{where(is_hidden: false)} + field :enable_consent_feature, :type => Boolean, :default => false + field :consent_contents, :type => String, :default => "", :localize => true field :already_fix_data, :type => Boolean, :default => false field :copy_id field :except_clone_relations, :type=>Array, :default => [] @@ -426,7 +428,7 @@ class QuestionnaireSurvey else oid = d['oid'] end - t2 += tmp[oid]["base"] rescue nil + t2 = tmp[oid]["base"] rescue nil if t2 t += t2 level2s.each do |level2_id| diff --git a/app/models/survey_answer.rb b/app/models/survey_answer.rb index 6d8f276..bf27829 100644 --- a/app/models/survey_answer.rb +++ b/app/models/survey_answer.rb @@ -4,6 +4,7 @@ class SurveyAnswer include Mongoid::Attributes::Dynamic field :user, type: BSON::ObjectId + field :consent_used, type: Boolean, :default => false field :scored_points, type: Integer, :default => 0 field :avg_points, type: Integer field :individual_total, type: Array, :default => [] diff --git a/app/views/admin/surveys/_form.html.erb b/app/views/admin/surveys/_form.html.erb index c153820..41f8ca4 100644 --- a/app/views/admin/surveys/_form.html.erb +++ b/app/views/admin/surveys/_form.html.erb @@ -124,7 +124,31 @@ <%= f.text_field :redirect_url, :class=>"input-xlarge", :placeholder=>"Redirect URL" %> - +
+ +
+ <%= f.check_box :enable_consent_feature, :id =>'enable_consent_feature' %> +
+
+
@@ -146,4 +170,8 @@ $("#questionnaire_survey_needs_login").click(function(){ $("#answer_repeat_block").toggleClass("hide"); }) + $("#enable_consent_feature").click(function(){ + $(".enable_consent_feature").toggleClass("hide"); + $(".enable_consent_feature .btn.active").click(); + }) \ No newline at end of file diff --git a/app/views/admin/surveys/answer_set.html.erb b/app/views/admin/surveys/answer_set.html.erb index adea825..677407e 100644 --- a/app/views/admin/surveys/answer_set.html.erb +++ b/app/views/admin/surveys/answer_set.html.erb @@ -53,6 +53,11 @@ <% end %>
+ <% if @survey_answer.consent_used %> +
+ <%= t('survey.consent_to_be_used_for_research') %> +
+ <% end %> <% @survey.survey_questions.each_with_index do |sq, index| %>
diff --git a/app/views/surveys/show.html.erb b/app/views/surveys/show.html.erb index bdf657b..a620c0a 100644 --- a/app/views/surveys/show.html.erb +++ b/app/views/surveys/show.html.erb @@ -52,7 +52,16 @@ qnum = 0 show_page_url = data["show_page_url"] %> - + <% if @survey.needs_login && current_user.nil? %>