Merge branch 'cxt_course' of https://git.trustie.net/jacknudt/trustieforge into cxt_course
This commit is contained in:
commit
1deb611ba2
|
@ -529,6 +529,7 @@ class FilesController < ApplicationController
|
|||
if attachment.publish_time > Date.today
|
||||
attachment.is_publish = 0
|
||||
end
|
||||
attachment.description = params[:description]
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
|
@ -628,16 +629,14 @@ class FilesController < ApplicationController
|
|||
end
|
||||
|
||||
def update_contributor_score(course, file )
|
||||
unless file.author.allowed_to?(:as_teacher, course)
|
||||
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5)
|
||||
else
|
||||
score = course_contributor_score.resource_num + 5
|
||||
total_score = course_contributor_score.total_score + 5
|
||||
course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score)
|
||||
end
|
||||
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5)
|
||||
else
|
||||
score = course_contributor_score.resource_num + 5
|
||||
total_score = course_contributor_score.total_score + 5
|
||||
course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1538,9 +1538,20 @@ class UsersController < ApplicationController
|
|||
#@user.save_attachments(params[:attachments],User.current)
|
||||
# Container_type为Principal
|
||||
Attachment.attach_filesex(@user, params[:attachments], params[:attachment_type])
|
||||
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
|
||||
if(params[:type].blank? || params[:type] == "1") # 我的资源
|
||||
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
|
||||
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
|
||||
if params[:status] == 2
|
||||
@attachments = get_course_resources(params[:id], user_course_ids)
|
||||
elsif params[:status] == "3"
|
||||
@attachments = get_project_resources(params[:id], user_project_ids)
|
||||
elsif params[:status] == "4"
|
||||
@attachments = get_attch_resources params[:id]
|
||||
elsif params[:status] == "5"
|
||||
@attachments = get_principal_resources params[:id]
|
||||
else
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
|
||||
end
|
||||
elsif params[:type] == "2" # 课程资源
|
||||
@attachments = get_course_resources(params[:id], user_course_ids)
|
||||
elsif params[:type] == "3" # 项目资源
|
||||
|
@ -1550,10 +1561,21 @@ class UsersController < ApplicationController
|
|||
elsif params[:type] == "5" #用户资源
|
||||
@attachments = get_principal_resources params[:id]
|
||||
elsif params[:type] == "6" # 公共资源
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
||||
if params[:status] == "2"
|
||||
@attachments = get_course_resources_public( user_course_ids)
|
||||
elsif params[:status] == "3"
|
||||
@attachments = get_project_resources_public(user_project_ids)
|
||||
elsif params[:status] == "4"
|
||||
@attachments = get_attch_resources_public
|
||||
elsif params[:status] == "5"
|
||||
@attachments = get_principal_resources_public
|
||||
else
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
||||
end
|
||||
end
|
||||
@type = params[:type] || 1
|
||||
@status = params[:status]
|
||||
@type = params[:type]
|
||||
@limit = 25
|
||||
@is_remote = true
|
||||
@atta_count = @attachments.count
|
||||
|
@ -1578,9 +1600,20 @@ class UsersController < ApplicationController
|
|||
user_course_ids = User.current.courses.map { |c| c.id}
|
||||
user_project_ids = User.current.projects.map {|p| p.id}
|
||||
# user_org_ids = User.current.organizations.map {|o| o.id}
|
||||
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
|
||||
if(params[:type].blank? || params[:type] == "1") # 我的资源
|
||||
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
|
||||
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
|
||||
if params[:status] == 2
|
||||
@attachments = get_course_resources(params[:id], user_course_ids)
|
||||
elsif params[:status] == "3"
|
||||
@attachments = get_project_resources(params[:id], user_project_ids)
|
||||
elsif params[:status] == "4"
|
||||
@attachments = get_attch_resources params[:id]
|
||||
elsif params[:status] == "5"
|
||||
@attachments = get_principal_resources params[:id]
|
||||
else
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
|
||||
end
|
||||
elsif params[:type] == "2" # 课程资源
|
||||
@attachments = get_course_resources(params[:id], user_course_ids)
|
||||
elsif params[:type] == "3" # 项目资源
|
||||
|
@ -1590,9 +1623,20 @@ class UsersController < ApplicationController
|
|||
elsif params[:type] == "5" #用户资源
|
||||
@attachments = get_principal_resources params[:id]
|
||||
elsif params[:type] == "6" # 公共资源
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
||||
if params[:status] == "2"
|
||||
@attachments = get_course_resources_public( user_course_ids)
|
||||
elsif params[:status] == "3"
|
||||
@attachments = get_project_resources_public(user_project_ids)
|
||||
elsif params[:status] == "4"
|
||||
@attachments = get_attch_resources_public
|
||||
elsif params[:status] == "5"
|
||||
@attachments = get_principal_resources_public
|
||||
else
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
||||
end
|
||||
end
|
||||
@status = params[:status]
|
||||
@type = params[:type]
|
||||
@limit = 25
|
||||
@is_remote = true
|
||||
|
@ -1678,6 +1722,9 @@ class UsersController < ApplicationController
|
|||
attach_copied_obj.attachtype = 4
|
||||
end
|
||||
if attach_copied_obj.save
|
||||
# 更新引用次数
|
||||
quotes = ori.quotes.to_i + 1
|
||||
ori.update_attribute(:quotes, quotes) unless ori.nil?
|
||||
ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
|
||||
end
|
||||
@save_message = attach_copied_obj.errors.full_messages
|
||||
|
@ -1690,10 +1737,11 @@ class UsersController < ApplicationController
|
|||
@flag = false
|
||||
end
|
||||
send_ids.each do |send_id|
|
||||
quotes = 0
|
||||
ori = Attachment.find_by_id(send_id)
|
||||
|
||||
unless course_ids.nil?
|
||||
course_ids.each do |id|
|
||||
quotes = 0
|
||||
next if ori.blank?
|
||||
@exist = false
|
||||
Course.find(id).attachments.each do |att| #如果课程中包含该资源
|
||||
|
@ -1716,6 +1764,9 @@ class UsersController < ApplicationController
|
|||
attach_copied_obj.attachtype = 4
|
||||
end
|
||||
if attach_copied_obj.save
|
||||
# 更新引用次数
|
||||
quotes = ori.quotes.to_i + 1
|
||||
ori.update_attribute(:quotes, quotes) unless ori.nil?
|
||||
ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
|
||||
end
|
||||
@save_message = attach_copied_obj.errors.full_messages
|
||||
|
@ -1776,6 +1827,9 @@ class UsersController < ApplicationController
|
|||
attach_copied_obj.attachtype = 1
|
||||
end
|
||||
if attach_copied_obj.save
|
||||
# 更新引用次数
|
||||
quotes = ori.quotes.to_i + 1
|
||||
ori.update_attribute(:quotes, quotes) unless ori.nil?
|
||||
ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
|
||||
end
|
||||
unless Project.find(project_id).project_score.nil?
|
||||
|
@ -1791,10 +1845,11 @@ class UsersController < ApplicationController
|
|||
@flag = false
|
||||
end
|
||||
send_ids.each do |send_id|
|
||||
|
||||
quotes = 0
|
||||
ori = Attachment.find_by_id(send_id)
|
||||
unless project_ids.nil?
|
||||
project_ids.each do |project_id|
|
||||
quotes = 0
|
||||
next if ori.blank?
|
||||
@exist = false
|
||||
Project.find(project_id).attachments.each do |att| #如果课程中包含该资源
|
||||
|
@ -1817,6 +1872,9 @@ class UsersController < ApplicationController
|
|||
attach_copied_obj.attachtype = 1
|
||||
end
|
||||
if attach_copied_obj.save
|
||||
# 更新引用次数
|
||||
quotes = ori.quotes.to_i + 1
|
||||
ori.update_attribute(:quotes, quotes) unless ori.nil?
|
||||
ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
|
||||
end
|
||||
unless Project.find(project_id).project_score.nil?
|
||||
|
@ -1876,6 +1934,9 @@ class UsersController < ApplicationController
|
|||
attach_copied_obj.attachtype = 1
|
||||
end
|
||||
if attach_copied_obj.save
|
||||
# 更新引用次数
|
||||
quotes = ori.quotes.to_i + 1
|
||||
ori.update_attribute(:quotes, quotes) unless ori.nil?
|
||||
ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
|
||||
end
|
||||
end
|
||||
|
@ -1887,7 +1948,7 @@ class UsersController < ApplicationController
|
|||
@flag = false
|
||||
end
|
||||
send_ids.each do |send_id|
|
||||
|
||||
quotes = 0
|
||||
ori = Attachment.find_by_id(send_id)
|
||||
unless subfield_id.nil?
|
||||
next if ori.blank?
|
||||
|
@ -1912,6 +1973,9 @@ class UsersController < ApplicationController
|
|||
attach_copied_obj.attachtype = 1
|
||||
end
|
||||
if attach_copied_obj.save
|
||||
# 更新引用次数
|
||||
quotes = ori.quotes.to_i + 1
|
||||
ori.update_attribute(:quotes, quotes) unless ori.nil?
|
||||
ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
|
||||
end
|
||||
end
|
||||
|
@ -2273,9 +2337,19 @@ class UsersController < ApplicationController
|
|||
attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
|
||||
end
|
||||
|
||||
# 获取公共资源课程
|
||||
def get_course_resources_public user_course_ids
|
||||
attchments = Attachment.where("(container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
|
||||
end
|
||||
|
||||
# 获取我的项目资源
|
||||
def get_project_resources author_id, user_project_ids
|
||||
attchments = Attachment.where("author_id = #{author_id} and container_type = 'Project'").order("created_on desc")
|
||||
attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Project') or (container_type = 'Course' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
|
||||
end
|
||||
|
||||
# 获取公共资源的项目资源
|
||||
def get_project_resources_public user_project_ids
|
||||
attchments = Attachment.where("(container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
|
||||
end
|
||||
|
||||
# 获取我上传的附件
|
||||
|
@ -2283,11 +2357,21 @@ class UsersController < ApplicationController
|
|||
attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc")
|
||||
end
|
||||
|
||||
# 获取公共资源中我上传的附件
|
||||
def get_attch_resources_public
|
||||
attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc")
|
||||
end
|
||||
|
||||
# 获取我的用户类型资源
|
||||
def get_principal_resources author_id
|
||||
attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc")
|
||||
end
|
||||
|
||||
# 获取我的用户类型资源
|
||||
def get_principal_resources_public
|
||||
attchments = Attachment.where("container_type = 'Principal'").order("created_on desc")
|
||||
end
|
||||
|
||||
# 资源库 分为全部 课程资源 项目资源 附件
|
||||
def user_resource
|
||||
# 别人的资源库是没有权限去看的
|
||||
|
@ -2300,7 +2384,18 @@ class UsersController < ApplicationController
|
|||
# user_org_ids = User.current.organizations.map {|o| o.id}
|
||||
if(params[:type].blank? || params[:type] == "1") # 我的资源
|
||||
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
|
||||
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
|
||||
if params[:status] == "2"
|
||||
@attachments = get_course_resources(params[:id], user_course_ids)
|
||||
elsif params[:status] == "3"
|
||||
@attachments = get_project_resources(params[:id], user_project_ids)
|
||||
elsif params[:status] == "4"
|
||||
@attachments = get_attch_resources params[:id]
|
||||
elsif params[:status] == "5"
|
||||
@attachments = get_principal_resources params[:id]
|
||||
else
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids)
|
||||
end
|
||||
elsif params[:type] == "2" # 课程资源
|
||||
@attachments = get_course_resources(params[:id], user_course_ids)
|
||||
elsif params[:type] == "3" # 项目资源
|
||||
|
@ -2310,9 +2405,20 @@ class UsersController < ApplicationController
|
|||
elsif params[:type] == "5" #用户资源
|
||||
@attachments = get_principal_resources params[:id]
|
||||
elsif params[:type] == "6" # 公共资源
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
||||
if params[:status] == "2"
|
||||
@attachments = get_course_resources_public( user_course_ids)
|
||||
elsif params[:status] == "3"
|
||||
@attachments = get_project_resources_public(user_project_ids)
|
||||
elsif params[:status] == "4"
|
||||
@attachments = get_attch_resources_public
|
||||
elsif params[:status] == "5"
|
||||
@attachments = get_principal_resources_public
|
||||
else
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
||||
end
|
||||
end
|
||||
@status = params[:status]
|
||||
@type = params[:type]
|
||||
@limit = 25
|
||||
@is_remote = true
|
||||
|
@ -2358,27 +2464,55 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def import_resources_search
|
||||
search = "%#{params[:search].strip.downcase}%"
|
||||
# 别人的资源库是没有权限去看的
|
||||
if User.current.id.to_i != params[:id].to_i
|
||||
render_403
|
||||
return
|
||||
end
|
||||
user_course_ids = User.current.courses.map { |c| c.id}
|
||||
user_project_ids = User.current.projects.map {|p| p.id}
|
||||
# user_org_ids = User.current.organizations.map {|o| o.id}
|
||||
if(params[:type].blank? || params[:type] == "1") # 我的资源
|
||||
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
|
||||
user_course_ids = User.current.courses.map { |c| c.id}
|
||||
user_project_ids = User.current.projects.map {|p| p.id}
|
||||
# user_org_ids = User.current.organizations.map {|o| o.id}
|
||||
@attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
|
||||
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
|
||||
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc")
|
||||
elsif params[:type] == "6" # 公共资源
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_public_resources(user_course_ids, user_project_ids)
|
||||
end
|
||||
@type = params[:type]
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@atta_count = @attachments.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
#@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
@attachments = paginateHelper @attachments,10
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {render :layout => 'new_base'}
|
||||
end
|
||||
end
|
||||
|
||||
# 内容导入到对象中
|
||||
def import_into_container
|
||||
# attachments = Attachment.where("id in (#{params[:checkbox1].join(',')})")
|
||||
# if params[:mul_type] == "Project"
|
||||
#
|
||||
# elsif params[:mul_type] == "Course"
|
||||
# Attachment.create(:container_id => params[:mul_id], :container_type => "Course", :name => attachment.name)
|
||||
# elsif params[:mul_type] == "SubfieldFile"
|
||||
# end
|
||||
|
||||
send_ids = params[:checkbox1]
|
||||
# mul_id为当前课程id、项目id、组织id的多种形态
|
||||
mul_id = params[:mul_id]
|
||||
if params[:mul_type] == "Course"
|
||||
mul_container = Course.find(mul_id)
|
||||
elsif params[:mul_type] == "Project"
|
||||
mul_container = Project.find(mul_id)
|
||||
elsif params[:mul_type] == "SubfieldFile"
|
||||
mul_container = OrgSubfield.find(mul_id)
|
||||
end
|
||||
unless params[:checkbox1].blank?
|
||||
send_ids = params[:checkbox1]
|
||||
# mul_id为当前课程id、项目id、组织id的多种形态
|
||||
mul_id = params[:mul_id]
|
||||
if params[:mul_type] == "Course"
|
||||
mul_container = Course.find(mul_id)
|
||||
elsif params[:mul_type] == "Project"
|
||||
mul_container = Project.find(mul_id)
|
||||
elsif params[:mul_type] == "SubfieldFile"
|
||||
mul_container = OrgSubfield.find(mul_id)
|
||||
end
|
||||
send_ids.each do |send_id|
|
||||
ori = Attachment.find_by_id(send_id)
|
||||
# 如果该附件已经存课程中,则只更新附件创建时间
|
||||
|
@ -2408,11 +2542,11 @@ class UsersController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.html {
|
||||
if params[:mul_type] == "Course"
|
||||
redirect_to course_files_url(mul_container)
|
||||
redirect_to course_files_url(mul_container) unless mul_container.nil?
|
||||
elsif params[:mul_type] == "Project"
|
||||
redirect_to project_files_url(mul_container)
|
||||
redirect_to project_files_url(mul_container) unless mul_container.nil?
|
||||
elsif params[:mul_type] == "SubfieldFile"
|
||||
redirect_to org_subfield_files_url(mul_container)
|
||||
redirect_to org_subfield_files_url(mul_container) unless mul_container.nil?
|
||||
end
|
||||
}
|
||||
end
|
||||
|
@ -2421,11 +2555,15 @@ class UsersController < ApplicationController
|
|||
# 根据资源关键字进行搜索
|
||||
def resource_search
|
||||
search = "%#{params[:search].strip.downcase}%"
|
||||
user_course_ids = User.current.courses.map { |c| c.id}
|
||||
user_project_ids = User.current.projects.map {|p| p.id}
|
||||
# user_org_ids = User.current.organizations.map {|o| o.id}
|
||||
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
|
||||
if User.current.id.to_i == params[:id].to_i
|
||||
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询
|
||||
@attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
|
||||
" or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))) and (filename like :p) ",:p=>search).order("created_on desc")
|
||||
|
||||
@attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
|
||||
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
|
||||
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc")
|
||||
else
|
||||
user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
|
||||
@attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type in" +
|
||||
|
@ -2463,8 +2601,9 @@ class UsersController < ApplicationController
|
|||
end
|
||||
elsif params[:type] == "6" #全部资源
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = Attachment.where("((is_public =1 and is_publish = 1 and container_id is not null)" +
|
||||
"or (author_id = #{params[:id]} and is_publish = 0)) and (filename like :p) ", :p => search).order("created_on desc")
|
||||
@attachments = Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+
|
||||
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
|
||||
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc")
|
||||
end
|
||||
@type = params[:type]
|
||||
@limit = 25
|
||||
|
|
|
@ -110,8 +110,7 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
# 更新课程英雄榜得分
|
||||
# user传过来必须是学生
|
||||
# 更新课程活跃度得分
|
||||
def course_member_score(course_id,user_id,type)
|
||||
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first
|
||||
case type
|
||||
|
@ -160,6 +159,15 @@ module ApplicationHelper
|
|||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score)
|
||||
end
|
||||
when "News"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1)
|
||||
else
|
||||
score = course_contributor_score.news_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:news_num => score, :total_score => total_score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -856,7 +856,9 @@ module CoursesHelper
|
|||
end
|
||||
|
||||
def contributor_course_scor(course_id)
|
||||
ccs = CourseContributorScore.where("course_id =?", course_id).order("total_score desc") .limit(9)
|
||||
ccs = CourseContributorScore.find_by_sql("SELECT * FROM `course_contributor_scores` where course_id = #{course_id} order by
|
||||
(message_num*2 + message_reply_num + news_reply_num + news_num +
|
||||
resource_num*5 + journal_num + homework_journal_num ) desc limit 9;")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -82,9 +82,7 @@ class Comment < ActiveRecord::Base
|
|||
# 课程成员得分(英雄榜)
|
||||
def act_as_student_score
|
||||
if self.commented.course
|
||||
unless self.author.allowed_to?(:as_teacher, self.commented.course)
|
||||
course_member_score(self.commented.course.id, self.author_id, "NewReply")
|
||||
end
|
||||
course_member_score(self.commented.course.id, self.author_id, "NewReply")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class CourseContributorScore < ActiveRecord::Base
|
||||
attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, :resource_num, :user_id, :total_score, :homework_journal_num
|
||||
attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num,
|
||||
:resource_num, :user_id, :total_score, :homework_journal_num, :news_num
|
||||
belongs_to :course
|
||||
belongs_to :user
|
||||
end
|
||||
|
|
|
@ -283,12 +283,12 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# 课程成员得分(英雄榜)
|
||||
# 课程成员得分(活跃度)
|
||||
def act_as_student_score
|
||||
if self.jour_type == "Course"
|
||||
course_member_score(self.jour_id, self.user_id, "JournalForMessage")
|
||||
elsif self.jour_type == "HomeworkCommon"
|
||||
course_member_score(self.jour_id, self.user_id, "HomeworkCommon")
|
||||
course_member_score(self.jour.course_id, self.user_id, "HomeworkCommon")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -341,17 +341,15 @@ class Message < ActiveRecord::Base
|
|||
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE
|
||||
end
|
||||
|
||||
# 课程成员得分(英雄榜)
|
||||
# 课程成员得分(活跃度)
|
||||
def act_as_student_score
|
||||
if self.course
|
||||
unless self.author.allowed_to?(:as_teacher, self.course)
|
||||
if self.parent_id.nil?
|
||||
# 发帖
|
||||
course_member_score(self.course.id, self.author_id, "Message")
|
||||
else
|
||||
# 回帖
|
||||
course_member_score(self.course.id, self.author_id, "MessageReply")
|
||||
end
|
||||
if self.parent_id.nil?
|
||||
# 发帖
|
||||
course_member_score(self.course.id, self.author_id, "Message")
|
||||
else
|
||||
# 回帖
|
||||
course_member_score(self.course.id, self.author_id, "MessageReply")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,7 +59,7 @@ class News < ActiveRecord::Base
|
|||
:author_key => :author_id
|
||||
acts_as_watchable
|
||||
|
||||
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count
|
||||
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score
|
||||
after_update :update_activity
|
||||
after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities
|
||||
|
||||
|
@ -195,4 +195,10 @@ class News < ActiveRecord::Base
|
|||
OrgActivity.where("container_type='OrgSubfield' and org_act_type='News' and org_act_id=?", self.id).destroy_all
|
||||
end
|
||||
|
||||
def act_as_student_score
|
||||
if self.course
|
||||
course_member_score(self.course.id, self.author_id, "News")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -91,7 +91,7 @@
|
|||
<%= form_tag( search_course_files_path(@course), method: 'get',:class => "re_search",:remote=>true) do %>
|
||||
<%= text_field_tag 'name', params[:name], name: "name", :class => 'researchBox fl',:style=>"padding: 0px"%>
|
||||
<%= submit_tag "课内搜索", :class => "blueBtn mr5 fl",:name => "incourse",:id => "incourse" %>
|
||||
<%= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %>
|
||||
<%#= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %>
|
||||
<% if is_course_teacher(User.current,@course) || (@course.publish_resource==1 && User.current.member_of_course?(@course) ) %>
|
||||
<input class="blueBtn fr mr5" value="上传资源" onclick="course_files_upload();">
|
||||
<%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %>
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
<p class="f_l mb5 fontGrey2">文件大小:<%= number_to_human_size(file.filesize) %></p>
|
||||
<p class="fl ml15 fontGrey2">下载<%= file.downloads%> | 引用<%= file.quotes.nil? ? 0:file.quotes %> </p>
|
||||
</div>
|
||||
<% unless file.description.blank? %>
|
||||
<div class="cl"></div>
|
||||
<div class="fontGrey2 mb4">资源描述:<%= file.description %></div>
|
||||
<% end %>
|
||||
<div class="cl"></div>
|
||||
<div class="tag_h">
|
||||
<!-- container_type = 1 代表是课程里的资源 -->
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<%= form_tag( search_files_in_subfield_org_subfield_files_path(@org_subfield), method: 'get',:class => "re_search",:remote=>true) do %>
|
||||
<%= text_field_tag 'name', params[:name], name: "name", :class => 'researchBox fl',:style=>"padding: 0px"%>
|
||||
<%= submit_tag "栏目内搜索", :class => "blueBtn mr5 fl",:style => 'width:72px;',:name => "inorg_subfield",:id => "inorg_subfield", :onmouseover => "presscss('inorg_subfield')",:onmouseout =>"buttoncss()" %>
|
||||
<%= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %>
|
||||
<%#= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %>
|
||||
<input class="blueBtn fr mr5" value="上传资源" onclick="org_upload_files(<%= org_subfield.id %>);">
|
||||
<%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :subfield_file_id => @org_subfield.id), :class => "blue-btn fr mr5", :remote => true) %>
|
||||
<%#= link_to "上传资源",subfield_upload_file_org_subfield_files_path(@org_subfield.id, :in_org => 1),:method => "post",:class=>"blueBtn fr mr5",:remote => true %>
|
||||
|
|
|
@ -22,6 +22,14 @@
|
|||
<%= render :partial => 'files/new_style_attachment_list',:locals => {:container => course} %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="mb5">
|
||||
<label class="fl c_dark f14" style="margin-top: 4px;">附件描述:</label>
|
||||
<div class="fl">
|
||||
<input type="text" name="description" placeholder="文件描述" class="fl W120 ">
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
||||
<% if User.current.allowed_to?(:as_teacher,course) %>
|
||||
<div class="mb5">
|
||||
<label class="fl c_dark f14" style="margin-top: 4px;">延迟发布:</label>
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<script type='text/javascript'>
|
||||
var slideHeight = 29;
|
||||
function readmore(aNode) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<% homework_num = @course.homework_commons.where("publish_time <= '#{Date.today}'").count %>
|
||||
<% end %>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="en" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>
|
||||
|
@ -142,32 +142,60 @@
|
|||
<div class="cl"></div>
|
||||
<% unless contributor_course_scor(@course.id).count == 0 %>
|
||||
<ul class="rankList">
|
||||
<h4>课程活跃度</h4>
|
||||
<h4>课程活跃度
|
||||
<a class="contributor_course" onmouseover ="message_titile_show2($(this),event)" onmouseout ="message_titile_hide2($(this))">积分规则</a>
|
||||
</h4>
|
||||
<div style="display: none;padding: 5px;" class="numIntro color_888">
|
||||
<div class="contributor_course_innor">积分规则</div>
|
||||
资源发布:资源数 x 5 </br>
|
||||
问答发布:发帖数 x 2 </br>
|
||||
通知发布:通知数 x 1 </br>
|
||||
问答回复:回复数 x 1 </br>
|
||||
作业留言:留言数 x 1 </br>
|
||||
通知留言:留言数 x 1 </br>
|
||||
课程留言:留言数 x 1 </br>
|
||||
总得分为以上得分之和
|
||||
</div>
|
||||
|
||||
<% contributor_course_scor(@course.id).each do |contributor_score| %>
|
||||
<% unless contributor_score.total_score ==0 %>
|
||||
<% total_score = contributor_score.resource_num.to_i * 5 + contributor_score.message_num.to_i * 2 +
|
||||
contributor_score.message_reply_num.to_i * 1 + contributor_score.journal_num.to_i * 1 +
|
||||
+ contributor_score.homework_journal_num.to_i * 1 + contributor_score.news_reply_num.to_i * 1 +
|
||||
contributor_score.news_num.to_i * 1 %>
|
||||
<% unless total_score ==0 %>
|
||||
<li> <a href="javascript:void:(0);"><%=link_to image_tag(url_to_avatar(contributor_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(contributor_score.user) %></a>
|
||||
<p><a href="javascript:void:(0);"><%=link_to contributor_score.user.show_name, user_path(contributor_score.user), :title => contributor_score.user.show_name %></a></p>
|
||||
<p><span class="c_green" style="cursor:pointer">
|
||||
<a onmouseover ="message_titile_show($(this),event)" onmouseout ="message_titile_hide($(this))" class="c_green"><%= contributor_score.total_score.to_i %></a></span></p>
|
||||
<div style="display: none" class="numIntro">
|
||||
<% unless contributor_score.resource_num == 0 %>
|
||||
课程资源:<%= contributor_score.resource_num %><br />
|
||||
<% end %>
|
||||
<% unless contributor_score.message_num == 0 %>
|
||||
课程讨论:<%= contributor_score.message_num %><br />
|
||||
<% end %>
|
||||
<% unless contributor_score.message_reply_num == 0 %>
|
||||
评论回复:<%= contributor_score.message_reply_num %><br />
|
||||
<% end %>
|
||||
<% unless contributor_score.journal_num == 0 %>
|
||||
课程留言:<%= contributor_score.journal_num %><br />
|
||||
<% end %>
|
||||
<% unless contributor_score.homework_journal_num == 0 %>
|
||||
作业留言:<%= contributor_score.homework_journal_num %><br />
|
||||
<% end %>
|
||||
<% unless contributor_score.news_reply_num == 0 %>
|
||||
课程通知:<%= contributor_score.news_reply_num %><br />
|
||||
<% end %>
|
||||
<a onmouseover ="message_titile_show($(this),event)" onmouseout ="message_titile_hide($(this))" class="c_green">
|
||||
<%=total_score %></a></span></p>
|
||||
<div style="display: none" class="numIntro color_888">
|
||||
<div class="contributor_course_calculate">积分计算</div>
|
||||
<%# unless contributor_score.resource_num.to_i == 0 %>
|
||||
<div style="padding-left: 2px;padding-bottom: 2px;padding-right: 2px">
|
||||
资源发布数 x 5 = <%= contributor_score.resource_num.to_i %> x 5 = <%= contributor_score.resource_num.to_i * 5 %></br>
|
||||
<%# end %>
|
||||
<%# unless contributor_score.message_num.to_i == 0 %>
|
||||
问答发布数 x 2 = <%= contributor_score.message_num.to_i %> x 2 = <%= contributor_score.message_num.to_i * 2 %></br>
|
||||
通知发布数 x 1 = <%= contributor_score.news_num.to_i %> x 1 = <%= contributor_score.news_num.to_i %></br>
|
||||
<%# end %>
|
||||
<%# unless contributor_score.message_reply_num.to_i == 0 %>
|
||||
问答回帖数 x 1 = <%= contributor_score.message_reply_num.to_i %> x 1 = <%= contributor_score.message_reply_num.to_i %></br>
|
||||
作业留言数 x 1 = <%= contributor_score.homework_journal_num.to_i %> x 1 = <%= contributor_score.homework_journal_num.to_i %></br>
|
||||
通知留言数 x 1 = <%= contributor_score.news_reply_num.to_i %> x 1 = <%= contributor_score.news_reply_num.to_i %></br>
|
||||
<%# end %>
|
||||
<%# unless contributor_score.journal_num.to_i == 0 %>
|
||||
课程留言数 x 1 = <%= contributor_score.journal_num.to_i %> x 1 = <%= contributor_score.journal_num.to_i %></br>
|
||||
<%# end %>
|
||||
<%# unless contributor_score.homework_journal_num.to_i == 0 %>
|
||||
|
||||
<%# end %>
|
||||
<%# unless contributor_score.news_reply_num.to_i == 0 %>
|
||||
|
||||
|
||||
<%# end %>
|
||||
总得分:<%=total_score %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
<% end %>
|
||||
|
@ -179,12 +207,17 @@
|
|||
<% hero_homework_scores = hero_homework_score(@course, "desc") %>
|
||||
<% unless hero_homework_scores.map(&:score).detect{|s| s.to_i != 0}.nil? %>
|
||||
<ul class="rankList">
|
||||
<h4>课程英雄榜</h4>
|
||||
<h4><span>课程英雄榜</span>
|
||||
<a class="contributor_course" onmouseover ="message_titile_show2($(this),event)" onmouseout ="message_titile_hide2($(this))">积分规则</a></h4>
|
||||
<div style="display: none" class="numIntro color_888">
|
||||
<div class="hero_course_innor">积分规则</div>
|
||||
英雄榜的得分是每个同学作业的得分总和
|
||||
</div>
|
||||
<% hero_homework_scores.each do |student_score| %>
|
||||
<% if student_score.score.to_i != 0 %>
|
||||
<li> <a href="javascript:void:(0);"><%=link_to image_tag(url_to_avatar(student_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(student_score.user) %></a>
|
||||
<p><a href="javascript:void:(0);"><%=link_to student_score.user.show_name, user_path(student_score.user), :title => student_score.user.show_name %></a></p>
|
||||
<p><span class="c_red" style="cursor:pointer" title="作业总分:<%= format("%.1f",student_score.score<0 ? 0 : student_score.score) %>"><%= student_score.score<0 ? 0 : student_score.score.to_i %></span></p>
|
||||
<p><span class="c_red" style="cursor:pointer" ><%= student_score.score<0 ? 0 : student_score.score.to_i %></span></p>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
@ -303,6 +336,16 @@
|
|||
obj.parent().parent().next("div").hide();
|
||||
}
|
||||
|
||||
function message_titile_show2(obj,e)
|
||||
{
|
||||
obj.parent().next("div").show();
|
||||
obj.parent().next("div").css("top",e.pageY).css("left",e.pageX).css("position","absolute");
|
||||
}
|
||||
function message_titile_hide2(obj)
|
||||
{
|
||||
obj.parent().next("div").hide();
|
||||
}
|
||||
|
||||
$("#expand_tools_expand").click(function(){
|
||||
$("#navContentCourse").toggle();
|
||||
});
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
<script>
|
||||
$(document).ready(function(){
|
||||
$(".subjectChoose").click(function(){
|
||||
$(".subjectChoose").removeClass("chooseActive");
|
||||
$(this).addClass("chooseActive");
|
||||
<% if type == "1" %>
|
||||
$("#my_resources_choose").addClass("choose-active");
|
||||
$("#public_resources_choose").removeClass("choose-active");
|
||||
<% end %>
|
||||
|
||||
$(".subject-choose").click(function(){
|
||||
$(".subject-choose").removeClass("choose-active");
|
||||
$(this).addClass("choose-active");
|
||||
});
|
||||
$(".popupClose").click(function(){
|
||||
$(".popupWrap").hide();
|
||||
|
@ -12,20 +17,20 @@
|
|||
<div class="f16 fb fontBlue mb10">选用资源库中的资源</div>
|
||||
<div class="subjectList fl mr10">
|
||||
<% if !params[:course_id].nil? %>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '6', :course_id => params[:course_id]) %>" class="subjectChoose chooseActive fl" data-remote="true">公共资源</a>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '1', :course_id => params[:course_id]) %>" class="subjectChoose fl" data-remote="true">我的资源</a>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '6', :course_id => params[:course_id]) %>" id="public_resources_choose" class="subject-choose choose-active fl" data-remote="true">公共资源</a>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '1', :course_id => params[:course_id]) %>" id="my_resources_choose" class="subject-choose fl" data-remote="true">我的资源</a>
|
||||
<% elsif !params[:project_id].nil? %>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '6', :project_id => params[:project_id]) %>" class="subjectChoose chooseActive fl" data-remote="true">公共资源</a>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '1', :project_id => params[:project_id]) %>" class="subjectChoose fl" data-remote="true">我的资源</a>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '6', :project_id => params[:project_id]) %>" id="public_resources_choose" class="subject-choose choose-active fl" data-remote="true">公共资源</a>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '1', :project_id => params[:project_id]) %>" id="my_resources_choose" class="subject-choose fl" data-remote="true">我的资源</a>
|
||||
<% elsif !params[:subfield_file_id].nil? %>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '6', :subfield_file_id => params[:subfield_file_id]) %>" class="subjectChoose chooseActive fl" data-remote="true">公共资源</a>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '1', :subfield_file_id => params[:subfield_file_id]) %>" class="subjectChoose fl" data-remote="true">我的资源</a>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '6', :subfield_file_id => params[:subfield_file_id]) %>" id="public_resources_choose" class="subject-choose choose-active fl" data-remote="true">公共资源</a>
|
||||
<a href="<%= import_resources_user_path(User.current, :type => '1', :subfield_file_id => params[:subfield_file_id]) %>" id="my_resources_choose" class="subject-choose fl" data-remote="true">我的资源</a>
|
||||
<% end %>
|
||||
<%= form_tag( url_for(:controller => 'users', :action => 'resource_search', :id => User.current.id),
|
||||
<%#= form_tag( url_for(:controller => 'users', :action => 'import_resources_search', :id => User.current.id, :type => 1),
|
||||
:remote => true , :method => 'get', :id => 'resource_search_form') do %>
|
||||
<input type="text" name="search" placeholder="输入资源关键词进行搜索" class="subjectSearch fr" />
|
||||
<%= hidden_field_tag(:type,type.nil? ? 1 : type) %>
|
||||
<% end %>
|
||||
<!--<input type="text" name="search" placeholder="输入资源关键词进行搜索" class="subjectSearch fr" />-->
|
||||
<%#= hidden_field_tag(:type,type.nil? ? 1 : type) %>
|
||||
<%# end %>
|
||||
|
||||
<div class="cl"></div>
|
||||
|
||||
|
@ -50,7 +55,7 @@
|
|||
</label>
|
||||
</li>
|
||||
<li class="subjectType fl"><%= get_resource_type(attach.container_type)%></li>
|
||||
<li class="subjectCount fl"><%= number_to_human_size(attach.filesize) %></li>
|
||||
<li class="subjectCount fl hidden"><%= number_to_human_size(attach.filesize) %></li>
|
||||
<li class="subjectPublisher fl"><%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %></li>
|
||||
<li class="fl subjectDate"><%= format_date(attach.created_on) %></li>
|
||||
</ul>
|
||||
|
|
|
@ -25,3 +25,350 @@
|
|||
<div class="cl"></div>
|
||||
<% 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) {
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<span class="uploadDialogText">上传资源 </span>
|
||||
<!--<div class="resourcePopupClose"> <a href="javascript:void(0);" class="resourceClose" onclick="closeModal();"></a></div>-->
|
||||
<div class="uploadBoxContainer">
|
||||
<%= form_tag(user_resource_create_user_path, :multipart => true,:remote => !ie8?,:name=>"upload_form",:id=>'upload_form') do %>
|
||||
<%= form_tag(user_resource_create_user_path(:type=>type,:status=>status), :multipart => true,:remote => !ie8?,:name=>"upload_form",:id=>'upload_form') do %>
|
||||
<div>
|
||||
<span id="attachments_fields" xmlns="http://www.w3.org/1999/html">
|
||||
<% if defined?(container) && container && container.saved_attachments %>
|
||||
|
@ -38,7 +38,7 @@
|
|||
</div>
|
||||
<div class="uploadResourceIntr">
|
||||
<div class="uploadResourceName"><span id="upload_file_count">(未选择文件)</span></div>
|
||||
<div class="uploadResourceIntr2">您可以上传小于<span class="c_red">50MB</span>的文件</div>
|
||||
<div class="uploadResourceIntr2"><!--您可以上传小于<span class="c_red">50MB</span>的文件--></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<% if params[:project_id] %>
|
||||
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :project_id => params[:project_id]} ) %>');
|
||||
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :project_id => params[:project_id]} ) %>');
|
||||
<% elsif params[:course_id] %>
|
||||
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :course_id => params[:course_id]} ) %>');
|
||||
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :course_id => params[:course_id]} ) %>');
|
||||
<% elsif params[:subfield_file_id] %>
|
||||
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :subfield_file_id => params[:subfield_file_id]} ) %>');
|
||||
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :subfield_file_id => params[:subfield_file_id]} ) %>');
|
||||
<% end %>
|
||||
showModal('ajax-modal', '615px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
//$("#resources_list").html('<%#= escape_javascript( render :partial => 'users/import_resource_info' ,:locals=>{ :attachments => @attachments, :type => @type})%>');
|
||||
//$("#pages").html('<%#= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
|
||||
//$("#res_all_count").html(<%#= @atta_count%>);
|
||||
//$("#res_count").html(0);
|
||||
//$("#checkboxAll").attr('checked',false);
|
||||
|
||||
|
||||
<% if params[:project_id] %>
|
||||
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :project_id => params[:project_id]} ) %>');
|
||||
<% elsif params[:course_id] %>
|
||||
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :course_id => params[:course_id]} ) %>');
|
||||
<% elsif params[:subfield_file_id] %>
|
||||
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :subfield_file_id => params[:subfield_file_id]} ) %>');
|
||||
<% end %>
|
||||
showModal('ajax-modal', '615px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal()' style='margin-left: 580px;'><img src='/images/bid/close.png' width='26px' height='26px' /></a>");
|
||||
<% if params[:project_id] %>
|
||||
$('#ajax-modal').parent().css("top","10%").css("left","34%").css("border","3px solid #269ac9");
|
||||
<% else %>
|
||||
$('#ajax-modal').parent().css("top","20%").css("left","42%").css("border","3px solid #269ac9");
|
||||
<% end %>
|
||||
$('#ajax-modal').parent().addClass("popbox_polls");
|
||||
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
}
|
||||
$(document).ready(function(){
|
||||
$(".resource-switch").click(function(){
|
||||
$(".resource-switch").click(function(){
|
||||
$(".resource-switch").children().removeClass("resource-tab-active");
|
||||
$(this).children().addClass("resource-tab-active");
|
||||
});
|
||||
|
@ -21,16 +21,6 @@
|
|||
$("#resource_search_form").submit();
|
||||
}
|
||||
|
||||
function show_upload(){
|
||||
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'upload_resource' ,:locals => {:user=>@user})%>');
|
||||
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 show_public_resource(){
|
||||
$("#resource_remote").html('<%= escape_javascript( render :partial => 'user_resource_info' ,:locals => { :tpye => 6}) %>');
|
||||
}
|
||||
|
@ -69,14 +59,13 @@
|
|||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<ul class="resource-banner">
|
||||
<li class="fl resource-switch">
|
||||
<a href="<%= user_resource_user_path(@user, :type => '6') %>" class="resource-tab resource-tab-active" data-remote="true">公共资源</a>
|
||||
<a href="<%= user_resource_user_path(@user, :type => '6', :status => @status) %>" class="resource-tab resource-tab-active" id="public_resource_list" data-remote="true">公共资源</a>
|
||||
</li>
|
||||
<li class="fl resource-switch">
|
||||
<a href="<%= user_resource_user_path(@user, :type => '1') %>" class="resource-tab" data-remote="true">我的资源</a>
|
||||
<a href="<%= user_resource_user_path(@user, :type => '1', :status => @status) %>" class="resource-tab" id="my_resource_list" data-remote="true">我的资源</a>
|
||||
</li>
|
||||
<li class="fl w770 border-bottom h34"> </li>
|
||||
<li class="fr resource-banner-li border-bottom h34">
|
||||
|
@ -84,19 +73,23 @@
|
|||
<li class="resourcesSelected"><a href="javascript:void(0);" class="resourcesIcon"></a>
|
||||
<ul class="resourcesType">
|
||||
<li>
|
||||
<%= link_to '全部' ,user_resource_user_path(:id => @user.id, :type => 1), :remote => true, :method => 'get', :class => 'resourcesTypeAll resourcesGrey' %>
|
||||
<a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 1)%>" id="resource_type_all" class="resourcesTypeAll resourcesGrey" data-method="get" data-remote="true">全部 </a>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to '课程资源' ,user_resource_user_path(:id => @user.id, :type => 2), :remote => true, :method => 'get', :class=> 'homepagePostTypeAssignment postTypeGrey' %>
|
||||
<a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 2) %>" id="resource_type_course" class="homepagePostTypeAssignment postTypeGrey'" data-method="get" data-remote="true">课程资源 </a>
|
||||
<%#= link_to '课程资源' ,user_resource_user_path(:id => @user.id, :type => 2), id="resource_type_course", :remote => true, :method => 'get', :class=> 'homepagePostTypeAssignment postTypeGrey' %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to '项目资源' ,user_resource_user_path(:id => @user.id, :type => 3), :remote => true, :method => 'get', :class => 'homepagePostTypeQuiz postTypeGrey' %>
|
||||
<a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 3) %>" id="resource_type_project" class="homepagePostTypeQuiz postTypeGrey" data-method="get" data-remote="true">项目资源 </a>
|
||||
<%#= link_to '项目资源' ,user_resource_user_path(:id => @user.id, :type => 3), id="resource_type_project", :remote => true, :method => 'get', :class => 'homepagePostTypeQuiz postTypeGrey' %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5),:remote=>true,:method => 'get', :class=>'resourcesTypeUser resourcesGrey' %>
|
||||
<a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 5) %>" id="resource_type_user" class="resourcesTypeUser resourcesGrey" data-method="get" data-remote="true">用户资源 </a>
|
||||
<%#= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5), id="resource_type_user", :remote=>true,:method => 'get', :class=>'resourcesTypeUser resourcesGrey' %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4),:remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %>
|
||||
<a href="<%= user_resource_user_path(:id => @user.id, :type => @type, :status => 4) %>" id="resource_type_file" class="resourcesTypeAtt resourcesGrey" data-method="get" data-remote="true">附件 </a>
|
||||
<%#= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4), id="resource_type_file", :remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -112,340 +105,5 @@
|
|||
<div class="cl"></div>
|
||||
|
||||
|
||||
<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 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)%>',
|
||||
$("#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)%>' + '?send_id=' + id,
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
}else{
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_course_user_path(@user)%>' + '?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)%>' + '?' + $("#resources_list_form").serialize(),
|
||||
data:{send_type:'file'}
|
||||
});
|
||||
}else{
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '<%= search_user_course_user_path(@user)%>' + '?'+ $("#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)%>'+"?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) %>'+ "?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)%>' + '?resource_id=' + id + '&type=' + $('#type').val()
|
||||
});
|
||||
}
|
||||
}else{
|
||||
alert('您无法删除此资源!')
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
|
|
@ -3,4 +3,13 @@ $("#resources_list").html('<%= escape_javascript( render :partial => 'resources_
|
|||
$("#pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
|
||||
$("#res_count").html(0);
|
||||
$("#checkboxAll").attr('checked',false);
|
||||
$("#res_all_count").html(<%= @atta_count%>);
|
||||
$("#res_all_count").html(<%= @atta_count %>);
|
||||
|
||||
$("#public_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '6', :status => @status) %>');
|
||||
$("#my_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '1', :status => @status) %>');
|
||||
|
||||
$("#resource_type_all").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 1) %>');
|
||||
$("#resource_type_course").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 2) %>');
|
||||
$("#resource_type_project").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 3) %>');
|
||||
$("#resource_type_user").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 5) %>');
|
||||
$("#resource_type_file").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 4) %>');
|
||||
|
|
|
@ -538,6 +538,7 @@ RedmineApp::Application.routes.draw do
|
|||
get 'edit_brief_introduction'
|
||||
get "user_resource"
|
||||
get "import_resources"
|
||||
get "import_resources_search"
|
||||
post "import_into_container"
|
||||
get "resource_search"
|
||||
post "user_resource_create"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddNewsNumToCourseContributorScores < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :course_contributor_scores, :news_num, :integer , :default => 0
|
||||
end
|
||||
end
|
|
@ -0,0 +1,51 @@
|
|||
class UodapteContributorCourse < ActiveRecord::Migration
|
||||
def up
|
||||
Course.all.each do |course|
|
||||
if course.course_activities.count > 1
|
||||
course.members.each do |s|
|
||||
puts course.id
|
||||
puts course.name
|
||||
puts s.user_id
|
||||
# board_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?",s.student_id, course.id, "Message").count * 2
|
||||
# 发帖数
|
||||
board_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is null;").count
|
||||
# 回帖数
|
||||
message_reply_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is not null").count * 1
|
||||
# 新闻回复
|
||||
common_reply_count = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{s.user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1
|
||||
# 通知
|
||||
common_count = News.find_by_sql("select n.* from news n where n.author_id = #{s.user_id} and n.course_id = #{course.id} ").count * 1
|
||||
# attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5
|
||||
# 附件数
|
||||
attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{s.user_id} and container_type ='Course'").count
|
||||
# 课程留言数
|
||||
journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.user_id, course.id, "Course").count * 1
|
||||
# 作业留言
|
||||
journal_homework_count = JournalsForMessage.find_by_sql("SELECT jfm.* FROM `journals_for_messages` jfm, homework_commons hc where hc.id = jfm.jour_id and hc.course_id =#{course.id} and jfm.user_id =#{s.user_id} and jfm.jour_type ='HomeworkCommon';").count * 1
|
||||
# journal_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "JournalsForMessage").count * 1
|
||||
# journal_reply_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and status =?", s.student_id, course.id, "Course",1).count * 1
|
||||
total = board_count + message_reply_count + common_reply_count + attachment_count + journal_count
|
||||
course_contributor = CourseContributorScore.where("course_id =? and user_id =?", course.id, s.user_id).first
|
||||
if course_contributor.nil?
|
||||
CourseContributorScore.create(:course_id => course.id, :user_id => s.user_id, :message_num => board_count, :message_reply_num => message_reply_count,
|
||||
:news_reply_num => common_reply_count, :news_num => common_count, :resource_num => attachment_count, :journal_num => journal_count,
|
||||
:homework_journal_num => journal_homework_count, :journal_reply_num => 0, :total_score => total)
|
||||
else
|
||||
course_contributor.message_num = board_count
|
||||
course_contributor.message_reply_num = message_reply_count
|
||||
course_contributor.news_reply_num = common_reply_count
|
||||
course_contributor.news_num = common_count
|
||||
course_contributor.resource_num = attachment_count
|
||||
course_contributor.journal_num = journal_count
|
||||
course_contributor.homework_journal_num = journal_homework_count
|
||||
course_contributor.save
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20160303103231) do
|
||||
ActiveRecord::Schema.define(:version => 20160304234903) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -436,6 +436,7 @@ ActiveRecord::Schema.define(:version => 20160303103231) do
|
|||
t.datetime "updated_at", :null => false
|
||||
t.integer "total_score"
|
||||
t.integer "homework_journal_num", :default => 0
|
||||
t.integer "news_num", :default => 0
|
||||
end
|
||||
|
||||
create_table "course_groups", :force => true do |t|
|
||||
|
|
|
@ -1285,3 +1285,8 @@ a.chooseActive {background-color:#269ac9; color:#ffffff;}
|
|||
.popupClose {background:url(../images/resource_icon_list.png) 0px -40px no-repeat; width:20px; height:20px; display:inline-block; position: absolute; z-index: 1000; right:10px; top:5px;}
|
||||
.subjectType {width:70px; text-align:center;}
|
||||
.subjectCount {width:65px; text-align:center;}
|
||||
a.contributor_course{float: right; color: #888; font-size: 12px; font-weight: normal;}
|
||||
.contributor_course_innor{font-size: 12px;color: #888;padding-left: 36px;}
|
||||
.hero_course_innor{font-size: 12px;color: #888;padding-left:77px;}
|
||||
.contributor_course_calculate{padding-left: 54px; font-size: 12px;color: #888}
|
||||
.color_888{color: #888}
|
||||
|
|
Loading…
Reference in New Issue