now redirects to answer set if already taken.

This commit is contained in:
Harry Bomrah 2015-11-30 18:11:58 +08:00
parent 19cc1e2fb3
commit 7c511361ff
5 changed files with 35 additions and 8 deletions

View File

@ -25,8 +25,12 @@ class Admin::SurveysController < OrbitAdminController
end
def answer_sets
if can_edit_or_delete?(@survey)
@table_fields = ['survey.taken_by', 'survey.taken_date']
@survey_answers = @survey.survey_answers.desc(:created_at).page(params[:page]).per(15)
else
render_401
end
end
def answer_set

View File

@ -5,8 +5,9 @@ class SurveysController < ApplicationController
def index
questionnairesurveys = QuestionnaireSurvey.any_of( {:postdate.lte => Time.now} ).desc(:postdate).page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
current_user = OrbitHelper.current_user
surveys = questionnairesurveys.collect do |a|
answer_present = (current_user.nil? ? false : (a.survey_answers.where(:user => current_user.id).count > 0 ? true : false))
if !OrbitHelper.params[:page_no].blank?
title = ('<a href="'+ OrbitHelper.url_to_show(a.to_param) + "?method=show_data&page_no=#{OrbitHelper.params[:page_no]}" + '">' + a.title + '</a>').html_safe
@ -18,7 +19,8 @@ class SurveysController < ApplicationController
"title" => title,
"time_range" => QuestionnaireSurvey.time_range(a),
"write" => QuestionnaireSurvey.write(a),
"result" => QuestionnaireSurvey.result(a)
"result" => QuestionnaireSurvey.result(a),
"answer_present" => answer_present
}
end
{
@ -40,9 +42,13 @@ class SurveysController < ApplicationController
params = OrbitHelper.params
survey = QuestionnaireSurvey.find_by(uid: params[:uid])
current_user = OrbitHelper.current_user
answer_present = (current_user.nil? ? false : (survey.survey_answers.where(:user => current_user.id).count > 0 ? true : false))
link_to_answer_set = (answer_present ? "/admin/surveys/#{survey.survey_answers.where(:user => current_user.id).first.id.to_s}/answer_set" : "")
{
'survey' => survey,
'answer_present' => answer_present,
'link_to_answer_set' => link_to_answer_set,
'time_range' => QuestionnaireSurvey.time_range(survey)
}
@ -66,7 +72,9 @@ class SurveysController < ApplicationController
else
questions = survey.survey_questions.all.entries
current_user = OrbitHelper.current_user
answer_present = (current_user.nil? ? false : (survey.survey_answers.where(:user => current_user.id).count > 0 ? true : false))
link_to_answer_set = (answer_present ? "/admin/surveys/#{survey.survey_answers.where(:user => current_user.id).first.id.to_s}/answer_set" : "")
if survey.jump_mode
answers = Hash[questions.collect{ |o| [o.id.to_s, o.id.to_s] }]
jumpable_questions = questions.select{ |q| q.jumpable? && q.can_set_jump? }
@ -75,8 +83,10 @@ class SurveysController < ApplicationController
{
'survey' => survey,
'redirect_url' => '',
'link_to_answer_set' => link_to_answer_set,
'questions' => questions,
'answers' => answers,
'answer_present' => answer_present,
'jump_tos_map' => jump_tos_map
}

View File

@ -80,9 +80,11 @@
</div>
<% end %>
</div>
<% if can_edit_or_delete?(@survey) %>
<div class="action">
<a href="/admin/surveys/<%= @survey.id.to_s %>/answer_sets" class="btn btn-primary">Back to answer sets</a>
</div>
<% end %>
</div>

View File

@ -6,7 +6,7 @@
@questions = data["questions"]
@jump_tos_map = data["jump_tos_map"]
@answers = data["answers"]
answer_present = data['answer_present']
@redirect_url = data["redirect_url"]
%>
@ -15,6 +15,11 @@
<script type="text/javascript">
window.location.href = "<%= new_session_path %>";
</script>
<% elsif answer_present %>
<script type="text/javascript">
alert("Survey already taken.");
window.location.href = "<%= data['link_to_answer_set'] %>"
</script>
<% end %>

View File

@ -4,6 +4,8 @@
data = action_data
@survey = data["survey"]
@time_range = data["time_range"]
answer_present = data["answer_present"]
link_to_answer_set = data["link_to_answer_set"]
%>
<article class="show-survey" id="spen-survey">
@ -31,5 +33,9 @@
<% else %>
<%= link_to t('back'), page_for_survey, :class => 'btn btn-primary' %>
<% end %>
<%= link_to "Take survey", OrbitHelper.url_to_show(@survey.to_param), :class => 'btn btn-primary' %>
<% if !answer_present %>
<%= link_to "Take survey", OrbitHelper.url_to_show(@survey.to_param), :class => 'btn btn-primary' %>
<% else %>
<%= link_to "View answers", link_to_answer_set, :class => "btn btn-primary" %>
<% end %>