diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 3986acc0a..821f75de1 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -329,20 +329,33 @@ class AttachmentsController < ApplicationController end end + # prams[:type] => history 历史版本 def destroy - if @attachment.container.respond_to?(:init_journal) - @attachment.container.init_journal(User.current) - end - if @attachment.container - if @attachment.container_type == "Issue" - @attachment.destroy - else - @attachment.container.attachments.delete(@attachment) + if params[:type] == "history" + begin + AttachmentHistory.find(params[:history_id]).destroy + @attachment = Attachment.find(params[:id]) + @is_history = true + @attachment_histories = @attachment.attachment_histories + rescue Exception => e + puts e end else - @attachment.destroy + if @attachment.container.respond_to?(:init_journal) + @attachment.container.init_journal(User.current) + end + if @attachment.container + if @attachment.container_type == "Issue" + @attachment.destroy + else + @attachment.container.attachments.delete(@attachment) + end + else + @attachment.destroy + end end + respond_to do |format| if !@attachment.container.nil? && (@attachment.container.is_a?(Course) || ((@attachment.container.has_attribute?(:course) || @attachment.container.has_attribute?(:course_id) ) && diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 2b31cae13..edffdd28b 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -460,6 +460,16 @@ class OrganizationsController < ApplicationController @members = paginateHelper @members, 20 end + def more_org_submains + @org_subfield = OrgSubfield.find params[:org_subfield_id].to_i + + @page = params[:page] + @submains = @org_subfield.sub_domains.reorder('priority').uniq.page((params[:page].to_i || 1) +1).per(5) + respond_to do |format| + format.js + end + end + def more_org_projects @organization = Organization.find params[:id] @page = params[:page] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 902061aa3..4e28fe662 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3056,7 +3056,7 @@ class UsersController < ApplicationController user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} - if( params[:type] == "1") # 我的资源 + if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) @@ -3070,7 +3070,7 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif (params[:type].blank? || params[:type] == "6") # 公共资源 + elsif (params[:type] == "6") # 公共资源 if params[:status] == "2" @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ef2a44422..2da5542ac 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1380,6 +1380,21 @@ module ApplicationHelper end end + # 判断课程、项目、组织是否有权限删除历史资源 + # 项目管理员或者附件的作者可以删除 + # (is_project_manager?(User.current.id, @project.id) || User.current.id == history.author_id) + def allow_to_delete_attachment history + attachment = history.attachment + case attachment.try(:container_type) + when "Project" + result = is_project_manager?(User.current.id, attachment.container_id) || User.current.id == history.author_id || User.current.admin? + when "Course" + result = User.current.allowed_to?(:as_teacher, attachment.container) || User.current.id == history.author_id || User.current.admin? + when "OrgSubfield" + result = User.current.id == history.author_id || User.current.admin_of_org?(@organization) || User.current.admin? + end + end + # Wiki links # # Examples: diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 879759c89..c83a7bf2a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -367,8 +367,9 @@ class Attachment < ActiveRecord::Base end end - #有了历史记录的数据记录是不能被删除的。 - #true 能被删除 false 不能被删除 + # 有了历史记录的数据记录是不能被删除的。 + # true 能被删除 false 不能被删除 + # 2016.10.14 修改成可以删除,删除时候添加提示全部删除 def destroyable self.attachment_histories.count == 0 end diff --git a/app/views/attachments/_show_attachment_history.html.erb b/app/views/attachments/_show_attachment_history.html.erb index db2cbdec6..9a1a278fc 100644 --- a/app/views/attachments/_show_attachment_history.html.erb +++ b/app/views/attachments/_show_attachment_history.html.erb @@ -1,66 +1,11 @@ - -更新资源版本 - -
-
-
当前版本 - - - -
- <% unless @attachment_histories.empty? %> - -
历史版本
-
- <% @attachment_histories.each do |history| %> - - <%= link_to truncate(history.filename,length: 35, omission: '...'), - download_history_attachment_path(history.id, history.filename), - :title => history.filename+"\n"+history.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis; max-width:300px;",:class => "linkBlue f_14 f_b upload_filename fl" %> - 版本号:<%= history.version %> -
-
- - <% end %> -
- <% end %> - -
- <%= form_tag(upload_attachment_version_path, :multipart => true,:remote => !ie8?,:name=>"upload_form",:id=>'upload_form') do %> - <%= hidden_field_tag :old_attachment_id,@attachment.id %> -
- - -
-
- - <%= render :partial => 'attachments/upload_attachment_new_version' %> -
- - -
-
- (未选择文件) - 您可以上传小于50MB的文件 -
-
-
-

