Project

General

Profile

Defect #28953 » diff-r17439.patch

Takenori TAKAKI, 2018-07-09 08:27

View differences:

app/views/attachments/_links.html.erb
8 8
</div>
9 9
<table>
10 10
<% for attachment in attachments %>
11
<tr>
11
<tr id="attachment_<%= attachment.id %>">
12 12
  <td>
13 13
    <%= link_to_attachment attachment, class: 'icon icon-attachment' -%>
14 14
    <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
......
23 23
  <td>
24 24
    <% if options[:deletable] %>
25 25
      <%= link_to l(:button_delete), attachment_path(attachment),
26
                  :data => {:confirm => l(:text_are_you_sure)},
26
                  :data => {:confirm => l(:text_are_you_sure), :remote => true},
27 27
                  :method => :delete,
28 28
                  :class => 'delete icon-only icon-del',
29 29
                  :title => l(:button_delete) %>
......
37 37
  <% if images.any? %>
38 38
  <div class="thumbnails">
39 39
    <% images.each do |attachment| %>
40
      <div><%= thumbnail_tag(attachment) %></div>
40
      <div id="thumbnail_<%= attachment.id %>"><%= thumbnail_tag(attachment) %></div>
41 41
    <% end %>
42 42
  </div>
43 43
  <% end %>
app/views/attachments/destroy.js.erb
1 1
$('#attachments_<%= j params[:attachment_id] %>').closest('.attachments_form').find('.add_attachment').show();
2
$('#attachments_<%= j params[:attachment_id] %>').remove();
2
$('#attachments_<%= j params[:attachment_id] %>, tr#attachment_<%= j params[:id] %>, div#thumbnail_<%= j params[:id] %>').remove();
3
$('#attachments_count').html('<%= @attachment.container.try(:attachments).try(:length) %>');
app/views/wiki/show.html.erb
46 46
<%= render(:partial => "wiki/content", :locals => {:content => @content}) %>
47 47

  
48 48
<fieldset class="collapsible collapsed">
49
  <legend onclick="toggleFieldset(this);"><%= l(:label_attachment_plural) %> (<%= @page.attachments.length %>)</legend>
49
  <legend onclick="toggleFieldset(this);"><%= l(:label_attachment_plural) %> (<span id="attachments_count"><%= @page.attachments.length %></span>)</legend>
50 50
  <div style="display: none;">
51 51

  
52 52
  <%= link_to_attachments @page, :thumbnails => true %>
test/functional/attachments_controller_test.rb
607 607
    assert_response 302
608 608
    assert Attachment.find_by_id(3)
609 609
  end
610

  
611
  def test_destroy_xhr
612
    set_tmp_attachments_directory
613
    @request.session[:user_id] = 2
614
    @attachment_count = Attachment.find(9).container.try(:attachments).try(:length)
615
    assert_difference 'Attachment.count', -1 do
616
      delete :destroy, :params => {
617
          :id => 9
618
        },
619
        :xhr => true
620
      assert_response :success
621
      assert_equal 'text/javascript', response.content_type
622
      assert_include (@attachment_count - 1).to_s, response.body
623
    end
624
  end
610 625
end
(1-1/3)