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 @@
  • <%= link_to truncate(attach.filename,:length=>18), download_named_attachment_path(attach.id, attach.filename), - :title => attach.filename+"\n"+attach.description.to_s,:class=>'resourcesBlack'%> + :title => attach.filename,:class=>'resourcesBlack'%>
  • <%= number_to_human_size(attach.filesize) %>
  • <%= get_resource_type(attach.container_type)%>
  • diff --git a/app/views/users/rename_resource.js.erb b/app/views/users/rename_resource.js.erb new file mode 100644 index 000000000..5556fb313 --- /dev/null +++ b/app/views/users/rename_resource.js.erb @@ -0,0 +1 @@ +alert(1) \ No newline at end of file diff --git a/app/views/users/resource_preview.js.erb b/app/views/users/resource_preview.js.erb index a38d46374..c3e1fb3ab 100644 --- a/app/views/users/resource_preview.js.erb +++ b/app/views/users/resource_preview.js.erb @@ -1,3 +1,5 @@ <% if @preview_able %> top.location.href = '<%=download_named_attachment_path(@file.id, @file.filename, preview: true) %>' +<% else %> +window.alert('该资源不可预览') <% end %> \ 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 d9b992129..1c54fc67e 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -71,13 +71,9 @@
    上传资源
    -
    - <%= form_tag( url_for(:controller => 'users',:action => 'resource_search',:id=>@user.id), - :remote=>true ,:method => 'post',:class=>'resourcesSearchloadBox',:id=>'resource_search_form') do %> - - <%= submit_tag '',:class=>'searchIcon',:style=>'border-style:none' %> - - <% end %> +
    + <%= render :partial => 'resource_search_form',:locals => {:user=>@user,:type=>@type} %> +
    @@ -168,7 +164,7 @@ $(".resourcesList").click(function(e) { } //将当前行改变为白色 line.children().css("background-color", 'white'); - //当前行恢复编辑状态 + //当前行恢复编辑状态到链接状态 if(ele.nodeName != 'INPUT') { restore(); } @@ -210,6 +206,7 @@ $(".resourcesList").click(function(e) { '"/> '+ '<% end %>'); $("#res_name").focus(); + document.getElementById('res_name').scrollIntoView() } String.prototype.trim = function() { var str = this, @@ -219,38 +216,42 @@ $(".resourcesList").click(function(e) { while (ws.test(str.charAt(--i))); return str.slice(0, i + 1); } + + //恢复编辑状态到链接状态 + //如果当前是编辑状态,任何的不在输入框里的单击右键事件都需要将编辑状态变回链接状态 + //如果是编辑状态,且做了修改,那么久要进行修改,并且将修改值经过处理替换到页面显示 function restore(){ + //上一行不为空 且链接不为空 if( last_line != null && res_link != null && res_link != '') { - name = $("#res_name").val().trim(); - if(name != res_name.trim()){ + name = $("#res_name") ? $("#res_name").val().trim() : $("#res_name") ; + if( name && name != res_name.trim()){ if(confirm('确定修改为 '+name)){ - //$("#res_name_form").submit(); -// $.ajax({ -// type:'post', -// url:'<%#=rename_resource_user_path(@user) %>', -// data: $("#res_name_form").serialize() -// }); $.post( '<%=rename_resource_user_path(@user) %>', $("#res_name_form").serialize(), function (data){ - if(data =='sucess'){ + if(data =='sucess'){//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变 last_line.children().first().html(res_link); last_line.children().first().children().attr('title',name); - last_line.children().first().children().html(name); + last_line.children().first().children().html(name.length > 17? name.substring(0,17)+'...' : name); }else{ last_line.children().first().html(res_link); + res_link = null; //如果修改失败,恢复之后将res_link置空 } }, 'text' ); }else{ - //last_line.children().first().html(res_link); + last_line.children().first().html(res_link); + res_link = null; //如果没有做修改,恢复之后将res_link置空 } }else { last_line.children().first().html(res_link); + res_link = null;//如果没有做修改,恢复之后将res_link置空 } + + } } @@ -261,7 +262,7 @@ $(".resourcesList").click(function(e) { } line.children().css("background-color", 'white'); id = line.children().last().html(); - if (confirm('确定要删除资源' + line.children().first().children().attr('title').trim() + '么')){ + if (confirm('确定要删除资源"' + line.children().first().children().attr('title').trim() + '"么?')){ $.ajax({ type: 'post', url: '<%= user_resource_delete_user_path(@user)%>' + '?resource_id=' + id diff --git a/app/views/users/user_resource.js.erb b/app/views/users/user_resource.js.erb index 69fc3dd43..d69a769af 100644 --- a/app/views/users/user_resource.js.erb +++ b/app/views/users/user_resource.js.erb @@ -1 +1,2 @@ +$("#search_div").html('<%= escape_javascript( render :partial => 'resource_search_form',:locals => {:user=>@user,:type=>@type} ) %>'); $("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments})%>'); \ No newline at end of file