socialforge/app/views/users/_user_programing_attr.html.erb

67 lines
3.5 KiB
Plaintext

<div id="programHomework">
<span class="f14 mt5 fl fontGrey3 mr10">测试集设置:</span>
<select class="InputBox W120 language_type" name="language_type" <%=not_allow_select ? 'disabled' : '' %>>
<%= options_for_select({"C语言"=>1, "C++"=>2, "Python"=>3, "Java"=>4}, (edit_mode && homework.is_program_homework?) ? homework.language : 1) %>
</select>
<span class="f12 c_red mt5 fr">温馨提示:您可以在发布作业后,在作业"模拟答题"中进行标准代码的检测。</span>
<div class="cl"></div>
<% if edit_mode && homework.is_program_homework? %>
<% homework.homework_tests.each_with_index do |test, index| %>
<div class="mt10" style="margin-left:63px;">
<label class="fl fontGrey2 mr10 mt5" name="inputs_label"><%=index+1 %>&nbsp;&nbsp;</label>
<textarea class="InputBox w265 fl mr10" placeholder="测试输入" name="program[input][]" <%=not_allow_select ? 'disabled' : '' %>><%= test.input %></textarea>
<textarea class="InputBox w265 fl mr5" placeholder="测试输出" name="program[output][]" <%=not_allow_select ? 'disabled' : '' %>><%= test.output %></textarea>
<% unless not_allow_select %>
<a href="javascript:void(0);" class=" fl icon_add" title="增加测试组"></a>
<% if index != 0 %>
<a href="javascript:void(0);" class=" fl icon_remove" title="删除测试组"></a>
<% end %>
<% end %>
<div class="cl"></div>
</div>
<% end %>
<% else %>
<div class="mt10" style="margin-left:63px;">
<label class="fl fontGrey2 mr10 mt5" name="inputs_label">1&nbsp;&nbsp;</label>
<textarea class="InputBox w265 fl mr10" placeholder="测试输入" name="program[input][]" id="textarea_input_test"></textarea>
<textarea class="InputBox w265 fl mr5" placeholder="测试输出" name="program[output][]" id="textarea_output_test"></textarea>
<a href="javascript:void(0);" class=" fl icon_add" title="增加测试组"></a>
<div class="cl"></div>
</div>
<% end %>
</div>
<script>
$(function(){
var bt=baidu.template;
bt.LEFT_DELIMITER='<!';
bt.RIGHT_DELIMITER='!>';
$("#programHomework").on('click', 'a.icon_add', function(){
var html = bt('t:test-answer-list', null);
$(this).parent('.mt10').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 + "&nbsp;&nbsp;" );
}
if (inputs.length == outputs.length) {
for (var i=0; i<inputs.length; i++) {
autoTextarea2(inputs[i], outputs[i]);
autoTextarea2(outputs[i], inputs[i]);
}
}
$(inputs[inputs.length - 1]).focus();
});
$("#programHomework").on('click', 'a.icon_remove', function(){
$(this).parent('.mt10').remove();
});
});
<% if !edit_mode %>
var text = document.getElementById("textarea_input_test");
var text2 = document.getElementById("textarea_output_test");
autoTextarea2(text,text2);
autoTextarea2(text2,text);
<% end %>
</script>