From 80bf13c516bc42a7d07db95cfd574610d4a90be2 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 14 Oct 2016 19:21:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E7=89=88=E6=9C=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 21 ++++++++ app/helpers/application_helper.rb | 2 +- .../_show_attachment_history_delete.html.erb | 11 ++++ .../attachment_versions_delete.js.erb | 2 + app/views/attachments/destroy.js.erb | 9 ++++ .../_attachment_history_popub_delete.html.erb | 54 +++++++++++++++++++ app/views/files/_resource_detail.html.erb | 8 +-- app/views/files/_tool_settings.html.erb | 6 ++- config/routes.rb | 1 + 9 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 app/views/attachments/_show_attachment_history_delete.html.erb create mode 100644 app/views/attachments/attachment_versions_delete.js.erb create mode 100644 app/views/files/_attachment_history_popub_delete.html.erb diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 821f75de1..211b8da57 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -336,11 +336,23 @@ class AttachmentsController < ApplicationController AttachmentHistory.find(params[:history_id]).destroy @attachment = Attachment.find(params[:id]) @is_history = true + @is_history_destroy = false + @attachment_histories = @attachment.attachment_histories + rescue Exception => e + puts e + end + elsif params[:type] == "history_delete" + begin + AttachmentHistory.find(params[:history_id]).destroy + @attachment = Attachment.find(params[:id]) + @is_history_delete = true + @is_history_destroy = false @attachment_histories = @attachment.attachment_histories rescue Exception => e puts e end else + @history = params[:history] if @attachment.container.respond_to?(:init_journal) @attachment.container.init_journal(User.current) end @@ -644,6 +656,7 @@ class AttachmentsController < ApplicationController #找到文件的所有的历史版本 def attachment_versions + @history = params[:history] @attachment = Attachment.find(params[:id]) @attachment_histories = @attachment.attachment_histories respond_to do |format| @@ -651,6 +664,14 @@ class AttachmentsController < ApplicationController end end + def attachment_versions_delete + @attachment = Attachment.find(params[:id]) + @attachment_histories = @attachment.attachment_histories + respond_to do |format| + format.js + end + end + #找到文件的所有的历史版本及当前版本 def attachment_history_download @attachment = Attachment.find(params[:id]) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2da5542ac..0782b55b0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1391,7 +1391,7 @@ module ApplicationHelper 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? + result = User.current.id == history.author_id || User.current.admin_of_org?(attachment.container) || User.current.admin? end end diff --git a/app/views/attachments/_show_attachment_history_delete.html.erb b/app/views/attachments/_show_attachment_history_delete.html.erb new file mode 100644 index 000000000..489eaeed0 --- /dev/null +++ b/app/views/attachments/_show_attachment_history_delete.html.erb @@ -0,0 +1,11 @@ +
+

删除资源

