Merge branch 'develop' into yuanke
This commit is contained in:
commit
879a941b01
|
@ -55,12 +55,11 @@ class StudentWorkController < ApplicationController
|
|||
render :json => resultObj
|
||||
end
|
||||
|
||||
$test_result = {}
|
||||
$test_status = {}
|
||||
#由于负载问题 不要使用全局变量
|
||||
#根据传入的tIndex确定是第几次测试
|
||||
def program_test_ex
|
||||
is_test = params[:is_test] == 'true'
|
||||
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1} #保存每测试一次返回的结果
|
||||
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果
|
||||
|
||||
student_work = find_or_save_student_work(is_test)
|
||||
|
||||
|
@ -81,7 +80,7 @@ class StudentWorkController < ApplicationController
|
|||
|
||||
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
||||
resultObj[:status] = -1
|
||||
resultObj[:results] = result["results"][0] #本次测试结果
|
||||
resultObj[:results] = result["results"].first #本次测试结果
|
||||
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
||||
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
|
@ -94,24 +93,6 @@ class StudentWorkController < ApplicationController
|
|||
resultObj[:status] = 200
|
||||
else
|
||||
|
||||
#索引
|
||||
work_id = student_work.id
|
||||
|
||||
#测试第一个时初始化下全局变量
|
||||
if index == 1
|
||||
$test_result[work_id] = [] #保存本次测试的结果 输入输出
|
||||
$test_status[work_id] = 0 #保存本次测试的结果 正确还是错误
|
||||
end
|
||||
|
||||
if result["status"].to_i == -2
|
||||
$test_result[work_id] = [result["error_msg"]]
|
||||
$test_status[work_id] = -2
|
||||
else
|
||||
#存下每次的结果 只有每次都为0才全部正确
|
||||
$test_status[work_id] = result["status"] != 0 ? result["status"]:$test_status[work_id]
|
||||
$test_result[work_id][index - 1] = resultObj[:results]
|
||||
end
|
||||
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
|
||||
|
@ -121,20 +102,31 @@ class StudentWorkController < ApplicationController
|
|||
student_work.late_penalty = 0
|
||||
end
|
||||
|
||||
#每次都要把数据存到数据库中
|
||||
status = resultObj[:status]
|
||||
if index == 1
|
||||
student_work_test = student_work.student_work_tests.build(status: resultObj[:status],
|
||||
results: [resultObj[:results]],src: params[:src])
|
||||
student_work_test.save!
|
||||
resultObj[:testid] = student_work_test.id
|
||||
else
|
||||
student_work_test = StudentWorkTest.find(params[:testid])
|
||||
results = student_work_test.results
|
||||
results << resultObj[:results]
|
||||
student_work_test.results = results
|
||||
student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status)
|
||||
student_work_test.save!
|
||||
status = student_work_test.status
|
||||
resultObj[:testid] = student_work_test.id
|
||||
end
|
||||
|
||||
#超时或编译错误则直接返回了并存入数据库
|
||||
if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size
|
||||
if $test_status[work_id] == 0
|
||||
if status == 0
|
||||
resultObj[:status] = 0
|
||||
end
|
||||
|
||||
student_work_test = student_work.student_work_tests.build(status: $test_status[work_id],
|
||||
results: $test_result[work_id],src: params[:src])
|
||||
student_work.save
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
|
||||
$test_result[work_id] = nil
|
||||
$test_status[work_id] = nil
|
||||
end
|
||||
|
||||
#渲染返回结果
|
||||
|
|
|
@ -44,7 +44,7 @@ class Principal < ActiveRecord::Base
|
|||
else
|
||||
pattern = "%#{q}%".gsub("/","//").gsub("_","/_")
|
||||
# sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ")
|
||||
sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) or LOWER(login) LIKE LOWER(:p) or LOWER(mail) LIKE LOWER(:p) escape '/'"
|
||||
sql= "LOWER(concat(lastname,firstname)) LIKE LOWER(:p) escape '/' or LOWER(login) LIKE LOWER(:p) escape '/' or LOWER(mail) LIKE LOWER(:p) escape '/'"
|
||||
params = {:p => pattern}
|
||||
if q =~ /^(.+)\s+(.+)$/
|
||||
a, b = "#{$1}%", "#{$2}%"
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
<div class="fl">
|
||||
<p class="f12 mb5"><%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %><div class="cl"></div> </p>
|
||||
<p class="f12">
|
||||
<% if course_file_num > 0 %>
|
||||
<span class="fl mr15 fontGrey4"><%= l(:project_module_attachments) %>(<%= link_to course_file_num, course_files_path(e_course), :class => "linkBlue2" %>)</span>
|
||||
<% if visable_attachemnts_incourse(e_course).count > 0 %>
|
||||
<span class="fl mr15 fontGrey4"><%= l(:project_module_attachments) %>(<%= link_to visable_attachemnts_incourse(e_course).count, course_files_path(e_course), :class => "linkBlue2" %>)</span>
|
||||
<% end %>
|
||||
<% if e_course.homework_commons.where("publish_time <= '#{Date.today}'").count > 0 %>
|
||||
<span class="fl fontGrey4"><%= l(:label_homework_commont) %>(<%= link_to e_course.homework_commons.where("publish_time <= '#{Date.today}'").count, homework_common_index_path(:course=>e_course.id), :class => "linkBlue2" %>)</span>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %>
|
||||
<% teacher_num = 0 %>
|
||||
<% student_num = 0 %>
|
||||
<% teacher_num = TeacherAndAssistantCount(@course) %>
|
||||
<% student_num = studentCount(@course) %>
|
||||
<div class="pr_info_logo fl mr10 mb5">
|
||||
<% if is_excellent_course(@course) %>
|
||||
<img src="/images/course/boutique.png" width="50" height="auto" alt="精品" class="boutiqueP" />
|
||||
|
|
|
@ -169,7 +169,7 @@
|
|||
<div class="cl"></div>
|
||||
</div><!--项目标签 end-->
|
||||
<!--课程推荐-->
|
||||
<%= render :partial => 'courses/recommendation', :locals => {:course => @course, :course_file_num => course_file_num} %>
|
||||
<%= render :partial => 'courses/recommendation', :locals => {:course => @course} %>
|
||||
<div class="fontGrey5 mt10 ml10 mb10">访问计数 <%= @course.visits.to_i %></div>
|
||||
</div><!--LSide end-->
|
||||
|
||||
|
|
|
@ -12,10 +12,12 @@
|
|||
if($("#document_title").val().trim() == "")
|
||||
{
|
||||
$("#doc_title_hint").html("<span class='c_red'>标题不能为空</span>").show();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#doc_title_hint").hide();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<div class="resources" nhname="new_topic_form" >
|
||||
<%= form_tag organization_org_document_comments_path(:organization_id => @organization.id, :field_id => params[:field_id]), :id => 'new_org_document_form' do |f| %>
|
||||
<div>
|
||||
<input class="postDetailInput fl mr15" style="margin-bottom:15px;" name="org_document_comment[title]" id="document_title" style="resize:none;" onfocus = "$('#org_document_editor').show();" placeholder="请输入文章标题"></input>
|
||||
<input class="postDetailInput fl mr15" name="org_document_comment[title]" id="document_title" style="resize:none;" onfocus = "$('#org_document_editor').show();" placeholder="请输入文章标题"></input>
|
||||
</div>
|
||||
<div id="doc_title_hint">
|
||||
</div>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
TO <%= link_to document.organization.name, organization_path(document.organization), :class => "newsBlue" %>
|
||||
|
|
||||
<span style="color:#269ac9;"><%= document.org_subfield_id.nil? ? "组织文章" :"#{OrgSubfield.find(document.org_subfield_id).name}" %></span>
|
||||
<% if @organization.home_id == document.id %>
|
||||
<% if document.organization.home_id == document.id %>
|
||||
<span class="red_homework_btn_cir ml5">已设为首页</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -26,349 +26,14 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<script>
|
||||
var pageX = 0;
|
||||
var pageY = 0;
|
||||
//当前选中的行
|
||||
var line;
|
||||
//已经选中的行,和当前选中的行的区别是:右键选中为line,换一行右键后,line变为last_line,line变为换行后的line
|
||||
var last_line;
|
||||
//资源名称
|
||||
var res_name;
|
||||
//资源名称的链接
|
||||
var res_link;
|
||||
var id; //资源id
|
||||
var sendType = '1'; //发送到课程 1 发送到项目 2
|
||||
var lastSendType; //保存上次发送的发送类型
|
||||
$("#resources_list").mousedown(function(e) {
|
||||
//如果是右键的话
|
||||
if (3 == e.which) {
|
||||
if( $("#res_name").length != 0 || $("#ajax-indicator").is(":hidden") == false){ //其他ajax在执行的时候阻止操作
|
||||
e.preventDefault();
|
||||
return ;
|
||||
}
|
||||
document.oncontextmenu = function() {return false;}
|
||||
pageX = e.clientX;
|
||||
pageY = e.clientY;
|
||||
$("#contextMenu").hide();
|
||||
$("#contextMenu").attr("style","display: block; position: fixed; top:"
|
||||
+ pageY
|
||||
+ "px; left:"
|
||||
+ pageX
|
||||
+ "px; width: 80px;");
|
||||
$("#contextMenu").show();
|
||||
//当前光标所在的对象
|
||||
|
||||
var ele = document.elementFromPoint(pageX,pageY);
|
||||
//转换为jquery对象
|
||||
line = $(ele).parent();
|
||||
//如果上一条存在被选中,那么将上一条的背景色改为白色
|
||||
if(last_line != null){
|
||||
last_line.children().css("background-color", 'white');
|
||||
restore();
|
||||
last_line == null;
|
||||
}
|
||||
//如果当前的tag是li,那么还要li的父级元素
|
||||
if(line.get(0).tagName === 'LI'){
|
||||
line = line.parent();
|
||||
}
|
||||
//将当前的元素的所有子元素的背景色改为蓝色
|
||||
line.children().css("background-color", '#e1e1e1');
|
||||
//将当前元素赋给 上一个对象 保存起来。
|
||||
last_line = line;
|
||||
}
|
||||
});
|
||||
//元素包含关系计算
|
||||
var contains = function(root, el) {
|
||||
if (root.compareDocumentPosition)
|
||||
return root === el || !!(root.compareDocumentPosition(el) & 16);
|
||||
if (root.contains && el.nodeType === 1){
|
||||
return root.contains(el) && root !== el;
|
||||
}
|
||||
while ((el = el.parentNode))
|
||||
if (el === root) return true;
|
||||
return false;
|
||||
}
|
||||
$(document.body).click(function(e) {
|
||||
//在列表上的任何单击事件都要恢复原来的样子
|
||||
//隐藏右键菜单
|
||||
//e.preventDefault();
|
||||
$("#contextMenu").hide();
|
||||
if( $("#ajax-indicator").is(":hidden") == false && $("#res_name").length != 0 ){ //其他ajax在执行的时候或者res_name仍然存在阻止操作
|
||||
return ;
|
||||
}
|
||||
document.oncontextmenu = function() {return true;}
|
||||
//如果当前行为空,那么要将当前行的拿到
|
||||
var ele;
|
||||
if(line == null){
|
||||
ele = document.elementFromPoint(e.clientX, e.clientY);
|
||||
line = $(ele).parent();
|
||||
//如果是在li上点击事件,那么要获得父组件
|
||||
if(line.get(0).tagName === 'LI'){
|
||||
line = line.parent();
|
||||
}
|
||||
|
||||
}
|
||||
//如果当前对象在表格里,将当前行改变为白色,这里主要是防止点击页面的其他链接的时候,那个链接背景色变白了
|
||||
if( contains($("#resources_list").get(0),line.get(0))){
|
||||
line.children().css("background-color", 'white');
|
||||
}
|
||||
|
||||
//当前行恢复编辑状态到链接状态
|
||||
if(ele && ele.nodeName != 'INPUT') {
|
||||
restore();
|
||||
}
|
||||
line = null;
|
||||
});
|
||||
//只要有一个选中了就是true
|
||||
function checkboxSelected(){
|
||||
selected = false;
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
if($(this).attr('checked') == true){
|
||||
selected = true;
|
||||
}
|
||||
});
|
||||
return selected;
|
||||
}
|
||||
//只有全选才是true
|
||||
function checkboxAllSelected(){
|
||||
allSelected = true;
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
if($(this).attr('checked') == undefined){
|
||||
allSelected = false;
|
||||
}
|
||||
});
|
||||
return allSelected;
|
||||
}
|
||||
//只有全部不选才是true
|
||||
function checkboxAllDeselected(){
|
||||
allDeselected = true;
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
if($(this).attr('checked') == 'checked'){
|
||||
allDeselected = false;
|
||||
}
|
||||
});
|
||||
return allDeselected;
|
||||
}
|
||||
//查看所有的checkbox状态,并且按情况更改$("#checkboxAll")的状态
|
||||
function checkAllBox(checkbox){
|
||||
//只有选中当前checkbox且这个时候所有的checkbox都被选中了,$("#checkboxAll")才是被选中状态,其余都是非选中状态
|
||||
if(checkbox.attr('checked') == 'checked' && checkboxAllSelected()){
|
||||
$("#checkboxAll").attr('checked',true);
|
||||
}else{
|
||||
$("#checkboxAll").attr('checked',false);
|
||||
}
|
||||
$("#res_count").html(getCheckBoxSeletedCount());
|
||||
|
||||
}
|
||||
//获取当前checkbox选中的数目
|
||||
function getCheckBoxSeletedCount(){
|
||||
var i = 0;
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
if($(this).attr('checked') == 'checked'){
|
||||
i ++;
|
||||
}
|
||||
});
|
||||
return i;
|
||||
}
|
||||
//全选反选
|
||||
function all_select(){
|
||||
|
||||
if($("#checkboxAll").attr('checked')){
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
$(this).attr('checked',true);
|
||||
});
|
||||
$("#res_count").html(getCheckBoxSeletedCount());
|
||||
}else{
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
$(this).attr('checked',false);
|
||||
});
|
||||
$("#res_count").html(0);
|
||||
}
|
||||
}
|
||||
|
||||
function show_upload(){
|
||||
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'upload_resource' ,:locals => {:user=>User.current.id,:type=>@type,:status=>@status})%>');
|
||||
showModal('ajax-modal', '452px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='closeModal();' style='margin-left: 435px;' class='resourceClose'></a>");
|
||||
$('#ajax-modal').parent().css("top","50%").css("left","50%").css("position","absolute");
|
||||
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||
}
|
||||
//批量删除
|
||||
function batch_delete(){
|
||||
var data = $("#resources_list_form").serialize();
|
||||
if($("input[type=checkbox][data-has-history=Y]:checked").length != 0){
|
||||
alert("您只能删除没有历史记录的资源,请重新选择后再删除。");
|
||||
return;
|
||||
}
|
||||
if($("input[type=checkbox][data-deleteble=N]:checked").length != 0){
|
||||
alert("您只能删除自己上传的资源,请重新选择后再删除。");
|
||||
return;
|
||||
}
|
||||
|
||||
if(data != "" && confirm('确认要删除这些资源吗?')) {
|
||||
$.post(
|
||||
'<%= user_resource_delete_user_path(User.current.id,:type=>@type,:status=>@status)%>',
|
||||
$("#resources_list_form").serialize(),//只会对选中的控件进行序列化提交
|
||||
function (data) {
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
<ul class="resource-list">
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" id="contextMenu">
|
||||
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)preview();" onfocus="this.blur()">预览</a></li>
|
||||
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)rename();" onfocus="this.blur()">重命名</a></li>
|
||||
<!-- data-remote="true" 这个属性会让ajax请求状态标志就在当前按钮的上方显示,就不会滚动浏览器,因而弹出框也会在当前窗口中央展示-->
|
||||
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)show_send_();" data-remote="true" onfocus="this.blur()" >发送</a></li>
|
||||
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)delete_file();" onfocus="this.blur()">删除</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
function show_send_(){
|
||||
$("#contextMenu").hide();
|
||||
document.oncontextmenu = function() {return true;}
|
||||
line.children().css("background-color",'white');
|
||||
id = line.children().last().html();
|
||||
if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_project_user_path(User.current.id)%>' + '?send_id=' + id,
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
}else{
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_course_user_path(User.current.id)%>' + '?send_id=' + id,
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function batch_send(){
|
||||
if($("#resources_list_form").serialize() == ""){
|
||||
alert('暂时不支持多页选择,您当前页没有选择任何资源');
|
||||
return ;
|
||||
}
|
||||
if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_project_user_path(User.current.id)%>' + '?' + $("#resources_list_form").serialize(),
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
}else{
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_course_user_path(User.current.id)%>' + '?'+ $("#resources_list_form").serialize(),
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function preview(){
|
||||
$("#contextMenu").hide();
|
||||
document.oncontextmenu = function() {return true;}
|
||||
line.children().css("background-color",'white');
|
||||
id = line.children().last().html();
|
||||
$.ajax({
|
||||
type:'get',
|
||||
url:'<%= resource_preview_user_path(User.current.id)%>'+"?resource_id="+id
|
||||
});
|
||||
}
|
||||
|
||||
function rename(){
|
||||
$("#contextMenu").hide();
|
||||
document.oncontextmenu = function() {return true;}
|
||||
line.children().css("background-color",'white');
|
||||
id = line.children().last().html();
|
||||
user_id = line.children().eq(5).html();
|
||||
if(user_id === '<%= User.current.id %>') {
|
||||
res_name = line.children().eq(1).children().attr('title');
|
||||
res_link = line.children().eq(1).html();
|
||||
line.children().eq(1).html(
|
||||
'<input name="res_name" id="res_name" ' +
|
||||
'style="height: 2em;line-height: 2em;overflow: hidden;" onblur="restore();" ' +
|
||||
' onkeypress="if(event.keyCode==13){event.preventDefault();this.blur();}" ' +
|
||||
'value="'+res_name+
|
||||
'"/> <input type="hidden" id ="res_id" name="res_id" value="'+id+'"/>');
|
||||
$("#res_name").focus();
|
||||
$("html,body").animate({scrollTop:$("#res_name").offset().top},1000)
|
||||
}else{
|
||||
alert('您无法修改此资源!')
|
||||
}
|
||||
}
|
||||
String.prototype.trim = function() {
|
||||
var str = this,
|
||||
str = str.replace(/^\s\s*/, ''),
|
||||
ws = /\s/,
|
||||
i = str.length;
|
||||
while (ws.test(str.charAt(--i)));
|
||||
return str.slice(0, i + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//恢复编辑状态到链接状态
|
||||
//如果当前是编辑状态,任何的不在输入框里的单击右键事件都需要将编辑状态变回链接状态
|
||||
//如果是编辑状态,且做了修改,那么久要进行修改,并且将修改值经过处理替换到页面显示
|
||||
function restore(){
|
||||
//上一行不为空 且链接不为空
|
||||
if( last_line != null && res_link != null && res_link != '') {
|
||||
name = $("#res_name").lenght != 0 && $("#res_name").val() != undefined ? $("#res_name").val().trim() : undefined ;
|
||||
if (name == undefined || name === 'undefined' ){ //只要res_name没有值,那么就不是编辑状态
|
||||
return;
|
||||
}
|
||||
if( name && name != res_name.trim()){
|
||||
|
||||
if(confirm('确定修改为 '+name)){
|
||||
$.ajax({
|
||||
url: '<%=rename_resource_user_path(User.current.id) %>'+ "?res_name="+$('#res_name').val() + "&res_id=" + $("#res_id").val(),
|
||||
type:'get',
|
||||
success:function (data)
|
||||
{
|
||||
if (data != 'fail' && name != undefined && name != 'undefined') {//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变
|
||||
last_line.children().eq(1).html(res_link);
|
||||
last_line.children().eq(1).children().attr('title', name);
|
||||
last_line.children().eq(1).children().attr('href', data);
|
||||
last_line.children().eq(1).children().html(name.length > 17 ? name.substring(0, 17) + '...' : name);
|
||||
} else {
|
||||
last_line.children().eq(1).html(res_link);
|
||||
res_link = null; //如果修改失败,恢复之后将res_link置空
|
||||
}
|
||||
}
|
||||
} );
|
||||
}else{
|
||||
last_line.children().eq(1).html(res_link);
|
||||
res_link = null; //如果没有做修改,恢复之后将res_link置空
|
||||
}
|
||||
}else {
|
||||
last_line.children().eq(1).html(res_link);
|
||||
res_link = null;//如果没有做修改,恢复之后将res_link置空
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function delete_file() {
|
||||
$("#contextMenu").hide();
|
||||
document.oncontextmenu = function () {
|
||||
return true;
|
||||
}
|
||||
line.children().css("background-color", 'white');
|
||||
id = line.children().last().html();
|
||||
user_id = line.children().eq(5).html();
|
||||
if(line.children().first().children().data('hasHistory') == 'Y'){
|
||||
alert('该资源存在历史版本,不能删除');
|
||||
return;
|
||||
}
|
||||
if(user_id === '<%= User.current.id%>') {
|
||||
if (confirm('确定要删除资源"' + line.children().eq(1).children().attr('title').trim() + '"么?')) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '<%= user_resource_delete_user_path(User.current.id)%>' + '?resource_id=' + id + '&type=<%=@type %>&status=<%=@status %>'
|
||||
});
|
||||
}
|
||||
}else{
|
||||
alert('您无法删除此资源!')
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
|
@ -37,12 +37,350 @@
|
|||
<!--<div id="upload_box" style="display: none">-->
|
||||
<!--<%#= render :partial => 'upload_resource' ,:locals => {:user=>@user}%>-->
|
||||
<!--</div>-->
|
||||
<ul class="resource-list">
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" id="contextMenu">
|
||||
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)preview();" onfocus="this.blur()">预览</a></li>
|
||||
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)rename();" onfocus="this.blur()">重命名</a></li>
|
||||
<!-- data-remote="true" 这个属性会让ajax请求状态标志就在当前按钮的上方显示,就不会滚动浏览器,因而弹出框也会在当前窗口中央展示-->
|
||||
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)show_send_();" data-remote="true" onfocus="this.blur()" >发送</a></li>
|
||||
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)delete_file();" onfocus="this.blur()">删除</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
<script>
|
||||
var pageX = 0;
|
||||
var pageY = 0;
|
||||
//当前选中的行
|
||||
var line;
|
||||
//已经选中的行,和当前选中的行的区别是:右键选中为line,换一行右键后,line变为last_line,line变为换行后的line
|
||||
var last_line;
|
||||
//资源名称
|
||||
var res_name;
|
||||
//资源名称的链接
|
||||
var res_link;
|
||||
var id; //资源id
|
||||
var sendType = '1'; //发送到课程 1 发送到项目 2
|
||||
var lastSendType; //保存上次发送的发送类型
|
||||
$("#resources_list").mousedown(function(e) {
|
||||
//如果是右键的话
|
||||
if (3 == e.which) {
|
||||
if( $("#res_name").length != 0 || $("#ajax-indicator").is(":hidden") == false){ //其他ajax在执行的时候阻止操作
|
||||
e.preventDefault();
|
||||
return ;
|
||||
}
|
||||
document.oncontextmenu = function() {return false;}
|
||||
pageX = e.clientX;
|
||||
pageY = e.clientY;
|
||||
$("#contextMenu").hide();
|
||||
$("#contextMenu").attr("style","display: block; position: fixed; top:"
|
||||
+ pageY
|
||||
+ "px; left:"
|
||||
+ pageX
|
||||
+ "px; width: 80px;");
|
||||
$("#contextMenu").show();
|
||||
//当前光标所在的对象
|
||||
|
||||
var ele = document.elementFromPoint(pageX,pageY);
|
||||
//转换为jquery对象
|
||||
line = $(ele).parent();
|
||||
//如果上一条存在被选中,那么将上一条的背景色改为白色
|
||||
if(last_line != null){
|
||||
last_line.children().css("background-color", 'white');
|
||||
restore();
|
||||
last_line == null;
|
||||
}
|
||||
//如果当前的tag是li,那么还要li的父级元素
|
||||
if(line.get(0).tagName === 'LI'){
|
||||
line = line.parent();
|
||||
}
|
||||
//将当前的元素的所有子元素的背景色改为蓝色
|
||||
line.children().css("background-color", '#e1e1e1');
|
||||
//将当前元素赋给 上一个对象 保存起来。
|
||||
last_line = line;
|
||||
}
|
||||
});
|
||||
//元素包含关系计算
|
||||
var contains = function(root, el) {
|
||||
if (root.compareDocumentPosition)
|
||||
return root === el || !!(root.compareDocumentPosition(el) & 16);
|
||||
if (root.contains && el.nodeType === 1){
|
||||
return root.contains(el) && root !== el;
|
||||
}
|
||||
while ((el = el.parentNode))
|
||||
if (el === root) return true;
|
||||
return false;
|
||||
}
|
||||
$(document.body).click(function(e) {
|
||||
//在列表上的任何单击事件都要恢复原来的样子
|
||||
//隐藏右键菜单
|
||||
//e.preventDefault();
|
||||
$("#contextMenu").hide();
|
||||
if( $("#ajax-indicator").is(":hidden") == false && $("#res_name").length != 0 ){ //其他ajax在执行的时候或者res_name仍然存在阻止操作
|
||||
return ;
|
||||
}
|
||||
document.oncontextmenu = function() {return true;}
|
||||
//如果当前行为空,那么要将当前行的拿到
|
||||
var ele;
|
||||
if(line == null){
|
||||
ele = document.elementFromPoint(e.clientX, e.clientY);
|
||||
line = $(ele).parent();
|
||||
//如果是在li上点击事件,那么要获得父组件
|
||||
if(line.get(0).tagName === 'LI'){
|
||||
line = line.parent();
|
||||
}
|
||||
|
||||
}
|
||||
//如果当前对象在表格里,将当前行改变为白色,这里主要是防止点击页面的其他链接的时候,那个链接背景色变白了
|
||||
if( contains($("#resources_list").get(0),line.get(0))){
|
||||
line.children().css("background-color", 'white');
|
||||
}
|
||||
|
||||
//当前行恢复编辑状态到链接状态
|
||||
if(ele && ele.nodeName != 'INPUT') {
|
||||
restore();
|
||||
}
|
||||
line = null;
|
||||
});
|
||||
//只要有一个选中了就是true
|
||||
function checkboxSelected(){
|
||||
selected = false;
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
if($(this).attr('checked') == true){
|
||||
selected = true;
|
||||
}
|
||||
});
|
||||
return selected;
|
||||
}
|
||||
//只有全选才是true
|
||||
function checkboxAllSelected(){
|
||||
allSelected = true;
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
if($(this).attr('checked') == undefined){
|
||||
allSelected = false;
|
||||
}
|
||||
});
|
||||
return allSelected;
|
||||
}
|
||||
//只有全部不选才是true
|
||||
function checkboxAllDeselected(){
|
||||
allDeselected = true;
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
if($(this).attr('checked') == 'checked'){
|
||||
allDeselected = false;
|
||||
}
|
||||
});
|
||||
return allDeselected;
|
||||
}
|
||||
//查看所有的checkbox状态,并且按情况更改$("#checkboxAll")的状态
|
||||
function checkAllBox(checkbox){
|
||||
//只有选中当前checkbox且这个时候所有的checkbox都被选中了,$("#checkboxAll")才是被选中状态,其余都是非选中状态
|
||||
if(checkbox.attr('checked') == 'checked' && checkboxAllSelected()){
|
||||
$("#checkboxAll").attr('checked',true);
|
||||
}else{
|
||||
$("#checkboxAll").attr('checked',false);
|
||||
}
|
||||
$("#res_count").html(getCheckBoxSeletedCount());
|
||||
|
||||
}
|
||||
//获取当前checkbox选中的数目
|
||||
function getCheckBoxSeletedCount(){
|
||||
var i = 0;
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
if($(this).attr('checked') == 'checked'){
|
||||
i ++;
|
||||
}
|
||||
});
|
||||
return i;
|
||||
}
|
||||
//全选反选
|
||||
function all_select(){
|
||||
|
||||
if($("#checkboxAll").attr('checked')){
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
$(this).attr('checked',true);
|
||||
});
|
||||
$("#res_count").html(getCheckBoxSeletedCount());
|
||||
}else{
|
||||
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
|
||||
$(this).attr('checked',false);
|
||||
});
|
||||
$("#res_count").html(0);
|
||||
}
|
||||
}
|
||||
|
||||
function show_upload(){
|
||||
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'upload_resource' ,:locals => {:user=>User.current.id,:type=>@type,:status=>@status})%>');
|
||||
showModal('ajax-modal', '452px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='closeModal();' style='margin-left: 435px;' class='resourceClose'></a>");
|
||||
$('#ajax-modal').parent().css("top","50%").css("left","50%").css("position","absolute");
|
||||
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||
}
|
||||
//批量删除
|
||||
function batch_delete(){
|
||||
var data = $("#resources_list_form").serialize();
|
||||
if($("input[type=checkbox][data-has-history=Y]:checked").length != 0){
|
||||
alert("您只能删除没有历史记录的资源,请重新选择后再删除。");
|
||||
return;
|
||||
}
|
||||
if($("input[type=checkbox][data-deleteble=N]:checked").length != 0){
|
||||
alert("您只能删除自己上传的资源,请重新选择后再删除。");
|
||||
return;
|
||||
}
|
||||
|
||||
if(data != "" && confirm('确认要删除这些资源吗?')) {
|
||||
$.post(
|
||||
'<%= user_resource_delete_user_path(User.current.id,:type=>@type,:status=>@status)%>',
|
||||
$("#resources_list_form").serialize(),//只会对选中的控件进行序列化提交
|
||||
function (data) {
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function show_send_(){
|
||||
$("#contextMenu").hide();
|
||||
document.oncontextmenu = function() {return true;}
|
||||
line.children().css("background-color",'white');
|
||||
id = line.children().last().html();
|
||||
if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_project_user_path(User.current.id)%>' + '?send_id=' + id,
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
}else{
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_course_user_path(User.current.id)%>' + '?send_id=' + id,
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function batch_send(){
|
||||
if($("#resources_list_form").serialize() == ""){
|
||||
alert('暂时不支持多页选择,您当前页没有选择任何资源');
|
||||
return ;
|
||||
}
|
||||
if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_project_user_path(User.current.id)%>' + '?' + $("#resources_list_form").serialize(),
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
}else{
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_course_user_path(User.current.id)%>' + '?'+ $("#resources_list_form").serialize(),
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function preview(){
|
||||
$("#contextMenu").hide();
|
||||
document.oncontextmenu = function() {return true;}
|
||||
line.children().css("background-color",'white');
|
||||
id = line.children().last().html();
|
||||
$.ajax({
|
||||
type:'get',
|
||||
url:'<%= resource_preview_user_path(User.current.id)%>'+"?resource_id="+id
|
||||
});
|
||||
}
|
||||
|
||||
function rename(){
|
||||
$("#contextMenu").hide();
|
||||
document.oncontextmenu = function() {return true;}
|
||||
line.children().css("background-color",'white');
|
||||
id = line.children().last().html();
|
||||
user_id = line.children().eq(5).html();
|
||||
if(user_id === '<%= User.current.id %>') {
|
||||
res_name = line.children().eq(1).children().attr('title');
|
||||
res_link = line.children().eq(1).html();
|
||||
line.children().eq(1).html(
|
||||
'<input name="res_name" id="res_name" ' +
|
||||
'style="height: 2em;line-height: 2em;overflow: hidden;" onblur="restore();" ' +
|
||||
' onkeypress="if(event.keyCode==13){event.preventDefault();this.blur();}" ' +
|
||||
'value="'+res_name+
|
||||
'"/> <input type="hidden" id ="res_id" name="res_id" value="'+id+'"/>');
|
||||
alert("test");
|
||||
$("#res_name").focus();
|
||||
$("html,body").animate({scrollTop:$("#res_name").offset().top},1000)
|
||||
}else{
|
||||
alert('您无法修改此资源!')
|
||||
}
|
||||
}
|
||||
String.prototype.trim = function() {
|
||||
var str = this,
|
||||
str = str.replace(/^\s\s*/, ''),
|
||||
ws = /\s/,
|
||||
i = str.length;
|
||||
while (ws.test(str.charAt(--i)));
|
||||
return str.slice(0, i + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//恢复编辑状态到链接状态
|
||||
//如果当前是编辑状态,任何的不在输入框里的单击右键事件都需要将编辑状态变回链接状态
|
||||
//如果是编辑状态,且做了修改,那么久要进行修改,并且将修改值经过处理替换到页面显示
|
||||
function restore(){
|
||||
//上一行不为空 且链接不为空
|
||||
if( last_line != null && res_link != null && res_link != '') {
|
||||
name = $("#res_name").lenght != 0 && $("#res_name").val() != undefined ? $("#res_name").val().trim() : undefined ;
|
||||
if (name == undefined || name === 'undefined' ){ //只要res_name没有值,那么就不是编辑状态
|
||||
return;
|
||||
}
|
||||
if( name && name != res_name.trim()){
|
||||
|
||||
if(confirm('确定修改为 '+name)){
|
||||
$.ajax({
|
||||
url: '<%=rename_resource_user_path(User.current.id) %>'+ "?res_name="+$('#res_name').val() + "&res_id=" + $("#res_id").val(),
|
||||
type:'get',
|
||||
success:function (data)
|
||||
{
|
||||
if (data != 'fail' && name != undefined && name != 'undefined') {//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变
|
||||
last_line.children().eq(1).html(res_link);
|
||||
last_line.children().eq(1).children().attr('title', name);
|
||||
last_line.children().eq(1).children().attr('href', data);
|
||||
last_line.children().eq(1).children().html(name.length > 17 ? name.substring(0, 17) + '...' : name);
|
||||
} else {
|
||||
last_line.children().eq(1).html(res_link);
|
||||
res_link = null; //如果修改失败,恢复之后将res_link置空
|
||||
}
|
||||
}
|
||||
} );
|
||||
}else{
|
||||
last_line.children().eq(1).html(res_link);
|
||||
res_link = null; //如果没有做修改,恢复之后将res_link置空
|
||||
}
|
||||
}else {
|
||||
last_line.children().eq(1).html(res_link);
|
||||
res_link = null;//如果没有做修改,恢复之后将res_link置空
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function delete_file() {
|
||||
$("#contextMenu").hide();
|
||||
document.oncontextmenu = function () {
|
||||
return true;
|
||||
}
|
||||
line.children().css("background-color", 'white');
|
||||
id = line.children().last().html();
|
||||
user_id = line.children().eq(5).html();
|
||||
if(line.children().first().children().data('hasHistory') == 'Y'){
|
||||
alert('该资源存在历史版本,不能删除');
|
||||
return;
|
||||
}
|
||||
if(user_id === '<%= User.current.id%>') {
|
||||
if (confirm('确定要删除资源"' + line.children().eq(1).children().attr('title').trim() + '"么?')) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '<%= user_resource_delete_user_path(User.current.id)%>' + '?resource_id=' + id + '&type=<%=@type %>&status=<%=@status %>'
|
||||
});
|
||||
}
|
||||
}else{
|
||||
alert('您无法删除此资源!')
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
|
@ -57,10 +57,12 @@ $(function(){
|
|||
);
|
||||
*/
|
||||
//先测试一次并返回测试集个数及结果再判断是否需要继续进行测试
|
||||
var test_post = function(i){
|
||||
var test_post = function(i, testid){
|
||||
$.post(
|
||||
'/student_work/program_test_ex',
|
||||
{homework: homework_id, student_work_id: student_work_id, src: src, title: title, is_test: is_test,tIndex:i},
|
||||
{homework: homework_id, student_work_id: student_work_id,
|
||||
src: src, title: title, is_test: is_test,tIndex:i,
|
||||
testid: testid},
|
||||
function(data,status){
|
||||
var tSeq = data.tseq;
|
||||
var tCount = data.tcount;
|
||||
|
@ -90,7 +92,7 @@ $(function(){
|
|||
return;
|
||||
}
|
||||
|
||||
test_post(i+1);
|
||||
test_post(i+1, data.testid);
|
||||
}
|
||||
).fail(function(xhr, status){
|
||||
if(status == 'timeout'){
|
||||
|
@ -100,9 +102,10 @@ $(function(){
|
|||
}
|
||||
return;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
test_post(1);
|
||||
test_post(1, 0);
|
||||
};
|
||||
|
||||
$('#test-program-btn').on('click', test_program);
|
||||
|
|
Loading…
Reference in New Issue