educoder/app/views/challenges/_evaluating_form.html.erb

216 lines
12 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script id="t:sample-answer-list" type="text/html">
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl" name="sample_inputs_label"></span>
<span class="fl mr20 ml10">
<input type="checkbox" name="test_set[lock][]" value="9" id="setlock_0" class="ml-3 mr5 magic-checkbox">
<label for="setlock_0" style="top: 0px;">锁定</label>
</span>
<input type="hidden" name="test_set[hidden][]"/>
<a href="javascript:void(0)" title="增加" class="sample_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
<a href="javascript:void(0)" title="删除" class="sample_icon_remove"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt7"></i></a>
</p>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="test_set[input][]" placeholder="输入" ></textarea>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="test_set[output][]" placeholder="希望输出" ></textarea>
</li>
</script>
<div id="shixun_form">
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>文件路径:</label>
<%= f.text_field :path, :class => "panel-form-width-690 panel-box-sizing fl", :id => "shixun_file_path", :no_label => true, :placeholder => "进入实训后将默认打开该文件src/test/welcome.java", :maxlength => "256" %>
<!--<input id="shixun_file_path" class="panel-form-width-690 panel-box-sizing fl">-->
<span style="display: none" class="c_red ml95" id="challenge_file_path">文件路径不能为空</span>
</li>
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>执行文件:</label>
<%= f.text_field :exec_path, :class => "panel-form-width-690 panel-box-sizing fl",:id => "shixun_file_path_play", :no_label => true, :placeholder => "输入关卡需要执行的文件路径src/test/main.java", :maxlength => "256" %>
<span style="display: none" class="c_red ml95" id="challenge_execfile_path">执行文件不能为空</span>
</li>
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>评测方式:</label>
<%= select_tag :evaluation_way, options_for_select([["输入输出", 1]]), :name => 'challenge[evaluation_way]', :class => " fl", :style => "height: 40px; width:200px;" %>
<span class="fl ml15 mt8">请选择自动检测学员是否完成本任务的评测标准</span>
</li>
<li class="clearfix">
<% if params[:action] == "edit" && @challenge.test_sets.count > 0 %>
<label class="panel-form-label fl">测试集设置:</label>
<ul class="fl task-bg-grey panel-box-sizing" >
<% @challenge.test_sets.each_with_index do |test_set, index| %>
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl" name="sample_inputs_label">组<%= index + 1 %></span>
<% if test_set.is_public? %>
<span class="fl mr20 ml10">
<input type="checkbox" name="test_set[lock][]" value="9" id="setlock_<%= index %>" class="ml-3 mr5 magic-checkbox">
<label for="setlock_<%= index %>" style="top: 0px;">锁定</label>
</span>
<!--<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8"><span class="fl mr5">锁定</span>-->
<% else %>
<span class="fl mr20 ml10">
<input type="checkbox" name="test_set[lock][]" value="9" id="setlock_<%= index %>" class="ml-3 mr5 magic-checkbox" checked="checked">
<label for="setlock_<%= index %>" style="top: 0px;">锁定</label>
</span>
<!--<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8" checked="checked"><span class="fl mr5">锁定</span>-->
<% end %>
<input type="hidden" name="test_set[hidden][]"/>
<% if index == 0 %>
<span class="color-grey fr" style="font-size:12px;">温馨提示:选中“锁定”,则对学员隐藏该条测试集,但在“提交评测”时也将被自动检测。</span>
<% end %>
<a href="javascript:void(0)" title="增加" class="sample_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
<% if index > 0 %>
<a href="javascript:void(0)" title="删除" class="sample_icon_remove"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt7"></i></a>
<% end %>
</p>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="test_set[input][]" placeholder="输入"><%= test_set.input %></textarea>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="test_set[output][]" placeholder="希望输出"><%= test_set.output %></textarea>
</li>
<% end %>
</ul>
<% else %>
<label class="panel-form-label fl">测试集设置:</label>
<ul class="fl task-bg-grey panel-box-sizing">
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl" name="sample_inputs_label">组1</span>
<span class="color-grey fr" style="font-size:12px;">温馨提示:选中“锁定”,在“提交评测”时它也将被自动检测,但学员暂不可查看内容。</span>
<span class="fl mr20 ml10">
<input type="checkbox" name="test_set[lock][]" value="9" id="setlock_1" class="ml-3 mr5 magic-checkbox">
<label for="setlock_1" style="top: 0px;">锁定</label>
</span>
<input type="hidden" name="test_set[hidden][]"/>
<a href="javascript:void(0)" title="增加" class="sample_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
</p>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="test_set[input][]" placeholder="输入" ></textarea>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="test_set[output][]" placeholder="希望输出" ></textarea>
</li>
</ul>
<% end %>
</li>
<li class="clearfix">
<a href="javascript:void(0);" class="task-btn task-btn-green fr" onclick="submit_shixun_evaluating();">保存</a>
<% if @challenge.evaluation_way != 0 %>
<a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 2) %>" class="task-btn fr mr10" id="evaluating_cancel">取消</a>
<% end %>
</li>
</div>
<script type="text/javascript">
$(function () {
var bt = baidu.template;
bt.LEFT_DELIMITER = '<!';
bt.RIGHT_DELIMITER = '!>';
// 获取版本库路径
$("#shixun_file_path").on('click', function (e) {
file_path();
$(this).addClass("change");
});
$("#shixun_file_path_play").on('click', function (e) {
file_path();
$(this).addClass("change");
});
function file_path(){
data = 0;
$.ajax({
url: '<%= search_file_list_shixun_path(@shixun) %>',
dataType: "script"
});
}
$("#shixun_form").on('click', 'a.test_icon_add', function () {
var html = bt('t:test-answer-list', null);
$(this).parent().parent('.clearfix').after(html);
var inputs = document.getElementsByName("program[input][]");
var outputs = document.getElementsByName("program[output][]");
var inputs_labels = document.getElementsByName("inputs_label");
for (var j = 0; j < inputs_labels.length; j++) {
$(inputs_labels[j]).html("测试集"+ (j + 1));
}
if (inputs.length == outputs.length) {
for (var i = 0; i < inputs.length; i++) {
// autoTextarea2(inputs[i], outputs[i], 0, 140);
// autoTextarea2(outputs[i], inputs[i], 0, 140);
}
}
$(inputs[inputs.length - 1]).focus();
});
$("#shixun_form").on('click', 'a.test_icon_remove', function () {
$(this).parent().parent('.clearfix').remove();
var inputs_labels = document.getElementsByName("inputs_label");
for (var j = 0; j < inputs_labels.length; j++) {
$(inputs_labels[j]).html("测试集" + (j + 1));
}
});
$("#shixun_form").on('click', 'a.sample_icon_add', function () {
var html = bt('t:sample-answer-list', null);
$(this).parent().parent('.clearfix').after(html);
var inputs = document.getElementsByName("test_set[input][]");
var outputs = document.getElementsByName("test_set[output][]");
var inputs_labels = document.getElementsByName("sample_inputs_label");
var inputs_set=document.getElementsByName("test_set[lock][]");
for (var j = 0; j < inputs_labels.length; j++) {
$(inputs_labels[j]).html("组" + (j + 1));
}
for(var i=0;i<inputs_set.length;i++){
$(inputs_set[i]).attr("id","setlock_"+i);
$(inputs_set[i]).siblings("label").attr("for","setlock_"+i);
}
// 设置测试集的的输入与输出的回车自动调整宽度
if (inputs.length == outputs.length) {
for (var i = 0; i < inputs.length; i++) {
autoTextarea(inputs[i], 0, 140);
autoTextarea(outputs[i], 0, 140);
}
}
$(inputs[inputs.length - 1]).focus();
});
$("#shixun_form").on('click', 'a.sample_icon_remove', function () {
$(this).parent().parent('.clearfix').remove();
var inputs_labels = document.getElementsByName("sample_inputs_label");
for (var j = 0; j < inputs_labels.length; j++) {
$(inputs_labels[j]).html("组" + (j + 1));
}
});
});
// 判断测试集是否锁定, 0未锁定1锁定
function test_set_whether_lock(){
var lock = document.getElementsByName("test_set[lock][]");
var hid = document.getElementsByName("test_set[hidden][]");
for(var o = 0; o < lock.length; o++){
if($(lock[o]).prop("checked")){
$(hid[o]).val(1);
}else{
$(hid[o]).val(0);
}
}
}
// 提交表单
function submit_shixun_evaluating(){
test_set_whether_lock();
if($("input[name='challenge[path]']").val().trim() == ""){
$("#challenge_file_path").show();
return;
}else if($("input[name='challenge[exec_path]']").val().trim() == ""){
$("#challenge_execfile_path").show();
return;
}
$('#challenge_evaluation_update').submit();
}
$("input[name='challenge[path]']").on("focus", function(){
$("#challenge_file_path").hide();
});
$("input[name='challenge[exec_path]']").on("focus", function(){
$("#challenge_execfile_path").hide();
});
</script>