Merge branch 'szzh' into dev_hjq

This commit is contained in:
huang 2015-09-11 16:37:50 +08:00
commit 27fde3f642
9 changed files with 136 additions and 82 deletions

View File

@ -154,7 +154,21 @@ class HomeworkCommonController < ApplicationController
#编程作业相关属性 #编程作业相关属性
if @homework.homework_type == 2 if @homework.homework_type == 2
@homework.homework_detail_programing ||= HomeworkDetailPrograming.new
@homework_detail_programing = @homework.homework_detail_programing
@homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6
@homework_detail_programing.language = params[:language_type].to_i
@homework.homework_tests.delete_all
inputs = params[:program][:input]
if Array === inputs
inputs.each_with_index do |val, i|
@homework.homework_tests << HomeworkTest.new(
input: val,
output: params[:program][:output][i]
)
end
end
end end
if @homework.save if @homework.save

View File

@ -641,7 +641,7 @@ class StudentWorkController < ApplicationController
unless @homework.save unless @homework.save
logger.debug @homework.errors.full_messages logger.debug @homework.errors.full_messages
else else
student_work = @homework.student_works.where(user_id: User.current.id).first student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
end end
end end
student_work student_work

View File

@ -355,11 +355,13 @@ class UsersController < ApplicationController
#导入作业,确定按钮 #导入作业,确定按钮
def user_select_homework def user_select_homework
homework = HomeworkCommon.find_by_id params[:checkMenu] homework = HomeworkCommon.find_by_id params[:checkMenu]
homework_detail_programing = homework.homework_detail_programing
@homework = HomeworkCommon.new @homework = HomeworkCommon.new
if homework if homework
@homework.name = homework.name @homework.name = homework.name
@homework.description = homework.description @homework.description = homework.description
@homework.end_time = homework.end_time @homework.end_time = homework.end_time
@homework.homework_type = homework.homework_type
@homework.course_id = homework.course_id @homework.course_id = homework.course_id
homework.attachments.each do |attachment| homework.attachments.each do |attachment|
att = attachment.copy att = attachment.copy
@ -369,6 +371,19 @@ class UsersController < ApplicationController
att.save att.save
@homework.attachments << att @homework.attachments << att
end end
if homework_detail_programing
@homework.homework_detail_programing = HomeworkDetailPrograming.new
@homework_detail_programing = @homework.homework_detail_programing
@homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion
@homework_detail_programing.language = homework_detail_programing.language
homework.homework_tests.each_with_index do |homework_test|
@homework.homework_tests << HomeworkTest.new(
input: homework_test.input,
output: homework_test.output
)
end
end
end end
respond_to do |format| respond_to do |format|
format.js format.js
@ -380,7 +395,7 @@ class UsersController < ApplicationController
@user = User.current @user = User.current
@homework = HomeworkCommon.find(params[:homework_id]) @homework = HomeworkCommon.find(params[:homework_id])
@is_test = params[:is_test] == 'true' @is_test = params[:is_test] == 'true'
@student_work = @homework.student_works.where(user_id: User.current.id).first @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
if @student_work.nil? if @student_work.nil?
@student_work = StudentWork.new @student_work = StudentWork.new
end end
@ -408,7 +423,7 @@ class UsersController < ApplicationController
def user_commit_homework def user_commit_homework
homework = HomeworkCommon.find(params[:homework]) homework = HomeworkCommon.find(params[:homework])
student_work = homework.student_works.where(user_id: User.current.id).first student_work = StudentWork.where(homework_common_id: homework.id, user_id: User.current.id).first
if student_work if student_work
student_work.save student_work.save
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)

View File

@ -60,6 +60,6 @@ class HomeworkCommon < ActiveRecord::Base
self.homework_type == 2 && self.homework_detail_programing self.homework_type == 2 && self.homework_detail_programing
end end
delegate :language_name, :to => :homework_detail_programing delegate :language_name, :language, :to => :homework_detail_programing
end end

View File

