From 45d5972a93d98b576c57a8a78ed82a283949ccad Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 28 Jul 2015 10:27:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=8F=91=E5=B8=83=E9=97=AE=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E4=B8=AD=E9=97=B4=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 16 +- app/views/poll/_new_MC.html.erb | 1 + app/views/poll/_poll_form.html.erb | 186 ++++++++++++++++++++- app/views/poll/_show_MC.html.erb | 18 +- app/views/poll/_show_MCQ.html.erb | 14 +- app/views/poll/_show_mulit.html.erb | 14 +- app/views/poll/_show_single.html.erb | 14 +- app/views/poll/create_poll_question.js.erb | 6 +- public/stylesheets/polls.css | 5 +- 9 files changed, 261 insertions(+), 13 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 758747e02..8f81bc2c6 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -137,11 +137,19 @@ class PollController < ApplicationController @poll_questions.poll_answers.new question_option end end - if @poll_questions.save - respond_to do |format| - format.js - end + # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 + if params[:quest_id] + @is_insert = true + @poll.poll_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1") + @poll_question_num = params[:quest_num].to_i + @poll_questions.question_number = params[:quest_num].to_i + 1 end + if @poll_questions.save + respond_to do |format| + format.js + end + end + end #修改题目 diff --git a/app/views/poll/_new_MC.html.erb b/app/views/poll/_new_MC.html.erb index 8c47baa01..e5f2a6b82 100644 --- a/app/views/poll/_new_MC.html.erb +++ b/app/views/poll/_new_MC.html.erb @@ -1,5 +1,6 @@ <%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%> + <% insert_begin = insert_begin %>
diff --git a/app/views/poll/_poll_form.html.erb b/app/views/poll/_poll_form.html.erb index 74ca9fb32..0a15143fb 100644 --- a/app/views/poll/_poll_form.html.erb +++ b/app/views/poll/_poll_form.html.erb @@ -6,23 +6,203 @@ function edit_head(){ $("#polls_description").val($("#polls_description_div").html()); } - function add_MC(){ +function chooseQuestionType(quest_type,quest_id){ + $("#div_"+quest_type+"_"+quest_id).css("position", "absolute"); + + $("#div_"+quest_type+"_"+quest_id).css("top", $("#add_"+quest_type+"_"+quest_id).offset().top+30); + + $("#div_"+quest_type+"_"+quest_id).css("left", $("#add_"+quest_type+"_"+quest_id).offset().left-10); + if( $("#div_"+quest_type+"_"+quest_id).css('display') == 'block') { + $("#div_"+quest_type+"_"+quest_id).css('display', 'none'); + } + else{ + $("#div_"+quest_type+"_"+quest_id).css('display', 'block'); + } +} + +function add_MC(){ $("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_MC') %>"); $("#poll_questions_title").focus(); - } - function add_MCQ(){ +} + + function insert_MC(quest_type,quest_num,quest_id){ + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( + '<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+ + '
'+ + '
'+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + '
'+ + '
'+ + '
    '+ + '
  • '+ + ''+ + ''+ + ''+ + ''+ + '
  • '+ + '
    '+ + '
  • '+ + ''+ + ''+ + ''+ + ''+ + '
  • '+ + '
    '+ + '
  • '+ + ''+ + ''+ + ''+ + ''+ + '
  • '+ + '
    '+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '<% end%>' + ); + $("#poll_questions_title").focus(); +} + +function add_MCQ(){ $("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_MCQ') %>"); $("#poll_questions_title").focus(); +} + +function insert_MCQ(quest_type,quest_num,quest_id){ + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( + '<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+ + '
'+ + '
'+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + '
'+ + '
'+ + '
    '+ + '
  • '+ + ''+ + ''+ + ''+ + ''+ + '
  • '+ + '
    '+ + '
  • '+ + ''+ + ''+ + ''+ + ''+ + '
  • '+ + '
    '+ + '
  • '+ + ''+ + ''+ + ''+ + ''+ + '
  • '+ + '
    '+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '<% end%>' + ); + $("#poll_questions_title").focus(); } + function add_single(){ $("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_single') %>"); $("#poll_questions_title").focus(); } + + function insert_SINGLE(quest_type,quest_num,quest_id){ + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( + '<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+ + '
'+ + '
'+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + '
'+ + ''+ + '
'+ + '
'+ + '<% end%>' + ); + $("#poll_questions_title").focus(); + } function add_mulit(){ $("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_mulit') %>"); $("#poll_questions_title").focus(); } + function insert_MULIT(quest_type,quest_num,quest_id){ + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( + '<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+ + '
'+ + '
'+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + '
'+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '<% end%>' + ); + $("#poll_questions_title").focus(); + } + //添加标题时确定按钮 function add_poll_question(doc) { diff --git a/app/views/poll/_show_MC.html.erb b/app/views/poll/_show_MC.html.erb index ff8e52f25..9c47894dc 100644 --- a/app/views/poll/_show_MC.html.erb +++ b/app/views/poll/_show_MC.html.erb @@ -1,3 +1,6 @@ +
@@ -9,9 +12,11 @@ * <%end%>
+ <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> +
@@ -29,4 +34,15 @@
-
\ No newline at end of file +
+ +
+
+ \ No newline at end of file diff --git a/app/views/poll/_show_MCQ.html.erb b/app/views/poll/_show_MCQ.html.erb index 63b9d1c1f..fb2c03080 100644 --- a/app/views/poll/_show_MCQ.html.erb +++ b/app/views/poll/_show_MCQ.html.erb @@ -12,6 +12,7 @@ <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> +
@@ -29,4 +30,15 @@
-
\ No newline at end of file + + +
+
+ \ No newline at end of file diff --git a/app/views/poll/_show_mulit.html.erb b/app/views/poll/_show_mulit.html.erb index 2d52fffb5..ad01d0a3e 100644 --- a/app/views/poll/_show_mulit.html.erb +++ b/app/views/poll/_show_mulit.html.erb @@ -13,9 +13,21 @@ <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> +
- \ No newline at end of file + + +
+
+ \ No newline at end of file diff --git a/app/views/poll/_show_single.html.erb b/app/views/poll/_show_single.html.erb index 8caa7b1a5..f5846b6b7 100644 --- a/app/views/poll/_show_single.html.erb +++ b/app/views/poll/_show_single.html.erb @@ -12,8 +12,20 @@ <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> +
- \ No newline at end of file + + +
+
+ \ 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 index ac44ebb4c..8a597514e 100644 --- a/app/views/poll/create_poll_question.js.erb +++ b/app/views/poll/create_poll_question.js.erb @@ -1,4 +1,8 @@ +<% if @is_insert %> + $("#poll_content").html('<%= escape_javascript(render :partial => 'poll_content', :locals => {:poll => @poll})%>'); +<% else %> $("#new_poll_question").html(""); + $("#poll_content").append("
" + "
" + "<% if @poll_questions.question_type == 1%>" + @@ -23,4 +27,4 @@ $("#poll_content").append("
" + "<% end%>" + "
" + "
"); - +<% end %> diff --git a/public/stylesheets/polls.css b/public/stylesheets/polls.css index 353ec3937..83fa5089b 100644 --- a/public/stylesheets/polls.css +++ b/public/stylesheets/polls.css @@ -28,7 +28,7 @@ a:hover.pollsbtn{ background:#64bdd9; color:#fff; text-decoration:none;} #polls div{word-break: break-all;word-wrap: break-word;} .ur_prefix_content{ color:#656565; text-indent:30px; margin-top:10px; } .ur_card{border-top:1px solid #dcdcdc;margin-top:20px; color:#3a3a3a;} -.ur_title{ padding:20px 0px ; float:left; width:604px; } +.ur_title{ padding:20px 0px ; float:left; width:564px; } .ur_required{ font-weight: bold; color:red;} .ur_inputs{ color:#666;} .ur_table{border-top:1px solid #dcdcdc; background:#fff;} @@ -101,10 +101,13 @@ a:hover.icon_remove{background:url(images/icons.png) -20px -338px no-repeat;} .ur_editor02{width:648px; border:1px solid #cbcbcb; padding:10px; margin-bottom:10px;} a.ur_button_submit{ display:block; width:106px; height:31px; margin:0 auto; background:#15bccf; color:#fff; font-size:16px; text-align:center; padding-top:4px; margin-bottom:10px; } a:hover.ur_button_submit{ background:#0fa9bb; text-decoration:none;} + a.ur_icon_de{ background:url(images/icons.png) 0px -338px no-repeat; width:16px; height:27px; display:block;float:right; margin-top:15px;} a:hover.ur_icon_de{ background:url(images/icons.png) -20px -338px no-repeat;} .ur_icon_edit{ background:url(images/icons.png) 0px -272px no-repeat; width:16px; height:27px; display:block;float:right; margin-top:15px; margin-right:10px;} a:hover.ur_icon_edit{ background:url(images/icons.png) -21px -272px no-repeat;} +.ur_icon_add{ background:url(images/icons.png) 0px -310px no-repeat; width:16px; height:27px; display:block;float:right; margin-top:15px; margin-right:10px;} +a:hover.ur_icon_add{background:url(images/icons.png) -20px -310px no-repeat;} /***弹框***/ .popbox_polls{width:300px;height:100px;position:fixed !important;z-index:100;left:50%;top:50%;margin:-100px 0 0 -150px; background:#fff; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; box-shadow:0px 0px 8px #194a81; overflow:auto;}