From dc2c96f59a839039ee64932cafc8b402a1466d9e Mon Sep 17 00:00:00 2001 From: z9hang Date: Fri, 16 Jan 2015 10:19:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=90=8E=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E5=8D=B7=E7=A6=81=E6=AD=A2=E6=9F=A5=E7=9C=8B=E4=B8=8E=E7=BC=96?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 29 +- app/helpers/poll_helper.rb | 10 + app/views/poll/index.html.erb | 6 +- app/views/poll/show.html.erb | 8 +- .../stylesheets/window_js/mac_os_x_dialog.css | 320 +++++++++--------- public/stylesheets/polls.css | 1 + 6 files changed, 196 insertions(+), 178 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index feeb3c324..3e5e131c8 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -1,5 +1,5 @@ class PollController < ApplicationController - before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll] + before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer] 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] @@ -19,10 +19,16 @@ class PollController < ApplicationController def show @poll = Poll.find params[:id] - poll_questions = @poll.poll_questions - @poll_questions = paginateHelper poll_questions,3 #分页 - respond_to do |format| - format.html {render :layout => 'base_courses'} + #已提交问卷的用户不能再访问该界面 + if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?) + render_403 + else + @can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin? + poll_questions = @poll.poll_questions + @poll_questions = paginateHelper poll_questions,3 #分页 + respond_to do |format| + format.html {render :layout => 'base_courses'} + end end end @@ -141,6 +147,10 @@ class PollController < ApplicationController #提交答案 def commit_answer pq = PollQuestion.find(params[:poll_question_id]) + if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?) + render :text => 'failure' + return + end if pq.question_type == 1 #单选题 pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id) @@ -188,15 +198,8 @@ class PollController < ApplicationController render :text => "failure" end else - + render :text => "failure" end - - - #respond_to do |format| - # format.js - # format.json - #end - end #提交问卷 diff --git a/app/helpers/poll_helper.rb b/app/helpers/poll_helper.rb index 1c9ecd40f..7816d8e37 100644 --- a/app/helpers/poll_helper.rb +++ b/app/helpers/poll_helper.rb @@ -37,4 +37,14 @@ module PollHelper pv.vote_text end end + + #判断用户是否已经提交了问卷 + def has_commit_poll?(poll_id,user_id) + pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id) + if pu.nil? + false + else + true + end + end end \ No newline at end of file diff --git a/app/views/poll/index.html.erb b/app/views/poll/index.html.erb index 9d0bd5549..e45bdfabb 100644 --- a/app/views/poll/index.html.erb +++ b/app/views/poll/index.html.erb @@ -13,7 +13,11 @@ <% @polls.each do |poll|%>