@ -1,3 +1,3 @@
$("#nh_user_tx").replaceWith('<%= image_tag(url_to_avatar(@user), :id=>'nh_user_tx',:style=>"width:90px;height:90px;overflow:hidden",:alt=>"头像") %>'); $("#nh_user_tx").replaceWith('<%= image_tag(url_to_avatar(@user), :id=>'nh_user_tx',:style=>"width:78px;height:78px;overflow:hidden",:alt=>"头像") %>');
$("#nh_user_logo").replaceWith('<%= image_tag(url_to_avatar(@user), :id=>'nh_user_logo',:width =>"40",:height => "40",:alt=>"头像") %>'); $("#nh_user_logo").replaceWith('<%= image_tag(url_to_avatar(@user), :id=>'nh_user_logo',:width =>"40",:height => "40",:alt=>"头像") %>');
hideModal(); hideModal();

View File

@ -1,6 +1,11 @@
<% content_for :header_tags do %> <% content_for :header_tags do %>
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg'%> <%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg'%>
<%= javascript_include_tag 'homework','baiduTemplate' %> <%= javascript_include_tag 'homework','baiduTemplate' %>
<script type="text/javascript">
$(function(){
$("#BluePopupBox a.BlueCirBtn").click();
});
</script>
<% end %> <% end %>
<div class="HomeWorkCon"> <div class="HomeWorkCon">
@ -57,7 +62,7 @@
<div class="cl"></div> <div class="cl"></div>
</div> </div>
<input type="hidden" name="homework_type" value="1"> <input type="hidden" name="homework_type" value="<%= edit_mode ? homework.homework_type : 1 %>">
</div> </div>
</div> </div>
@ -84,27 +89,5 @@
<div class="BluePopupBox" id="BluePopupBox" style="display:none"> <div class="BluePopupBox" id="BluePopupBox" style="display:none">
<a href="javascript:void(0);" class="CloseBtn" title="关闭弹框"></a> <%= render :partial => 'users/user_programing_attr', :locals => {:edit_mode => edit_mode, :homework=>homework} %>
<h2 class="BluePopuph2 fl">编程作业的测试集设置</h2>
<div class="cl"></div>
<div class="HomeWorkCon">
<div class="mt15">
<select class="InputBox W120 language_type" >
<option value="1" selected>C语言</option>
<option value="2">C++</option>
</select>
</div>
<div class="mt10">
<textarea class="InputBox W320 fl mr10" placeholder="测试输入" id="textarea_input_test"></textarea><textarea class="InputBox W320 fl mr5" placeholder="测试输出"></textarea>
<a href="javascript:void(0);" class=" fl icon_add" title="增加测试组"></a>
<div class="cl"></div>
</div>
<div class="mt10">
<a href="javascript:void(0);" class="BlueCirBtn fr">确&nbsp;&nbsp;定</a>
<div class="cl"></div>
</div>
</div><!----HomeWorkCon end-->
</div><!----BluePopupBox end--> </div><!----BluePopupBox end-->

View File

@ -0,0 +1,36 @@
<a href="javascript:void(0);" class="CloseBtn" title="关闭弹框"></a>
<h2 class="BluePopuph2 fl">编程作业的测试集设置</h2>
<div class="cl"></div>
<div class="HomeWorkCon">
<div class="mt15">
<select class="InputBox W120 language_type" >
<%= options_for_select({"C语言"=>1, "C++"=>2}, (edit_mode && homework.is_program_homework?) ? homework.language : 1) %>
</select>
</div>
<% if edit_mode && homework.is_program_homework? %>
<% homework.homework_tests.each_with_index do |test, index| %>
<div class="mt10">
<textarea class="InputBox W320 fl mr10" placeholder="测试输入" id="textarea_input_test"><%= test.input %></textarea>
<textarea class="InputBox W320 fl mr5" placeholder="测试输出"><%= test.output %></textarea>
<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 %>
<div class="cl"></div>
</div>
<% end %>
<% else %>
<div class="mt10">
<textarea class="InputBox W320 fl mr10" placeholder="测试输入" id="textarea_input_test"></textarea>
<textarea class="InputBox W320 fl mr5" placeholder="测试输出"></textarea>
<a href="javascript:void(0);" class=" fl icon_add" title="增加测试组"></a>
<div class="cl"></div>
</div>
<% end %>
<div class="mt10">
<a href="javascript:void(0);" class="BlueCirBtn fr">确&nbsp;&nbsp;定</a>
<div class="cl"></div>
</div>
</div><!----HomeWorkCon end-->

