diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 63307f28e..105000495 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -231,7 +231,6 @@ class FilesController < ApplicationController if params[:sort] params[:sort].split(",").each do |sort_type| order_by = sort_type.split(":") - case order_by[0] when "filename" attribute = "filename" diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index d40bc7c7c..625a1882e 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -320,6 +320,88 @@ class TagsController < ApplicationController end end + def update_project_tag_name + @tag_name = params[:tagName] + @rename_tag_name = params[:renameName] + @taggable_id = params[:taggableId] + @taggable_type = numbers_to_object_type(params[:taggableType]) + @project_id = params[:projectId] + + @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 @project_id + project = Project.find @project_id + if project + project.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?(Project) + @project = @obj.container + @tag_list = @tag_list = get_course_tag_list @project + elsif @project_id + @project = Project.find(@project_id) + @tag_list = get_project_tag_list @project + + #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 + @flag = params[:flag] || false + sort = "" + @sort = "" + @order = "" + @is_remote = false + @isproject = false + + sort = "#{Attachment.table_name}.created_on desc" + + @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] + + show_attachments @containers + elsif @obj && @obj_flag == '5' + @forum = @obj + end + respond_to do |format| + format.js + end + end + def update_org_subfield_tag_name @tag_name = params[:tagName] @rename_tag_name = params[:renameName] diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 2e8b98a2d..8847f4163 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -73,6 +73,16 @@ def course_contains_attachment? course,attachment false end +#判断项目project中是否包含课件attachment,project中引用了attachment也算作包含 +def project_contains_attachment? project,attachment + project.attachments.each do |att| + if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from + return true + end + end + false +end + #判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期 def has_course? user,file result = false diff --git a/app/views/files/_project_list.html.erb b/app/views/files/_project_list.html.erb index 217f48ef7..d84c1cada 100644 --- a/app/views/files/_project_list.html.erb +++ b/app/views/files/_project_list.html.erb @@ -33,7 +33,7 @@ <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %>
- <%= render :partial => 'tool_settings', :locals => {:project => @project, :delete_allowed => delete_allowed, :file => file} %> + <%= render :partial => 'files/tool_settings', :locals => {:project => @project, :delete_allowed => delete_allowed, :file => file} %>
@@ -45,12 +45,8 @@ <% end %> <% end %> -<% if project_attachments.count == 10%> - <% if params[:action] == 'search' %> - <%=link_to "点击展开更多", search_project_project_files_path({:project_id => project.id, :page => @obj_pages.nil? ? @feedback_pages.page + 1 : @obj_pages.page + 1}.merge(params)),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> - <%else%> - - <%=link_to "列表点击展开更多", project_files_path({:project_id => project.id, :page => @obj_pages.nil? ? @feedback_pages.page + 1 : @obj_pages.page + 1}.merge(params)),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> - <%end%> -<% end%> + + diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index 4ab7e5765..b702d5872 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -428,6 +428,65 @@ // }); <%end %> + <% if @project %> + 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(String(id) != '' || '<%=is_project_manager?(User.current.id, @project.id)%>' == 'true' ) { //如果有id ,或者是老师就都能编辑,否则,没有id,不是老师就不能编辑 + 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(''); + 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( + '<%= update_project_tag_name_path %>', + {"taggableId": tagId, "taggableType": taggableType, "tagName": tagName, "renameName": $("#renameTagName").val().trim(),"projectId":<%= @project.id %>} + ); + } + } + } + <%end %> + <% if @org_subfield %> var tagNameHtml; //当前双击的链接的父节点的html var tagName; //标签的值 diff --git a/app/views/files/index.js.erb b/app/views/files/index.js.erb index 584eeb276..fe24c9be0 100644 --- a/app/views/files/index.js.erb +++ b/app/views/files/index.js.erb @@ -1,5 +1,5 @@ <% if @course %> - $("#show_more_attachments").replaceWith("<%= escape_javascript( render :partial => 'files/course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} )%>"); + $("#show_more_attachments").replaceWith("<%= escape_javascript( render :partial => 'files/course_list',:locals => {course:@course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} )%>"); <% elsif @project %> $("#show_more_attachments").replaceWith("<%= escape_javascript( render :partial => 'files/project_list', :locals => {project:@project, all_attachments:@all_attachments, sort:@sort, order:@order, project_attachments:@obj_attachments})%>"); <%end %> \ No newline at end of file diff --git a/app/views/tags/update_project_tag_name.js.erb b/app/views/tags/update_project_tag_name.js.erb new file mode 100644 index 000000000..df11b8e57 --- /dev/null +++ b/app/views/tags/update_project_tag_name.js.erb @@ -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,:select_tag_name => @select_tag_name}) %>'); +$("#tags_name_<%=@obj.id%>").val(""); +$("#add_tag_<%=@obj.id%>").hide(); +<% else %> +$("#course_list").html("<%= escape_javascript(render :partial => 'files/project_list', + :locals => {project: @project,all_attachments: @all_attachments,sort:@sort,order:@order,project_attachments:@obj_attachments}) %>"); +<% end %> +$("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun_project", :locals => {:tag_list => @tag_list,:project => @project,:tag_name => @select_tag_name}) %>"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 946c4e4e9..c630d376d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1083,6 +1083,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_project_tag_name',:as => "update_project_tag_name" match 'tags/update_org_subfield_tag_name' match 'words/add_brief_introdution'