资源库标签 上方的tag重命名的话,所有的含有该tag的资源的那个标签页要重命名

This commit is contained in:
lizanle 2015-09-22 16:19:39 +08:00
parent 7624b917f0
commit b4561fa68d
7 changed files with 118 additions and 46 deletions

View File

@ -15,6 +15,7 @@ class TagsController < ApplicationController
include ContestsHelper include ContestsHelper
include ActsAsTaggableOn::TagsHelper include ActsAsTaggableOn::TagsHelper
include TagsHelper include TagsHelper
include FilesHelper
helper :projects helper :projects
helper :courses helper :courses
helper :tags helper :tags
@ -236,12 +237,21 @@ class TagsController < ApplicationController
@rename_tag_name = params[:renameName] @rename_tag_name = params[:renameName]
@taggable_id = params[:taggableId] @taggable_id = params[:taggableId]
@taggable_type = numbers_to_object_type(params[:taggableType]) @taggable_type = numbers_to_object_type(params[:taggableType])
@course_id = params[:courseId]
@rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank?
@obj = get_object(@taggable_id,params[:taggableType]) @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank?
if @taggable_id.blank? #如果没有传tag_id那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。
#看重命名后的tag是否存在。如果存在的话只需要更改taggings里边的id即可
if @rename_tag
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type)
@taggings.update_attributes({:tag_id=>@rename_tag.id})
else #如果不存在那么就直接更新该tag名称为新的名称
(ActsAsTaggableOn::Tag.find_by_name(@tag_name)).update_attributes(:name=>@rename_tag_name)
end
else
if(@rename_tag.nil?) #这次命名的是新的tag if(@rename_tag.nil?) #这次命名的是新的tag
# 是否还有其他记录 引用了 tag_id # 是否还有其他记录 引用了 tag_id
@ -267,16 +277,49 @@ class TagsController < ApplicationController
@taggings.update_attributes({:tag_id=>@rename_tag.id}) @taggings.update_attributes({:tag_id=>@rename_tag.id})
end end
end end
end
@obj_flag = params[:taggableType] @obj_flag = params[:taggableType]
if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course)
@course = @obj.container @course = @obj.container
@tag_list = @tag_list = get_course_tag_list @course @tag_list = @tag_list = get_course_tag_list @course
elsif @course_id
@course = Course.find(@course_id)
@tag_list = get_course_tag_list @course
#这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。
@flag = params[:flag] || false
sort = ""
@sort = ""
@order = ""
@is_remote = false
@isproject = false
sort = "#{Attachment.table_name}.created_on desc"
@containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
show_attachments @containers
end end
respond_to do |format| respond_to do |format|
format.js format.js
end end
end end
def show_attachments obj
@attachments = []
obj.each do |container|
@attachments += container.attachments
end
@all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments)
@limit = 10
@feedback_count = @all_attachments.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
#@curse_attachments_all = @all_attachments[@offset, @limit]
@obj_attachments = paginateHelper @all_attachments,10
end
def tag_save def tag_save
@select_tag_name = params[:tag_for_save][:tag_name] @select_tag_name = params[:tag_for_save][:tag_name]
@tags = params[:tag_for_save][:name] @tags = params[:tag_for_save][:name]

View File

@ -1,5 +1,6 @@
module TagsHelper module TagsHelper
include StoresHelper include StoresHelper
include CoursesHelper
# 通过 id和type获取对象 # 通过 id和type获取对象
def get_object(obj_id,obj_type) def get_object(obj_id,obj_type)
@obj = nil @obj = nil
@ -62,6 +63,27 @@ module TagsHelper
end end
#判断课程course中是否包含课件attachmentcourse中引用了attachment也算作包含
def course_contains_attachment? course,attachment
course.attachments.each do |att|
if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from
return true
end
end
false
end
#判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期
def has_course? user,file
result = false
user.courses.each do |course|
if !course_contains_attachment?(course,file) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course)
return true
end
end
result
end
# 判断用户是否是贴吧的管理员 # 判断用户是否是贴吧的管理员
# add by chenmin # add by chenmin
def is_forum_manager?(user_id,forum_id) def is_forum_manager?(user_id,forum_id)

View File

@ -3,13 +3,13 @@
<p class="f_l c_blue f_b f_14">共有&nbsp;<%= all_attachments.count%>&nbsp;个资源</p> <p class="f_l c_blue f_b f_14">共有&nbsp;<%= all_attachments.count%>&nbsp;个资源</p>
<p class="f_r" style="color: #808080"> <p class="f_r" style="color: #808080">
<% if order == "asc" %> <% if order == "asc" %>
按&nbsp;<%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %>&nbsp;/&nbsp; 按&nbsp;<%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %>&nbsp;/&nbsp;
<%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>&nbsp;/&nbsp; <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>&nbsp;/&nbsp;
<%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"quotes"} %>&nbsp;排序 <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %>&nbsp;排序
<% else %> <% else %>
按&nbsp;<%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %>&nbsp;/&nbsp; 按&nbsp;<%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %>&nbsp;/&nbsp;
<%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>&nbsp; /&nbsp; <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>&nbsp; /&nbsp;
<%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"quotes"} %>&nbsp;排序 <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %>&nbsp;排序
<% end %> <% end %>
</p> </p>
</div> </div>

View File