View File

@ -5,4 +5,7 @@ $("#homework_end_time").val("<%= @homework.end_time%>");
$("#course_id").val("<%= @homework.course_id%>"); $("#course_id").val("<%= @homework.course_id%>");
$("#homework_attachments").html("<%= escape_javascript(render :partial => 'users/user_homework_attachment', :locals => { :container => @homework,:has_program => true })%>"); $("#homework_attachments").html("<%= escape_javascript(render :partial => 'users/user_homework_attachment', :locals => { :container => @homework,:has_program => true })%>");
homework_description_editor.html("<%= escape_javascript(@homework.description.html_safe)%>"); homework_description_editor.html("<%= escape_javascript(@homework.description.html_safe)%>");
$("#BluePopupBox").html("<%=escape_javascript( render :partial => 'users/user_programing_attr', :locals => {:edit_mode => true, :homework => @homework})%>");
//$("input[name='homework_type']").val("<%#= @homework.homework_type%>");
$("#homework_editor").show(); $("#homework_editor").show();
$("#BluePopupBox a.BlueCirBtn").click();

View File

@ -58,10 +58,10 @@ $(function(){
); );
}; };
$('#test-program-btn').live('click', test_program); $('#test-program-btn').on('click', test_program);
$('#commit-program-work-btn').live('click', function(){ $('#commit-program-work-btn').on('click', function(){
if(!valid_form()){ if(!valid_form()){
return; return;
} }
@ -89,11 +89,10 @@ $(function(){
$(".HomeWorkCon form").submit(); $(".HomeWorkCon form").submit();
}); });
$('form.edit_student_work').live('keydown', '#program-src', function(){ $('form.edit_student_work').on('keydown', '#program-src', function(){
tested = false; tested = false;
}); });
//发布作业 //发布作业
$('#program-src').focus(function(){ $('#program-src').focus(function(){
@ -104,23 +103,26 @@ $(function(){
$('input.date-input').datepicker(datepickerOptions); $('input.date-input').datepicker(datepickerOptions);
$('a.pic_date').live('click', function(){ $('a.pic_date').on('click', function(){
$(this).parent().prev().first().focus(); $(this).parent().prev().first().focus();
}) })
$('a.ProBtn').live('click', function(){
$("#BluePopupBox").dialog({ $("#BluePopupBox").dialog({
modal: true, modal: true,
autoOpen: false,
dialogClass: 'BluePopupBox', dialogClass: 'BluePopupBox',
minWidth: 753 minWidth: 753
}); });
$(".ui-dialog-titlebar").hide();
$("a.CloseBtn").live('click', function(){ $('a.ProBtn').live('click', function(){
$("#BluePopupBox").dialog("open");
$(".ui-dialog-titlebar").hide();
$("a.CloseBtn").on('click', function(){
$("#BluePopupBox" ).dialog("close"); $("#BluePopupBox" ).dialog("close");
}); });
$('#textarea_input_test').focus(); $('#textarea_input_test').focus();
});
$("#BluePopupBox a.BlueCirBtn").live('click', function(){ $("#BluePopupBox a.BlueCirBtn").live('click', function(){
var test_numbers = 0; var test_numbers = 0;
@ -157,17 +159,18 @@ $(function(){
$('.program-input').remove(); $('.program-input').remove();
var html=bt('t:program-input-list',data); var html=bt('t:program-input-list',data);
$("input[name=homework_type]").after(html); $("input[name=homework_type]").after(html);
if($( "#BluePopupBox" ).dialog( "isOpen" )){
$("#BluePopupBox").dialog( "close" ); $("#BluePopupBox").dialog( "close" );
} }
}); }
}); });
$("#BluePopupBox").live('click', 'a.icon_add', function(){ $("#BluePopupBox").on('click', 'a.icon_add', function(){
var html = bt('t:test-answer-list', null); var html = bt('t:test-answer-list', null);
$(this).parent('.mt10').after(html); $(this).parent('.mt10').after(html);
}); });
$("#BluePopupBox").live('click', 'a.icon_remove', function(){ $("#BluePopupBox").on('click', 'a.icon_remove', function(){
$(this).parent('.mt10').remove(); $(this).parent('.mt10').remove();
}); });
}); });