课程、项目、组织资源导入

This commit is contained in:
huang 2016-03-03 17:15:47 +08:00
parent 3368680e49
commit 5fd36c0e78
8 changed files with 88 additions and 8 deletions

View File

@ -2236,6 +2236,69 @@ class UsersController < ApplicationController
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
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)
# 如果该附件已经存课程中,则只更新附件创建时间
mul_container.attachments.each do |att|
if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
att.created_on = Time.now
att.save
@exist = true
break
end
end
next if @exist
attach_copied_obj = ori.copy
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
attach_copied_obj.container = mul_container
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.is_public = 0
attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
end
end
if params[:mul_type] == "Course"
respond_to do |format|
redirect_to course_files_url(mul_container)
end
elsif params[:mul_type] == "Project"
respond_to do |format|
redirect_to project_files_url(mul_container)
end
elsif params[:mul_type] == "SubfieldFile"
respond_to do |format|
redirect_to org_subfield_files_url(mul_container)
end
end
end
# 根据资源关键字进行搜索
def resource_search
search = "%#{params[:search].strip.downcase}%"

View File

@ -94,7 +94,7 @@
<%= 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 => true), :class => "blue-btn fr mr5", :remote => true) %>
<%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %>
<% end %>
<% end %>

View File

@ -66,7 +66,7 @@
<!--REDO: 权限测试-->
<% if User.current.member_of?(@project) %>
<input class="blueBtn fr mr5" value="上传资源" onclick="project_files_upload();">
<%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :project => true), :class => "blue-btn fr mr5", :remote => true) %>
<%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :project_id => @project.id), :class => "blue-btn fr mr5", :remote => true) %>
<!--<input class="blueBtn fr mr5" value="导入资源" onclick="project_files_import();">-->
<% end %>
<% end %>

View File

@ -42,7 +42,7 @@
<%= 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()" %>
<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 => true), :class => "blue-btn fr mr5", :remote => true) %>
<%= 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 %>
<% end %>
</div><!---re_top end-->

View File

@ -20,6 +20,7 @@
<% end %>
<div class="cl"></div>
<div style="height:441px; min-height:441px; max-height:441px;">
<ul class="subjectBanner mt10">
<li class="subjectName fl hidden"><span style="padding-left:15px;">资源名称</span></li>
@ -28,7 +29,11 @@
<li class="subjectPublisher fl">上传者</li>
<li class="fl subjectDate">上传时间</li>
</ul>
<% @attachments.each do |attach| %>
<%= form_tag( url_for({:controller => 'users', :action => 'import_into_container',
:mul_id => params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id],
:mul_type => params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"}),
:remote => true , :method => 'post', :id => 'resource_import_container_form') do %>
<% @attachments.each do |attach| %>
<ul class="subjectRow">
<li class="subjectName fl hidden">
<label>
@ -41,11 +46,13 @@
<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>
<% end %>
<% end %>
</div>
<div class="courseSendSubmit mr15"><a href="javascript:void(0);" class="sendSourceText">选用</a></div>
<div class="courseSendCancel"><a href="javascript:void(0);" class="sendSourceText">取消</a></div>
<div class="courseSendSubmit mr15"><a href="javascript:void(0);" class="sendSourceText" onclick="$('#resource_import_container_form').submit();hideModal()">选用</a></div>
<div class="courseSendCancel"><a href="javascript:void(0);" class="sendSourceText" onclick="hideModal()">取消</a></div>
<div class="pageRoll mt0">
<ul class="wlist" id="pages" style="margin-top: 5px;">
<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>

View File

@ -0,0 +1,3 @@
<% if @flag == true%>
alert("发送成功")
<% end %>

View File

@ -1,8 +1,14 @@
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1} ) %>');
<% 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] %>
<% 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");

View File

@ -536,6 +536,7 @@ RedmineApp::Application.routes.draw do
get 'edit_brief_introduction'
get "user_resource"
get "import_resources"
post "import_into_container"
get "resource_search"
post "user_resource_create"
post "user_resource_delete"