双击资源栏目标签可编辑,编辑标签后更新标签
This commit is contained in:
parent
8d7a84285b
commit
977100e92e
|
@ -320,6 +320,86 @@ class TagsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update_org_subfield_tag_name
|
||||
@tag_name = params[:tagName]
|
||||
@rename_tag_name = params[:renameName]
|
||||
@taggable_id = params[:taggableId]
|
||||
@taggable_type = numbers_to_object_type(params[:taggableType])
|
||||
@rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag
|
||||
@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) unless @taggable_id.blank?
|
||||
@obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank?
|
||||
if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。
|
||||
if params[:org_subfield_id]
|
||||
org_subfield = OrgSubfield.find params[:org_subfield_id]
|
||||
if org_subfield
|
||||
org_subfield.attachments.each do |attachment|
|
||||
taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class)
|
||||
if taggings
|
||||
taggings.delete
|
||||
attachment.tag_list.add(@rename_tag_name.split(","))
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if(@rename_tag.nil?) #这次命名的是新的tag
|
||||
|
||||
# 是否还有其他记录 引用了 tag_id
|
||||
@tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}")
|
||||
# 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字
|
||||
if @tagging.count == 1
|
||||
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
|
||||
@tag.update_attributes({:name=>@rename_tag_name})
|
||||
else #如果tagging表中的记录大于1,那么就要新增tag记录
|
||||
|
||||
unless @obj.nil?
|
||||
@obj.tag_list.add(@rename_tag_name.split(","))
|
||||
@obj.save
|
||||
end
|
||||
#删除原来的对应的taggings的记录
|
||||
unless @taggings.nil?
|
||||
@taggings.delete
|
||||
end
|
||||
end
|
||||
else #这是已有的tag
|
||||
# 更改taggings记录里的tag_id
|
||||
unless @taggings.nil?
|
||||
@taggings.update_attributes({:tag_id=>@rename_tag.id})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@obj_flag = params[:taggableType]
|
||||
if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield)
|
||||
@org_subfield = @obj.container
|
||||
@tag_list = @tag_list = get_org_subfield_tag_list @org_subfield
|
||||
elsif params[:org_subfield_id]
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@tag_list = get_org_subfield_tag_list @org_subfield
|
||||
|
||||
#这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。
|
||||
@flag = params[:flag] || false
|
||||
sort = ""
|
||||
@sort = ""
|
||||
@order = ""
|
||||
@is_remote = false
|
||||
@isproject = false
|
||||
|
||||
sort = "#{Attachment.table_name}.created_on desc"
|
||||
|
||||
@containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)]
|
||||
|
||||
show_attachments @containers
|
||||
elsif @obj && @obj_flag == '5'
|
||||
@forum = @obj
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def show_attachments obj
|
||||
@attachments = []
|
||||
obj.each do |container|
|
||||
|
|
|
@ -12,13 +12,15 @@
|
|||
<% else%>
|
||||
<span class="files_tag_icon" >
|
||||
<a title="双击可编辑"
|
||||
onclick="search_org_subfield_tag_attachment('<%= search_org_subfield_tag_attachment_org_subfield_files_path(org_subfield)%>','<%= k%>','<%= @q%>','<%= org_subfield.id%>');"
|
||||
onclick="search_org_subfield_tag_attachment('<%= search_org_subfield_tag_attachment_org_subfield_files_path(org_subfield)%>','<%= k %>','<%= @q %>','<%= org_subfield.id %>');"
|
||||
ondblclick="rename_tag($(this),'<%= k %>','',<%= 6 %>);"><%= k%>(<%= v%>)</a></span>
|
||||
<% end%>
|
||||
<% end%>
|
||||
<% end%>
|
||||
|
||||
<script>
|
||||
var clickFunction = null; //单击事件函数
|
||||
var isdb = false; //是否双击
|
||||
function search_org_subfield_tag_attachment(url,tag_name,q,org_subfield_id,sort) {
|
||||
//alert("111");
|
||||
//clearTimeout(clickFunction);
|
||||
|
@ -26,7 +28,7 @@
|
|||
search_func();
|
||||
}, 500);
|
||||
function search_func() {
|
||||
// if (isdb != false) return;
|
||||
if (isdb != false) return;
|
||||
$.get(
|
||||
url,
|
||||
{
|
||||
|
|
|
@ -309,6 +309,65 @@
|
|||
// });
|
||||
<%end %>
|
||||
|
||||
<% if @org_subfield %>
|
||||
var tagNameHtml; //当前双击的链接的父节点的html
|
||||
var tagName; //标签的值
|
||||
var parentCssBorder; //当前双击的链接的父节点
|
||||
var ele; //当前双击的链接
|
||||
var tagId; //标签的id
|
||||
var taggableType; //被标签的类型
|
||||
//这里renameTag有两种情况,一种是改变某个资源的tag名称。如果其他资源也有这个tag。则新增一个改变后的tag名
|
||||
//第二种是改变某个tag名称。其他所有的资源如果拥有这个tag。那么对应的tag名也要改掉。
|
||||
//目前这两种依据 的来源就是 是否 传了参数 id。如果有id。就指定了资源id,就是第一种情况。如果没有id。就是第二种情况
|
||||
function rename_tag(domEle,name,id,type){
|
||||
if(1) {
|
||||
isdb = true; //这是双击
|
||||
//clearTimeout(clickFunction);
|
||||
if (domEle.children().get(0) != undefined) { //已经是编辑框的情况下不要动
|
||||
return;
|
||||
}
|
||||
tagNameHtml = domEle.parent().html()
|
||||
tagName = name;
|
||||
parentCssBorder = domEle.parent().css("border");
|
||||
ele = domEle;
|
||||
tagId = id;
|
||||
taggableType = type;
|
||||
width = parseInt(domEle.css('width').replace('px', '')) >= 100 ? parseInt(domEle.css('width').replace('px', '')) : 100
|
||||
domEle.html('<input name="" id="renameTagName" maxlength="120" minlength="1" style="width:' + width + 'px;" value="' + name + '"/>');
|
||||
domEle.parent().css("border", "1px solid #ffffff");
|
||||
$("#renameTagName").focus();
|
||||
}
|
||||
}
|
||||
//监听所有的单击事件
|
||||
$(function(){
|
||||
$("#renameTagName").live("blur",function(){
|
||||
updateTagName();
|
||||
}).live("keypress",function(e){
|
||||
if (e.keyCode == '13') {
|
||||
updateTagName();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//执行修改TAGName方法
|
||||
function updateTagName(){
|
||||
if(isdb){
|
||||
isdb = false;
|
||||
if($("#renameTagName").val() == tagName){ //如果值一样,则恢复原来的状态
|
||||
ele.parent().css("border","");
|
||||
ele.parent().html(tagNameHtml);
|
||||
|
||||
}
|
||||
else{
|
||||
$.post(
|
||||
'<%= tags_update_org_subfield_tag_name_path %>',
|
||||
{"taggableId": tagId, "taggableType": taggableType, "tagName": tagName, "renameName": $("#renameTagName").val().trim(),"org_subfield_id":<%= @org_subfield.id %>}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
<%end %>
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<% if @obj %>
|
||||
$("#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}) %>');
|
||||
$("#tags_name_<%=@obj.id%>").val("");
|
||||
$("#add_tag_<%=@obj.id%>").hide();
|
||||
$("#files_tag").html("<%= escape_javascript(render :partial => "files/subfield_tags", :locals => {:tag_list => @tag_list,:org_subfield => @org_subfield,:tag_name => @select_tag_name}) %>");
|
||||
<% else %>
|
||||
$("#org_subfield_list").html("<%= escape_javascript(render :partial => 'files/org_subfield_list',
|
||||
:locals => {org_subfield: @org_subfield,all_attachments: @all_attachments,sort:@sort,order:@order,org_subfield_attachments:@obj_attachments}) %>");
|
||||
<% end %>
|
|
@ -1047,6 +1047,7 @@ RedmineApp::Application.routes.draw do
|
|||
match 'tags/remove_tag_new', :as=>"remove_tag_new"
|
||||
match 'tags/tag_save', :as => "save_tag"
|
||||
match 'tags/update_tag_name',:as => "update_tag_name"
|
||||
match 'tags/update_org_subfield_tag_name'
|
||||
|
||||
match 'words/add_brief_introdution'
|
||||
|
||||
|
|
Loading…
Reference in New Issue