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 @@ + + +
+
+
将资源发送至
+
+ +
+
+
+
+ <%= form_tag search_user_project_user_path(user),:method => 'get', + :remote=>true,:id=>'search_user_project_form',:class=>'resourcesSearchBox' do %> + <%= hidden_field_tag(:send_id, @send_id) %> + + + <%= submit_tag '',:class=>'searchIconPopup',:onfocus=>"this.blur();",:style=>'border-style:none' %> + <% end %> +
+ <%= form_tag add_exist_file_to_project_user_path(user),:remote=>true,:id=>'projects_list_form' %> +
+ + <%= hidden_field_tag(:send_id, @send_id) %> + <% if !projects.empty? %> + <% projects.each do |project| %> + + <% end %> + +
+
+
+ + <%= submit_tag '确定',:class=>'sendSourceText',:onfocus=>'this.blur();' %> +
+ +
+
+ <% end %> +
+ diff --git a/app/views/users/_resource_share_popup.html.erb b/app/views/users/_resource_share_popup.html.erb index cad94056c..ca85cf262 100644 --- a/app/views/users/_resource_share_popup.html.erb +++ b/app/views/users/_resource_share_popup.html.erb @@ -4,9 +4,9 @@
将资源发送至
- + +
@@ -30,7 +30,7 @@
  • -
  • <%= course.name%>
  • +
  • <%= truncate(course.name,:length=>18)%>
  • <% end %> diff --git a/app/views/users/add_exist_file_to_course.js.erb b/app/views/users/add_exist_file_to_course.js.erb index 903212798..c5b9f8fbe 100644 --- a/app/views/users/add_exist_file_to_course.js.erb +++ b/app/views/users/add_exist_file_to_course.js.erb @@ -1 +1,2 @@ +alert('发送成功') closeModal(); \ No newline at end of file diff --git a/app/views/users/add_exist_file_to_project.js.erb b/app/views/users/add_exist_file_to_project.js.erb new file mode 100644 index 000000000..6ed846821 --- /dev/null +++ b/app/views/users/add_exist_file_to_project.js.erb @@ -0,0 +1,2 @@ +alert('发送成功'); +closeModal(); \ No newline at end of file diff --git a/app/views/users/search_user_project.js.erb b/app/views/users/search_user_project.js.erb new file mode 100644 index 000000000..c22e4ad6d --- /dev/null +++ b/app/views/users/search_user_project.js.erb @@ -0,0 +1,11 @@ +var screenWidth = $(window).width(); +var screenHeight = $(window).height(); //当前浏览器窗口的 宽高 +var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度 +var objLeft = (screenWidth - 2)/2.5 ; //2 可以根据需要修改 +var objTop = (screenHeight - 100)/2 + scrolltop; //100可以根据需要修改 +var popupHeight = $(".resourceSharePopup").outerHeight(true); +$(".resourceSharePopup").css("marginTop",-popupHeight/2); + +$("#upload_box").css('left',objLeft).css('top',objTop); +$("#upload_box").html('<%= escape_javascript( render :partial => "resource_share_for_project_popup" ,:locals => {:projects=>@projects,:user=>@user})%>'); +$("#upload_box").css('display','block'); \ No newline at end of file diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 5867c463f..6938e389e 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -3,7 +3,11 @@ <%= stylesheet_link_tag 'project' %> <%= stylesheet_link_tag 'leftside' %> <%= javascript_include_tag 'attachments'%> - + + + + + diff --git a/config/routes.rb b/config/routes.rb index c77a1e892..1318a495e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -350,8 +350,10 @@ RedmineApp::Application.routes.draw do post "user_resource_delete" get "search_user_course" post "add_exist_file_to_course" + post "add_exist_file_to_project" get 'resource_preview' post 'rename_resource' + get 'search_user_project' # end end end