From 76c2c47adf5107dc067f3fa14aebb17dbdacd96f Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 20 Aug 2015 10:14:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 42 +++++++++++++++- ..._resource_share_for_project_popup.html.erb | 48 +++++++++++++++++++ .../users/_resource_share_popup.html.erb | 8 ++-- .../users/add_exist_file_to_course.js.erb | 1 + .../users/add_exist_file_to_project.js.erb | 2 + app/views/users/search_user_project.js.erb | 11 +++++ app/views/users/user_resource.html.erb | 43 +++++++++++++++-- config/routes.rb | 2 + 8 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 app/views/users/_resource_share_for_project_popup.html.erb create mode 100644 app/views/users/add_exist_file_to_project.js.erb create mode 100644 app/views/users/search_user_project.js.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e4109e5bb..76ce9efaf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -43,7 +43,8 @@ class UsersController < ApplicationController :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score,:user_activities,:user_projects_index, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist, - :user_resource,:user_resource_create,:user_resource_delete,:rename_resource,:search_user_course,:add_exist_file_to_course,:resource_preview,:resource_search] + :user_resource,:user_resource_create,:user_resource_delete,:rename_resource,:search_user_course,:add_exist_file_to_course, + :search_user_project,:resource_preview,:resource_search,:add_exist_file_to_project] #edit has been deleted by huang, 2013-9-23 before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, @@ -878,6 +879,20 @@ class UsersController < ApplicationController end end + # 根据id或者名称搜索当前用户所在的项目 + def search_user_project + @user = User.current + if !params[:search].nil? + @projects = @user.projects.where(" #{Project.table_name}.id = #{params[:search].to_i } or #{Project.table_name}.name like '%#{params[:search.to_s]}%'") + else + @projects = @user.projects + end + @send_id = params[:send_id] + respond_to do |format| + format.js + end + end + # 将资源发送到对应的课程 def add_exist_file_to_course send_id = params[:send_id] @@ -903,6 +918,31 @@ class UsersController < ApplicationController end end + # 添加资源到对应的项目 + def add_exist_file_to_project + send_id = params[:send_id] + project_ids = params[:projects_ids] + ori = Attachment.find_by_id(send_id) + unless project_ids.nil? + project_ids.each do |project_id| + next if ori.blank? + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = Project.find(project_id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 1 + end + attach_copied_obj.save + end + end + + respond_to do |format| + format.js + end + end + # 资源预览 def resource_preview preview_id = params[:resource_id] diff --git a/app/views/users/_resource_share_for_project_popup.html.erb b/app/views/users/_resource_share_for_project_popup.html.erb new file mode 100644 index 000000000..70191e5f3 --- /dev/null +++ b/app/views/users/_resource_share_for_project_popup.html.erb @@ -0,0 +1,48 @@ + + +