Feature #21106 » note_edit_with_attachment.patch
| app/controllers/journals_controller.rb | ||
|---|---|---|
|
journal_attributes = params[:journal]
|
||
|
journal_attributes[:updated_by] = User.current
|
||
|
@journal.safe_attributes = journal_attributes
|
||
|
@issue = @journal.issue
|
||
|
@issue.save_attachments(params[:attachments])
|
||
|
@issue.save
|
||
|
@journal.save
|
||
|
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
|
||
|
call_hook(:controller_journals_edit_post, {:journal => @journal, :params => params})
|
||
| app/views/journals/_notes_form.html.erb | ||
|---|---|---|
|
<%= form_tag(journal_path(@journal),
|
||
|
:remote => true,
|
||
|
:method => 'put',
|
||
|
:multipart => true,
|
||
|
:id => "journal-#{@journal.id}-form") do %>
|
||
|
<%= label_tag "notes", l(:description_notes), :class => "hidden-for-sighted", :for => "journal_#{@journal.id}_notes" %>
|
||
|
<%= textarea_tag 'journal[notes]', @journal.notes, :id => "journal_#{@journal.id}_notes", :class => 'wiki-edit',
|
||
|
:rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min),
|
||
|
:data => {
|
||
|
:auto_complete => true
|
||
|
}.merge(list_autofill_data_attributes)
|
||
|
%>
|
||
|
<% if @journal.safe_attribute? 'private_notes' %>
|
||
|
<%= hidden_field_tag 'journal[private_notes]', '0' %>
|
||
|
<%= check_box_tag 'journal[private_notes]', '1', @journal.private_notes, :id => "journal_#{@journal.id}_private_notes" %>
|
||
|
<label for="journal_<%= @journal.id %>_private_notes"><%= l(:field_private_notes) %></label>
|
||
|
<% end %>
|
||
|
<%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %>
|
||
|
<p><%= submit_tag l(:button_save) %>
|
||
|
<%= link_to l(:button_cancel), '#', :onclick => "$('#journal-#{@journal.id}-form').remove(); $('#journal-#{@journal.id}-notes').show(); return false;" %></p>
|
||
|
<div class="box">
|
||
|
<%= textarea_tag 'journal[notes]', @journal.notes, :id => "journal_#{@journal.id}_notes", :class => 'wiki-edit',
|
||
|
:rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min),
|
||
|
:data => {
|
||
|
:auto_complete => true
|
||
|
}.merge(list_autofill_data_attributes)
|
||
|
%>
|
||
|
<% if @journal.safe_attribute? 'private_notes' %>
|
||
|
<%= hidden_field_tag 'journal[private_notes]', '0' %>
|
||
|
<%= check_box_tag 'journal[private_notes]', '1', @journal.private_notes, :id => "journal_#{@journal.id}_private_notes" %>
|
||
|
<label for="journal_<%= @journal.id %>_private_notes"><%= l(:field_private_notes) %></label>
|
||
|
<% end %>
|
||
|
<%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %>
|
||
|
<p><%= render :partial => 'attachments/form', :locals => {:container => @journal.issue} %></p>
|
||
|
<p><%= submit_tag l(:button_save) %>
|
||
|
<%= link_to l(:button_cancel), '#', :onclick => "$('#journal-#{@journal.id}-form').remove(); $('#journal-#{@journal.id}-notes').show(); return false;" %></p>
|
||
|
</div>
|
||
|
<% end %>
|
||
|
<%= wikitoolbar_for "journal_#{@journal.id}_notes", preview_issue_path(:project_id => @project, :issue_id => @journal.issue) %>
|
||
|
<%= javascript_tag do %>
|
||
|
$(document).ready(setupFileDrop);
|
||
|
<% end %>
|
||
| test/functional/journals_controller_test.rb | ||
|---|---|---|
|
assert_nil Journal.find_by_id(2)
|
||
|
assert_include 'change-2', response.body
|
||
|
end
|
||
|
def test_update_with_attachments
|
||
|
set_tmp_attachments_directory
|
||
|
@request.session[:user_id] = 1
|
||
|
post(
|
||
|
:update,
|
||
|
:params => {
|
||
|
:id => 2,
|
||
|
:journal => {
|
||
|
:notes => 'Updated notes'
|
||
|
},
|
||
|
:attachments => {
|
||
|
'1' => {
|
||
|
'file' => uploaded_test_file('2010/11/101123161450_testfile_1.png', 'image/png'),
|
||
|
'description' => 'update_with_attachments'
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
:xhr => true
|
||
|
)
|
||
|
assert_response :success
|
||
|
assert_equal 'text/javascript', response.media_type
|
||
|
journal = Journal.find(2)
|
||
|
assert_equal 'Updated notes', journal.notes
|
||
|
attachment = Attachment.order(id: :desc).first
|
||
|
issue = Issue.find(journal.journalized_id)
|
||
|
assert_equal issue, attachment.container
|
||
|
assert_equal 1, attachment.author_id
|
||
|
assert_equal '101123161450_testfile_1.png', attachment.filename
|
||
|
assert_equal 'image/png', attachment.content_type
|
||
|
assert_equal 'update_with_attachments', attachment.description
|
||
|
assert_equal 2654, attachment.filesize
|
||
|
assert File.exist?(attachment.diskfile)
|
||
|
assert_equal 2654, File.size(attachment.diskfile)
|
||
|
end
|
||
|
end
|
||