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