多选题的上限

This commit is contained in:
cxt 2016-10-27 18:25:47 +08:00
parent df4bb86cdd
commit cc2ef93808
12 changed files with 120 additions and 39 deletions

View File

@ -143,7 +143,7 @@ class PollController < ApplicationController
if @before_que && @poll_question.update_attribute('question_number', @poll_question.question_number - 1)
@before_que.update_attribute('question_number', @before_que.question_number + 1)
end
elsif params[:opr] == 'down' && @poll_question.question_number < members.count
elsif params[:opr] == 'down' && @poll_question.question_number < poll_questions.count
@after_que = poll_questions.where("question_number = #{@poll_question.question_number + 1}").first
if @after_que && @poll_question.update_attribute('question_number', @poll_question.question_number + 1)
@after_que.update_attribute('question_number', @after_que.question_number - 1)
@ -157,12 +157,15 @@ class PollController < ApplicationController
#添加题目
def create_poll_question
@last_question = @poll.poll_questions.last
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" ? 1 : 0),
:question_title => question_title,
:question_type => params[:question_type] || 1,
:question_number => @poll.poll_questions.count + 1
:question_number => @poll.poll_questions.count + 1,
:max_choices => params[:max_choices].to_i || 0,
:min_choices => params[:min_choices].to_i || 0,
}
@poll_questions = @poll.poll_questions.new option
if params[:question_answer]

View File

@ -9,18 +9,6 @@
</div>
<div class="ur_editor_content">
<ul>
<li class='ur_item'>
<div class="fl mr30">
<label>下限<span class='ur_index'></span>&nbsp;&nbsp;&nbsp;</label>
<select class="poll-multiple-limit"></select>
<span>(可选)答题时最少选几项</span>
</div>
<div class="fl">
<label>上限<span class='ur_index'></span>&nbsp;&nbsp;&nbsp;</label>
<select class="poll-multiple-limit"></select>
<span>(可选)答题时最多选几项</span>
</div>
</li>
<li class='ur_item new_answer'>
<label>选项<span class='ur_index'></span>&nbsp;&nbsp;&nbsp;</label>
<input maxlength="200" type='text' name='question_answer[0]' placeholder='新建选项'/>
@ -41,6 +29,22 @@
<div class='cl'></div>
</ul>
<ul>
<li class='ur_item'>
<div class="fl mr30">
<label>下限<span class='ur_index'></span>&nbsp;&nbsp;&nbsp;</label>
<select name="min_choices" class="poll-multiple-limit"></select>
<span class="fontGrey2">(可选)答题时最少选几项</span>
</div>
</li>
<div class="cl"></div>
<li class='ur_item'>
<div class="fl mr30">
<label>上限<span class='ur_index'></span>&nbsp;&nbsp;&nbsp;</label>
<select name="max_choices" class="poll-multiple-limit"></select>
<span class="fontGrey2">(可选)答题时最多选几项</span>
</div>
</li>
<div class="cl"></div>
<li class="ur_item">
<div class="dash-block new-question" onclick='add_single_answer($(this));'>新建选项</div>
</li>

View File

@ -24,16 +24,3 @@
</div>
</div>
<% end %>
<script>
$(".poll-add").mouseover(function(){
$(this).next().show();
}).mouseout(function(){
$(this).next().hide();
});
$(".poll-add-menu").mouseover(function(){
$(this).show();
}).mouseout(function(){
$(this).hide();
});
</script>

View File

