论坛的标签可修改

This commit is contained in:
lizanle 2015-09-23 11:02:22 +08:00
parent 1d84064221
commit 272d9fa527
5 changed files with 59 additions and 3 deletions

View File

@ -300,6 +300,8 @@ class TagsController < ApplicationController
@containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
show_attachments @containers show_attachments @containers
elsif @obj && @obj_flag == '5'
@forum = @obj
end end
respond_to do |format| respond_to do |format|
format.js format.js

View File

@ -242,7 +242,8 @@
ele = domEle; ele = domEle;
tagId = id; tagId = id;
taggableType = type; taggableType = type;
domEle.html('<input name="" id="renameTagName" maxlength="<%=Setting.tags_max_length%>" minlength="<%= Setting.tags_min_length%>" style="width:'+domEle.css('width') +'" value="'+name+'"/>'); width = parseInt(domEle.css('width').replace('px','')) >=100 ? parseInt(domEle.css('width').replace('px','')) : 100
domEle.html('<input name="" id="renameTagName" maxlength="<%=Setting.tags_max_length%>" minlength="<%= Setting.tags_min_length%>" style="width:'+width +'px;" value="'+name+'"/>');
domEle.parent().css("border","1px solid #ffffff"); domEle.parent().css("border","1px solid #ffffff");
$("#renameTagName").focus(); $("#renameTagName").focus();
} }

View File

@ -1,7 +1,8 @@
<% forum.tag_list.each do |tag|%> <% forum.tag_list.each do |tag|%>
<span class="postlabel mr10"> <span class="postlabel mr10">
<a href="javascript:void(0);" class="fontGrey2 mr5"><%= tag %></a> <a href="javascript:void(0);" ondblclick="rename_tag($(this),<%= tag %>,<%= forum.id%>,5);" class="fontGrey2 mr5"><%= tag %></a>
<%if forum.creator.id == User.current.id%> <%if forum.creator.id == User.current.id%>
<a href="javascript:void(0);" class="fontGrey2" onclick="delete_forum_tag($(this));">×</a></span> <a href="javascript:void(0);" class="fontGrey2" onclick="delete_forum_tag($(this));">×</a>
<% end %> <% end %>
</span>
<% end %> <% end %>

View File

@ -66,12 +66,62 @@
'<%= add_forum_tag_forum_path(@forum)%>' + "?tag_str=" + $("input[name='addTag']").val(), '<%= add_forum_tag_forum_path(@forum)%>' + "?tag_str=" + $("input[name='addTag']").val(),
{} {}
); );
$("input[name='addTag']").val('');
}else{ }else{
alert("标签名字长度不能超过14个字符"); alert("标签名字长度不能超过14个字符");
} }
} }
} }
} }
var tagNameHtml; //当前双击的链接的父节点的html
var tagName; //标签的值
var parentCssBorder; //当前双击的链接的父节点
var ele; //当前双击的链接
var taggableId; //标签的id
var taggableType; //被标签的类型
//这里renameTag有两种情况一种是改变某个资源的tag名称。如果其他资源也有这个tag。则新增一个改变后的tag名
//第二种是改变某个tag名称。其他所有的资源如果拥有这个tag。那么对应的tag名也要改掉。
//目前这两种依据 的来源就是 是否 传了参数 id。如果有id。就指定了资源id就是第一种情况。如果没有id。就是第二种情况
function rename_tag(domEle,name,id,type){
if(domEle.children().get(0) != undefined ){ //已经是编辑框的情况下不要动
return;
}
tagNameHtml = domEle.parent().html()
tagName = name;
parentCssBorder = domEle.parent().css("border");
ele = domEle;
taggableId = 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="<%=Setting.tags_max_length%>" minlength="<%= Setting.tags_min_length%>" style="width:'+width+'px;" value="'+name+'"/>');
domEle.parent().css("border","1px solid #ffffff");
$("#renameTagName").focus();
}
//监听所有的单击事件
$(document).click(function(e){
node = document.elementFromPoint(e.clientX, e.clientY);
if(node.tagName == "INPUT"){ //如果是输入框的聚焦,那么就不要进行下去了
return;
}
if($("#renameTagName")[0] != undefined ){//存在renameTagName,则处于编辑状态
if($("#renameTagName").val().trim() == tagName){ //如果值一样,则恢复原来的状态
ele.parent().css("border","");
ele.parent().html(tagNameHtml);
}else{ //否则就要更新tag名称了
if(confirm("是否将标签改为 "+ $("#renameTagName").val().trim())){
$.post(
'<%= update_tag_name_path %>',
{"taggableId": taggableId, "taggableType": taggableType, "tagName": tagName, "renameName": $("#renameTagName").val().trim()}
)
}else{
ele.parent().css("border","");
ele.parent().html(tagNameHtml);
}
}
}
});
</script> </script>
</head> </head>
<body class="<%= h body_css_classes %>"> <body class="<%= h body_css_classes %>">

View File

@ -40,6 +40,8 @@ $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/new_tag_nam
$('#tags_name').val(""); $('#tags_name').val("");
<% elsif @obj_flag == '10'%> <% elsif @obj_flag == '10'%>
//$("#put-tag-form-<%#=@obj.class%>-<%#=@obj.id%>").hide(); //$("#put-tag-form-<%#=@obj.class%>-<%#=@obj.id%>").hide();
<% elsif @obj_flag == '5'%>
$('#forum_tag_list').html('<%= escape_javascript(render :partial=>'forums/forum_tag_list',:locals=>{:forum=>@forum})%>')
<% else%> <% else%>
$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name', $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');