资源库删除历史版本功能
This commit is contained in:
parent
2d7c7dc05d
commit
80bf13c516
|
@ -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])
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<div class="muban_popup_top">
|
||||
<h3 class="fl">删除资源</h3>
|
||||
<a href="javascript:void(0);" class="muban_icons_close fr" onclick="hideModal();"></a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<div class="muban_popup_con" >
|
||||
|
||||
<div class=" clear ml15 mr15 mt15" id="attachment_history_popub">
|
||||
<%= render :partial => "files/attachment_history_popub_delete" %>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,2 @@
|
|||
var htmlvalue = "<%= escape_javascript(render :partial => 'attachments/show_attachment_history_delete') %>";
|
||||
pop_box_new(htmlvalue,820,360);
|
|
@ -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%>")) {
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<table class="muban_table mb10" cellpadding="0" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>资源名称</th>
|
||||
<th >下载数</th>
|
||||
<th>引用数</th>
|
||||
<th>版本号</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th ><p class="popup_ziyuan_title"><%= @attachment.filename %><span class="muban_icons_blue ml5">当前版本</span></p></th>
|
||||
<th><%= @attachment.downloads %></th>
|
||||
<th><%= @attachment.try(:quotes).to_i %></th>
|
||||
<th><%= format_time(@attachment.created_on) %></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @attachment_histories.each do |history| %>
|
||||
<tr>
|
||||
<th ><p class="popup_ziyuan_title">
|
||||
<%= link_to history.filename, download_history_attachment_path(history.id, history.filename), :title => history.filename+"\n"+history.description.to_s %></p>
|
||||
</th>
|
||||
<th><%= history.downloads %></th>
|
||||
<th><%= history.try(:quotes).to_i %></th>
|
||||
<th><%= format_time(history.created_on) %></th>
|
||||
<th>
|
||||
<%= 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) %>
|
||||
</th>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<div>
|
||||
<% 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 %>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -81,9 +81,11 @@
|
|||
</li>
|
||||
<%end%>
|
||||
<li>
|
||||
<%= 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 %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
|
|
@ -27,7 +27,11 @@
|
|||
</li>
|
||||
<% end %>
|
||||
<li>
|
||||
<%= 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 %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue