This commit is contained in:
sw 2015-07-29 18:26:21 +08:00
commit a68fcf74aa
5 changed files with 81 additions and 1 deletions

View File

@ -336,6 +336,37 @@ class PollController < ApplicationController
end
end
def import_poll
@poll = Poll.find(params[:to_id])
question_num = @poll.poll_questions.select("max(question_number) question_number").first.question_number
import_poll = Poll.find(params[:import_id])
import_poll.poll_questions.each_with_index do |question,index|
option = {
:is_necessary => question.is_necessary,
:question_title => question.question_title,
:question_type => question.question_type,
:question_number => question_num + index+1
}
poll_questions = @poll.poll_questions.new option
for i in 1..question.poll_answers.count
answer = question.poll_answers[i-1][:answer_text]
question_option = {
:answer_position => i,
:answer_text => answer
}
poll_questions.poll_answers.new question_option
end
@poll.poll_questions << poll_questions
end
if @poll.save
@poll = Poll.find(params[:to_id])
respond_to do |format|
format.js
end
end
end
#重新发布问卷
def republish_poll
@poll.poll_questions.each do |poll_question|

View File

@ -3,6 +3,7 @@
<script type="text/javascript">
//编辑问卷描述之后
var popWindow ; //弹出框的引用
var importPollPopWindow; //选择导入的弹出框引用
function edit_head(){
$("#polls_description").val($("#polls_description_div").html());
}
@ -13,6 +14,9 @@ $(function(){
if(popWindow && e.target.nodeName != 'A' && !popWindow.is(e.target) && popWindow.has(e.target).length === 0){ // Mark 1
popWindow.css('display', 'none');
}
if(importPollPopWindow && e.target.nodeName != 'A' && !importPollPopWindow.is(e.target) && importPollPopWindow.has(e.target).length === 0){
importPollPopWindow.css('display', 'none');
}
});
})
@ -22,6 +26,7 @@ function dismiss(quest_type,quest_id){
popWindow.css('display', 'none');
}
}
function chooseQuestionType(quest_type,quest_id){
//quest_type 分为 mc mcq single multi
//quest_id 是quetion的id 下同
@ -228,6 +233,31 @@ function insert_MCQ(quest_type,quest_num,quest_id){
$("#poll_questions_title").focus();
}
//选择导入调查问卷
function importPoll(){
importPollPopWindow = $("#import_poll");
$("#import_poll").css("position", "absolute");
$("#import_poll").css("top", $("#import_btn").offset().top+30);
$("#import_poll").css("left", $("#import_btn").offset().left-65);
$("#import_poll").css("display","block")
}
function remote_import(){
importPollPopWindow.css('display', 'none');
if($("#import_poll").val() === 0){
return;
}else{
if(confirm("确认导入问卷"+$("#import_poll").find("option:selected").text()+"?")){
$("#import_form").submit();
}else{
return;
}
}
}
//添加标题时确定按钮
function add_poll_question(doc)
{
@ -352,5 +382,16 @@ function insert_MCQ(quest_type,quest_num,quest_id){
</div>
</div>
<div class="cl"></div>
<!-- 新增问题 -->
<div id="import_poll" style="display: none">
<%= form_tag({:controller => 'poll', :action => 'import_poll', :to_id => @poll.id},:remote=>'true', :method => :get,:id=>"import_form") do %>
<%= select( :poll, :id, Poll.where("polls_group_id = #{@poll.polls_group_id} and polls_type='course' and id != #{@poll.id}").map{|c| [c.polls_name, c.id]}.unshift(["选择要导入的问卷",0]),
{ :include_blank => false,:selected=> 0,:class=>"w90"
},
{:onchange=>"remote_import();",:id=>"import_id",:name=>"import_id"}
)
%>
<% end%>
</select>
</div>
</div><!--编辑end-->

View File

@ -1,5 +1,8 @@
<div class="ur_page_head ur_editor02" ><!--头部显示 start-->
<a href="javascript:" class="ur_icon_edit" title="编辑" onclick="pollsEdit();"></a>
<!-- <a class='ur_icon_add' title='导入' id="import_btn" onclick="importPoll();"></a> -->
<h1 class="ur_page_title" id="polls_name_h"><%= poll.polls_name%></h1>
<%= @poll.polls_description.nil? ? "" : @poll.polls_description.html_safe%>
<div class="cl"></div>

View File

@ -0,0 +1,4 @@
/**
* Created by lizanle on 2015/7/29.
*/
$("#poll_content").html('<%= escape_javascript(render :partial => 'poll_content', :locals => {:poll => @poll})%>');

View File

@ -82,6 +82,7 @@ RedmineApp::Application.routes.draw do
get 'poll_result'
get 'close_poll'
get 'export_poll'
get 'import_poll'
end
collection do
delete 'delete_poll_question'