Defect #28953 » diff-r17442.patch
| app/controllers/attachments_controller.rb | ||
|---|---|---|
| 149 | 149 | |
| 150 | 150 |
respond_to do |format| |
| 151 | 151 |
format.html { redirect_to_referer_or project_path(@project) }
|
| 152 |
format.js |
|
| 152 |
format.js { render :json => {:id => @attachment.id, :attachments_count => @attachment.container.attachments.length}, :content_type => 'application/json' if @attachment.container }
|
|
| 153 | 153 |
format.api { render_api_ok }
|
| 154 | 154 |
end |
| 155 | 155 |
end |
| app/views/attachments/_links.html.erb | ||
|---|---|---|
| 6 | 6 |
:class => 'icon-only icon-edit' |
| 7 | 7 |
) if options[:editable] %> |
| 8 | 8 |
</div> |
| 9 |
<table> |
|
| 9 |
<table id="existing-attachments-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 %> |
| 44 | 44 |
<% end %> |
| 45 | 45 |
</div> |
| 46 |
<%= javascript_tag do %> |
|
| 47 |
$('a.delete').on('ajax:success', function(event, data, status, xhr){
|
|
| 48 |
$('tr#attachment-' + data.id + ', div#thumbnail-' + data.id).remove();
|
|
| 49 |
if (data.attachments_count=='0'){ $('div.attachments div.contextual, table#existing-attachments-table, div.thumbnails').remove(); }
|
|
| 50 |
}); |
|
| 51 |
<% end %> |
|
| app/views/issues/_edit.html.erb | ||
|---|---|---|
| 44 | 44 |
<div class="contextual"><%= link_to l(:label_edit_attachments), '#', :onclick => "$('#existing-attachments').toggle(); return false;" %></div>
|
| 45 | 45 |
<div id="existing-attachments" style="<%= @issue.deleted_attachment_ids.blank? ? 'display:none;' : '' %>"> |
| 46 | 46 |
<% @issue.attachments.each do |attachment| %> |
| 47 |
<span class="existing-attachment"> |
|
| 47 |
<span class="existing-attachment" id="existing-attachment-<%= attachment.id %>">
|
|
| 48 | 48 |
<%= text_field_tag '', attachment.filename, :class => "icon icon-attachment filename", :disabled => true %> |
| 49 | 49 |
<label> |
| 50 | 50 |
<%= check_box_tag 'issue[deleted_attachment_ids][]', |
| ... | ... | |
| 78 | 78 |
<% end %> |
| 79 | 79 | |
| 80 | 80 |
<div id="preview" class="wiki"></div> |
| 81 |
<%= javascript_tag do %> |
|
| 82 |
$('a.delete').on('ajax:success', function(event, data, status, xhr){
|
|
| 83 |
$('span#existing-attachment-' + data.id).remove();
|
|
| 84 |
if (data.attachments_count=='0'){ $('fieldset div.contextual, div#existing-attachments').remove(); }
|
|
| 85 |
}); |
|
| 86 |
<% end %> |
|
| 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 %> |
| ... | ... | |
| 84 | 84 |
<% end %> |
| 85 | 85 | |
| 86 | 86 |
<% html_title @page.pretty_title %> |
| 87 |
<%= javascript_tag do %> |
|
| 88 |
$('a.delete').on('ajax:success', function(event, data, status, xhr){
|
|
| 89 |
$('span#attachments-count').html(data.attachments_count);
|
|
| 90 |
}); |
|
| 91 |
<% end %> |
|
| 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_attachment_container_exist |
|
| 612 |
set_tmp_attachments_directory |
|
| 613 |
@request.session[:user_id] = 2 |
|
| 614 |
assert_difference 'Attachment.count', -1 do |
|
| 615 |
delete :destroy, :params => {
|
|
| 616 |
:id => 9 |
|
| 617 |
}, |
|
| 618 |
:xhr => true |
|
| 619 |
assert_response :success |
|
| 620 |
assert_equal 'application/json', response.content_type |
|
| 621 |
end |
|
| 622 |
end |
|
| 623 | ||
| 624 |
def test_destroy_xhr_attachment_container_not_exist |
|
| 625 |
set_tmp_attachments_directory |
|
| 626 |
@request.session[:user_id] = 2 |
|
| 627 |
Attachment.find(9).update_attributes(:container_id => nil) |
|
| 628 |
assert_difference 'Attachment.count', -1 do |
|
| 629 |
delete :destroy, :params => {
|
|
| 630 |
:id => 9 |
|
| 631 |
}, |
|
| 632 |
:xhr => true |
|
| 633 |
assert_response :success |
|
| 634 |
assert_equal 'text/javascript', response.content_type |
|
| 635 |
end |
|
| 636 |
end |
|
| 610 | 637 |
end |
- « Previous
- 1
- 2
- 3
- Next »