From 0821320dfefd4c7187dbdd7c65b5f329f3f89f97 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 19 Nov 2014 10:07:49 +0800 Subject: [PATCH] =?UTF-8?q?tag=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=8C=E7=BF=BB=E9=A1=B5=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 35 +++++++++++++++++++++++++++ app/views/files/_course_file.html.erb | 2 +- app/views/tags/_tag_list.html.erb | 2 +- app/views/tags/remove_tag_new.js.erb | 6 +++++ config/routes.rb | 1 + public/stylesheets/resource.css | 10 +++++--- 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 app/views/tags/remove_tag_new.js.erb diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 27f7fe61d..5bd5fb0e3 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -14,6 +14,7 @@ class TagsController < ApplicationController include AttachmentsHelper include ContestsHelper include ActsAsTaggableOn::TagsHelper + include TagsHelper helper :projects helper :courses helper :tags @@ -189,6 +190,40 @@ class TagsController < ApplicationController end end + # 只删除某个对象的该tag + def remove_tag_new + @obj = nil + @object_flag = nil + + if request.get? + # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 + @tag_name = params[:tag_name] + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id + @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 + @taggable_type = numbers_to_object_type(params[:taggable_type]) + + @obj = get_object(@taggable_id,params[:taggable_type]) + @object_flag = params[:taggable_type] + + # if can_remove_tag?(User.current,@taggable_id,@taggable_type) + + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) + + unless @taggings.nil? + @taggings.delete + end + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) + # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 + if @tagging.nil? + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.delete unless @tag.nil? + end + # end + end + end + def tag_save @tags = params[:tag_for_save][:name] @obj_id = params[:tag_for_save][:object_id] diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 8edd054be..603318cf6 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -11,7 +11,7 @@ - 发布资源 + 上传资源
diff --git a/app/views/tags/_tag_list.html.erb b/app/views/tags/_tag_list.html.erb index 092e0d898..c815d71f8 100644 --- a/app/views/tags/_tag_list.html.erb +++ b/app/views/tags/_tag_list.html.erb @@ -7,7 +7,7 @@ <% case object_flag %> <% when '6' %> <% if obj.author_id == User.current.id || User.current.admin?%> - <%= link_to 'x', :controller => "tags", :action => "remove_tag", :remote => true, :tag_name => tag, + <%= link_to 'x', :controller => "tags", :action => "remove_tag_new", :remote => true, :tag_name => tag, :taggable_id => obj.id, :taggable_type => object_flag %> <% end %> <% end %> diff --git a/app/views/tags/remove_tag_new.js.erb b/app/views/tags/remove_tag_new.js.erb new file mode 100644 index 000000000..24d52a35f --- /dev/null +++ b/app/views/tags/remove_tag_new.js.erb @@ -0,0 +1,6 @@ +//本js使用的新的tag显示方法 +<% if @object_flag == "6"%> +$("#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}) %>'); +<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 35b7b6ca2..3e2abce47 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -792,6 +792,7 @@ RedmineApp::Application.routes.draw do match 'parise_tread/tread_plus', :as=>"tread" match 'tags/delete' match 'tags/remove_tag', :as=>"remove_tag" + match 'tags/remove_tag_new', :as=>"remove_tag_new" match 'tags/tag_save', :as => "save_tag" match 'words/add_brief_introdution' diff --git a/public/stylesheets/resource.css b/public/stylesheets/resource.css index 3c7ab35bb..f179b6683 100644 --- a/public/stylesheets/resource.css +++ b/public/stylesheets/resource.css @@ -55,10 +55,12 @@ a:hover.re_open{background:url(images/pic_open02.png) 0 0 no-repeat;} a.re_de{ color:#6883b6; margin-left:15px;} .re_con_box{ border-bottom:1px dashed #dadada; padding:10px 0;} /****翻页***/ -.wlist{ margin-top:15px;} -.wlist a{ float:right; border:1px solid #15bccf; padding:0 5px; margin-left:3px; color:#15bccf;} -.wlist a:hover{border:1px solid #15bccf; background-color:#15bccf; color:#fff;} -.wlist_select a { background-color:#64bdd9; color:#fff;} +ul.wlist{ float:right; border-bottom:none; height:30px; margin-top:20px; } +.wlist li{float: left;} +.wlist span{ border:1px solid #15bccf; padding:0 5px; margin-left:3px;} +.wlist a{display: block; border:1px solid #15bccf; padding:0 5px; margin-left:3px;} +.wlist a:hover{ background:#15bccf; color:#fff; text-decoration:none;} +.wlist_select { background-color:#64bdd9; color:#fff; padding:0 5px; margin-left:3px; border:1px solid #64bdd9;} /****标签***/ a.yellowBtn{ display:inline-block;color:#0d90c3; height:22px;} .submit