diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0df07acff..6bbfbd12b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -40,7 +40,8 @@ class UsersController < ApplicationController :user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index, :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_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] #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, @@ -1139,11 +1140,37 @@ class UsersController < ApplicationController # 根据资源关键字进行搜索 def resource_search search = params[:search].to_s.strip.downcase - if User.current.id == params[:id] - @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and (filename like '%#{search}%') ").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and is_public = 1 and (filename like '%#{search}%') ").order("created_on desc") + # if User.current.id == params[:id] + # @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and (filename like '%#{search}%') ").order("created_on desc") + # else + # @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and is_public = 1 and (filename like '%#{search}%') ").order("created_on desc") + # end + if(params[:type].nil? || params[:type] == "1") #全部 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%') ").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%') ").order("created_on desc") + end + elsif params[:type] == "2" #课程资源 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Course' and (filename like '%#{search}%')").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' and (filename like '%#{search}%') ").order("created_on desc") + end + elsif params[:type] == "3" #项目资源 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like '%#{search}%')").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like '%#{search}%') ").order("created_on desc") + end + elsif params[:type] == "4" #附件 + if User.current.id == params[:id] + @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") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%')").order("created_on desc") + end end + @type = params[:type] respond_to do |format| format.js end diff --git a/app/views/users/_resource_search_form.html.erb b/app/views/users/_resource_search_form.html.erb new file mode 100644 index 000000000..0c48514b3 --- /dev/null +++ b/app/views/users/_resource_search_form.html.erb @@ -0,0 +1,7 @@ +<%= form_tag( url_for(:controller => 'users',:action => 'resource_search',:id=>user.id), + :remote=>true ,:method => 'post',:class=>'resourcesSearchloadBox',:id=>'resource_search_form') do %> + + <%= hidden_field_tag(:type,type) %> + <%= submit_tag '',:class=>'searchIcon',:style=>'border-style:none' %> + +<% end %> \ No newline at end of file diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index 078ee2c94..6f9ba0fee 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -5,7 +5,7 @@