项目资源库历史版本更新及局部刷新

This commit is contained in:
huang 2016-10-14 13:45:47 +08:00
parent 39cc6c36ea
commit db63a5514d
9 changed files with 174 additions and 87 deletions

View File

@ -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) ) &&
@ -631,6 +644,7 @@ class AttachmentsController < ApplicationController
#找到文件的所有的历史版本
def attachment_versions
@project = Project.find(params[:project_id])
@attachment = Attachment.find(params[:id])
@attachment_histories = @attachment.attachment_histories
respond_to do |format|

View File

@ -1,66 +1,11 @@
<!--<div class="resourceUploadPopup">-->
<span class="uploadDialogText">更新资源版本</span>
<!--<div class="resourcePopupClose"> <a href="javascript:void(0);" class="resourceClose" onclick="closeModal();"></a></div>-->
<div>
<div>
<div>当前版本
<span class="attachment" >
<input readonly="readonly" name="attachments[1][filename]" value="<%=@attachment.filename%>" class="upload_filename readonly" type="text">
</span>
</div>
<% unless @attachment_histories.empty? %>
<div >历史版本</div>
<div style="max-height: 95px;overflow-y:auto; background-color: #e3e3e3;" class="mb10 p10">
<% @attachment_histories.each do |history| %>
<span class="attachment">
<%= 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" %>
<span class="fr">版本号:<%= history.version %></span>
<div class="cl"></div>
</span>
<% end %>
</div>
<% end %>
</div>
<%= 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 %>
<div>
<span id="attachments_fields" xmlns="http://www.w3.org/1999/html">
</span>
</div>
<div class="uploadBox">
<input type="hidden" name="attachment_type" value="1">
<%= render :partial => 'attachments/upload_attachment_new_version' %>
<div class="cl"></div>
<!--<a href="javascript:void(0);" class=" fr grey_btn mr40" onclick="closeModal();"><%#= l(:button_cancel)%></a>-->
<!--<a id="submit_resource" href="javascript:void(0);" class="blue_btn fr" onclick="submit_resource();"><%#= l(:button_confirm)%></a>-->
</div>
<div class="W300 uploadResourceIntr fontGrey2">
<span id="upload_file_count" class="mr15">(未选择文件)</span>
<span>您可以上传小于<span class="c_red">50MB</span>的文件</span>
</div>
<div class="cl"></div>
<div class="mb5 mt5">
<p class="c_dark f14" style="line-height:30px;">描述:</p>
<div class="fl">
<textarea style="resize:none" type="text" placeholder="请编辑资源描述" name="description" class="InputBox fl H60 W420" ><%= @attachment.description %></textarea>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
<div style="margin-top: 10px" >
<div class="courseSendSubmit">
<!--<a href="javascript:void(0);" class="sendSourceText" onclick="">确定</a>-->
<%= submit_tag '确定',:onclick=>'upload_attachment_version(event);',:onfocus=>'this.blur()',:id=>'upload_files_submit_btn',:class=>'sendSourceText' %>
</div>
<div class="courseSendCancel"><a href="javascript:void(0);" id="upload_files_cancle_btn" class="sendSourceText" onclick="hideModal();">取消</a></div>
</div>
<% end %>
<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>
<div class="muban_popup_con" >
<div class=" clear ml15 mr15 mt15" id="attachment_history_popub">
<%= render :partial => "files/attachment_history_popub" %>
</div>
</div>

View File

@ -1,8 +1,8 @@
<div class="clear mb10">
<a class="sub_btn fl" name="button" onclick="_file.click()" onmouseover="" style="<%= ie8? ? 'display:none' : ''%>">文件浏览</a>
<p class="fl ml5 mt3 sy_cgrey">(未选择文件) 您可以上传小于<span class="c_red">50MB</span>的文件</p>
</div>
<!--<button name="button" class="sub_btn" onclick="_file.click()" onmouseover="this.focus()" style="<%#= ie8? ? 'display:none' : ''%>" type="button" ><%#= l(:label_browse) %></button>-->
<a href="javascript:void(0);" class="uploadIcon f14" name="button" onclick="_file.click()" onmouseover="" style="<%= ie8? ? 'display:none' : ''%>">
<span class="chooseFile">选择文件</span></a>
<%= file_field_tag 'attachments[dummy][file]',
:id => '_file',
:class => ie8? ? '':'file_selector',

View File

