From 31e8ad98aed4051dfaadab4de161a5b4e271c42f Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 30 Jul 2014 15:48:13 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E7=AB=9E=E8=B5=9B=E4=BD=9C?= =?UTF-8?q?=E5=93=81=E6=AF=8F=E6=AC=A1=E4=BF=AE=E6=94=B9=E4=B9=8B=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E9=83=BD=E4=BC=9A=E5=90=A7=E5=9B=BE=E7=89=87=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E7=9A=84BUG=202.=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E4=BD=9C=E5=93=81=E5=9B=BE=E7=89=87=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 11 +++++++++++ app/controllers/softapplications_controller.rb | 4 ++-- app/views/attachments/_links.html.erb | 9 +++++++++ app/views/attachments/delete_softapplications.js.erb | 2 ++ app/views/softapplications/_form.html.erb | 6 ++++-- config/routes.rb | 1 + 6 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 app/views/attachments/delete_softapplications.js.erb diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 0aec29e6a..44d68de26 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -217,6 +217,17 @@ class AttachmentsController < ApplicationController end end + #删除竞赛作品的附件 + def delete_softapplications + @attachment = Attachment.find params[:id] + @softapplication = @attachment.container if @attachment!=nil + @attachment.container.attachments.delete(@attachment) if @attachment!=nil + respond_to do |format| + format.html { redirect_to_referer_or edit_softapplication_path(@softapplication) } + #format.js + end + end + def autocomplete # modify by nwb if params[:project_id] diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index c216a3e93..f2b0a0c83 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -172,8 +172,8 @@ class SoftapplicationsController < ApplicationController # PUT /softapplications/1.json def update # @softapplication = Softapplication.find(params[:id]) - @softapplication.attachments.map{|attach| attach.destroy } - @softapplication.save_attachments(params[:attachments]) + #@softapplication.attachments.map{|attach| attach.destroy } + @softapplication.save_attachments(params[:attachments]) if params[:attachments] #@softapplication.deposit_project = params[:project] @softapplication.project = Project.find_by_id(params[:project]) diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index 4d938707e..cdd1fdd2f 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -18,11 +18,20 @@ :method => :delete, :class => 'delete', :title => l(:button_delete) %> + <%# elsif attachment.container_type == 'Softapplication'%> + <%#= link_to image_tag('delete.png'), delete_softapplications_attachments_path(:id => attachment.id), + :data => {:confirm => l(:text_are_you_sure)}, + :method => :delete, + :class => 'delete', + :remote => true, + :title => l(:button_delete) %> <% else %> <%= link_to image_tag('delete.png'), attachment_path(attachment), :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :class => 'delete', + :remote => true, + #:id => "attachments_" + attachment.id.to_s, :title => l(:button_delete) %> <% end %> <% end %> diff --git a/app/views/attachments/delete_softapplications.js.erb b/app/views/attachments/delete_softapplications.js.erb new file mode 100644 index 000000000..95085ba93 --- /dev/null +++ b/app/views/attachments/delete_softapplications.js.erb @@ -0,0 +1,2 @@ +<% options = {:author => true, :deletable => true} %> +$("#soft_attachments_links").html('<%= escape_javascript(render(:partial => 'links', :locals => {:attachments => @softapplication.attachments, :options => options} )) %>'); \ No newline at end of file diff --git a/app/views/softapplications/_form.html.erb b/app/views/softapplications/_form.html.erb index 58f8093a6..17cb20598 100644 --- a/app/views/softapplications/_form.html.erb +++ b/app/views/softapplications/_form.html.erb @@ -102,8 +102,10 @@

<% options = {:author => true, :deletable => true} %> - <%= render :partial => 'attachments/links', - :locals => {:attachments => @softapplication.attachments, :options => options} %> + + <%= render :partial => 'attachments/links', + :locals => {:attachments => @softapplication.attachments, :options => options} %> +

<%=l(:label_upload_softworkpacket_photo)%> <%= render_flash_messages %> diff --git a/config/routes.rb b/config/routes.rb index 8d55fe300..af70b76da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -520,6 +520,7 @@ RedmineApp::Application.routes.draw do match "updateType" , via: [:get, :post] match "updateFileDense" , via: [:get, :post] match "renderTag" , via: [:get, :post] + match 'delete_softapplications', via: [:get, :post] end end