答题相关方法添加

This commit is contained in:
z9hang 2015-01-15 09:41:19 +08:00
parent b6826a74d3
commit 6d82e79e7f
5 changed files with 80 additions and 3 deletions

View File

@ -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]

View File

@ -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

View File

@ -0,0 +1,3 @@
<% if @pv_saved %>
$('#poll_vote_poll_answer_id_<%= @pv.poll_answer_id %>').checked = true;
<% end %>

View File

@ -4,6 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>问卷调查_问卷页面</title>
<%= stylesheet_link_tag 'polls', :media => 'all' %>
<%= javascript_heads %>
</head>
<body>
@ -33,20 +34,37 @@
</div>
<div class="cl"></div>
<div class="ur_inputs">
<%= form_tag(commit_answer_poll_path(@poll),:remote => true,:id => 'form_'+ pq.id.to_s) do %>
<table class="ur_table" >
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label >
<input class="ur_radio" type="radio" value="新建选项" >
<%= pa.answer_text %>
<script>
function clickOK()
{
$.ajax({
type: "GET",
url: "<%= bid.comment_status == 0 ? start_anonymous_comment_bid_path(bid) : stop_anonymous_comment_bid_path(bid)%>",
data: 'text',
success: function (data) {
}
});
}
</script>
<%= radio_button "poll_vote","poll_answer_id",pa.id,:class=>"ur_radio",:onclick =>"this.form.submit();return false" %>
<%= hidden_field_tag "poll_question_id",pq.id %>
<%= pa.answer_text %>
</label>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
</li>
<% elsif pq.question_type == 2 %>

View File

@ -62,6 +62,7 @@ RedmineApp::Application.routes.draw do
member do
get 'statistics_result'
get 'add_mc'
post 'commit_answer'
end
end