diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb
index f9a07b134..084c43545 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]
+ before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question]
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,8 +19,8 @@ class PollController < ApplicationController
def show
@poll = Poll.find params[:id]
- @poll_questions = @poll.poll_questions
-
+ poll_questions = @poll.poll_questions
+ @poll_questions = paginateHelper poll_questions,3 #分页
respond_to do |format|
format.html {render :layout => 'base_courses'}
end
@@ -54,7 +54,9 @@ class PollController < ApplicationController
end
def edit
-
+ respond_to do |format|
+ format.html{render :layout => 'base_courses'}
+ end
end
def update
@@ -83,8 +85,30 @@ class PollController < ApplicationController
end
#添加单选题
- def add_mc
-
+ def create_poll_question
+ question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
+ option = {
+ :is_necessary => params[:is_necessary] || true,
+ :question_title => question_title,
+ :question_type => params[:question_type] || 1,
+ :question_number => @poll.poll_questions.count + 1
+ }
+ @poll_questions = @poll.poll_questions.new option
+ if params[:question_answer]
+ for i in 1..params[:question_answer].count
+ answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
+ question_option = {
+ :answer_position => i,
+ :answer_text => params[:question_answer].values[i-1]
+ }
+ @poll_questions.poll_answers.new question_option
+ end
+ end
+ if @poll_questions.save
+ respond_to do |format|
+ format.js
+ end
+ end
end
private
diff --git a/app/models/poll.rb b/app/models/poll.rb
index 803ee6ac6..06f1369c1 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -3,7 +3,7 @@ class Poll < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :user
- has_many :poll_questions, :dependent => :destroy
+ has_many :poll_questions, :dependent => :destroy,:order => "#{PollQuestion.table_name}.question_number"
has_many :poll_users, :dependent => :destroy
has_many :users, :through => :poll_users #该文件被哪些用户提交答案过
end
diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb
index 66dcea67e..2d9912fc2 100644
--- a/app/models/poll_question.rb
+++ b/app/models/poll_question.rb
@@ -3,6 +3,6 @@ class PollQuestion < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :poll
- has_many :poll_answers, :dependent => :destroy
+ has_many :poll_answers, :order => "#{PollAnswer.table_name}.answer_position",:dependent => :destroy
has_many :poll_votes, :dependent => :destroy
end
diff --git a/app/views/poll/_edit_MC.html.erb b/app/views/poll/_edit_MC.html.erb
index 73d967ca9..0f031f61c 100644
--- a/app/views/poll/_edit_MC.html.erb
+++ b/app/views/poll/_edit_MC.html.erb
@@ -1,33 +1,45 @@
-
-
\ No newline at end of file
+<% end%>
\ No newline at end of file
diff --git a/app/views/poll/_poll_form.html.erb b/app/views/poll/_poll_form.html.erb
new file mode 100644
index 000000000..473c1df83
--- /dev/null
+++ b/app/views/poll/_poll_form.html.erb
@@ -0,0 +1,83 @@
+
+
+
+
+
问卷调查_问卷编辑
+ <%= stylesheet_link_tag 'polls', :media => 'all' %>
+
+
+
+
+
+
+
+
+
+ <%= render :partial => 'edit_head'%>
+
+
+ <% @poll.poll_questions.each do |poll_question|%>
+ <%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %>
+ <% end%>
+
+
+ <%#= render :partial => 'edit_MC'%>
+
+
+
+
+
+
+
+
diff --git a/app/views/poll/_show_MC.html.erb b/app/views/poll/_show_MC.html.erb
index b156bc0bc..a33967ffd 100644
--- a/app/views/poll/_show_MC.html.erb
+++ b/app/views/poll/_show_MC.html.erb
@@ -1,10 +1,13 @@
- 第<%= question_index%>题:
+ 第<%= poll_question.question_number%>题:
- <%= poll_questions.question_title%>
- *
+ <%= poll_question.question_title %>
+ <%if poll_question.is_necessary == 1%>
+ *
+ <%end%>
+
@@ -12,24 +15,16 @@
diff --git a/app/views/poll/_show_head.html.erb b/app/views/poll/_show_head.html.erb
new file mode 100644
index 000000000..f8a2d58f0
--- /dev/null
+++ b/app/views/poll/_show_head.html.erb
@@ -0,0 +1,8 @@
+
+
标题标题标题标题标题标题标题
+
描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述
+ 描述描述描述描述描述描述描述描述描述描述描述描述
+
+
+
+
\ No newline at end of file
diff --git a/app/views/poll/create_poll_question.js.erb b/app/views/poll/create_poll_question.js.erb
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/views/poll/edit.html.erb b/app/views/poll/edit.html.erb
index a35b1d2e7..d346d0699 100644
--- a/app/views/poll/edit.html.erb
+++ b/app/views/poll/edit.html.erb
@@ -1,13 +1,2 @@
-
-<%= form_for(@poll) do |f|%>
- <%= f.text_field :polls_name, :required => true, :name => "polls_name"%>
-
- <%= l(:label_button_ok) %>
-
-<% end%>
+<%= render :partial => 'poll_form'%>
diff --git a/app/views/poll/index.html.erb b/app/views/poll/index.html.erb
index 150c13382..9d0bd5549 100644
--- a/app/views/poll/index.html.erb
+++ b/app/views/poll/index.html.erb
@@ -26,6 +26,11 @@
method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml20 mr10") %>
<% end%>
+
+ <% if @is_teacher%>
+ <%= link_to l(:button_edit), edit_poll_path(poll.id), :class => "polls_de fr ml20"%>
+ <% end%>
+
<%= format_time poll.created_at%>
diff --git a/app/views/poll/new.html.erb b/app/views/poll/new.html.erb
index 06ef2fae8..eddb3a590 100644
--- a/app/views/poll/new.html.erb
+++ b/app/views/poll/new.html.erb
@@ -1,59 +1 @@
-
-
-
-
-
问卷调查_问卷编辑
- <%= stylesheet_link_tag 'polls', :media => 'all' %>
-
-
-
-
-
-
-
-
-
-<%= render :partial => 'edit_head'%>
-
-
-
-
-
-
-
-
-
-
+<%= render :partial => 'poll_form'%>
\ No newline at end of file
diff --git a/app/views/poll/show.html.erb b/app/views/poll/show.html.erb
index 66fcd3bcd..26daa8fc5 100644
--- a/app/views/poll/show.html.erb
+++ b/app/views/poll/show.html.erb
@@ -20,86 +20,105 @@
-
- -
-
- 第1题: 单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题 *
-
-
-
-
- -
-
- 第2题: 多选题 *
-
-
-
-
-
- -
-
- 第3题: 单行主观
-
-
-
-
-
-
- -
-
-
-
+ <% @poll_questions.each do |pq| %>
+ <% if pq.question_type == 1 %>
+
+ -
+
+ 第<%= pq.question_number %>题:
+ <%= pq.question_title %>
+ <% if pq.is_necessary == 1 %>
+ *
+ <% end %>
+
+
+
+
+ <% elsif pq.question_type == 2 %>
+
+ -
+
+ 第<%= pq.question_number %>题:
+ <%= pq.question_title %>
+ <% if pq.is_necessary == 1 %>
+ *
+ <% end %>
+
+
+
+
+ <% elsif pq.question_type == 3 %>
+
+ -
+
+ 第<%= pq.question_number %>题:
+ <%= pq.question_title %>
+ <% if pq.is_necessary == 1 %>
+ *
+ <% end %>
+
+
+
+
+
+
+ <% elsif pq.question_type == 4 %>
+
+ -
+
+
+ 第<%= pq.question_number %>题:
+ <%= pq.question_title %>
+ <% if pq.is_necessary == 1 %>
+ *
+ <% end %>
+
+
+
+
+
+
+
+ <% else %>
+
+ <% end %>
+ <% end %>
-
-