diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb
index 18248331c..d13c02d27 100644
--- a/app/controllers/exercise_controller.rb
+++ b/app/controllers/exercise_controller.rb
@@ -1,7 +1,7 @@
class ExerciseController < ApplicationController
layout "base_courses"
- before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer]
+ before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise]
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list]
include ExerciseHelper
@@ -261,7 +261,7 @@ class ExerciseController < ApplicationController
end
# 发布试卷
- def publish_excercise
+ def publish_exercise
@exercise.exercise_status = 2
@exercise.publish_time = Time.now
if @exercise.save
@@ -276,16 +276,17 @@ class ExerciseController < ApplicationController
end
# 重新发布试卷
- def republish_excercise
+ # 重新发布的时候会删除所有的答题
+ def republish_exercise
@exercise.exercise_questions.each do |exercise_question|
exercise_question.exercise_ansers.destroy_all
end
- # @poll.poll_users.destroy_all
- # @poll.polls_status = 1
- # @poll.save
- # respond_to do |format|
- # format.js
- # end
+ @exercise.exercise_users.destroy_all
+ @exercise.exercise_status = 1
+ @exercise.save
+ respond_to do |format|
+ format.js
+ end
end
def student_exercise_list
diff --git a/app/views/exercise/_alert.html.erb b/app/views/exercise/_alert.html.erb
new file mode 100644
index 000000000..b3de53d1f
--- /dev/null
+++ b/app/views/exercise/_alert.html.erb
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb
index 15a684a62..e44cd69c6 100644
--- a/app/views/exercise/_exercise.html.erb
+++ b/app/views/exercise/_exercise.html.erb
@@ -19,9 +19,9 @@
<% end%>
<% if exercise.exercise_status == 1 %>
- 发布试卷
+ 发布试卷
<% elsif exercise.exercise_status == 2%>
- 取消发布
+ 取消发布
<% else%>
发布试卷
<% end%>
diff --git a/app/views/exercise/_exercise_republish.html.erb b/app/views/exercise/_exercise_republish.html.erb
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb
index bbe4dd707..8e8940f33 100644
--- a/app/views/exercise/index.html.erb
+++ b/app/views/exercise/index.html.erb
@@ -1,4 +1,91 @@
<%= stylesheet_link_tag 'polls', :media => 'all' %>
+
<%= render :partial => 'exercises_list'%>
\ No newline at end of file
diff --git a/app/views/exercise/publish_exercise.js.erb b/app/views/exercise/publish_exercise.js.erb
new file mode 100644
index 000000000..ac2899402
--- /dev/null
+++ b/app/views/exercise/publish_exercise.js.erb
@@ -0,0 +1,10 @@
+$("#exercises_<%= @exercise.id %>").html("<%= escape_javascript(render :partial => 'exercise',:locals => {:exercise => @exercise}) %>");
+$('#ajax-modal').html("<%= escape_javascript(render :partial => 'alert', locals: { :message => l(:label_memo_create_succ)}) %>");
+showModal('ajax-modal', '250px');
+//$('#ajax-modal').css('height','111px');
+$('#ajax-modal').siblings().remove();
+$('#ajax-modal').before("" +
+ "
");
+$('#ajax-modal').parent().removeClass("alert_praise");
+$('#ajax-modal').parent().css("top","").css("left","");
+$('#ajax-modal').parent().addClass("poll_alert_form");
\ No newline at end of file
diff --git a/app/views/exercise/republish_exercise.js.erb b/app/views/exercise/republish_exercise.js.erb
new file mode 100644
index 000000000..320cd3cf0
--- /dev/null
+++ b/app/views/exercise/republish_exercise.js.erb
@@ -0,0 +1,10 @@
+$("#exercises_<%= @exercise.id %>").html("<%= escape_javascript(render :partial => 'exercise_content',:locals => {:exercise => @exercise}) %>");
+$('#ajax-modal').html("<%= escape_javascript(render :partial => 'alert', locals: { :message => l(:label_poll_republish_success)}) %>");
+showModal('ajax-modal', '250px');
+//$('#ajax-modal').css('height','80px');
+$('#ajax-modal').siblings().remove();
+$('#ajax-modal').before("" +
+ "
");
+$('#ajax-modal').parent().removeClass("alert_praise");
+$('#ajax-modal').parent().css("top","").css("left","");
+$('#ajax-modal').parent().addClass("poll_alert_form");
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 516b8977f..559bf4376 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -152,6 +152,8 @@ RedmineApp::Application.routes.draw do
get 'statistics_result'
get 'student_exercise_list'
get 'export_exercise'
+ get 'publish_exercise'
+ get 'republish_exercise'
post 'create_exercise_question'
post 'commit_answer'
post 'commit_exercise'