添加、删除TAG云时TAG云列表刷新

This commit is contained in:
sw 2015-04-16 14:01:58 +08:00
parent e334dd69f8
commit b7e9442800
7 changed files with 42 additions and 19 deletions

View File

@ -220,6 +220,15 @@ class TagsController < ApplicationController
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
@tag.delete unless @tag.nil?
end
if @obj && @object_flag == '6' && @obj.container.kind_of?(Course)
@course = @obj.container
all_attachments = @course.attachments.select{|attachment| attachment.is_public? ||
(attachment.container_type == "Course" && User.current.member_of_course?(@course))||
attachment.author_id == User.current.id
}
@tag_list = attachment_tag_list all_attachments
end
# end
end
end
@ -263,6 +272,14 @@ class TagsController < ApplicationController
else
logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}"
end
if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course)
@course = @obj.container
all_attachments = @course.attachments.select{|attachment| attachment.is_public? ||
(attachment.container_type == "Course" && User.current.member_of_course?(@course))||
attachment.author_id == User.current.id
}
@tag_list = attachment_tag_list all_attachments
end
respond_to do |format|
format.js
format.html

View File

@ -2097,4 +2097,13 @@ module ApplicationHelper
request.env["HTTP_USER_AGENT"] =~ /MSIE 8.0/
end
#获取指定资源列表的TAG的集合以及每个TAG的数量降序排序
def attachment_tag_list attachments
tag_list = Hash.new
attachments.each do |attachment|
attachment.tag_list.map{|tag| tag_list.has_key?(tag) ? tag_list[tag] = tag_list[tag] + 1 : tag_list[tag] = 1}
end
tag_list.sort {|a,b| b[1]<=>a[1]}
end
end

View File

@ -120,14 +120,6 @@ module FilesHelper
result
end
def attachment_tag_list attachments
tag_list = Hash.new
attachments.each do |attachment|
attachment.tag_list.map{|tag| tag_list.has_key?(tag) ? tag_list[tag] = tag_list[tag] + 1 : tag_list[tag] = 1}
end
tag_list.sort {|a,b| b[1]<=>a[1]}
end
def get_attachments_by_tag attachments,tag
attachments.each do |attachment|
attachment.tag_list.include?(tag)

View File

@ -15,12 +15,8 @@
</div>
<div class="cl"></div>
<div class="files_tag">
<% unless @tag_list.nil?%>
<% @tag_list.each do |k,v|%>
<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%><span class="c_red"><%= v%></span></a>
<% end%>
<% end%>
<div class="files_tag" id="files_tag">
<%= render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => course}%>
</div>
<div class="cl"></div>

View File

@ -0,0 +1,5 @@
<% unless tag_list.nil?%>
<% tag_list.each do |k,v|%>
<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%><span class="c_red"><%= v%></span></a>
<% end%>
<% end%>

View File

@ -3,6 +3,8 @@
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_list',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @object_flag}) %>');
$("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course}) %>");
<% end %>
<% if @object_flag == "10"%>
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();

View File

@ -5,11 +5,13 @@ $('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_n
//$('#put-tag-form-issue').hide();
$('#name-issue').val("");
<% elsif @obj_flag == '6'%>
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();
$("#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}) %>');
$("#tags_name_<%=@obj.id%>").val("");
$("#add_tag_<%=@obj.id%>").hide();
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();
$("#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}) %>');
$("#tags_name_<%=@obj.id%>").val("");
$("#add_tag_<%=@obj.id%>").hide();
$("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course}) %>");
<% elsif @obj_flag == '9'%>
$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/new_tag_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');