forked from bofh/fetsite
update für questions
This commit is contained in:
@@ -16,7 +16,7 @@ class Survey::ChoicesController < ApplicationController
|
|||||||
@survey_choice = Survey::Choice.find(params[:id])
|
@survey_choice = Survey::Choice.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # show.html.erb
|
format.html {redirect_to @survey_choice.question}
|
||||||
format.json { render json: @survey_choice }
|
format.json { render json: @survey_choice }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,17 +3,14 @@ class Survey::QuestionsController < ApplicationController
|
|||||||
# GET /survey/questions.json
|
# GET /survey/questions.json
|
||||||
def index
|
def index
|
||||||
@survey_questions = Survey::Question.all
|
@survey_questions = Survey::Question.all
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.json { render json: @survey_questions }
|
format.json { render json: @survey_questions }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def answer
|
def answer
|
||||||
@survey_question = Survey::Question.find(params[:id])
|
@survey_question = Survey::Question.find(params[:id])
|
||||||
|
@survey_question.do_answer(params[:survey_question][:selected],current_user)
|
||||||
|
|
||||||
@survey_question.do_answer(params[:survey_question][:selected],current_user)
|
|
||||||
render :show
|
render :show
|
||||||
end
|
end
|
||||||
# GET /survey/questions/1
|
# GET /survey/questions/1
|
||||||
|
|||||||
@@ -13,18 +13,21 @@ class Survey::Question < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def do_answer(choice_ids, user)
|
def do_answer(choice_ids, user)
|
||||||
unless user.nil?
|
unless (user.nil? || choice_ids.nil? || choice_ids.empty?)
|
||||||
cid=choice_ids.map{|c|c.to_i}
|
cid=choice_ids.map{|c|c.to_i}
|
||||||
unless cid.empty?
|
if (Survey::Answer.where(user_id: user.id, choice_id: cid).count > 0 )
|
||||||
Survey::Answer.where(user_id: user.id, choice_id: self.choice_ids).delete_all
|
found_ids=Survey::Answer.where(user_id: user.id, choice_id: cid).includes(:choice).pluck(:choice_id)
|
||||||
cid.each do |c|
|
cid= cid - found_ids
|
||||||
if self.choice_ids.include?(c)
|
Survey::Answer.where(user_id: user.id, choice_id: found_ids).delete_all
|
||||||
a=Survey::Answer.new(user_id: user.id, choice_id: c.to_i)
|
else
|
||||||
a.save
|
Survey::Answer.where(user_id: user.id, choice_id: self.choice_ids).delete_all
|
||||||
|
end
|
||||||
|
cid.each do |c|
|
||||||
|
if self.choice_ids.include?(c)
|
||||||
|
a=Survey::Answer.new(user_id: user.id, choice_id: c.to_i)
|
||||||
|
a.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ $(function () {
|
|||||||
},
|
},
|
||||||
labels: {
|
labels: {
|
||||||
overflow: 'justify'
|
overflow: 'justify'
|
||||||
}
|
},
|
||||||
|
minTickInterval: 1
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
valueSuffix: ' votes'
|
valueSuffix: ' votes'
|
||||||
@@ -52,17 +53,6 @@ $(function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
legend: {
|
|
||||||
layout: 'vertical',
|
|
||||||
align: 'right',
|
|
||||||
verticalAlign: 'top',
|
|
||||||
x: -40,
|
|
||||||
y: 80,
|
|
||||||
floating: true,
|
|
||||||
borderWidth: 1,
|
|
||||||
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
|
|
||||||
shadow: true
|
|
||||||
},
|
|
||||||
credits: {
|
credits: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user