@ -3,7 +3,7 @@
<% if tag_name && tag_name == k%> <% if tag_name && tag_name == k%>
<a href="javascript:void(0);" class="files_tag_select"><%= k%>×<%= v%></a> <a href="javascript:void(0);" class="files_tag_select"><%= k%>×<%= v%></a>
<% else%> <% else%>
<a href="javascript:void(0);" class="files_tag_icon" onclick="search_tag_attachment('<%= search_tag_attachment_course_files_path(course)%>','<%= k%>','<%= @q%>','<%= course.id%>');"><%= k%>×<%= v%></a> <a href="javascript:void(0);" class="files_tag_icon" onclick="rename_tag($(this),'<%= k %>','',<%= 6 %>);"><%= k%>×<%= v%></a>
<% end%> <% end%>
<% end%> <% end%>
<% end%> <% end%>

View File

@ -229,6 +229,9 @@
var ele; //当前双击的链接 var ele; //当前双击的链接
var tagId; //标签的id var tagId; //标签的id
var taggableType; //被标签的类型 var taggableType; //被标签的类型
//这里renameTag有两种情况一种是改变某个资源的tag名称。如果其他资源也有这个tag。则新增一个改变后的tag名
//第二种是改变某个tag名称。其他所有的资源如果拥有这个tag。那么对应的tag名也要改掉。
//目前这两种依据 的来源就是 是否 传了参数 id。如果有id。就指定了资源id就是第一种情况。如果没有id。就是第二种情况
function rename_tag(domEle,name,id,type){ function rename_tag(domEle,name,id,type){
if(domEle.children().get(0) != undefined ){ //已经是编辑框的情况下不要动 if(domEle.children().get(0) != undefined ){ //已经是编辑框的情况下不要动
return; return;
@ -258,11 +261,7 @@
if(confirm("是否将标签改为 "+ $("#renameTagName").val().trim())){ if(confirm("是否将标签改为 "+ $("#renameTagName").val().trim())){
$.post( $.post(
'<%= update_tag_name_path %>', '<%= update_tag_name_path %>',
{"taggableId":tagId,"taggableType":taggableType,"tagName":tagName,"renameName":$("#renameTagName").val().trim()} {"taggableId": tagId, "taggableType": taggableType, "tagName": tagName, "renameName": $("#renameTagName").val().trim(),"courseId":<%= @course.id%>}
// function(data){
// ele.parent().css("border","");
// ele.parent().html(tagNameHtml);
// }
) )
}else{ }else{
ele.parent().css("border",""); ele.parent().css("border","");

View File

@ -14,18 +14,26 @@ $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_project
$('#tags_name2').val(""); $('#tags_name2').val("");
<% elsif @obj_flag == '6'%> <% elsif @obj_flag == '6'%>
<%if @course%> <%if @course%>
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); <% if @obj %>
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_list', $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_list',
:locals => {:obj => @obj,:object_flag => @obj_flag,:select_tag_name => @select_tag_name}) %>'); :locals => {:obj => @obj,:object_flag => @obj_flag,:select_tag_name => @select_tag_name}) %>');
$("#tags_name_<%=@obj.id%>").val("");
$("#add_tag_<%=@obj.id%>").hide();
<% else %>
$("#course_list").html("<%= escape_javascript(render :partial => 'files/course_list',
:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments}) %>");
<% end %>
$("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course,:tag_name => @select_tag_name}) %>"); $("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course,:tag_name => @select_tag_name}) %>");
<%else%> <%else%>
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/course_attachment_tag_name', $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/course_attachment_tag_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
<%end%>
$("#tags_name_<%=@obj.id%>").val(""); $("#tags_name_<%=@obj.id%>").val("");
$("#add_tag_<%=@obj.id%>").hide(); $("#add_tag_<%=@obj.id%>").hide();
<%end%>
<% elsif @obj_flag == '9'%> <% elsif @obj_flag == '9'%>
$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/new_tag_name', $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/new_tag_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');

View File

@ -551,7 +551,7 @@ a.wzan_visited{background:url(../images/new_project/public_icon.png) 0px -503px
.vi_zan{color:#28be6c;} .vi_zan{color:#28be6c;}
.newwork_btn a{background:#64bdd9;color:#fff;font-size:14px; font-weight:normal; padding:2px 10px; display:block; text-align:center; float:right;} .newwork_btn a{background:#64bdd9;color:#fff;font-size:14px; font-weight:normal; padding:2px 10px; display:block; text-align:center; float:right;}
.newwork_btn a:hover{ background:#329cbd;} .newwork_btn a:hover{ background:#329cbd;}
.files_tag{ width:670px; height:22px; overflow:hidden; margin-bottom:10px;} .files_tag{ width:670px; min-height:22px;margin-bottom:10px;}/* overflow:hidden; */
a.files_tag_icon{ background:#e2f3f9; color:#54aeca; border:1px solid #bbe2ef; padding:1px 10px; float:left; margin-right:10px;margin-bottom:10px; } a.files_tag_icon{ background:#e2f3f9; color:#54aeca; border:1px solid #bbe2ef; padding:1px 10px; float:left; margin-right:10px;margin-bottom:10px; }
a.files_tag_select{ background:#64bdd9; color:#fff; border:1px solid #64bdd9; padding:1px 10px; float:left; margin-right:10px;margin-bottom:10px;} a.files_tag_select{ background:#64bdd9; color:#fff; border:1px solid #64bdd9; padding:1px 10px; float:left; margin-right:10px;margin-bottom:10px;}