cache_sweeper :issue_sweeper, :only => [ :new, :edit, :update, :destroy ]
+ helper :journals
helper :projects
include ProjectsHelper
helper :custom_fields
--- /dev/null
+# redMine - project management software
+# Copyright (C) 2006-2008 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+class JournalsController < ApplicationController
+ layout 'base'
+ before_filter :find_journal
+
+ def edit
+ if request.post?
+ @journal.update_attributes(:notes => params[:notes]) if params[:notes]
+ respond_to do |format|
+ format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
+ format.js { render :action => 'update' }
+ end
+ return
+ end
+ end
+
+private
+ def find_journal
+ @journal = Journal.find(params[:id])
+ render_403 and return false unless @journal.editable_by?(User.current)
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+end
--- /dev/null
+# redMine - project management software
+# Copyright (C) 2006-2008 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+module JournalsHelper
+ def render_notes(journal, options={})
+ content = ''
+ editable = journal.editable_by?(User.current)
+ if editable
+ links = []
+ links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
+ { :controller => 'journals', :action => 'edit', :id => journal },
+ :title => l(:button_edit))
+ content << content_tag('div', links.join(' '), :class => 'contextual')
+ end
+ content << textilizable(journal, :notes)
+ content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => (editable ? 'editable' : nil))
+ end
+
+ def link_to_in_place_notes_editor(text, field_id, url, options={})
+ onclick = "new Ajax.Request('#{url_for(url)}', {asynchronous:true, evalScripts:true, method:'get'}); return false;"
+ link_to text, '#', options.merge(:onclick => onclick)
+ end
+end
c = details.detect {|detail| detail.prop_key == prop}
c ? c.value : nil
end
+
+ def editable_by?(usr)
+ usr && usr.admin?
+ end
end
<li><%= show_detail(detail) %></li>
<% end %>
</ul>
- <%= textilizable(journal.notes) unless journal.notes.blank? %>
+ <%= render_notes(journal) unless journal.notes.blank? %>
<% note_id += 1 %>
<% end %>
--- /dev/null
+<% form_remote_tag(:url => {}, :html => { :id => "journal-#{@journal.id}-form" }) do %>
+ <%= text_area_tag :notes, @journal.notes, :class => 'wiki-edit',
+ :rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %>
+ <p><%= submit_tag l(:button_save) %>
+ <%= link_to l(:button_cancel), '#', :onclick => "Element.remove('journal-#{@journal.id}-form'); " +
+ "Element.show('journal-#{@journal.id}-notes'); return false;" %></p>
+<% end %>
--- /dev/null
+page.hide "journal-#{@journal.id}-notes"
+page.insert_html :after, "journal-#{@journal.id}-notes",
+ :partial => 'notes_form'
--- /dev/null
+page.replace "journal-#{@journal.id}-notes", render_notes(@journal)
+page.show "journal-#{@journal.id}-notes"
+page.remove "journal-#{@journal.id}-form"
width: .6em; height: .6em;
}
-.contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px;font-size:0.9em;}
+.contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px; padding-left: 10px; font-size:0.9em;}
.contextual input {font-size:0.9em;}
.splitcontentleft{float:left; width:49%;}
padding:0.6em;
z-index:100;
filter:alpha(opacity=50);
--moz-opacity:0.5;
opacity: 0.5;
-khtml-opacity: 0.5;
}
journalized_type: Issue\r
user_id: 1\r
journalized_id: 1\r
+journals_002: \r
+ created_on: <%= 1.days.ago.to_date.to_s(:db) %>\r
+ notes: "Some notes"\r
+ id: 2\r
+ journalized_type: Issue\r
+ user_id: 2\r
+ journalized_id: 1\r
+
\ No newline at end of file
--- /dev/null
+# redMine - project management software
+# Copyright (C) 2006-2008 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'journals_controller'
+
+# Re-raise errors caught by the controller.
+class JournalsController; def rescue_action(e) raise e end; end
+
+class JournalsControllerTest < ActionController::TestCase
+ fixtures :projects, :users, :members, :roles, :issues, :journals, :journal_details, :enabled_modules
+
+ def setup
+ @controller = JournalsController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ User.current = nil
+ end
+
+ def test_get_edit
+ @request.session[:user_id] = 1
+ xhr :get, :edit, :id => 2
+ assert_response :success
+ assert_select_rjs :insert, :after, 'journal-2-notes' do
+ assert_select 'form[id=journal-2-form]'
+ assert_select 'textarea'
+ end
+ end
+
+ def test_post_edit
+ @request.session[:user_id] = 1
+ xhr :post, :edit, :id => 2, :notes => 'Updated notes'
+ assert_response :success
+ assert_select_rjs :replace, 'journal-2-notes'
+ assert_equal 'Updated notes', Journal.find(2).notes
+ end
+end