added qustions span and ranges
This commit is contained in:
parent
4d57437144
commit
c828fe7ace
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -2,6 +2,14 @@
|
|||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
<%= stylesheet_link_tag "lib/wrap-nav" %>
|
||||
<%= stylesheet_link_tag "lib/main-list" %>
|
||||
<style>
|
||||
.criteria-block{
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
border-bottom: 2px solid;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
</style>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "jquery-ui-custom.js" %>
|
||||
|
@ -67,23 +75,37 @@
|
|||
</div>
|
||||
<div id="criterias" class="controls" style="width:850px;">
|
||||
<% if @survey.result_criteria.blank? %>
|
||||
<div class="criteria-span" style="margin-left:0px;display:block;">
|
||||
<label style="padding-left:0px;" for="" class="radio inline"> From : <input name="questionnaire_survey[result_criteria][0][]" class="span1" max="<%= @survey.total_points %>" type="number"></label>
|
||||
<label for="" class="radio inline"> To : <input name="questionnaire_survey[result_criteria][0][]" class="span1" max="<%= @survey.total_points %>" type="number"></label>
|
||||
<div class="criteria-block">
|
||||
<div class="criteria" style="margin-left:0px;display:block;">
|
||||
<label style="padding-left:0px;" for="" class="radio inline"> Question from : <input name="questionnaire_survey[result_criteria][0][questions][]" class="span1" max="<%= @surveysurvey_questionscount %>" type="number" min="1"></label>
|
||||
<label for="" class="radio inline"> Question to : <input name="questionnaire_survey[result_criteria][0][questions][]" class="span1" min="1" max="<%= @survey.survey_questions.count %>" type="number"></label>
|
||||
</div>
|
||||
<div class="criteria" style="margin-left:0px;display:block;">
|
||||
<label style="padding-left:0px;" for="" class="radio inline"> From : <input name="questionnaire_survey[result_criteria][0][range][]" class="span1" max="<%= @survey.total_points %>" type="number"></label>
|
||||
<label for="" class="radio inline"> To : <input name="questionnaire_survey[result_criteria][0][range][]" class="span1" max="<%= @survey.total_points %>" type="number"></label>
|
||||
<label for="" class="radio inline">Save to add text</label>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<% @survey.result_criteria.each_with_index do |criteria, idx| %>
|
||||
<div class="criteria-span" style="margin-left:0px;display:block;margin-bottom:50px;">
|
||||
<label style="padding-left:0px;" for="" class="radio inline"> From : <input name="questionnaire_survey[result_criteria][<%= idx %>][]" class="span1" max="<%= @survey.total_points %>" type="number" value="<%= criteria[0] %>"></label>
|
||||
<label for="" class="radio inline"> To : <input name="questionnaire_survey[result_criteria][<%= idx %>][]" class="span1" max="<%= @survey.total_points %>" type="number" value="<%= criteria[1] %>"></label>
|
||||
<div class="criteria-block">
|
||||
<div class="criteria">
|
||||
<label style="padding-left:0px;" for="" class="radio inline"> Question from : <input name="questionnaire_survey[result_criteria][<%= idx %>][questions][]" class="span1" max="<%= @survey.survey_questions.count %>" min="1" type="number" value="<%= criteria["questions"][0] rescue "" %>"></label>
|
||||
<label for="" class="radio inline"> Question to : <input name="questionnaire_survey[result_criteria][<%= idx %>][questions][]" class="span1" max="<%= @survey.survey_questions.count %>" min="1" type="number" value="<%= criteria["questions"][1] rescue "" %>"></label>
|
||||
</div>
|
||||
<div class="criteria" style="margin-left:0px;display:block;margin-bottom:50px;">
|
||||
<label style="padding-left:0px;" for="" class="radio inline"> From : <input name="questionnaire_survey[result_criteria][<%= idx %>][range][]" class="span1" max="<%= @survey.total_points %>" type="number" value="<%= criteria["range"][0] rescue "" %>"></label>
|
||||
<label for="" class="radio inline"> To : <input name="questionnaire_survey[result_criteria][<%= idx %>][range][]" class="span1" max="<%= @survey.total_points %>" type="number" value="<%= criteria["range"][1] rescue "" %>"></label>
|
||||
<% if idx != 0 %>
|
||||
<a href="" style="margin-left:5px;" class="btn btn-danger delete-critera"><i class="icon icon-trash"></i></a>
|
||||
<% end %>
|
||||
<label for="" class="radio inline">
|
||||
<textarea class="ckeditor" name="questionnaire_survey[result_criteria][<%= idx %>][]"><%= criteria[2] %></textarea>
|
||||
</label>
|
||||
</div>
|
||||
<div class="criteria">
|
||||
<label for="" class="radio inline">
|
||||
<textarea class="ckeditor" name="questionnaire_survey[result_criteria][<%= idx %>][msg]"><%= criteria["msg"] rescue "" %></textarea>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
@ -108,7 +130,7 @@
|
|||
$(".selectable[data-type=" + selectedOption.value + "]").removeClass("hide");
|
||||
}
|
||||
var index = <%= @survey.result_criteria.count == 0 ? 1 : @survey.result_criteria.count + 1 %>,
|
||||
html = '<div data-critera-number="criteria_{index}" class="criteria-span" style="width:800px;"><label style="padding-left:0px;" for="" class="radio inline"> From : <input name="questionnaire_survey[result_criteria][{index}][]" class="span1" max="<%= @survey.total_points %>" type="number"></label><label for="" class="radio inline"> To : <input name="questionnaire_survey[result_criteria][{index}][]" class="span1" max="<%= @survey.total_points %>" type="number"></label><a href="" style="margin-left:5px;" class="btn btn-primary delete-critera"><i class="icon icon-trash"></i></a><span class="radio inline">Save to add text</span></div>';
|
||||
html = '<div class="criteria-block"><div><label style="padding-left:0px;" for="" class="radio inline"> Questions from : <input name="questionnaire_survey[result_criteria][{index}][questions][]" class="span1" min="1" max="<%= @survey.survey_questions.count %>" type="number"></label><label for="" class="radio inline"> Questions to : <input name="questionnaire_survey[result_criteria][{index}][questions][]" class="span1" min="1" max="<%= @survey.survey_questions.count %>" type="number"></label></div><div data-critera-number="criteria_{index}" class="criteria" style="width:800px;"><label style="padding-left:0px;" for="" class="radio inline"> From : <input name="questionnaire_survey[result_criteria][{index}][range][]" class="span1" max="<%= @survey.total_points %>" type="number"></label><label for="" class="radio inline"> To : <input name="questionnaire_survey[result_criteria][{index}][range][]" class="span1" max="<%= @survey.total_points %>" type="number"></label><a href="" style="margin-left:5px;" class="btn btn-primary delete-critera"><i class="icon icon-trash"></i></a><span class="radio inline">Save to add text</span></div></div>';
|
||||
|
||||
$("#add-criteria").on("click",function(){
|
||||
var newhtml = html.replace(/{index}/g,index);
|
||||
|
@ -119,7 +141,7 @@
|
|||
})
|
||||
|
||||
$(document).on("click", ".delete-critera" ,function(){
|
||||
$(this).parent().remove();
|
||||
$(this).parent().parent().remove();
|
||||
return false;
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -7,8 +7,14 @@
|
|||
<% if @survey.result_type == 3 %>
|
||||
<h3>Your total score is <%= @answer_model.scored_points %> </h3>
|
||||
<% @survey.result_criteria.each do |criteria| %>
|
||||
<% if (criteria[0].to_i..criteria[1].to_i).cover?(@answer_model.scored_points) %>
|
||||
<div> <%= criteria[2].html_safe %> </div>
|
||||
<%
|
||||
total_criteria_score = 0
|
||||
(criteria["questions"][0].to_i..criteria["questions"][1].to_i).each do |x|
|
||||
total_criteria_score = (total_criteria_score + @answer_model.individual_total[x].to_i) rescue 0
|
||||
end
|
||||
%>
|
||||
<% if (criteria["range"][0].to_i..criteria["range"][1].to_i).cover?(total_criteria_score) %>
|
||||
<div> <%= criteria["msg"].html_safe %> </div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
|
|
Loading…
Reference in New Issue