新建测验题目、问卷题目防止多次提交表单

This commit is contained in:
cxt 2016-05-13 16:50:41 +08:00
parent 3e340b6ef9
commit bc39b68bb2
13 changed files with 135 additions and 36 deletions

View File

@ -87,10 +87,19 @@
var standard_ans = $.trim($("#question_standard_ans").val());
if(title.length == 0 || score.length == 0){
alert("题目标题/分数不能为空");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
}else if(!/^[1-9][0-9]*$/.test(score)) {
alert("分数必须是非零开头的数字");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
}else if(quest_type !=3 && standard_ans.length == 0) {
alert("标准答案不能为空");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
}else{
doc.parent().parent().parent().submit();}
}

View File

@ -54,9 +54,16 @@
</ul>
</div>
<div class="ur_editor_footer">
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),1);"> 保存 </a>
<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question"> 保存 </a>
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();"> 取消 </a>
</div>
<div class="cl"></div>
</div>
<% end %>
<script type="text/javascript">
$(function(){
$("#add_new_question").one('click', function(){
add_poll_question($(this),1);
});
});
</script>

View File

@ -54,9 +54,16 @@
</ul>
</div>
<div class="ur_editor_footer">
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),2);"> 保存 </a>
<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question"> 保存 </a>
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();"> 取消 </a>
</div>
<div class="cl"></div>
</div>
<% end %>
<script type="text/javascript">
$(function(){
$("#add_new_question").one('click', function(){
add_poll_question($(this),2);
});
});
</script>

View File

@ -42,9 +42,16 @@
</ul>
</div>
<div class="ur_editor_footer">
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),3);"> 保存 </a>
<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question"> 保存 </a>
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();"> 取消 </a>
</div>
<div class="cl"></div>
</div>
<% end %>
<script type="text/javascript">
$(function(){
$("#add_new_question").one('click', function(){
add_poll_question($(this),3);
});
});
</script>

View File

@ -90,7 +90,7 @@
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),1);">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question">'+
'保存'+
'</a>'+
'<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -102,6 +102,9 @@
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this),1);
});
}
}
else {

View File

@ -89,7 +89,7 @@
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),2);">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question">'+
'保存'+
'</a>'+
'<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -101,6 +101,9 @@
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this),2);
});
}
}else {
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html("");

View File

@ -65,7 +65,7 @@
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this),3);">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question">'+
'保存'+
'</a>'+
'<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -77,6 +77,9 @@
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this),3);
});
}
} else {
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html("");

View File

@ -5,7 +5,7 @@
<div class="ur_editor_title">
<label>问题:&nbsp;&nbsp;</label>
<input type="hidden" name="question_type" value="1"/>
<input maxlength="250" class="ur_question_title" type="text" name="poll_questions_title" id="poll_questions_title" placeholder="请输入单选题标题"/>
<input maxlength="250" class="ur_question_title" type="text" name="poll_questions_title" id="poll_questions_title_new" placeholder="请输入单选题标题"/>
<input type="checkbox" name="is_necessary" value="true" checked/>
<label>必答</label>
</div>
@ -35,7 +35,7 @@
</ul>
</div>
<div class="ur_editor_footer">
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this));">
<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question_new">
<%= l(:label_button_ok)%>
</a>
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">
@ -46,3 +46,10 @@
</div>
<!--编辑单选 end-->
<% end%>
<script type="text/javascript">
$(function(){
$("#add_new_question_new").one('click', function(){
add_poll_question_new($(this));
});
});
</script>

View File

@ -3,7 +3,7 @@
<div class="ur_editor_title">
<label>问题:&nbsp;&nbsp;</label>
<input type="hidden" name="question_type" value="2"/>
<input maxlength="250" class="ur_question_title" type="text" name="poll_questions_title" id="poll_questions_title" placeholder="请输入多选题标题"/>
<input maxlength="250" class="ur_question_title" type="text" name="poll_questions_title" id="poll_questions_title_new" placeholder="请输入多选题标题"/>
<input type="checkbox" name="is_necessary" value="true" checked/>
<label>必答</label>
</div>
@ -33,7 +33,7 @@
</ul>
</div>
<div class="ur_editor_footer">
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this));">
<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question_new">
<%= l(:label_button_ok)%>
</a>
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">
@ -43,3 +43,10 @@
<div class="cl"></div>
</div>
<% end%><!--编辑多选 end-->
<script type="text/javascript">
$(function(){
$("#add_new_question_new").one('click', function(){
add_poll_question_new($(this));
});
});
</script>

View File

@ -3,7 +3,7 @@
<div class="ur_editor_title">
<label for="ur_question_title">问题:&nbsp;&nbsp;</label>
<input type="hidden" name="question_type" value="4"/>
<input maxlength="250" id="poll_questions_title" class="ur_question_title" contenteditable="true" type="text" name="poll_questions_title" placeholder="请输入多行主观标题"/>
<input maxlength="250" id="poll_questions_title_new" class="ur_question_title" contenteditable="true" type="text" name="poll_questions_title" placeholder="请输入多行主观标题"/>
<input type="checkbox" name="is_necessary" value="true" checked/>
<label>必答</label>
</div>
@ -13,7 +13,7 @@
<!--<label>高 <input name="rows" type="number" min="1" value="5"> 行</label>-->
</div>
<div class="ur_editor_footer">
<a class="btn_submit c_white" data-button="ok" onclick="add_poll_question($(this));">
<a class="btn_submit c_white" data-button="ok" id="add_new_question_new">
<%= l(:label_button_ok)%>
</a>
<a class="btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">
@ -23,3 +23,10 @@
<div class="cl"></div>
</div><!--编辑多行文字end-->
<% end%>
<script type="text/javascript">
$(function(){
$("#add_new_question_new").one('click', function(){
add_poll_question_new($(this));
});
});
</script>