+ +
+
+
+ +
+ <%= render :partial => "files/attachment_history_popub_delete" %> +
+
diff --git a/app/views/attachments/attachment_versions_delete.js.erb b/app/views/attachments/attachment_versions_delete.js.erb new file mode 100644 index 000000000..165d0e3d7 --- /dev/null +++ b/app/views/attachments/attachment_versions_delete.js.erb @@ -0,0 +1,2 @@ +var htmlvalue = "<%= escape_javascript(render :partial => 'attachments/show_attachment_history_delete') %>"; +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 310ad74d5..97d3fd3ec 100644 --- a/app/views/attachments/destroy.js.erb +++ b/app/views/attachments/destroy.js.erb @@ -3,6 +3,15 @@ $("#attachment_history_popub").html('<%= escape_javascript( render :partial => 'files/attachment_history_popub') %>'); <% end %> +<% if @is_history_delete %> +$("#attachment_history_popub").html('<%= escape_javascript( render :partial => 'files/attachment_history_popub_delete') %>'); +<% end %> + +//历史版本删除局部刷新 +<% if @is_history_destroy %> +$("#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_delete.html.erb b/app/views/files/_attachment_history_popub_delete.html.erb new file mode 100644 index 000000000..0f9624119 --- /dev/null +++ b/app/views/files/_attachment_history_popub_delete.html.erb @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + <% @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_delete"), + :remote => true, + :data => {:confirm => l(:text_are_you_sure)}, + :method => :delete, + :class => "postOptionLink", + :class => "btn") if allow_to_delete_attachment(history) %> +
+
+ <% if @attachment.container_type == "Project" %> + <%= link_to( '删除所有资源', attachment_path(@attachment, :history_delete => true), :data => {:confirm => l(:text_history_are_you_sure)}, :method => :delete,:class => "fr fontGrey2 mb5", :onclick =>"hideModal();") if (is_project_manager?(User.current.id, @attachment.container_id) || User.current.id == @attachment.author_id || User.current.admin?) %> + <% elsif @attachment.container_type == "Course" %> + <%= link_to( '删除所有资源', attachment_path(@attachment, :history_delete => true), :data => {:confirm => l(:text_history_are_you_sure)}, :method => :delete,:class => "fr fontGrey2 mb5", :onclick =>"hideModal();") if (User.current.allowed_to?(:as_teacher, @attachment.container) || User.current.id == @attachment.author_id || User.current.admin?) %> + <% elsif @attachment.container_type == "OrgSubfield" %> + <%= link_to( '删除所有资源', attachment_path(@attachment, :history => true), :data => {:confirm => l(:text_history_are_you_sure)}, :method => :delete,:class => "fr fontGrey2 mb5", :onclick =>"hideModal();") if (User.current.id == @attachment.author_id || User.current.admin_of_org?(@attachment) || User.current.admin?) %> + <% end %> +
+ + + + + + diff --git a/app/views/files/_resource_detail.html.erb b/app/views/files/_resource_detail.html.erb index d8d3e1612..fd804ca9c 100644 --- a/app/views/files/_resource_detail.html.erb +++ b/app/views/files/_resource_detail.html.erb @@ -81,9 +81,11 @@ <%end%>
  • - <%= 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 == @course.id && file.container_type == "Course" %> + <% if file.destroyable %> + <%= 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" %> + <% else %> + <%= link_to '删除资源',attachment_versions_delete_path(file), :class => "postOptionLink", :remote => true %> + <% end %>
  • <% end %> diff --git a/app/views/files/_tool_settings.html.erb b/app/views/files/_tool_settings.html.erb index aaad31704..ccce43b05 100644 --- a/app/views/files/_tool_settings.html.erb +++ b/app/views/files/_tool_settings.html.erb @@ -27,7 +27,11 @@ <% end %>
  • - <%= 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" %> + <% if file.destroyable %> + <%= 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" %> + <% else %> + <%= link_to '删除资源',attachment_versions_delete_path(file), :class => "postOptionLink", :remote => true %> + <% end %>
  • <% end %> diff --git a/config/routes.rb b/config/routes.rb index 265244a18..d8b4b8cf4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1015,6 +1015,7 @@ RedmineApp::Application.routes.draw do # additional routes for having the file name at the end of url get 'attachments/:id/:filename', :to => 'attachments#show', :id => /\d+/, :filename => /.*/, :as => 'named_attachment' get 'attachments/attachment_versions/:id',:to=>'attachments#attachment_versions',:as=>'attachments_versions' + get 'attachments/attachment_versions_delete/:id',:to=>'attachments#attachment_versions_delete',:as=>'attachment_versions_delete' get 'attachments/attachment_history_download/:id',:to=>'attachments#attachment_history_download',:as=>'attachment_history_download' post 'attachments/upload_attachment_version',:to=>'attachments#upload_attachment_version',:as=>'upload_attachment_version' get 'attachments/download/:id/:filename', :to => 'attachments#download', :id => /\d+/, :filename => /.*/, :as => 'download_named_attachment'