描述:

-
- -
-
-
-
-
-
-
-
- - <%= submit_tag '确定',:onclick=>'upload_attachment_version(event);',:onfocus=>'this.blur()',:id=>'upload_files_submit_btn',:class=>'sendSourceText' %> -
-
取消
-
- <% end %> +
+

更新资源版本

+
- \ No newline at end of file +
+
+ +
+ <%= render :partial => "files/attachment_history_popub" %> +
+
diff --git a/app/views/attachments/_upload_attachment_new_version.html.erb b/app/views/attachments/_upload_attachment_new_version.html.erb index cd35535c0..0e03bab47 100644 --- a/app/views/attachments/_upload_attachment_new_version.html.erb +++ b/app/views/attachments/_upload_attachment_new_version.html.erb @@ -1,8 +1,8 @@ +
+ 文件浏览 +

(未选择文件) 您可以上传小于50MB的文件

+
- - - - 选择文件 <%= file_field_tag 'attachments[dummy][file]', :id => '_file', :class => ie8? ? '':'file_selector', diff --git a/app/views/attachments/attachment_versions.js.erb b/app/views/attachments/attachment_versions.js.erb index ff704a869..613ee0ac3 100644 --- a/app/views/attachments/attachment_versions.js.erb +++ b/app/views/attachments/attachment_versions.js.erb @@ -1,7 +1,2 @@ -$("#ajax-modal").html('<%= escape_javascript( render :partial => 'attachments/show_attachment_history' )%>'); -showModal('ajax-modal', '452px'); -$('#ajax-modal').siblings().remove(); -$('#ajax-modal').before(""); -$('#ajax-modal').parent().css("top","40%").css("left","50%").css("position","fixed"); -$('#ajax-modal').parent().addClass("resourceUploadPopup"); -$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); \ No newline at end of file +var htmlvalue = "<%= escape_javascript(render :partial => 'attachments/show_attachment_history') %>"; +pop_box_new(htmlvalue,820,360); \ No newline at end of file diff --git a/app/views/attachments/destroy.js.erb b/app/views/attachments/destroy.js.erb index 02a613e6e..310ad74d5 100644 --- a/app/views/attachments/destroy.js.erb +++ b/app/views/attachments/destroy.js.erb @@ -1,3 +1,8 @@ +//历史版本删除局部刷新 +<% if @is_history %> +$("#attachment_history_popub").html('<%= escape_javascript( render :partial => 'files/attachment_history_popub') %>'); +<% end %> + <% if @is_destroy%> $("#attachment_<%= @attachment.id%>").remove(); if(document.getElementById("revise_attachment_div_<%= @attachment.id%>")) { diff --git a/app/views/files/_attachment_history_popub.html.erb b/app/views/files/_attachment_history_popub.html.erb new file mode 100644 index 000000000..7aa553680 --- /dev/null +++ b/app/views/files/_attachment_history_popub.html.erb @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + <% @attachment_histories.each do |history| %> + + + + + + + + <% end %> + +
资源名称下载数引用数版本号
<%= @attachment.downloads %><%= @attachment.try(:quotes).to_i %><%= format_time(@attachment.created_on) %>
+ <%= history.downloads %><%= history.try(:quotes).to_i %><%= format_time(history.created_on) %> + <%= link_to( '删除资源', attachment_path(history.attachment, :history_id => history, :type => "history"), + :remote => true, + :data => {:confirm => l(:text_are_you_sure)}, + :method => :delete, + :class => "postOptionLink", + :class => "btn") if allow_to_delete_attachment(history) %> +
+<%= form_tag(upload_attachment_version_path, :multipart => true,:remote => !ie8?,:name=>"upload_form",:id=>'upload_form') do %> + <%= hidden_field_tag :old_attachment_id,@attachment.id %> +
+ + +
+
+ + <%= render :partial => 'attachments/upload_attachment_new_version' %> +
+ + +
+
+ +
+ 取消 + <%= submit_tag '确定', :onclick => 'upload_attachment_version(event);', :onfocus => 'this.blur()', :id => 'upload_files_submit_btn', :class => 'btn btn-blue fr mr5' %> +
+<% end %> \ No newline at end of file diff --git a/app/views/files/_org_subfield_list.html.erb b/app/views/files/_org_subfield_list.html.erb index 45aa7095b..05d307016 100644 --- a/app/views/files/_org_subfield_list.html.erb +++ b/app/views/files/_org_subfield_list.html.erb @@ -80,7 +80,7 @@ <% end %>
  • <%= link_to( '删除资源', attachment_path(file), - :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == org_subfield.id && file.container_type == "OrgSubfield" && file.destroyable %> + :data => {:confirm => file.destroyable ? l(:text_are_you_sure) : l(:text_history_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == org_subfield.id && file.container_type == "OrgSubfield" %>
  • <%else%> diff --git a/app/views/files/_resource_detail.html.erb b/app/views/files/_resource_detail.html.erb index 08b85ab2f..c9431f7d3 100644 --- a/app/views/files/_resource_detail.html.erb +++ b/app/views/files/_resource_detail.html.erb @@ -82,8 +82,8 @@ <%end%>
  • <%= link_to( '删除资源', attachment_path(file), - :data => {:confirm => l(:text_are_you_sure)}, - :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" && file.destroyable %> + :data => {:confirm => file.destroyable ? l(:text_are_you_sure) : l(:text_history_are_you_sure)}, + :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" %>
  • <% end %> diff --git a/app/views/files/_tool_settings.html.erb b/app/views/files/_tool_settings.html.erb index 572db0606..aaad31704 100644 --- a/app/views/files/_tool_settings.html.erb +++ b/app/views/files/_tool_settings.html.erb @@ -27,7 +27,7 @@ <% end %>
  • - <%= link_to( '删除资源', attachment_path(file),:data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == project.id && file.container_type == "Project" && file.destroyable %> + <%= link_to( '删除资源', attachment_path(file),:data => {:confirm => file.destroyable ? l(:text_are_you_sure) : l(:text_history_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == project.id && file.container_type == "Project" %>
  • <% end %> diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index 528265c26..a278c585b 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -1,17 +1,16 @@ - - <% if @container_type == 0 %> -
    - <%= render :partial => 'project_file', locals: {project: @project} %> -
    - <% elsif @container_type == 1 %> -
    - <%= render :partial => 'course_file', locals: {course: @course} %> -
    - <% elsif @container_type == 2 %> -
    - <%= render :partial => 'files/subfield_files', locals: {org_subfield: @org_subfield} %> -
    - <% end %> +<% if @container_type == 0 %> +
    + <%= render :partial => 'project_file', locals: {project: @project} %> +
    +<% elsif @container_type == 1 %> +
    + <%= render :partial => 'course_file', locals: {course: @course} %> +
    +<% elsif @container_type == 2 %> +
    + <%= render :partial => 'files/subfield_files', locals: {org_subfield: @org_subfield} %> +
    +<% end %> +
    - + " id="sendexcel" class="hw_btn_blue fr" alt="导出EXCEL" onclick="remote_function_export('<%= @project.id %>')">导出EXCEL
    <% unless @project.enabled_modules.where("name = 'issue_tracking'").empty? %> @@ -168,4 +286,4 @@
    - \ No newline at end of file + diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index cdc752e7e..a51551d0b 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -8,7 +8,7 @@ <%= link_to "首页",user_activities_path(User.current), :class => "c_white f16 db p10", :title => "回到个人首页"%> <% if hidden_unproject_infos %> <% end %> -<%# if subdomains.size == 5 %> - - - - -<%# end%> \ No newline at end of file +<% if subdomains.size == 5 %> +
  • + + +
  • +<% end%> + diff --git a/app/views/organizations/more_org_submains.js.erb b/app/views/organizations/more_org_submains.js.erb new file mode 100644 index 000000000..088c9ed34 --- /dev/null +++ b/app/views/organizations/more_org_submains.js.erb @@ -0,0 +1 @@ +$("#show_more_org_submains").replaceWith("<%= escape_javascript( render :partial => 'organizations/org_subdomain',:locals => {:subdomains => @submains, :org_subfield_id => @org_subfield.id, :page=> @page, :org_id => @organization } )%>"); \ No newline at end of file diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 6c0e067db..7fe945df9 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -45,10 +45,10 @@