From b3e3737fb5ae7e9477ef868cb6f692f551721353 Mon Sep 17 00:00:00 2001
From: lizanle <491823689@qq.com>
Date: Tue, 1 Sep 2015 11:29:43 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E5=8F=91=E5=B8=83=E4=BD=9C=E4=B8=9A?=
=?UTF-8?q?=E6=97=B6=E4=BB=8E=E8=B5=84=E6=BA=90=E5=BA=93=E9=80=89=E6=8B=A9?=
=?UTF-8?q?=E8=B5=84=E6=BA=90=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/users_controller.rb | 95 ++++++++++++++++++-
app/views/users/_show_user_resource.html.erb | 87 ++++++++++++-----
.../users/_user_homework_attachment.html.erb | 3 +-
.../users/import_resources_to_homework.js.erb | 16 ++++
app/views/users/user_homeworks.html.erb | 4 +
app/views/users/user_import_resource.js.erb | 13 +--
.../users/user_ref_resource_search.js.erb | 2 +
app/views/users/user_resource_type.js.erb | 2 +
config/routes.rb | 3 +
public/stylesheets/new_user.css | 8 +-
10 files changed, 198 insertions(+), 35 deletions(-)
create mode 100644 app/views/users/import_resources_to_homework.js.erb
create mode 100644 app/views/users/user_ref_resource_search.js.erb
create mode 100644 app/views/users/user_resource_type.js.erb
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 0058e6e4c..a88068be7 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -381,14 +381,107 @@ class UsersController < ApplicationController
#用户从资源库导入资源到作业
def user_import_resource
- user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
+ @user = User.current
+ user_course_ids = @user.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','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(',')}))").order("created_on desc")
+ @type = params[:type]
+ @homework_id = params[:homework_id]
+ @limit = 7
+ @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,7
respond_to do |format|
format.js
end
end
+ #引入资源列表根据类型过滤
+ def user_resource_type
+ if User.current.id.to_i != params[:id].to_i
+ render_403
+ return
+ end
+ if(params[:type].nil? || params[:type] == "1") #全部
+ user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','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(',')}))").order("created_on desc")
+ elsif params[:type] == "2" #课程资源
+ user_course_ids = User.current.courses.map { |c| c.id}
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) ").order("created_on desc")
+ elsif params[:type] == "3" #项目资源
+ @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project'").order("created_on desc")
+ elsif params[:type] == "4" #附件
+ @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc")
+ elsif params[:type] == "5" #用户资源
+ @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal'").order("created_on desc")
+ end
+ @type = params[:type]
+ @limit = 7
+ @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,7
+ respond_to do |format|
+ format.js
+ end
+ end
+
+
+ #引入资源列表根据关键词过滤
+ def user_ref_resource_search
+ search = params[:search].to_s.strip.downcase
+ if(params[:type].nil? || params[:type] == "1") #全部
+ user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询
+ @attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','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 '%#{search}%') ").order("created_on desc")
+ elsif params[:type] == "2" #课程资源
+ user_course_ids = User.current.courses.map { |c| c.id}
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like '%#{search}%') ").order("created_on desc")
+ elsif params[:type] == "3" #项目资源
+ @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like '%#{search}%')").order("created_on desc")
+ elsif params[:type] == "4" #附件
+ @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%')").order("created_on desc")
+ elsif params[:type] == "5" #用户资源
+ @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like '%#{search}%')").order("created_on desc")
+ end
+ @type = params[:type]
+ @limit = 7
+ @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,7
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ #将资源批量引入
+ def import_resources_to_homework
+ @attachments = []
+ unless params[:checkbox1].nil? || params[:checkbox1].blank?
+ params[:checkbox1].each do |id|
+ atta = Attachment.find(id)
+ att_copy = atta.copy
+ att_copy.container_id = nil
+ att_copy.container_type = nil
+ att_copy.copy_from = atta.id
+ att_copy.save
+ @attachments << att_copy
+ end
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
include CoursesHelper
def user_courses
diff --git a/app/views/users/_show_user_resource.html.erb b/app/views/users/_show_user_resource.html.erb
index a27a51d65..a3c82d995 100644
--- a/app/views/users/_show_user_resource.html.erb
+++ b/app/views/users/_show_user_resource.html.erb
@@ -1,26 +1,67 @@
-
\ No newline at end of file
+ <% end %>
+
diff --git a/app/views/users/_user_homework_attachment.html.erb b/app/views/users/_user_homework_attachment.html.erb
index 1613b144e..00d80dd22 100644
--- a/app/views/users/_user_homework_attachment.html.erb
+++ b/app/views/users/_user_homework_attachment.html.erb
@@ -46,8 +46,9 @@
+
上传附件
- <%#= link_to "资源库", user_import_resource_user_path(User.current.id),:class => "FilesBtn fl mr15 mt3",:remote => true%>
+ <%= link_to "资源库",{:controller => 'users',:action=>'user_import_resource',:id=>User.current.id,:homework_id=>container.id},:class => "FilesBtn fl mr15 mt3",:remote => true%>
<% content_for :header_tags do %>
diff --git a/app/views/users/import_resources_to_homework.js.erb b/app/views/users/import_resources_to_homework.js.erb
new file mode 100644
index 000000000..b77590095
--- /dev/null
+++ b/app/views/users/import_resources_to_homework.js.erb
@@ -0,0 +1,16 @@
+<% unless @attachments.empty?%>
+ <% @attachments.each_with_index do |attachment, i| %>
+ $("#attachments_fields").append(
+ ''+
+ '<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => "filename link_file", :readonly=>"readonly")%>'+
+ '<%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => "description", :style=>"display: inline-block;") %>'+
+ '<%= l(:field_is_public)%>:'+
+ '<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => "is_public")%>'+
+ '<%= link_to(" ".html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => "js"), :method => "delete", :remote => true, :class => "remove-upload") unless attachment.id.nil? %>'+
+ '<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>'+
+ ''+
+ '')
+
+ <% end %>
+ hideModal();
+<% end %>
\ No newline at end of file
diff --git a/app/views/users/user_homeworks.html.erb b/app/views/users/user_homeworks.html.erb
index 74e4df4f0..d401ea314 100644
--- a/app/views/users/user_homeworks.html.erb
+++ b/app/views/users/user_homeworks.html.erb
@@ -19,6 +19,10 @@
$("#homework_attachments").html("<%= escape_javascript(render :partial => 'users/user_homework_attachment', :locals => { :container => HomeworkCommon.new })%>");
homework_description_editor.html("");
}
+
+ function checkAllBox(doc){
+
+ }
<% if User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)%>
diff --git a/app/views/users/user_import_resource.js.erb b/app/views/users/user_import_resource.js.erb
index ce70d68ad..dc3682d30 100644
--- a/app/views/users/user_import_resource.js.erb
+++ b/app/views/users/user_import_resource.js.erb
@@ -1,7 +1,8 @@
-$('#ajax-modal').html('<%= escape_javascript(render :partial => 'users/show_user_homeworks') %>');
-showModal('ajax-modal', '580px');
-$('#ajax-modal').css('height','300px').css("width","580px");
+$('#ajax-modal').html('<%= escape_javascript(render :partial => 'users/show_user_resource',:locals => {:user => @user,:homework_id=>@homework_id}) %>');
+showModal('ajax-modal', '730px');
+$('#ajax-modal').css('height','500px').css("width","730px");
$('#ajax-modal').siblings().remove();
-$('#ajax-modal').before("" +
-"");
-$('#ajax-modal').parent().css("top","20%").css("left","25%").css("position","fixed");
\ No newline at end of file
+$('#ajax-modal').before("");
+$('#ajax-modal').parent().css("top","").css("left","").css("position","fixed").css("padding-left","16px").css("padding-bottom","16px").css("padding-right","16px");
+$('#ajax-modal').parent().addClass("popbox").addClass("referenceResourcesPopup");
\ No newline at end of file
diff --git a/app/views/users/user_ref_resource_search.js.erb b/app/views/users/user_ref_resource_search.js.erb
new file mode 100644
index 000000000..52f54bee4
--- /dev/null
+++ b/app/views/users/user_ref_resource_search.js.erb
@@ -0,0 +1,2 @@
+$("#user_ref_resources").html('<%= escape_javascript(render :partial => 'resources_list',:locals=>{:attachments => @attachments})%>');
+$("#resource_ref_pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
\ No newline at end of file
diff --git a/app/views/users/user_resource_type.js.erb b/app/views/users/user_resource_type.js.erb
new file mode 100644
index 000000000..52f54bee4
--- /dev/null
+++ b/app/views/users/user_resource_type.js.erb
@@ -0,0 +1,2 @@
+$("#user_ref_resources").html('<%= escape_javascript(render :partial => 'resources_list',:locals=>{:attachments => @attachments})%>');
+$("#resource_ref_pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 8451b7365..4e6bba8a7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -365,6 +365,9 @@ RedmineApp::Application.routes.draw do
get 'resource_preview'
post 'rename_resource'
get 'search_user_project'
+ get 'user_resource_type'
+ get 'user_ref_resource_search'
+ post 'import_resources_to_homework'
# end
end
end
diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css
index 2adf15822..72648b894 100644
--- a/public/stylesheets/new_user.css
+++ b/public/stylesheets/new_user.css
@@ -677,13 +677,13 @@ ul.list_watch{
.w450{width: 450px;}
/*引用资源库弹窗*/
-.referenceResourcesPopup {width:710px; height:auto; border:3px solid #269ac9; padding-left:20px; padding-right:20px; padding-bottom:35px; background-color:#ffffff; position:absolute; top:50%; left:50%; margin-left:-375px; z-index:1000;}
+.referenceResourcesPopup {width:710px; height:500px !important; border:3px solid #269ac9 !important; padding-left:20px; padding-right:20px; padding-bottom:35px; background-color:#ffffff; position:absolute; top:50%; left:50%; margin-left:-375px; z-index:1000;}
.referenceText {font-size:16px; color:#269ac9; line-height:16px; padding-top:20px; display:inline-block; font-weight:bold;}
.referenceSearchBox {border:1px solid #e6e6e6; width:235px; height:32px; background-color:#ffffff; margin-top:12px; margin-bottom:15px;}
.searchReferencePopup {border:none; outline:none; background-color:#ffffff; width:190px; height:32px; padding-left:10px; display:inline-block; float:left;}
-.referenceSearchIcon{width:31px; height:25px; background-color:#ffffff; background:url(../images/homepage_icon.png) -170px -135px no-repeat; display:inline-block; float:left;}
-.referenceSearchIcon:hover {background:url(../images/homepage_icon.png) -170px -190px no-repeat;}
-.referenceResourceType {font-size:14px; width:355px; height:34px; line-height:34px; vertical-align:middle; background-color:#f6f6f6; margin-top:15px;}
+.referenceSearchIcon{width:31px; height:25px; background-color:#ffffff; background:url(../images/homepage_icon.png) -180px -270px no-repeat; display:inline-block; float:left;}
+.referenceSearchIcon:hover {background:url(../images/homepage_icon.png) -180px -311px no-repeat;}
+.referenceResourceType {font-size:14px; width:475px; height:34px; line-height:34px; vertical-align:middle; background-color:#f6f6f6; margin-top:15px;}
.referenceTypeActive {background-color:#269ac9; color:#ffffff !important;}
a.referenceTypeBlock {color:#888888; display:inline-block; padding:0px 20px;}
From a78128f5ac747e0491238195b9c9882edeacd691 Mon Sep 17 00:00:00 2001
From: lizanle <491823689@qq.com>
Date: Tue, 1 Sep 2015 14:11:04 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E6=90=9C=E4=B8=8D=E5=88=B0=E8=B5=84?=
=?UTF-8?q?=E6=BA=90=E7=9A=84=E6=97=B6=E5=80=99=20=E6=94=B9=E4=B8=BA?=
=?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=95=B0=E6=8D=AE=E5=8F=AF=E4=BB=A5=E5=B1=95?=
=?UTF-8?q?=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/views/users/_resources_list.html.erb | 3 +++
1 file changed, 3 insertions(+)
diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb
index b41b9f28f..387b38936 100644
--- a/app/views/users/_resources_list.html.erb
+++ b/app/views/users/_resources_list.html.erb
@@ -1,5 +1,8 @@
<% if attachments.nil? || attachments.empty? %>
+
+ <%= l(:label_no_data) %>
+
<% else %>
<% attachments.each do |attach| %>