diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 6b03cff1e..cb61177f5 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -244,13 +244,18 @@ class TagsController < ApplicationController @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存在。 - #看重命名后的tag是否存在。如果存在的话,只需要更改taggings里边的id, - if @rename_tag - @taggings = ActsAsTaggableOn::Tagging.where(" `taggings`.`tag_id` = #{ @tag_id} AND `taggings`.`taggable_type` = 'Attachment' ")#find_by_tag_id_and_taggable_type(@tag_id,@taggable_type) - @taggings.each { |t| t.update_attributes({:tag_id=> @rename_tag.id}) if t.tag_id != @rename_tag.id } - ActsAsTaggableOn::Tag.find(@tag_id).update_attributes(:name=>@rename_tag_name)#并且将该tag改名 - else #如果不存在,那么就直接更新该tag名称为新的名称 - (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).update_attributes(:name=>@rename_tag_name) + if @course_id + course = Course.find @course_id + if course + course.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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ae0b4d7c9..7e44174fe 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -112,17 +112,10 @@ class UsersController < ApplicationController case params[:type] when nil @message_alls = [] - system_message_types = MessageAll.where("message_type =?", "SystemMessage").order("created_at desc") - messages = MessageAll.where("user_id =? and message_type !=?" ,@user, "SystemMessage").order("created_at desc") + messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user, "SystemMessage", "SystemMessage").order("created_at desc") messages.each do |message_all| @message_alls << message_all.message end - # 系统消息需要给每个人发送,之所以这样做,可以避免遍历系统所有用户 - system_message_types.each do |system_message_type| - @message_alls << system_message_type.message - end - # 取出所有符合条件的按照创建时间排序 - @message_alls = @message_alls.sort {|a,b| b.created_at <=> a.created_at} when 'unviewed' @message_alls = [] messages = MessageAll.where("user_id =?", @user).order("created_at desc") diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index 6b1fdb2e9..656baaf63 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -246,36 +246,63 @@ tagId = id; taggableType = type; width = parseInt(domEle.css('width').replace('px','')) >=100 ? parseInt(domEle.css('width').replace('px','')) : 100 - domEle.html(''); + domEle.html(''); domEle.parent().css("border","1px solid #ffffff"); $("#renameTagName").focus(); } //监听所有的单击事件 - $(document.body).click(function(e){ - isdb = false; //这是单击 - node = document.elementFromPoint(e.clientX, e.clientY); - if(node.tagName == "INPUT"){ //如果是输入框的聚焦,那么就不要进行下去了 - isdb = true; //为了防止在编辑的时候又去单击其他tag去过滤。导致tag过滤不可用 - return; - } - if($("#renameTagName")[0] != undefined ){//存在renameTagName,则处于编辑状态 - if($("#renameTagName").val().trim() == tagName){ //如果值一样,则恢复原来的状态 - ele.parent().css("border",""); - ele.parent().html(tagNameHtml); + $(function(){ + $("#renameTagName").live("blur",function(){ + updateTagName(); + }).live("keypress",function(e){ + if (e.keyCode == '13') { + updateTagName(); + } + }); + }); - }else{ //否则就要更新tag名称了 -// if(confirm("是否将标签改为 "+ $("#renameTagName").val().trim())){ 去掉询问 - $.post( - '<%= update_tag_name_path %>', - {"taggableId": tagId, "taggableType": taggableType, "tagName": tagName, "renameName": $("#renameTagName").val().trim(),"courseId":<%= @course.id%>} - ) -// }else{ -// ele.parent().css("border",""); -// ele.parent().html(tagNameHtml); -// } - } - } - }); + //执行修改TAGName方法 + function updateTagName(){ + if(isdb){ + isdb = false; + if($("#renameTagName").val() == tagName){ //如果值一样,则恢复原来的状态 + ele.parent().css("border",""); + ele.parent().html(tagNameHtml); + + } + else{ + $.post( + '<%= update_tag_name_path %>', + {"taggableId": tagId, "taggableType": taggableType, "tagName": tagName, "renameName": $("#renameTagName").val().trim(),"courseId":<%= @course.id%>} + ); + } + } + } +// $(document.body).click(function(e){ +// isdb = false; //这是单击 +// node = document.elementFromPoint(e.clientX, e.clientY); +// if(node.tagName == "INPUT"){ //如果是输入框的聚焦,那么就不要进行下去了 +// isdb = true; //为了防止在编辑的时候又去单击其他tag去过滤。导致tag过滤不可用 +// 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(),"courseId":<%= @course.id%>} +// ) +//// }else{ +//// ele.parent().css("border",""); +//// ele.parent().html(tagNameHtml); +//// } +// } +// } +// }); <%end %> diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index a95645571..fee28f761 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -191,8 +191,10 @@