@ -480,9 +480,9 @@ function insert_MCQ(quest_type,quest_id){
//多选题答题限制数实时更新
function multiLimit(){
var upperLimit = $(".questionContainer .new_answer").size();
$(".poll-multiple-limit").append("<option></option>");
$(".poll-multiple-limit").append("<option value='0'></option>");
for(var i = 1; i <= upperLimit; i++){
$(".poll-multiple-limit").append("<option>" + i + "</option>");
$(".poll-multiple-limit").append("<option value='"+ i +"'>" + i + "</option>");
}
}

View File

@ -4,8 +4,14 @@
<span class="c_red questionLabel ml5" title="必答">*</span>
<%end%>
</p>
<a class="poll-up mb8" title="上移"></a>
<a class="poll-down mb8" title="下移"></a>
<% poll = poll_question.poll %>
<% count = poll.poll_questions.count %>
<% unless poll_question.question_number == 1 %>
<%= link_to('', {:controller => 'poll', :action => 'update_question_num', :id => poll.id, :ques_id => poll_question.id, :opr => 'up'},:remote => true, :method => 'post', :class => "poll-up mb8", :title => '上移') %>
<% end %>
<% if poll_question.question_number < count %>
<%= link_to('', {:controller => 'poll', :action => 'update_question_num', :id => poll.id, :ques_id => poll_question.id, :opr => 'down'},:remote => true, :method => 'post', :class => "poll-down mb8", :title => '下移') %>
<% end %>
<a href="javascript:void(0);" class="poll-add mb8"></a>
<ul class="poll-add-menu fontGrey3">
<li><a href="javascript:void(0);" onclick=" dismiss('<%=type %>',<%=poll_question.id%>);insert_MC('<%=type %>',<%=poll_question.id%>);">单选题</a></li>

View File

@ -38,3 +38,15 @@
<!-- 新增问题 -->
<div id="insert_new_poll_question_mc_<%=poll_question.id%>">
</div>
<script>
$(".poll-add").mouseover(function(){
$(this).next().show();
}).mouseout(function(){
$(this).next().hide();
});
$(".poll-add-menu").mouseover(function(){
$(this).show();
}).mouseout(function(){
$(this).hide();
});
</script>

View File

@ -6,6 +6,17 @@
<div class="testEditTitle" style="padding-top:0;">
<span class="formatContainer m_w500"><%= poll_question.question_title %></span>
<span class="fontBlue">[多选题]</span>
<% if poll_question.min_choices != 0 || poll_question.max_choices != 0 %>
<p class="fontGrey2">
<% if poll_question.min_choices != 0 && poll_question.max_choices != 0 %>
答题时最少选<%=poll_question.min_choices %>项、最多选<%=poll_question.max_choices %>项
<% elsif poll_question.min_choices != 0 %>
答题时最少选<%=poll_question.min_choices %>项
<% elsif poll_question.max_choices != 0 %>
答题时最多选<%=poll_question.max_choices %>项
<% end %>
</p>
<% end %>
</div>
<a class="poll-edit" title="编辑" onclick="pollQuestionEdit(<%= poll_question.id%>);"></a>
<div class="cl"></div>
@ -37,3 +48,15 @@
<!-- 新增问题 -->
<div id="insert_new_poll_question_mcq_<%=poll_question.id%>">
</div>
<script>
$(".poll-add").mouseover(function(){
$(this).next().show();
}).mouseout(function(){
$(this).next().hide();
});
$(".poll-add-menu").mouseover(function(){
$(this).show();
}).mouseout(function(){
$(this).hide();
});
</script>

View File

@ -21,3 +21,15 @@
<!-- 新增问题 -->
<div id="insert_new_poll_question_mulit_<%=poll_question.id%>">
</div>
<script>
$(".poll-add").mouseover(function(){
$(this).next().show();
}).mouseout(function(){
$(this).next().hide();
});
$(".poll-add-menu").mouseover(function(){
$(this).show();
}).mouseout(function(){
$(this).hide();
});
</script>

View File

@ -18,3 +18,15 @@
<!-- 新增问题 -->
<div id="insert_new_poll_question_single_<%=poll_question.id%>">
</div>
<script>
$(".poll-add").mouseover(function(){
$(this).next().show();
}).mouseout(function(){
$(this).next().hide();
});
$(".poll-add-menu").mouseover(function(){
$(this).show();
}).mouseout(function(){
$(this).hide();
});
</script>

View File

@ -2,6 +2,17 @@
$("#poll_content").html('<%= escape_javascript(render :partial => 'poll_content', :locals => {:poll => @poll})%>');
<% else %>
$("#new_poll_question_new").html("");
<% if @last_question %>
<% if @last_question.question_type == 1%>
$("#show_poll_questions_<%= @last_question.id %>").html("<%= escape_javascript(render :partial => 'show_MC', :locals => {:poll_question => @last_question}) %>");
<% elsif @last_question.question_type == 2%>
$("#show_poll_questions_<%= @last_question.id %>").html("<%= escape_javascript(render :partial => 'show_MCQ', :locals => {:poll_question => @last_question}) %>");
<% elsif @last_question.question_type == 3%>
$("#show_poll_questions_<%= @last_question.id %>").html("<%= escape_javascript(render :partial => 'show_single', :locals => {:poll_question => @last_question}) %>");
<% elsif @last_question.question_type == 4%>
$("#show_poll_questions_<%= @last_question.id %>").html("<%= escape_javascript(render :partial => 'show_mulit', :locals => {:poll_question => @last_question}) %>");
<% end%>
<% end %>
$("#poll_content").append("<div id='poll_questions_<%= @poll_questions.id%>'>" +
"<div id='show_poll_questions_<%= @poll_questions.id %>'>" +
"<% if @poll_questions.question_type == 1%>" +

View File

@ -109,6 +109,17 @@
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
<% end %>
<% if pq.min_choices != 0 || pq.max_choices != 0 %>
<p class="fontGrey2">
<% if pq.min_choices != 0 && pq.max_choices != 0 %>
答题时最少选<%=pq.min_choices %>项、最多选<%=pq.max_choices %>项
<% elsif pq.min_choices != 0 %>
答题时最少选<%=pq.min_choices %>项
<% elsif pq.max_choices != 0 %>
答题时最多选<%=pq.max_choices %>项
<% end %>
</p>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">

View File

@ -269,7 +269,7 @@ RedmineApp::Application.routes.draw do
get 'close_poll'
get 'export_poll'
get 'import_poll'
post 'update_question_num'
end
collection do
delete 'delete_poll_question'