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

memcached_alan
sw 10 years ago
parent e334dd69f8
commit b7e9442800

@ -220,6 +220,15 @@ class TagsController < ApplicationController
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
@tag.delete unless @tag.nil? @tag.delete unless @tag.nil?
end 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 end
end end
@ -263,6 +272,14 @@ class TagsController < ApplicationController
else else
logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}" logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}"
end 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| respond_to do |format|
format.js format.js
format.html format.html

@ -2097,4 +2097,13 @@ module ApplicationHelper
request.env["HTTP_USER_AGENT"] =~ /MSIE 8.0/ request.env["HTTP_USER_AGENT"] =~ /MSIE 8.0/
end 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 end

@ -120,14 +120,6 @@ module FilesHelper
result result
end 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 def get_attachments_by_tag attachments,tag
attachments.each do |attachment| attachments.each do |attachment|
attachment.tag_list.include?(tag) attachment.tag_list.include?(tag)

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

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

@ -3,6 +3,8 @@
$("#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/tag_list', $("#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}) %>'); :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 %> <% end %>
<% if @object_flag == "10"%> <% if @object_flag == "10"%>
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();

@ -5,11 +5,13 @@ $('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_n
//$('#put-tag-form-issue').hide(); //$('#put-tag-form-issue').hide();
$('#name-issue').val(""); $('#name-issue').val("");
<% elsif @obj_flag == '6'%> <% elsif @obj_flag == '6'%>
$("#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}) %>');
$("#tags_name_<%=@obj.id%>").val(""); $("#tags_name_<%=@obj.id%>").val("");
$("#add_tag_<%=@obj.id%>").hide(); $("#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'%> <% 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}) %>');

Loading…
Cancel
Save