Defect #28953 » diff-r17442.patch
| app/controllers/attachments_controller.rb | ||
|---|---|---|
|
respond_to do |format|
|
||
|
format.html { redirect_to_referer_or project_path(@project) }
|
||
|
format.js
|
||
|
format.js { render :json => {:id => @attachment.id, :attachments_count => @attachment.container.attachments.length}, :content_type => 'application/json' if @attachment.container }
|
||
|
format.api { render_api_ok }
|
||
|
end
|
||
|
end
|
||
| app/views/attachments/_links.html.erb | ||
|---|---|---|
|
:class => 'icon-only icon-edit'
|
||
|
) if options[:editable] %>
|
||
|
</div>
|
||
|
<table>
|
||
|
<table id="existing-attachments-table">
|
||
|
<% for attachment in attachments %>
|
||
|
<tr>
|
||
|
<tr id="attachment-<%= attachment.id %>">
|
||
|
<td>
|
||
|
<%= link_to_attachment attachment, class: 'icon icon-attachment' -%>
|
||
|
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
||
| ... | ... | |
|
<td>
|
||
|
<% if options[:deletable] %>
|
||
|
<%= link_to l(:button_delete), attachment_path(attachment),
|
||
|
:data => {:confirm => l(:text_are_you_sure)},
|
||
|
:data => {:confirm => l(:text_are_you_sure), :remote => true},
|
||
|
:method => :delete,
|
||
|
:class => 'delete icon-only icon-del',
|
||
|
:title => l(:button_delete) %>
|
||
| ... | ... | |
|
<% if images.any? %>
|
||
|
<div class="thumbnails">
|
||
|
<% images.each do |attachment| %>
|
||
|
<div><%= thumbnail_tag(attachment) %></div>
|
||
|
<div id="thumbnail-<%= attachment.id %>"><%= thumbnail_tag(attachment) %></div>
|
||
|
<% end %>
|
||
|
</div>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
</div>
|
||
|
<%= javascript_tag do %>
|
||
|
$('a.delete').on('ajax:success', function(event, data, status, xhr){
|
||
|
$('tr#attachment-' + data.id + ', div#thumbnail-' + data.id).remove();
|
||
|
if (data.attachments_count=='0'){ $('div.attachments div.contextual, table#existing-attachments-table, div.thumbnails').remove(); }
|
||
|
});
|
||
|
<% end %>
|
||
| app/views/issues/_edit.html.erb | ||
|---|---|---|
|
<div class="contextual"><%= link_to l(:label_edit_attachments), '#', :onclick => "$('#existing-attachments').toggle(); return false;" %></div>
|
||
|
<div id="existing-attachments" style="<%= @issue.deleted_attachment_ids.blank? ? 'display:none;' : '' %>">
|
||
|
<% @issue.attachments.each do |attachment| %>
|
||
|
<span class="existing-attachment">
|
||
|
<span class="existing-attachment" id="existing-attachment-<%= attachment.id %>">
|
||
|
<%= text_field_tag '', attachment.filename, :class => "icon icon-attachment filename", :disabled => true %>
|
||
|
<label>
|
||
|
<%= check_box_tag 'issue[deleted_attachment_ids][]',
|
||
| ... | ... | |
|
<% end %>
|
||
|
<div id="preview" class="wiki"></div>
|
||
|
<%= javascript_tag do %>
|
||
|
$('a.delete').on('ajax:success', function(event, data, status, xhr){
|
||
|
$('span#existing-attachment-' + data.id).remove();
|
||
|
if (data.attachments_count=='0'){ $('fieldset div.contextual, div#existing-attachments').remove(); }
|
||
|
});
|
||
|
<% end %>
|
||
| app/views/wiki/show.html.erb | ||
|---|---|---|
|
<%= render(:partial => "wiki/content", :locals => {:content => @content}) %>
|
||
|
<fieldset class="collapsible collapsed">
|
||
|
<legend onclick="toggleFieldset(this);"><%= l(:label_attachment_plural) %> (<%= @page.attachments.length %>)</legend>
|
||
|
<legend onclick="toggleFieldset(this);"><%= l(:label_attachment_plural) %> (<span id="attachments-count"><%= @page.attachments.length %></span>)</legend>
|
||
|
<div style="display: none;">
|
||
|
<%= link_to_attachments @page, :thumbnails => true %>
|
||
| ... | ... | |
|
<% end %>
|
||
|
<% html_title @page.pretty_title %>
|
||
|
<%= javascript_tag do %>
|
||
|
$('a.delete').on('ajax:success', function(event, data, status, xhr){
|
||
|
$('span#attachments-count').html(data.attachments_count);
|
||
|
});
|
||
|
<% end %>
|
||
| test/functional/attachments_controller_test.rb | ||
|---|---|---|
|
assert_response 302
|
||
|
assert Attachment.find_by_id(3)
|
||
|
end
|
||
|
def test_destroy_xhr_attachment_container_exist
|
||
|
set_tmp_attachments_directory
|
||
|
@request.session[:user_id] = 2
|
||
|
assert_difference 'Attachment.count', -1 do
|
||
|
delete :destroy, :params => {
|
||
|
:id => 9
|
||
|
},
|
||
|
:xhr => true
|
||
|
assert_response :success
|
||
|
assert_equal 'application/json', response.content_type
|
||
|
end
|
||
|
end
|
||
|
def test_destroy_xhr_attachment_container_not_exist
|
||
|
set_tmp_attachments_directory
|
||
|
@request.session[:user_id] = 2
|
||
|
Attachment.find(9).update_attributes(:container_id => nil)
|
||
|
assert_difference 'Attachment.count', -1 do
|
||
|
delete :destroy, :params => {
|
||
|
:id => 9
|
||
|
},
|
||
|
:xhr => true
|
||
|
assert_response :success
|
||
|
assert_equal 'text/javascript', response.content_type
|
||
|
end
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- 2
- 3
- Next »