This commit is contained in:
sw 2014-11-27 10:27:02 +08:00
commit 2b5160f2d9
8 changed files with 57 additions and 10 deletions

View File

@ -25,6 +25,7 @@ class AttachmentsController < ApplicationController
#before_filter :login_without_softapplication, only: [:download] #before_filter :login_without_softapplication, only: [:download]
accept_api_auth :show, :download, :upload accept_api_auth :show, :download, :upload
require 'iconv' require 'iconv'
include AttachmentsHelper
def show def show
@ -346,8 +347,18 @@ class AttachmentsController < ApplicationController
def add_exist_file_to_courses def add_exist_file_to_courses
file = Attachment.find(params[:file_id]) file = Attachment.find(params[:file_id])
courses = params[:courses][:course] courses = params[:courses][:course]
@message = ""
courses.each do |course| courses.each do |course|
c = Course.find(course); c = Course.find(course);
if course_contains_attachment?(c,file)
if @message && @message == ""
@message += l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
else
@message += "<br/>" + l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
end
end
attach_copied_obj = file.copy attach_copied_obj = file.copy
attach_copied_obj.tag_list.add(file.tag_list) # tag关联 attach_copied_obj.tag_list.add(file.tag_list) # tag关联
attach_copied_obj.container = c attach_copied_obj.container = c

View File

@ -28,6 +28,7 @@ class FilesController < ApplicationController
include SortHelper include SortHelper
include FilesHelper include FilesHelper
helper :project_score helper :project_score
include CoursesHelper
def show_attachments obj def show_attachments obj
@attachments = [] @attachments = []

View File

@ -67,6 +67,15 @@ module AttachmentsHelper
end end
end end
def course_contains_attachment? course,attachment
course.attachments.each do |att|
if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from
return true
end
end
false
end
private private
def deletable? container, user=User.current def deletable? container, user=User.current

View File

@ -486,6 +486,20 @@ module CoursesHelper
term term
end end
def course_in_current_or_next_term course
is_current_term = false
is_next_term = false
if course.time == Time.now.year && course.term == cur_course_term
is_current_term = true
end
if cur_course_term == "秋季学期" && course.time == (Time.now.year + 1) && course.term == "春季学期"
is_next_term = true
elsif cur_course_term == "春季学期" && course.time == Time.now.year && course.term == "秋季学期"
is_next_term = true
end
is_current_term || is_next_term
end
#获取课程动态 #获取课程动态
def get_course_activity courses, activities def get_course_activity courses, activities
@course_ids=activities.keys() @course_ids=activities.keys()

View File

@ -47,18 +47,18 @@ module FilesHelper
def courses_check_box_tags(name,courses,current_course,attachment) def courses_check_box_tags(name,courses,current_course,attachment)
s = '' s = ''
courses.each do |course| courses.each do |course|
if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course)
s << "<label>#{ check_box_tag name, course.id, false, :id => nil } #{h course.name}</label><br/>" s << "<label>#{ check_box_tag name, course.id, false, :id => nil } #{h course.name}</label>&nbsp;[#{get_course_term course}]<br/>"
end end
end end
s.html_safe s.html_safe
end end
#判断用户是否拥有课程,需用户在该课程中角色为教师 #判断用户是否拥有课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期
def has_course? user def has_course? user
result = false result = false
user.courses.each do |course| user.courses.each do |course|
if is_course_teacher(user,course) if is_course_teacher(User.current,course) && course_in_current_or_next_term(course)
return true return true
end end
end end
@ -86,7 +86,7 @@ module FilesHelper
def visable_attachemnts attachments def visable_attachemnts attachments
result = [] result = []
attachments.each do |attachment| attachments.each do |attachment|
if attachment.is_public? || attachment.author_id == User.current.id if attachment.is_public? || (attachment.container_type == "Course" && attachment.author.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id
result << attachment result << attachment
end end
end end
@ -94,9 +94,15 @@ module FilesHelper
end end
def get_qute_number attachment def get_qute_number attachment
if attachment.copy_from.nil? if attachment.copy_from
return 0 result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}")
else
result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}")
end
if result.nil? || result.count <= 0
return 0
else
return result[0].number
end end
count = Attachment.find_by_sql("select count(*) from attachments where copy_from = #{attachment.copy_from}")
end end
end end

View File

@ -1,5 +1,7 @@
<% if !@save_flag%> <% if !@save_flag && @save_message %>
$("#error_show").html("<%= @save_message.join(', ') %>"); $("#error_show").html("<%= @save_message.join(', ') %>");
<% elsif @message && @message != "" %>
$("#error_show").html("<%= @message.html_safe %>");
<% else %> <% else %>
closeModal(); closeModal();
<% end %> <% end %>

View File

@ -41,7 +41,7 @@
<p class="f_l c_grey02 font">文件大小:<%= number_to_human_size(file.filesize) %></p> <p class="f_l c_grey02 font">文件大小:<%= number_to_human_size(file.filesize) %></p>
<%= link_to( l(:button_delete), attachment_path(file), <%= link_to( l(:button_delete), attachment_path(file),
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if delete_allowed && file.container_id == @course.id && file.container_type == "Course"%> :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if delete_allowed && file.container_id == @course.id && file.container_type == "Course"%>
<p class="f_r c_grey02" ><%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>&nbsp;&nbsp;|&nbsp;&nbsp;下载<%= file.downloads %>&nbsp;&nbsp;<!--|&nbsp;&nbsp;引用<%#=get_qute_number file %>--> </p> <p class="f_r c_grey02" ><%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>&nbsp;&nbsp;|&nbsp;&nbsp;下载<%= file.downloads %>&nbsp;&nbsp;|&nbsp;&nbsp;引用<%= get_qute_number file %> </p>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
<div class="tag_h"> <div class="tag_h">

View File

@ -2205,3 +2205,7 @@ zh:
label_my_score: 我的评分 label_my_score: 我的评分
field_open_anonymous_evaluation: 是否使用匿评 field_open_anonymous_evaluation: 是否使用匿评
label_course_empty_select: 尚未选择课程! label_course_empty_select: 尚未选择课程!
label_course_prompt: 课程:
label_contain_resource: 已包含资源:
label_quote_resource_failed: ",此资源引用失败! "