Feature #21106 » note_edit_with_attachment.patch
| app/controllers/journals_controller.rb | ||
|---|---|---|
| 88 | 88 |
journal_attributes = params[:journal] |
| 89 | 89 |
journal_attributes[:updated_by] = User.current |
| 90 | 90 |
@journal.safe_attributes = journal_attributes |
| 91 |
@issue = @journal.issue |
|
| 92 |
@issue.save_attachments(params[:attachments]) |
|
| 93 |
@issue.save |
|
| 91 | 94 |
@journal.save |
| 92 | 95 |
@journal.destroy if @journal.details.empty? && @journal.notes.blank? |
| 93 | 96 |
call_hook(:controller_journals_edit_post, {:journal => @journal, :params => params})
|
| app/views/journals/_notes_form.html.erb | ||
|---|---|---|
| 1 | 1 |
<%= form_tag(journal_path(@journal), |
| 2 | 2 |
:remote => true, |
| 3 | 3 |
:method => 'put', |
| 4 |
:multipart => true, |
|
| 4 | 5 |
:id => "journal-#{@journal.id}-form") do %>
|
| 5 | 6 |
<%= label_tag "notes", l(:description_notes), :class => "hidden-for-sighted", :for => "journal_#{@journal.id}_notes" %>
|
| 6 |
<%= textarea_tag 'journal[notes]', @journal.notes, :id => "journal_#{@journal.id}_notes", :class => 'wiki-edit',
|
|
| 7 |
:rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min), |
|
| 8 |
:data => {
|
|
| 9 |
:auto_complete => true |
|
| 10 |
}.merge(list_autofill_data_attributes) |
|
| 11 |
%> |
|
| 12 |
<% if @journal.safe_attribute? 'private_notes' %> |
|
| 13 |
<%= hidden_field_tag 'journal[private_notes]', '0' %> |
|
| 14 |
<%= check_box_tag 'journal[private_notes]', '1', @journal.private_notes, :id => "journal_#{@journal.id}_private_notes" %>
|
|
| 15 |
<label for="journal_<%= @journal.id %>_private_notes"><%= l(:field_private_notes) %></label> |
|
| 16 |
<% end %> |
|
| 17 |
<%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %>
|
|
| 18 |
<p><%= submit_tag l(:button_save) %> |
|
| 19 |
<%= link_to l(:button_cancel), '#', :onclick => "$('#journal-#{@journal.id}-form').remove(); $('#journal-#{@journal.id}-notes').show(); return false;" %></p>
|
|
| 7 | ||
| 8 |
<div class="box"> |
|
| 9 |
<%= textarea_tag 'journal[notes]', @journal.notes, :id => "journal_#{@journal.id}_notes", :class => 'wiki-edit',
|
|
| 10 |
:rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min), |
|
| 11 |
:data => {
|
|
| 12 |
:auto_complete => true |
|
| 13 |
}.merge(list_autofill_data_attributes) |
|
| 14 |
%> |
|
| 15 |
<% if @journal.safe_attribute? 'private_notes' %> |
|
| 16 |
<%= hidden_field_tag 'journal[private_notes]', '0' %> |
|
| 17 |
<%= check_box_tag 'journal[private_notes]', '1', @journal.private_notes, :id => "journal_#{@journal.id}_private_notes" %>
|
|
| 18 |
<label for="journal_<%= @journal.id %>_private_notes"><%= l(:field_private_notes) %></label> |
|
| 19 |
<% end %> |
|
| 20 | ||
| 21 |
<%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %>
|
|
| 22 |
<p><%= render :partial => 'attachments/form', :locals => {:container => @journal.issue} %></p>
|
|
| 23 |
<p><%= submit_tag l(:button_save) %> |
|
| 24 |
<%= link_to l(:button_cancel), '#', :onclick => "$('#journal-#{@journal.id}-form').remove(); $('#journal-#{@journal.id}-notes').show(); return false;" %></p>
|
|
| 25 |
</div> |
|
| 20 | 26 |
<% end %> |
| 21 | 27 |
<%= wikitoolbar_for "journal_#{@journal.id}_notes", preview_issue_path(:project_id => @project, :issue_id => @journal.issue) %>
|
| 28 | ||
| 29 |
<%= javascript_tag do %> |
|
| 30 |
$(document).ready(setupFileDrop); |
|
| 31 |
<% end %> |
|
| 32 | ||
| test/functional/journals_controller_test.rb | ||
|---|---|---|
| 366 | 366 |
assert_nil Journal.find_by_id(2) |
| 367 | 367 |
assert_include 'change-2', response.body |
| 368 | 368 |
end |
| 369 | ||
| 370 |
def test_update_with_attachments |
|
| 371 |
set_tmp_attachments_directory |
|
| 372 | ||
| 373 |
@request.session[:user_id] = 1 |
|
| 374 |
post( |
|
| 375 |
:update, |
|
| 376 |
:params => {
|
|
| 377 |
:id => 2, |
|
| 378 |
:journal => {
|
|
| 379 |
:notes => 'Updated notes' |
|
| 380 |
}, |
|
| 381 |
:attachments => {
|
|
| 382 |
'1' => {
|
|
| 383 |
'file' => uploaded_test_file('2010/11/101123161450_testfile_1.png', 'image/png'),
|
|
| 384 |
'description' => 'update_with_attachments' |
|
| 385 |
} |
|
| 386 |
} |
|
| 387 |
}, |
|
| 388 |
:xhr => true |
|
| 389 |
) |
|
| 390 |
assert_response :success |
|
| 391 |
assert_equal 'text/javascript', response.media_type |
|
| 392 | ||
| 393 |
journal = Journal.find(2) |
|
| 394 |
assert_equal 'Updated notes', journal.notes |
|
| 395 | ||
| 396 |
attachment = Attachment.order(id: :desc).first |
|
| 397 |
issue = Issue.find(journal.journalized_id) |
|
| 398 |
assert_equal issue, attachment.container |
|
| 399 |
assert_equal 1, attachment.author_id |
|
| 400 |
assert_equal '101123161450_testfile_1.png', attachment.filename |
|
| 401 |
assert_equal 'image/png', attachment.content_type |
|
| 402 |
assert_equal 'update_with_attachments', attachment.description |
|
| 403 |
assert_equal 2654, attachment.filesize |
|
| 404 |
assert File.exist?(attachment.diskfile) |
|
| 405 |
assert_equal 2654, File.size(attachment.diskfile) |
|
| 406 |
end |
|
| 369 | 407 |
end |