diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb
index 739adfe1c..6890b8dd7 100644
--- a/app/controllers/poll_controller.rb
+++ b/app/controllers/poll_controller.rb
@@ -1,8 +1,8 @@
class PollController < ApplicationController
- before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll]
+ before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:republish_poll]
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,:publish_poll]
+ before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll]
include PollHelper
def index
if @course
@@ -311,6 +311,19 @@ class PollController < ApplicationController
end
end
+ #重新发布问卷
+ def republish_poll
+ @poll.poll_questions.each do |poll_question|
+ poll_question.poll_votes.destroy_all
+ end
+ @poll.poll_users.destroy_all
+ @poll.polls_status = 1
+ @poll.save
+ respond_to do |format|
+ format.js
+ end
+ end
+
private
def find_poll_and_course
@poll = Poll.find params[:id]
@@ -337,7 +350,8 @@ class PollController < ApplicationController
end
def is_course_teacher
- render_403 unless(@course && User.current.allowed_to?(:as_teacher,@course))
+ @is_teacher = User.current.allowed_to?(:as_teacher,@course)
+ render_403 unless(@course && @is_teacher)
end
#获取未完成的题目
diff --git a/app/views/poll/_poll.html.erb b/app/views/poll/_poll.html.erb
new file mode 100644
index 000000000..8ae766516
--- /dev/null
+++ b/app/views/poll/_poll.html.erb
@@ -0,0 +1,43 @@
+
+ <% if @is_teacher %>
+ <% if has_commit_poll?(poll.id ,User.current) %>
+ <%= poll.polls_name %>
+ <% else %>
+ <%= link_to poll.polls_name, poll_path(poll.id), :class => "polls_title fl" %>
+ <% end %>
+ <% else %>
+ <% if has_commit_poll?(poll.id ,User.current) && poll.polls_status == 2 %>
+
+ <%= poll.polls_name %>
+
+ <% elsif (!has_commit_poll?(poll.id ,User.current)) && poll.polls_status == 2 %>
+ <%= link_to poll.polls_name, poll_path(poll.id), :class => "polls_title fl" %>
+ <% end %>
+ <% end %>
+
+
+ <%if @is_teacher && poll.polls_status == 2%>
+ <%= link_to l(:label_statistical_results), statistics_result_poll_path(poll.id), :class => "pollsbtn fl ml10"%>
+ <% end%>
+
+
+ <% if @is_teacher %>
+
+ <%= link_to(l(:button_delete), poll,
+ method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml20 mr10") %>
+ <% end%>
+
+
+ <% if @is_teacher && poll.polls_status == 1%>
+
+ <%= link_to l(:button_edit), edit_poll_path(poll.id), :class => "polls_de fr ml20"%>
+ <% end%>
+
+
+ <% if @is_teacher && poll.polls_status == 2%>
+ <%= link_to "重新发布", republish_poll_poll_path(poll.id), :remote => true, :class => 'polls_de fr ml20' %>
+ <% end %>
+
+
+ <%= format_time poll.created_at%>
+
\ No newline at end of file
diff --git a/app/views/poll/index.html.erb b/app/views/poll/index.html.erb
index e57674c7a..fa378fc7b 100644
--- a/app/views/poll/index.html.erb
+++ b/app/views/poll/index.html.erb
@@ -12,44 +12,7 @@
<% @polls.each do |poll|%>
- -
- <% if @is_teacher %>
- <% if has_commit_poll?(poll.id ,User.current) %>
- <%= poll.polls_name %>
- <% else %>
- <%= link_to poll.polls_name, poll_path(poll.id), :class => "polls_title fl" %>
- <% end %>
- <% else %>
- <% if has_commit_poll?(poll.id ,User.current) && poll.polls_status == 2 %>
-
- <%= poll.polls_name %>
-
- <% elsif (!has_commit_poll?(poll.id ,User.current)) && poll.polls_status == 2 %>
- <%= link_to poll.polls_name, poll_path(poll.id), :class => "polls_title fl" %>
- <% end %>
- <% end %>
-
- -
- <%if @is_teacher && poll.polls_status == 2%>
- <%= link_to l(:label_statistical_results), statistics_result_poll_path(poll.id), :class => "pollsbtn fl ml10"%>
- <% end%>
-
- -
- <% if @is_teacher %>
-
- <%= link_to(l(:button_delete), poll,
- method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml20 mr10") %>
- <% end%>
-
- -
- <% if @is_teacher && poll.polls_status == 1%>
-
- <%= link_to l(:button_edit), edit_poll_path(poll.id), :class => "polls_de fr ml20"%>
- <% end%>
-
- -
- <%= format_time poll.created_at%>
-
+ <%= render :partial => 'poll', :locals => {:poll => poll} %>
<% end%>
diff --git a/app/views/poll/republish_poll.js.erb b/app/views/poll/republish_poll.js.erb
new file mode 100644
index 000000000..a7399af5b
--- /dev/null
+++ b/app/views/poll/republish_poll.js.erb
@@ -0,0 +1 @@
+$("#polls_<%= @poll.id %>").html("<%= escape_javascript(render :partial => 'poll',:locals => {:poll => @poll}) %>");
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index bd1b27dee..67b0118b0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -65,6 +65,7 @@ RedmineApp::Application.routes.draw do
post 'create_poll_question'
post 'commit_poll'
get 'publish_poll'
+ get 'republish_poll'
end
collection do
delete 'delete_poll_question'