512 lines
27 KiB
Plaintext
512 lines
27 KiB
Plaintext
<%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %>
|
||
<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %>
|
||
<%= stylesheet_link_tag "/assets/codemirror/codemirror" %>
|
||
|
||
<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %>
|
||
<%= javascript_include_tag '/editormd/editormd.min.js','/editormd/examples/js/jquery.min.js' %>
|
||
<style>
|
||
.CodeMirror-scroll{
|
||
overflow: auto !important;
|
||
margin-bottom: -30px;
|
||
margin-right: -30px;
|
||
padding-bottom: 30px;
|
||
height: 100%;
|
||
outline: none;
|
||
position: relative;
|
||
}
|
||
</style>
|
||
<script type="text/javascript">
|
||
$(function() {
|
||
taskpass_editormd = editormd("challenge_task_pass", {
|
||
width : "89.6%",
|
||
height : 600,
|
||
syncScrolling : "single",
|
||
//你的lib目录的路径,我这边用JSP做测试的
|
||
path : "/editormd/lib/",
|
||
tex : true,
|
||
autoFocus: false,
|
||
toolbarIcons : function() {
|
||
// Or return editormd.toolbarModes[name]; // full, simple, mini
|
||
// Using "||" set icons align right.
|
||
return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear" ]
|
||
},
|
||
toolbarCustomIcons : {
|
||
testIcon : "<a type=\"inline\" class=\"latex\" ><div class='zbg'></div></a>",
|
||
testIcon1 : "<a type=\"latex\" class=\"latex\" ><div class='zbg_latex'></div></a>"
|
||
},
|
||
//这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。
|
||
saveHTMLToTextarea : true,
|
||
// 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标
|
||
dialogMaskOpacity : 0.6,
|
||
placeholder: "请输入完成当前任务依赖的知识点或者其它相关信息",
|
||
imageUpload : true,
|
||
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"],
|
||
imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>"//url
|
||
});
|
||
taskanswer_editormd = editormd("challenge_answer", {
|
||
width : "89.6%",
|
||
height : 300,
|
||
syncScrolling : "single",
|
||
tex : true,
|
||
//你的lib目录的路径,我这边用JSP做测试的
|
||
path : "/editormd/lib/",
|
||
autoFocus: false,
|
||
toolbarIcons : function() {
|
||
// Or return editormd.toolbarModes[name]; // full, simple, mini
|
||
// Using "||" set icons align right.
|
||
return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear" ]
|
||
},
|
||
toolbarCustomIcons : {
|
||
testIcon : "<a type=\"inline\" class=\"latex\" ><div class='zbg'></div></a>",
|
||
testIcon1 : "<a type=\"latex\" class=\"latex\" ><div class='zbg_latex'></div></a>"
|
||
},
|
||
//这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。
|
||
saveHTMLToTextarea : true,
|
||
// 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标
|
||
dialogMaskOpacity : 0.6,
|
||
placeholder: "",
|
||
imageUpload : true,
|
||
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"],
|
||
imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>"//url
|
||
});
|
||
});
|
||
</script>
|
||
|
||
<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>
|
||
<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8" value=""><span class="fl mr5">锁定</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 :subject, :class => "panel-form-width-690 fl panel-box-sizing", :no_label => true, :placeholder => "请输入当前任务的名称(此信息将提前泄露给学员)" %>
|
||
<span style="display: none;margin-left: 10%;" class="c_red ml95" id="new_shixun_name">任务名称不能为空</span>
|
||
</li>
|
||
<li class="clearfix">
|
||
<label class="panel-form-label fl">文件路径:</label>
|
||
<%= f.text_field :path, :class => "panel-form-width-690 panel-box-sizing fl", :no_label => true, :placeholder => "进入实训后将默认打开该文件,如:src/test/welcome.java", :maxlength => "256" %>
|
||
</li>
|
||
<li class="clearfix">
|
||
<label class="panel-form-label fl">执行文件:</label>
|
||
<%= f.text_field :exec_path, :class => "panel-form-width-690 panel-box-sizing fl", :no_label => true, :placeholder => "输入关卡需要执行的文件路径,如:src/test/main.java", :maxlength => "256" %>
|
||
</li>
|
||
<li class="clearfix">
|
||
<label class="panel-form-label fl"><span class="c_red mr5">*</span>过关任务:</label>
|
||
<%#= f.kindeditor :task_pass, :editor_id => "challenge_task_pass", :width=>'87.5%', :height => 159, :resizeType => 0, :no_label => true %>
|
||
<%#= f.text_area :task_pass, :class => "panel-form-width-690 panel-box-sizing", :no_label => true %>
|
||
<div id="challenge_task_pass" class="new_li">
|
||
<%#= f.text_area :ready_knowledge, :placeholder => "请输入完成当前任务依赖的知识点或者其它相关信息,指导学员完成任务" %>
|
||
<textarea name="challenge[task_pass]"><%= @challenge.task_pass %></textarea>
|
||
</div>
|
||
<span style="display: none;margin-left: 10%;" class="c_red" id="new_shixun_pass">过关任务不能为空</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">
|
||
<label class="panel-form-label fl">代码行标:</label>
|
||
<%= f.text_field :code_line, :class => "panel-form-width-200 panel-box-sizing fl", :no_label => true %>
|
||
</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"><input type="checkbox" name="test_set[lock][]" value="" id="shixun" class="ml-3 mr5 magic-checkbox">
|
||
<label for="shixun" 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"><input type="checkbox" name="test_set[lock][]" checked="checked" value="" id="shixun" class="ml-3 mr5 magic-checkbox">
|
||
<label for="shixun" 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 ml10 mr5"><input type="checkbox" name="test_set[lock][]" value="" id="shixun" class="ml-3 mr5 magic-checkbox">
|
||
<label for="shixun" style="top: 0px;">锁定</label></span>
|
||
<!--<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8" value=""><span class="fl mr5">锁定</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">
|
||
<label class=" panel-form-label fl"> 技能标签:</label>
|
||
<div class="fl task-bd-grey">
|
||
<% if params[:action] == "edit" && @challenge_tags.count > 0 %>
|
||
<% @challenge_tags.each do |tag| %>
|
||
<div class="task-tag tag-grey mt5 mr10 fl">
|
||
<button data-dismiss="alert" class="close fr mt3 ml5" type="button" onclick="close_tag(this)">×</button>
|
||
<input class='knowledge_frame' name='knowledge[input][]' value="<%= tag.try(:name)%>" />
|
||
</div>
|
||
<% end %>
|
||
<% end %>
|
||
<button class="close fl mt8 mr10" type="button" onclick="$('#add_shixun_skill').slideToggle();" id="add_knowledge">+</button>
|
||
<div class="task-tag tag-grey mt5 mr10 fl undis" id="add_shixun_skill">
|
||
<button data-dismiss="alert" class="close fr mt3 ml5" type="button" onclick="$('#add_shixun_skill').slideToggle();">×</button>
|
||
<input type="text" class="task-tag-input" onblur="add_tag();" id="shixun_skill_input" placeholder="请输入知识/技能点" />
|
||
</div>
|
||
</div>
|
||
</li>
|
||
<li class="clearfix" style="line-height:1.9;">
|
||
<label class=" panel-form-label fl"> 参考答案:</label>
|
||
<div id="challenge_answer" class="new_li">
|
||
<%#= f.text_area :ready_knowledge, :placeholder => "请输入完成当前任务依赖的知识点或者其它相关信息,指导学员完成任务" %>
|
||
<textarea name="challenge[answer]"><%= @challenge.answer %></textarea>
|
||
</div>
|
||
<%#= f.text_area :answer, :class => "panel-form-width-690 panel-form-height-150 fl task-textarea-pd", :no_label => true, :style => "line-height:1.9;" %>
|
||
</li>
|
||
|
||
<li class="clearfix">
|
||
<label class="panel-form-label fl"><span class="c_red mr5">*</span>难易度:</label>
|
||
<%= radio_button_tag("challenge[difficulty]", 1, checked = (@challenge.difficulty ==1 ? true : false), :class=> "magic-radio fl mt3") %>
|
||
<!--<input id="edit_allow_late_1" class="magic-radio fl mt3" type="radio" name="homework_allow_late" value="1" checked="">-->
|
||
<label for="challenge_difficulty_1" class="fl mr20 mt3">简单</label>
|
||
<%= radio_button_tag("challenge[difficulty]", 2, checked = (@challenge.difficulty ==2 ? true : false), :class=> "magic-radio fl mt3") %>
|
||
<!--<input id="edit_allow_late_2" class="magic-radio fl mt3" type="radio" name="homework_allow_late" value="2" checked="">-->
|
||
<label for="challenge_difficulty_2" class="fl mr20 mt3">中等</label>
|
||
<%= radio_button_tag("challenge[difficulty]", 3, checked = (@challenge.difficulty ==3 ? true : false), :class=> "magic-radio fl mt3") %>
|
||
<!--<input id="edit_allow_late_3" class="magic-radio fl mt3" type="radio" name="homework_allow_late" value="3" checked="">-->
|
||
<label for="challenge_difficulty_3" class="fl mr20 mt3">困难</label>
|
||
|
||
|
||
<!--<span class="mt10 fl"><%#= radio_button_tag("challenge[difficulty]", 1, checked = (@challenge.difficulty ==1 ? true : false)) %></span><span class="ml5 fl mt8 mr15">简单</span>-->
|
||
<!--<span class="mt10 fl"><%#= radio_button_tag("challenge[difficulty]", 2, checked = (@challenge.difficulty ==2 ? true : false)) %></span><span class="ml5 fl mt8 mr15">中等</span>-->
|
||
<!--<span class="mt10 fl"><%#= radio_button_tag("challenge[difficulty]", 3, checked = (@challenge.difficulty ==3 ? true : false)) %></span><span class="ml5 fl mt8 mr15">困难 </span>-->
|
||
<!-- <span class="fl color-orange ml30 mt8"><i class="fa fa-exclamation-circle mr5"></i>请选择难易度并设定通过本关后,学员得到的经验值</span>-->
|
||
</li>
|
||
|
||
<li class="clearfix">
|
||
<label class="panel-form-label fl"><span class="c_red mr5">*</span>奖励经验值:</label>
|
||
<%#= f.text_field :score, :class => "panel-form-height-30 fl", :no_label => true, :style => "padding:5px;", :placeholder => "请输入分值(只能是数字)" %>
|
||
<%= select_tag :challenge_score, options_for_select([100, 200]), :name => 'challenge[score]', :class => " fl", :style => "height: 40px; width:170px;" %>
|
||
<div class="clear"></div>
|
||
<span style="display: none" class="c_red ml90" id="new_shixun_score">分值设定不能为空</span>
|
||
</li>
|
||
<li class="clearfix">
|
||
<% if params[:action] == "edit" %>
|
||
<a href="javascript:void(0)" class="task-btn task-btn-green fr" onclick="challenge_update()">保存</a>
|
||
<a href="<%= shixun_challenge_path(@challenge, :shixun_id => @shixun) %>" class="task-btn fr mr10">取消</a>
|
||
<% else %>
|
||
<a href="javascript:void(0)" class="task-btn task-btn-green fr" onclick="challenge_create()">保存</a>
|
||
<a href="<%= shixun_challenges_path(@shixun) %>" class="task-btn fr mr10">取消</a>
|
||
<% end %>
|
||
|
||
</li>
|
||
</div>
|
||
|
||
<script type="text/javascript">
|
||
$(function () {
|
||
var bt = baidu.template;
|
||
bt.LEFT_DELIMITER = '<!';
|
||
bt.RIGHT_DELIMITER = '!>';
|
||
|
||
$("#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");
|
||
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++) {
|
||
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));
|
||
}
|
||
});
|
||
|
||
// 根据难易程度设置不同的奖励经验值(适用新建与编辑模式)
|
||
var list= $('input:radio[name="challenge[difficulty]"]:checked').val(); // 获取select的索引值
|
||
if(list == 1){
|
||
$("#challenge_score").empty();
|
||
for(var i= 100; i <= 200; i += 100){
|
||
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
|
||
}
|
||
}else if(list == 2){
|
||
$("#challenge_score").empty();
|
||
for(var i= 300; i <= 600; i += 100){
|
||
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
|
||
}
|
||
}else if(list == 3){
|
||
$("#challenge_score").empty();
|
||
for(var i= 700; i <= 1000; i += 100){
|
||
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
|
||
}
|
||
}
|
||
$("#challenge_score").find("option[value='<%= @challenge.score %>']").attr("selected",true); // 设置option默认值
|
||
$("#challenge_difficulty_1").click(function(){
|
||
$("#challenge_score").empty();
|
||
for(var i= 100; i <= 200; i += 100){
|
||
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
|
||
}
|
||
});
|
||
$("#challenge_difficulty_2").click(function(){
|
||
$("#challenge_score").empty();
|
||
for(var i= 300; i <= 600; i += 100){
|
||
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
|
||
}
|
||
});
|
||
$("#challenge_difficulty_3").click(function(){
|
||
$("#challenge_score").empty();
|
||
for(var i= 700; i <= 1000; i += 100){
|
||
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
|
||
}
|
||
})
|
||
|
||
// 知识技能点添加,清空输入框,并focus
|
||
$("#add_knowledge").click(function(){
|
||
$("#shixun_skill_input").val("");
|
||
$("#shixun_skill_input").focus();
|
||
});
|
||
|
||
});
|
||
|
||
window.onload = function(){
|
||
$("#challenge_task_pass [type=\"latex\"]").bind("click", function(){
|
||
taskpass_editormd.cm.replaceSelection("```latex");
|
||
taskpass_editormd.cm.replaceSelection("\n");
|
||
taskpass_editormd.cm.replaceSelection("\n");
|
||
taskpass_editormd.cm.replaceSelection("```");
|
||
var __Cursor = taskpass_editormd.cm.getDoc().getCursor();
|
||
taskpass_editormd.cm.setCursor(__Cursor.line-1, 0);
|
||
});
|
||
|
||
$("#challenge_answer [type=\"latex\"]").bind("click", function(){
|
||
taskanswer_editormd.cm.replaceSelection("```latex");
|
||
taskanswer_editormd.cm.replaceSelection("\n");
|
||
taskanswer_editormd.cm.replaceSelection("\n");
|
||
taskanswer_editormd.cm.replaceSelection("```");
|
||
var __Cursor = taskanswer_editormd.cm.getDoc().getCursor();
|
||
taskanswer_editormd.cm.setCursor(__Cursor.line-1, 0);
|
||
});
|
||
|
||
$("#challenge_task_pass [type=\"inline\"]").bind("click", function(){
|
||
taskpass_editormd.cm.replaceSelection("$$$$");
|
||
var __Cursor = taskpass_editormd.cm.getDoc().getCursor();
|
||
taskpass_editormd.cm.setCursor(__Cursor.line, __Cursor.ch-2);
|
||
taskpass_editormd.cm.focus();
|
||
});
|
||
|
||
$("#challenge_answer [type=\"inline\"]").bind("click", function(){
|
||
taskanswer_editormd.cm.replaceSelection("$$$$");
|
||
var __Cursor = taskanswer_editormd.cm.getDoc().getCursor();
|
||
taskanswer_editormd.cm.setCursor(__Cursor.line, __Cursor.ch-2);
|
||
taskanswer_editormd.cm.focus();
|
||
});
|
||
$("[type=\"inline\"]").attr("title", "行内公式");
|
||
$("[type=\"latex\"]").attr("title", "多行公式");
|
||
|
||
}
|
||
|
||
// 设置textarea的宽度到140以后出现滚动条
|
||
var test_set_inputs = document.getElementsByName("test_set[input][]");
|
||
var test_set_outputs = document.getElementsByName("test_set[output][]");
|
||
if (test_set_inputs.length == test_set_outputs.length) {
|
||
for (var i = 0; i < test_set_inputs.length; i++) {
|
||
autoTextarea(test_set_inputs[i], 0, 140);
|
||
autoTextarea(test_set_outputs[i], 0, 140);
|
||
}
|
||
}
|
||
/* autoTextarea(text1, 0, 140);
|
||
autoTextarea(text2, 0, 140);
|
||
|
||
var text3 = document.getElementById("textarea_sample_input_test");
|
||
var text4 = document.getElementById("textarea_sample_output_test");
|
||
autoTextarea2(text3, text4, 0, 140);
|
||
autoTextarea2(text4, text3, 0, 140);*/
|
||
$("#challenge_score").keyup(function(){
|
||
(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)
|
||
});
|
||
$("#challenge_score").keyup(function(){
|
||
this.v();
|
||
});
|
||
$("#challenge_subject").keydown(function(){
|
||
$("#new_shixun_name").hide();
|
||
});
|
||
$("#challenge_subject").keydown(function(){
|
||
$("#new_shixun_pass").hide();
|
||
});
|
||
|
||
// 判断测试集是否锁定, 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 challenge_create(){
|
||
test_set_whether_lock();
|
||
if($('#challenge_subject').val().trim() == ""){
|
||
$("#challenge_subject").focus();
|
||
$("#new_shixun_name").show();
|
||
}else if($("#challenge_task_pass textarea").val().trim() == ""){
|
||
$("#challenge_task_pass textarea").focus();
|
||
$("#new_shixun_pass").show();
|
||
}else if($("#challenge_score").val().trim()==""){
|
||
$("#challenge_score").focus();
|
||
$("#new_shixun_score").show();
|
||
}else{
|
||
$('#challenge_shixun_create').submit();
|
||
}
|
||
}
|
||
|
||
function challenge_update(){
|
||
test_set_whether_lock();
|
||
if($('#challenge_subject').val().trim() == ""){
|
||
$("#challenge_subject").focus();
|
||
$("#new_shixun_name").show();
|
||
}else if($("#challenge_task_pass textarea").val().trim() == ""){
|
||
$("#challenge_task_pass textarea").focus();
|
||
$("#new_shixun_pass").show();
|
||
}else if($("#challenge_score").val().trim()==""){
|
||
$("#challenge_score").focus();
|
||
$("#new_shixun_score").show();
|
||
}else{
|
||
$('#edit_challenge_<%= @challenge.id %>').submit();
|
||
}
|
||
}
|
||
|
||
/* var editor = CodeMirror.fromTextArea(document.getElementById("challenge_answer"), {
|
||
mode: {name: '<%#= @language %>',
|
||
version: 2,
|
||
singleLineStringErrors: false},
|
||
lineNumbers: true,
|
||
indentUnit: 2,
|
||
matchBrackets: true
|
||
});
|
||
|
||
editor.on('change',function(cMirror){
|
||
// get value right from instance
|
||
$('#challenge_answer').val(cMirror.getValue());
|
||
});*/
|
||
|
||
/* challenge_task_pass_editor = KindEditor.create('#challenge_task_pass',
|
||
{"width":"89.7%",
|
||
"resizeType":0,
|
||
"no_label":true,
|
||
"autoHeightMode":true,
|
||
"height":200,
|
||
"allowFileManager":true,
|
||
afterBlur:function () { this.sync(); },
|
||
"uploadJson":"/kindeditor/upload",
|
||
"fileManagerJson":"/kindeditor/filemanager"
|
||
});
|
||
challenge_task_editor = KindEditor.create('#challenge_ready_knowledge',
|
||
{"width":"89.7%",
|
||
"resizeType":0,
|
||
"no_label":true,
|
||
"autoHeightMode":true,
|
||
"height":200,
|
||
"allowFileManager":true,
|
||
afterBlur:function () { this.sync(); },
|
||
"uploadJson":"/kindeditor/upload",
|
||
"fileManagerJson":"/kindeditor/filemanager"
|
||
});
|
||
|
||
*/
|
||
function add_tag(){
|
||
var num = $(".task-bd-grey").children('div').length;
|
||
var val = $(".task-tag-input").val().trim();
|
||
if (val != ""){
|
||
testLength = $(".task-tag-input").val().trim().length;
|
||
$("#add_knowledge").before("<div class='task-tag tag-grey mt5 mr10 fl' id='knowledge_" + num + "'>" +
|
||
"<button data-dismiss='alert' class='close fr mt3 ml5' type='button' onclick='close_tag(this)'>×</button>" +
|
||
"<input style='width:"+ testLength*12 +"px' class='knowledge_frame' name='knowledge[input][]' value='" + val +"'>" +
|
||
" </div>");
|
||
$(".task-tag-input").attr("value","");
|
||
}
|
||
$("#shixun_skill_input").val("");
|
||
}
|
||
|
||
function close_tag(thisObj){
|
||
// 获取父节点的id
|
||
var obj = thisObj.parentNode.id;
|
||
$("#"+obj).remove();
|
||
}
|
||
</script>
|