diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 88bbfff46..3ea1934f5 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -3,7 +3,7 @@ class PollController < ApplicationController before_filter :find_container, :only => [:new,:create, :index] before_filter :is_member_of_course, :only => [:index,:show] before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy] - + include PollHelper def index if @course @is_teacher = User.current.allowed_to?(:as_teacher,@course) @@ -86,6 +86,26 @@ class PollController < ApplicationController end + #提交答案 + def commit_answer + @pv = get_poll_vote(User.current.id,params[:poll_question_id]) + if params[:poll_vote][:poll_answer_id] + @pv.poll_answer_id = params[:poll_vote][:poll_answer_id] + end + if params[:poll_vote][:vote_text] + @pv.vote_text = params[:poll_vote][:vote_text] + end + @pv_saved = false + if @pv.save + @pv_saved = true + end + #respond_to do |format| + # format.js + # format.json + #end + render :text => "ok" + end + private def find_poll_and_course @poll = Poll.find params[:id] diff --git a/app/helpers/poll_helper.rb b/app/helpers/poll_helper.rb new file mode 100644 index 000000000..202f33eaa --- /dev/null +++ b/app/helpers/poll_helper.rb @@ -0,0 +1,35 @@ +# encoding: utf-8 +# +# Redmine - project management software +# Copyright (C) 2006-2013 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module PollHelper + def get_poll_vote(user_id,poll_question_id) + pq = PollQuestion.find(poll_question_id) + if pq.question_type == 1 + pv = PollVote.find_by_poll_question_id_and_user_id(poll_question_id,user_id) + if pv.nil? + pv = PollVote.new + pv.user_id = user_id + pv.poll_question_id = poll_question_id + pv + else + pv + end + end + end +end \ No newline at end of file diff --git a/app/views/poll/commit_answer.js.erb b/app/views/poll/commit_answer.js.erb new file mode 100644 index 000000000..b698d8658 --- /dev/null +++ b/app/views/poll/commit_answer.js.erb @@ -0,0 +1,3 @@ +<% if @pv_saved %> +$('#poll_vote_poll_answer_id_<%= @pv.poll_answer_id %>').checked = true; +<% end %> \ No newline at end of file diff --git a/app/views/poll/show.html.erb b/app/views/poll/show.html.erb index 26daa8fc5..08dae18b2 100644 --- a/app/views/poll/show.html.erb +++ b/app/views/poll/show.html.erb @@ -4,6 +4,7 @@