View File

@ -3,12 +3,12 @@
<div class="ur_editor_title">
<label for="ur_question_title">问题:&nbsp;&nbsp;</label>
<input type="hidden" name="question_type" value="3"/>
<input maxlength="250" id="poll_questions_title" class="ur_question_title" contenteditable="true" type="text" name="poll_questions_title" placeholder="请输入单行主观标题"/>
<input maxlength="250" id="poll_questions_title_new" class="ur_question_title" contenteditable="true" type="text" name="poll_questions_title" placeholder="请输入单行主观标题"/>
<input type="checkbox" name="is_necessary" value="true" checked/>
<label for="ur_question_require">必答</label>
</div>
<div class="ur_editor_footer">
<a class="btn_submit c_white" data-button="ok" onclick="add_poll_question($(this));">
<a class="btn_submit c_white" data-button="ok" id="add_new_question_new">
<%= l(:label_button_ok)%>
</a>
<a class="btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">
@ -18,3 +18,10 @@
<div class="cl"></div>
</div><!--编辑单行文字end-->
<% end%>
<script type="text/javascript">
$(function(){
$("#add_new_question_new").one('click', function(){
add_poll_question_new($(this));
});
});
</script>

View File

@ -51,8 +51,8 @@ function chooseQuestionType(quest_type,quest_id){
}
function add_MC(){
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_MC') %>");
$("#poll_questions_title").focus();
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_MC') %>");
$("#poll_questions_title_new").focus();
}
function insert_MC(quest_type,quest_num,quest_id){
@ -94,7 +94,7 @@ function add_MC(){
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this));">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -106,11 +106,14 @@ function add_MC(){
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
}
function add_MCQ(){
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_MCQ') %>");
$("#poll_questions_title").focus();
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_MCQ') %>");
$("#poll_questions_title_new").focus();
}
function insert_MCQ(quest_type,quest_num,quest_id){
@ -152,7 +155,7 @@ function insert_MCQ(quest_type,quest_num,quest_id){
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="add_poll_question($(this));">'+
'<a class="btn btn_dark btn_submit c_white" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'<a class="btn btn_light btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -164,11 +167,14 @@ function insert_MCQ(quest_type,quest_num,quest_id){
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
}
function add_single(){
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_single') %>");
$("#poll_questions_title").focus();
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_single') %>");
$("#poll_questions_title_new").focus();
}
function insert_SINGLE(quest_type,quest_num,quest_id){
@ -185,7 +191,7 @@ function insert_MCQ(quest_type,quest_num,quest_id){
'<label for="ur_question_require">必答</label>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn_submit c_white" data-button="ok" onclick="add_poll_question($(this));">'+
'<a class="btn_submit c_white" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'<a class="btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -197,10 +203,13 @@ function insert_MCQ(quest_type,quest_num,quest_id){
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
}
function add_mulit(){
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_mulit') %>");
$("#poll_questions_title").focus();
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_mulit') %>");
$("#poll_questions_title_new").focus();
}
function insert_MULIT(quest_type,quest_num,quest_id){
@ -219,7 +228,7 @@ function insert_MCQ(quest_type,quest_num,quest_id){
'<div class="ur_editor_toolbar">'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="btn_submit c_white" data-button="ok" onclick="add_poll_question($(this));">'+
'<a class="btn_submit c_white" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'<a class="btn_cancel" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
@ -231,6 +240,9 @@ function insert_MCQ(quest_type,quest_num,quest_id){
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
}
//选择导入调查问卷
@ -262,7 +274,27 @@ function insert_MCQ(quest_type,quest_num,quest_id){
function add_poll_question(doc)
{
var title = $.trim($("#poll_questions_title").val());
if(title.length == 0){alert("标题不能为空");}else{doc.parent().parent().parent().submit();}
if(title.length == 0){
alert("标题不能为空");
doc.one('click', function(){
add_poll_question($(this));
});
}else{
doc.parent().parent().parent().submit();
}
}
function add_poll_question_new(doc)
{
var title = $.trim($("#poll_questions_title_new").val());
if(title.length == 0){
alert("标题不能为空");
doc.one('click', function(){
add_poll_question($(this));
});
}else{
doc.parent().parent().parent().submit();
}
}
//修改标题时确定按钮
function edit_poll_question(doc,id)
@ -373,7 +405,7 @@ function insert_MCQ(quest_type,quest_num,quest_id){
</div><!--选项 end-->
<!-- 新增问题 -->
<div id="new_poll_question">
<div id="new_poll_question_new">
</div>
<div class="ur_buttons">

View File

@ -1,7 +1,7 @@
<% if @is_insert %>
$("#poll_content").html('<%= escape_javascript(render :partial => 'poll_content', :locals => {:poll => @poll})%>');
<% else %>
$("#new_poll_question").html("");
$("#new_poll_question_new").html("");
$("#poll_content").append("<div id='poll_questions_<%= @poll_questions.id%>'>" +
"<div id='show_poll_questions_<%= @poll_questions.id %>'>" +