Project

General

Profile

Patch #22575 » enable_to_update_private_notes_trunk_r15336.patch

Takenori TAKAKI, 2016-04-18 03:41

View differences:

app/controllers/journals_controller.rb
90 90

  
91 91
  def update
92 92
    (render_403; return false) unless @journal.editable_by?(User.current)
93
    @journal.update_attributes(:notes => params[:notes]) if params[:notes]
93
    @journal.notes = params[:notes] if params[:notes]
94
    @journal.private_notes = (params[:private_notes] || false)
95
    @journal.save if @journal.changed?
94 96
    @journal.destroy if @journal.details.empty? && @journal.notes.blank?
95 97
    call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
96 98
    respond_to do |format|
app/helpers/journals_helper.rb
58 58
    css_classes << " editable" if editable
59 59
    content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
60 60
  end
61

  
62
  def render_private_notes(journal)
63
    content = journal.private_notes? ? l(:field_is_private) : ''
64
    css_classes = journal.private_notes? ? 'private' : ''
65
    content_tag('span', content.html_safe, :id => "journal-#{journal.id}-private_notes", :class => css_classes)
66
  end
61 67
end
app/views/issues/_history.html.erb
5 5
    <h4><a href="#note-<%= journal.indice %>" class="journal-link">#<%= journal.indice %></a>
6 6
    <%= avatar(journal.user, :size => "24") %>
7 7
    <%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %>
8
    <%= content_tag('span', l(:field_is_private), :class => 'private') if journal.private_notes? %></h4>
8
    <%= render_private_notes(journal) %></h4>
9 9

  
10 10
    <% if journal.details.any? %>
11 11
    <ul class="details">
app/views/journals/_notes_form.html.erb
7 7
          :id => "journal_#{@journal.id}_notes",
8 8
          :class => 'wiki-edit',
9 9
          :rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %>
10
    <% if @journal.issue.safe_attribute? 'private_notes' %>
11
      <%= check_box_tag 'private_notes', '1', @journal.private_notes, :id => "journal_#{@journal.id}_private_notes" %> <label for="journal_<%= @journal.id %>_private_notes"><%= l(:field_private_notes) %></label>
12
    <% end %>
10 13
    <%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %>
11 14
    <p><%= submit_tag l(:button_save) %>
12 15
    <%= preview_link preview_edit_issue_path(:project_id => @project, :id => @journal.issue), 
app/views/journals/update.js.erb
1 1
<% if @journal.frozen? %>
2 2
  $("#change-<%= @journal.id %>").remove();
3 3
<% else %>
4
  $("#change-<%= @journal.id %>").attr('class', '<%= @journal.css_classes %>');
4 5
  $("#journal-<%= @journal.id %>-notes").replaceWith('<%= escape_javascript(render_notes(@journal.issue, @journal, :reply_links => authorize_for('issues', 'edit'))) %>');
6
  $("#journal-<%= @journal.id %>-private_notes").replaceWith('<%= escape_javascript(render_private_notes(@journal)) %>');
5 7
  $("#journal-<%= @journal.id %>-notes").show();
6 8
  $("#journal-<%= @journal.id %>-form").remove();
7 9
<% end %>
test/functional/journals_controller_test.rb
207 207
    assert_include 'journal-2-notes', response.body
208 208
  end
209 209

  
210
  def test_update_xhr_with_private_notes_checked
211
    @request.session[:user_id] = 1
212
    xhr :post, :update, :id => 2, :private_notes => '1'
213
    assert_response :success
214
    assert_template 'update'
215
    assert_equal 'text/javascript', response.content_type
216
    assert_equal true, Journal.find(2).private_notes
217
    assert_include 'change-2', response.body
218
    assert_include 'journal-2-private_notes', response.body
219
  end
220

  
221
  def test_update_xhr_with_private_notes_unchecked
222
    @request.session[:user_id] = 1
223
    xhr :post, :update, :id => 2
224
    assert_response :success
225
    assert_template 'update'
226
    assert_equal 'text/javascript', response.content_type
227
    assert_equal false, Journal.find(2).private_notes
228
    assert_include 'change-2', response.body
229
    assert_include 'journal-2-private_notes', response.body
230
  end
231

  
210 232
  def test_update_xhr_with_empty_notes_should_delete_the_journal
211 233
    @request.session[:user_id] = 1
212 234
    assert_difference 'Journal.count', -1 do
(2-2/5)