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 @@ -
-
-
- - - - -
-
-
    -
  • - - - - -
  • +<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%> +
    + +
    +
    + + + + + +
    +
    +
      +
    • + + + + +
    • +
      +
    • + + + + +
    • +
      +
    • + + + + +
    • +
      +
    +
    +
    -
  • - - - - -
  • -
    -
+
+
- -
-
- \ 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'%> +
+ +
+ + <%= l(:label_memo_create)%> + +
+
+ +
+ + 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 @@
- - - - - - - - - + <% poll_question.poll_answers.reorder("answer_position").each do |poll_answer| %> + + + + <% end %>
- -
- -
- -
+ +
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. -
      - 第1题: 单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题 * -
      -
      - - - - - - - - - - - - -
      - -
      - -
      - -
      -
      -
    2. - -
    3. -
      - 第2题: 多选题 * -
      -
      - - - - - - - - - - - - -
      - -
      - -
      - -
      -
      -
    4. - - -
    5. -
      - 第3题: 单行主观 -
      -
      - -
      -
    6. - -
    7. -
      -
      - 第4题: 多行主观 -
      -
      - -
      -
      -
    8. - + <% @poll_questions.each do |pq| %> + <% if pq.question_type == 1 %> + +
    9. +
      + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
      +
      +
      + + + <% pq.poll_answers.each do |pa| %> + + + + <% end %> + +
      + +
      +
      +
    10. + <% elsif pq.question_type == 2 %> + +
    11. +
      + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
      +
      +
      + + + <% pq.poll_answers.each do |pa| %> + + + + <% end %> + +
      + +
      +
      +
    12. + <% elsif pq.question_type == 3 %> + +
    13. +
      + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
      +
      +
      + +
      +
    14. + <% elsif pq.question_type == 4 %> + +
    15. +
      +
      + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
      +
      +
      + +
      +
      +
    16. + <% else %> + + <% end %> + <% end %>
    - -
    - 下一页 +
      + <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> +
    +
    +
    diff --git a/config/locales/zh.yml b/config/locales/zh.yml index d130cc666..9dae54818 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2249,5 +2249,7 @@ zh: label_MCQ: 多选题 label_single: 单行文字 label_mulit: 多行文字 + label_enter_single_title: 请输入单选题标题 + label_new_answer: 新建选项 diff --git a/config/routes.rb b/config/routes.rb index af0b75ae7..d2d0c73a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,7 +61,7 @@ RedmineApp::Application.routes.draw do resources :poll do member do get 'statistics_result' - get 'add_mc' + post 'create_poll_question' end end diff --git a/db/migrate/20150114022710_add_question_number_to_poll_questions.rb b/db/migrate/20150114022710_add_question_number_to_poll_questions.rb new file mode 100644 index 000000000..71f0328be --- /dev/null +++ b/db/migrate/20150114022710_add_question_number_to_poll_questions.rb @@ -0,0 +1,9 @@ +class AddQuestionNumberToPollQuestions < ActiveRecord::Migration + def self.up + add_column :poll_questions, :question_number, :integer + end + + def self.down + remove_column :poll_questions, :question_number + end +end diff --git a/db/schema.rb b/db/schema.rb index 627529a57..6c2a9f58a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -815,8 +815,9 @@ ActiveRecord::Schema.define(:version => 20150112090810) do t.integer "question_type" t.integer "is_necessary" t.integer "poll_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "question_number" end create_table "poll_users", :force => true do |t| diff --git a/public/stylesheets/polls.css b/public/stylesheets/polls.css index 428ade808..b13cb1da2 100644 --- a/public/stylesheets/polls.css +++ b/public/stylesheets/polls.css @@ -13,6 +13,11 @@ div,html,img,ul,li,p,body,h1,h2,h3,h4,p,a,table,tr,td,fieldset,input,span{ margi #polls .fl{ float: left;} #polls .fr{ float:right;} +/*问卷按钮*/ +.polls_btn{ height:33px;border-top:1px solid #15bed1; border-bottom:1px solid #15bed1;border-right:1px solid #cee6e6; width:225px; padding:7px 0 0 15px; } +.polls_btn a{font-size:14px; color:#444444;font-weight:bold;} +.polls_btn span{ color:#15bed1; font-size:12px; font-weight:normal;} + /*问卷列表*/ .polls_content{ width:615px;} .polls_head{ width:677px; height:48px; background:#eaeaea;}