This commit is contained in:
cxt 2015-09-15 15:45:29 +08:00
commit 5ccace15da
6 changed files with 164 additions and 20 deletions

View File

@ -230,6 +230,53 @@ class TagsController < ApplicationController
end
end
#更新某个tag名称
def update_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)
@obj = get_object(@taggable_id,params[:taggableType])
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
@obj_flag = params[:taggableType]
if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course)
@course = @obj.container
@tag_list = @tag_list = get_course_tag_list @course
end
respond_to do |format|
format.js
end
end
def tag_save
@select_tag_name = params[:tag_for_save][:tag_name]
@tags = params[:tag_for_save][:name]

View File

@ -223,6 +223,54 @@
});
}
var tagNameHtml; //当前双击的链接的父节点的html
var tagName; //标签的值
var parentCssBorder; //当前双击的链接的父节点
var ele; //当前双击的链接
var tagId; //标签的id
var taggableType; //被标签的类型
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;
tagId = id;
taggableType = type;
domEle.html('<input name="" id="renameTagName" style="width: 100px;" value="'+name+'"/>');
domEle.parent().css("border","1px solid #ffffff");
$("#renameTagName").focus();
}
//监听所有的单击事件
$(document.body).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":tagId,"taggableType":taggableType,"tagName":tagName,"renameName":$("#renameTagName").val().trim()}
// function(data){
// ele.parent().css("border","");
// ele.parent().html(tagNameHtml);
// }
)
}else{
ele.parent().css("border","");
ele.parent().html(tagNameHtml);
}
}
}
});
</script>

View File

@ -2,7 +2,8 @@
<% if @tags.size > 0 %>
<% @tags.each do |tag| %>
<span class="re_tag f_l"> <%= link_to tag, :controller => "tags", :action => "index", :q => tag, :object_flag => object_flag, :obj_id => obj.id %>
<span class="re_tag f_l"> <%#= link_to tag, :controller => "tags", :action => "index", :q => tag, :object_flag => object_flag, :obj_id => obj.id %>
<a ondblclick="rename_tag($(this),'<%= tag %>',<%= obj.id%>,<%= object_flag%>);"><%= tag %></a>
<!-- 对用户主页 是本人 ,对项目,需求,问题是管理员 -->
<% case object_flag %>
<% when '10' %>

View File

@ -0,0 +1,40 @@
//本js使用的新的tag显示方法
<% if @obj_flag == '3'%>
$('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
//$('#put-tag-form-issue').hide();
$('#name-issue').val("");
<% elsif @obj_flag == '1'%>
$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_user_new_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
$('#tags_name3').val("");
<% elsif @obj_flag == '2'%>
$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_project_new_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
$('#tags_name2').val("");
<% elsif @obj_flag == '6'%>
<%if @course%>
$("#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}) %>');
$("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course,:tag_name => @select_tag_name}) %>");
<%else%>
$("#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}) %>');
<%end%>
$("#tags_name_<%=@obj.id%>").val("");
$("#add_tag_<%=@obj.id%>").hide();
<% 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}) %>');
$('#tags_name').val("");
<% elsif @obj_flag == '10'%>
//$("#put-tag-form-<%#=@obj.class%>-<%#=@obj.id%>").hide();
<% else%>
$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
$('#tags_name').val("");
//$('#put-tag-form').hide();
<% end %>

View File

@ -884,6 +884,7 @@ RedmineApp::Application.routes.draw do
match 'tags/remove_tag', :as=>"remove_tag"
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 'words/add_brief_introdution'

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150911064528) do
ActiveRecord::Schema.define(:version => 20150911031029) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -497,26 +497,23 @@ ActiveRecord::Schema.define(:version => 20150911064528) do
add_index "documents", ["created_on"], :name => "index_documents_on_created_on"
add_index "documents", ["project_id"], :name => "documents_project_id"
create_table "dts", :primary_key => "Num", :force => true do |t|
t.string "Defect", :limit => 50
t.string "Category", :limit => 50
t.string "File"
t.string "Method"
t.string "Module", :limit => 20
t.string "Variable", :limit => 50
t.integer "StartLine"
t.integer "IPLine"
t.string "IPLineCode", :limit => 200
t.string "Judge", :limit => 15
t.integer "Review", :limit => 1
create_table "dts", :force => true do |t|
t.string "IPLineCode"
t.string "Description"
t.text "PreConditions", :limit => 2147483647
t.text "TraceInfo", :limit => 2147483647
t.text "Code", :limit => 2147483647
t.string "Num"
t.string "Variable"
t.string "TraceInfo"
t.string "Method"
t.string "File"
t.string "IPLine"
t.string "Review"
t.string "Category"
t.string "Defect"
t.string "PreConditions"
t.string "StartLine"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "enabled_modules", :force => true do |t|
@ -781,6 +778,16 @@ ActiveRecord::Schema.define(:version => 20150911064528) do
add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id"
create_table "journal_details_copy", :force => true do |t|
t.integer "journal_id", :default => 0, :null => false
t.string "property", :limit => 30, :default => "", :null => false
t.string "prop_key", :limit => 30, :default => "", :null => false
t.text "old_value"
t.text "value"
end
add_index "journal_details_copy", ["journal_id"], :name => "journal_details_journal_id"
create_table "journal_replies", :id => false, :force => true do |t|
t.integer "journal_id"
t.integer "user_id"