From 5d82f3336e9a0392dc5990c04704dc7e5f2923b8 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Mon, 10 Aug 2015 09:12:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E4=BD=9C=E8=80=85?= =?UTF-8?q?=E6=98=AF=E6=88=91=EF=BC=8C=E4=BD=86=E6=98=AF=E9=97=AE=E5=8D=B7?= =?UTF-8?q?=E5=9C=A8=E5=85=B6=E4=BB=96=E8=AF=BE=E7=A8=8B=E9=87=8C=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E5=8D=B7=EF=BC=8C=E5=8F=AF=E4=BB=A5=E5=A4=9A=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 62 ++++++++++++++++++++++++++++++ app/helpers/poll_helper.rb | 9 +++++ app/views/poll/_poll.html.erb | 1 + app/views/poll/_poll_list.html.erb | 14 ++----- app/views/poll/index.html.erb | 5 +++ config/routes.rb | 3 ++ public/stylesheets/polls.css | 2 +- 7 files changed, 85 insertions(+), 11 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index dda5b81b2..b376a9acd 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -410,6 +410,68 @@ class PollController < ApplicationController end end + # 将其他地方的问卷导出来 + def other_poll + # 查作者是我,且不在当前课程内的问卷 进行导入 + @polls = Poll.where("user_id = #{User.current.id} and polls_type = 'course' and polls_group_id != #{params[:polls_group_id]}") + @polls_group_id = params[:polls_group_id] + respond_to do |format| + format.js + end + end + + # 将问卷导入本课程 + def import_other_poll + course_id = params[:course_id] + @course = Course.find(course_id) + params[:polls].each_with_index do |p,i| + poll = Poll.find(p) + option = { + :polls_name => poll.polls_name, + :polls_type => 'Course', + :polls_group_id => course_id, + :polls_status => 1, + :user_id => User.current.id, + :published_at => Time.now, + :closed_at => Time.now, + :show_result => 1, + :polls_description => poll.polls_description + } + @poll = Poll.create option + + poll.poll_questions.each do | q| + #question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title] + option = { + :is_necessary => q[:is_necessary], + :question_title => q[:question_title], + :question_type => q[:question_type] || 1, + :question_number => q[:question_number] + } + @poll_questions = @poll.poll_questions.new option + + for i in 1..q.poll_answers.count + answer = q.poll_answers[i-1].nil? ? l(:label_new_answer) : q.poll_answers[i-1][:answer_text] + question_option = { + :answer_position => i, + :answer_text => answer + } + @poll_questions.poll_answers.new question_option + end + end + @poll.save + end + @is_teacher = User.current.allowed_to?(:as_teacher,@course) + if @is_teacher + polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}") + else + polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2") + end + @polls = paginateHelper polls,20 #分页 + respond_to do |format| + format.js + end + end + private def find_poll_and_course @poll = Poll.find params[:id] diff --git a/app/helpers/poll_helper.rb b/app/helpers/poll_helper.rb index 3156f1b3a..0baad37ee 100644 --- a/app/helpers/poll_helper.rb +++ b/app/helpers/poll_helper.rb @@ -74,4 +74,13 @@ module PollHelper end end + #带勾选框的问卷列表 + def poll_check_box_tags(name,polls,current_poll) + s = '' + polls.each do |poll| + s << "
" + end + s.html_safe + end + end \ No newline at end of file diff --git a/app/views/poll/_poll.html.erb b/app/views/poll/_poll.html.erb index 180fed0f0..b4d944220 100644 --- a/app/views/poll/_poll.html.erb +++ b/app/views/poll/_poll.html.erb @@ -41,6 +41,7 @@
  • 导出
  • <% elsif poll.polls_status == 2 || poll.polls_status == 3 %>
  • <%= link_to "导出", export_poll_poll_path(poll.id,:format => "xls"), :class => "polls_de fr ml5"%>
  • + <% end%> diff --git a/app/views/poll/_poll_list.html.erb b/app/views/poll/_poll_list.html.erb index becfc32a5..fb8b765a3 100644 --- a/app/views/poll/_poll_list.html.erb +++ b/app/views/poll/_poll_list.html.erb @@ -3,20 +3,14 @@ (<%= @obj_count%>) <% if @is_teacher%> + <%= link_to "导入", other_poll_poll_index_path(:polls_group_id => @course.id), :remote=>true,:class => "newbtn"%> <%= link_to l(:label_new_poll), new_poll_path(:polls_type => "Course",:polls_group_id => @course.id), :class => "newbtn" %> <% end%>
    -
    - <% @polls.each do |poll|%> - -
    - <% end%> +
    + + <%= render :partial => 'polls_list', :locals => {:polls => @polls,:obj_pages=>@obj_pages,:obj_count=>@obj_count} %> -
    \ No newline at end of file diff --git a/app/views/poll/index.html.erb b/app/views/poll/index.html.erb index bede915b4..92a42cbac 100644 --- a/app/views/poll/index.html.erb +++ b/app/views/poll/index.html.erb @@ -80,6 +80,11 @@ $('#ajax-modal').parent().css("top","").css("left",""); $('#ajax-modal').parent().addClass("popbox_polls"); } + + function closeModal() + { + hideModal($("#popbox_upload")); + }
    <%= render :partial => 'poll_list'%> diff --git a/config/routes.rb b/config/routes.rb index 5af5ea3d7..9a14b4599 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,10 +83,13 @@ RedmineApp::Application.routes.draw do get 'close_poll' get 'export_poll' get 'import_poll' + end collection do delete 'delete_poll_question' post 'update_poll_question' + get 'other_poll' + post 'import_other_poll' end end diff --git a/public/stylesheets/polls.css b/public/stylesheets/polls.css index 83fa5089b..97faa0f57 100644 --- a/public/stylesheets/polls.css +++ b/public/stylesheets/polls.css @@ -130,7 +130,7 @@ a:hover.btn_de{ background:#ff5d31;} a.btn_pu{ border:1px solid #3cb761; color:#3cb761; } a:hover.btn_pu{ background:#3cb761;} .pollsbtn_grey{ border:1px solid #b1b1b1; color:#b1b1b1; padding:0px 9px; height:19px; padding-top:3px; } -.polls_title_w { width:300px; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;} +.polls_title_w { width:280px; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;} .polls_title_st { max-width:530px; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;} .polls_de_grey{ color:#b1b1b1; margin-top:3px;} .ml5{ margin-left:5px;} From 44f22feefd93b3e85745724bdb9cf950b74cd179 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Mon, 10 Aug 2015 09:13:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E4=BD=9C=E8=80=85?= =?UTF-8?q?=E6=98=AF=E6=88=91=EF=BC=8C=E4=BD=86=E6=98=AF=E9=97=AE=E5=8D=B7?= =?UTF-8?q?=E5=9C=A8=E5=85=B6=E4=BB=96=E8=AF=BE=E7=A8=8B=E9=87=8C=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E5=8D=B7=EF=BC=8C=E5=8F=AF=E4=BB=A5=E5=A4=9A=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/poll/_other_poll.html.erb | 27 +++++++++++++++++++++++++ app/views/poll/_polls_list.html.erb | 10 +++++++++ app/views/poll/import_other_poll.js.erb | 1 + app/views/poll/other_poll.js.erb | 9 +++++++++ 4 files changed, 47 insertions(+) create mode 100644 app/views/poll/_other_poll.html.erb create mode 100644 app/views/poll/_polls_list.html.erb create mode 100644 app/views/poll/import_other_poll.js.erb create mode 100644 app/views/poll/other_poll.js.erb diff --git a/app/views/poll/_other_poll.html.erb b/app/views/poll/_other_poll.html.erb new file mode 100644 index 000000000..c899f0d47 --- /dev/null +++ b/app/views/poll/_other_poll.html.erb @@ -0,0 +1,27 @@ +
    +
    +

    将以下问卷导入本课程

    +
    +
    + <%= form_tag import_other_poll_poll_index_path, + method: :post, + remote: true, + id: "relation_file_form" do %> + + <%= content_tag('div', poll_check_box_tags('polls[]', polls,polls_group_id), :id => 'courses')%> + 导  入 + 取  消 + <% end -%> +
    + + +
    +
    + + \ No newline at end of file diff --git a/app/views/poll/_polls_list.html.erb b/app/views/poll/_polls_list.html.erb new file mode 100644 index 000000000..c096f396d --- /dev/null +++ b/app/views/poll/_polls_list.html.erb @@ -0,0 +1,10 @@ +<% polls.each do |poll|%> + +
    +<% end%> + + \ No newline at end of file diff --git a/app/views/poll/import_other_poll.js.erb b/app/views/poll/import_other_poll.js.erb new file mode 100644 index 000000000..f60cea1c5 --- /dev/null +++ b/app/views/poll/import_other_poll.js.erb @@ -0,0 +1 @@ +$('#polls_list').html('<%= escape_javascript(render :partial => 'polls_list', :locals => {:polls => @polls,:obj_pages=>@obj_pages,:obj_count=>@obj_count}) %>
    '); \ No newline at end of file diff --git a/app/views/poll/other_poll.js.erb b/app/views/poll/other_poll.js.erb new file mode 100644 index 000000000..34f53b73e --- /dev/null +++ b/app/views/poll/other_poll.js.erb @@ -0,0 +1,9 @@ + +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'other_poll',:locals => {:polls => @polls,:polls_group_id=>@polls_group_id}) %>'); + + +showModal('ajax-modal', '513px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("popbox_polls"); \ No newline at end of file