@ -1,7 +1,11 @@
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'attachments/show_attachment_history' )%>');
showModal('ajax-modal', '452px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 435px;' class='resourceClose'></a>");
$('#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");
//$("#ajax-modal").html('<%#= escape_javascript( render :partial => 'attachments/show_attachment_history' )%>');
//showModal('ajax-modal', '452px');
//$('#ajax-modal').siblings().remove();
//$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 435px;' class='resourceClose'></a>");
//$('#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");
var htmlvalue = "<%= escape_javascript(render :partial => 'attachments/show_attachment_history') %>";
pop_box_new(htmlvalue,820,360);

View File

@ -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%>")) {

View File

@ -0,0 +1,57 @@
<table class="muban_table mb15" 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.quotes %></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"),
:remote => true,
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,:class => "postOptionLink",
:class => "btn") if (is_project_manager?(User.current.id, @project.id) || User.current.id == history.author_id) %>
</th>
</tr>
<% end %>
</tbody>
</table>
<%= 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 %>
<div>
<span id="attachments_fields" xmlns="http://www.w3.org/1999/html">
</span>
</div>
<div class="clear mb10">
<input type="hidden" name="attachment_type" value="1">
<%= render :partial => 'attachments/upload_attachment_new_version' %>
<div class="cl"></div>
<!--<a href="javascript:void(0);" class=" fr grey_btn mr40" onclick="closeModal();"><%#= l(:button_cancel)%></a>-->
<!--<a id="submit_resource" href="javascript:void(0);" class="blue_btn fr" onclick="submit_resource();"><%#= l(:button_confirm)%></a>-->
</div>
<div class="cl"></div>
<textarea style="resize:none" type="text" placeholder="请在此编辑资源描述" name="description" class="mr15 mb10 muban_textarea" ><%= @attachment.description %></textarea>
<div class="clear ">
<%= submit_tag '确定', :onclick => 'upload_attachment_version(event);', :onfocus => 'this.blur()', :id => 'upload_files_submit_btn', :class => 'btn btn-blue fr mr5' %>
<a href="javascript:void(0);" id="upload_files_cancle_btn" class="btn fr" onclick="hideModal();">取消</a>
</div>
<% end %>

View File

@ -12,7 +12,7 @@
<%= favicon %>
<%= javascript_heads %>
<%= heads_for_theme %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common','css/structure','scm','css/public', 'css/project','css/popup','prettify','repository','css/gantt', 'css/calendar' %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common','css/structure','scm','css/public', 'css/project','css/popup','prettify','repository','css/gantt', 'css/calendar', "css/moduel" %>
<%= javascript_include_tag 'cookie','project',"avatars", 'header','prettify','select_list_move','attachments' %>
<%= call_hook :view_layouts_base_html_head %>

View File

@ -0,0 +1,59 @@
/* 模板弹框 20161013byLB */
#muban_popup_box{ background:#fff;padding-bottom:15px;-webkit-border-radius:5px;-moz-border-radius:5px;-o-border-radius:5px;border-radius:5px;box-shadow: 0px 2px 8px rgba(146, 153, 169, 0.5);}
.muban_popup_top{background:#3b94d6;height:40px;-webkit-border-radius: 5px 5px 0px 0px;-moz-border-radius: 5px 5px 0px 0px;-o-border-radius: 5px 5px 0px 0px;border-radius: 5px 5px 0px 0px;}
.muban_popup_top h3{ font-size:16px; color:#fff; font-weight:normal; line-height:40px; padding-left:10px; }
a.muban_icons_close{width:20px; height:20px;display:block;background: url(/images/sy/sy_icons_close.png) 0 0px no-repeat; margin:8px 10px 0 0;}
a:hover.muban_icons_close{background: url(/images/sy/sy_icons_close.png) -40px 0px no-repeat;}
/*模板表格 20161013byLB*/
.muban_table{ width:100%; background:#fff; border:1px solid #e5e5e5; border-bottom: none; }
.muban_table thead tr{ height:40px; line-height:40px;}
.muban_table thead tr th{ border-bottom:1px solid #e5e5e5;}
.muban_table tbody tr:hover{ background:#f5f5f5;}
.muban_table tbody tr th{ height:40px; line-height:40px; border-bottom:1px solid #e5e5e5; font-weight:normal; color:#888;}
/*模板icons 20161013byLB*/
.muban_icons_orange{font-size: 12px;padding: 0 5px;border-radius: 3px;line-height: 14px;color: #ff4a1b;border: 1px solid #ff4a1b;}
.muban_icons_blue{font-size: 12px;padding: 0 5px;border-radius: 3px;line-height: 14px;color: #3b94d6;border: 1px solid #3b94d6;}
/*模板buttons 20161013byLB*/
.btn{display: inline-block;border:none; padding:0 10px;color: #333;background: #e1e1e1; text-align:center;font-size: 12px; height: 30px;line-height: 30px;-webkit-border-radius: 3px;-moz-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; }
.btn:hover{background: #c3c3c3; color: #333;}
.btn-green{background: #60b25e; color: #fff;}
.btn-green:hover{background: #51a74f; color: #fff;}
.btn-blue{background: #3b94d6; color: #fff;}
.btn-blue:hover{background: #2788d0; color: #fff;}
.btn-orange{background:#ff7b33; color: #fff;}
.btn-orange:hover{background:#ee4a1f; color: #fff;}
.btn-line{display: inline-block;border:none; padding:0 10px;color: #333;background:#fff; border: 1px solid #d5d5d5; text-align:center;font-size: 12px; height: 30px;line-height: 30px;-webkit-border-radius: 3px;-moz-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; }
.btn-line:hover{background:#eee; }
.btn-line-green{border: 1px solid #51a74f; color: #51a74f;}
.btn-line-green:hover{ background: #51a74f; color: #fff;}
.btn-line-blue{border: 1px solid #2788d0; color: #2788d0;}
.btn-line-blue:hover{ background: #2788d0; color: #fff;}
.btn-line-orange{border: 1px solid #ee4a1f; color: #ee4a1f;}
.btn-line-orange:hover{ background: #ee4a1f; color: #fff;}
.btn-small{ padding: 0px 10px; font-size: 12px;line-height: 20px; background-image: linear-gradient(#fcfcfc, #eee); border: 1px solid #d5d5d5;-webkit-border-radius: 3px;-moz-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; color: #333;}
.btn-small:hover{background-image:linear-gradient(#ededed, #dddddd);}
.sub_btn{ cursor:pointer; -moz-border-radius:3px; -webkit-border-radius:3px; border:1px solid #707070; color:#000; border-radius:3px; padding:1px 10px; background:#dbdbdb;}
.sub_btn:hover{ background:#b5e2fa; color:#000; border:1px solid #3c7fb1;}
/*模板a标签按钮 20161013byLB*/
a.btn{display: inline-block;border:none; padding:0 10px;color: #333;background: #e1e1e1; text-align:center;font-size: 12px; height: 30px;line-height: 30px;-webkit-border-radius: 3px;-moz-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; }
a:hover.btn{background: #c3c3c3; color: #333;}
a.btn-green{background: #60b25e; color: #fff;}
a:hover.btn-green{background: #51a74f; color: #fff;}
a.btn-blue{background: #3b94d6; color: #fff;}
a:hover.btn-blue{background: #2788d0; color: #fff;}
a.btn-orange{background:#ff7b33; color: #fff;}
a:hover.btn-orange:hover{background:#ee4a1f; color: #fff;}
a.btn-line{display: inline-block;border:none; padding:0 10px;color: #333;background:#fff; border: 1px solid #d5d5d5; text-align:center;font-size: 12px; height: 30px;line-height: 30px;-webkit-border-radius: 3px;-moz-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; }
a:hover.btn-line{background:#eee; }
a.btn-line-green{border: 1px solid #51a74f; color: #51a74f;}
a:hover.btn-line-green{ background: #51a74f; color: #fff;}
a.btn-line-blue{border: 1px solid #2788d0; color: #2788d0;}
a:hover.btn-line-blue{ background: #2788d0; color: #fff;}
a.btn-line-orange{border: 1px solid #ee4a1f; color: #ee4a1f;}
a:hover.btn-line-orange{ background: #ee4a1f; color: #fff;}
a.btn-small{ padding: 0px 10px; font-size: 12px;line-height: 20px; background-image: linear-gradient(#fcfcfc, #eee); border: 1px solid #d5d5d5;-webkit-border-radius: 3px;-moz-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; color: #333;}
a:hover.btn-small{background-image:linear-gradient(#ededed, #dddddd);}
a.sub_btn{ cursor:pointer; -moz-border-radius:3px; -webkit-border-radius:3px; border:1px solid #707070; color:#000; border-radius:3px; padding:1px 10px; background:#dbdbdb;}
a:hover.sub_btn{ background:#b5e2fa; color:#000; border:1px solid #3c7fb1;}
/*模板form 20161013byLB*/
textarea.muban_textarea{ width: 98.5%;border:1px solid #ddd; background:#fff; color:#666; padding:5px;}

View File

@ -894,4 +894,7 @@ a.sy_btn_pink{
-o-border-radius:3px;
border-radius:3px;
}
a:hover.sy_btn_pink{ background: #e64c4c;}
a:hover.sy_btn_pink{ background: #e64c4c;}
/*项目历史版本删除功能*/
.popup_ziyuan_title{ display: block; margin-left: 10px; text-align: left;width:360px; overflow:hidden;white-space: nowrap; text-overflow:ellipsis;}