Branch_szzh
lizanle 10 years ago
parent 76be15f79b
commit 7219586b1e

@ -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

@ -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 %>
<input type="text" name="search" placeholder="输入资源关键词进行" class="searchResource" />
<%= hidden_field_tag(:type,type) %>
<%= submit_tag '',:class=>'searchIcon',:style=>'border-style:none' %>
<!--<a href="javascript:void(0);" onclick='this.parent.submit();return false;' class="searchIcon"></a>-->
<% end %>

@ -5,7 +5,7 @@
<li class="resourcesListName fl">
<!--<a href="javascript:void(0);" class="resourcesBlack"><%#=truncate(attach.filename,:length=>18)%></a>-->
<%= 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'%>
</li>
<li class="resourcesListSize fl"><%= number_to_human_size(attach.filesize) %></li>
<li class="resourcesListType fl"><%= get_resource_type(attach.container_type)%></li>

@ -1,3 +1,5 @@
<% if @preview_able %>
top.location.href = '<%=download_named_attachment_path(@file.id, @file.filename, preview: true) %>'
<% else %>
window.alert('该资源不可预览')
<% end %>

@ -71,13 +71,9 @@
<div class="resourcesUploadBox">
<div class="uploadIcon"></div>
<a href="javascript:void(0);" onclick="show_upload();" class="uploadText">上传资源</a></div>
<div>
<%= form_tag( url_for(:controller => 'users',:action => 'resource_search',:id=>@user.id),
:remote=>true ,:method => 'post',:class=>'resourcesSearchloadBox',:id=>'resource_search_form') do %>
<input type="text" name="search" placeholder="输入资源关键词进行" class="searchResource" />
<%= submit_tag '',:class=>'searchIcon',:style=>'border-style:none' %>
<!--<a href="javascript:void(0);" onclick='this.parent.submit();return false;' class="searchIcon"></a>-->
<% end %>
<div id="search_div">
<%= render :partial => 'resource_search_form',:locals => {:user=>@user,:type=>@type} %>
</div>
</div>
<div class="resourcesListBanner">
@ -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) {
'"/> <input type="hidden" name="res_id" value="'+id+'"/>'+
'<% 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

@ -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})%>');
Loading…
Cancel
Save