Permalink
Browse files

edit checkpoint/expenditure notes

  • Loading branch information...
nackd committed Sep 26, 2011
1 parent d908272 commit 1a408741aa724326f7a00d335997c3e6bc27e9b6
@@ -104,6 +104,27 @@ def new_journal
}
end
+ def edit_journal
+ @journal = Journal.find(params[:id])
+ (render_403; return false) unless @journal.editable_by?(User.current)
+ if request.post?
+ @journal.update_attributes(:notes => params[:notes]) if params[:notes]
+ @journal.destroy if @journal.details.empty? && @journal.notes.blank?
+ respond_to do |format|
+ format.html { redirect_to :action => 'show', :id => @journal.journalized_id }
+ format.js { render :template => 'metrics/update' }
+ end
+ else
+ respond_to do |format|
+ format.html {
+ # TODO: implement non-JS journal update
+ render :nothing => true
+ }
+ format.js { render :template => 'metrics/edit_journal' }
+ end
+ end
+ end
+
private
def find_checkpoint
@@ -103,6 +103,27 @@ def new_journal
}
end
+ def edit_journal
+ @journal = Journal.find(params[:id])
+ (render_403; return false) unless @journal.editable_by?(User.current)
+ if request.post?
+ @journal.update_attributes(:notes => params[:notes]) if params[:notes]
+ @journal.destroy if @journal.details.empty? && @journal.notes.blank?
+ respond_to do |format|
+ format.html { redirect_to :action => 'show', :id => @journal.journalized_id }
+ format.js { render :template => 'metrics/update' }
+ end
+ else
+ respond_to do |format|
+ format.html {
+ # TODO: implement non-JS journal update
+ render :nothing => true
+ }
+ format.js { render :template => 'metrics/edit_journal' }
+ end
+ end
+ end
+
private
def find_expenditure
@@ -97,7 +97,7 @@ def render_notes(model, journal, options={})
{ :url => {:action => 'new_journal', :id => model, :journal_id => journal} },
:title => l(:button_quote)) if options[:reply_links]
links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
- { :controller => 'journals', :action => 'edit', :id => journal },
+ { :action => 'edit_journal', :id => journal },
:title => l(:button_edit)) if editable
end
content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty?
@@ -0,0 +1,20 @@
+<% form_remote_tag(:url => {}, :html => { :id => "journal-#{@journal.id}-form" }) do %>
+ <%= text_area_tag :notes, @journal.notes,
+ :id => "journal_#{@journal.id}_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_remote l(:label_preview),
+ { :url => {:action => 'preview', :id => @journal.journalized, :project_id => @journal.project},
+ :method => 'put',
+ :update => "journal_#{@journal.id}_preview",
+ :with => "Form.serialize('journal-#{@journal.id}-form')",
+ :complete => "Element.scrollTo('journal_#{@journal.id}_preview')"
+ }, :accesskey => accesskey(:preview) %>
+ |
+ <%= link_to l(:button_cancel), '#', :onclick => "Element.remove('journal-#{@journal.id}-form'); " +
+ "Element.show('journal-#{@journal.id}-notes'); return false;" %></p>
+ <div id="journal_<%= @journal.id %>_preview" class="wiki"></div>
+<% end %>
+<%= wikitoolbar_for "journal_#{@journal.id}_notes" %>
@@ -0,0 +1,20 @@
+<% form_remote_tag(:url => {}, :html => { :id => "journal-#{@journal.id}-form" }) do %>
+ <%= text_area_tag :notes, @journal.notes,
+ :id => "journal_#{@journal.id}_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_remote l(:label_preview),
+ { :url => {:action => 'preview', :id => @journal.journalized, :project_id => @journal.project},
+ :method => 'put',
+ :update => "journal_#{@journal.id}_preview",
+ :with => "Form.serialize('journal-#{@journal.id}-form')",
+ :complete => "Element.scrollTo('journal_#{@journal.id}_preview')"
+ }, :accesskey => accesskey(:preview) %>
+ |
+ <%= link_to l(:button_cancel), '#', :onclick => "Element.remove('journal-#{@journal.id}-form'); " +
+ "Element.show('journal-#{@journal.id}-notes'); return false;" %></p>
+ <div id="journal_<%= @journal.id %>_preview" class="wiki"></div>
+<% end %>
+<%= wikitoolbar_for "journal_#{@journal.id}_notes" %>
@@ -0,0 +1,3 @@
+page.hide "journal-#{@journal.id}-notes"
+page.insert_html :after, "journal-#{@journal.id}-notes",
+ :partial => 'notes_form'
@@ -0,0 +1,8 @@
+if @journal.frozen?
+ # journal was destroyed
+ page.remove "change-#{@journal.id}"
+else
+ page.replace "journal-#{@journal.id}-notes", render_notes(@journal.journalized, @journal, :reply_links => authorize_for(params[:controller], 'new_journal'))
+ page.show "journal-#{@journal.id}-notes"
+ page.remove "journal-#{@journal.id}-form"
+end
View
@@ -1,5 +1,9 @@
ActionController::Routing::Routes.draw do |map|
- map.resources :checkpoints, :path_prefix => '/projects/:project_id/metrics', :member => { :preview => :put, :new_journal => :post }
- map.resources :expenditures, :path_prefix => '/projects/:project_id/expenses', :member => { :preview => :put, :new_journal => :post }
+ map.resources :checkpoints,
+ :path_prefix => '/projects/:project_id/metrics',
+ :member => { :preview => :put, :new_journal => :post, :edit_journal => [:get, :post] }
+ map.resources :expenditures,
+ :path_prefix => '/projects/:project_id/expenses',
+ :member => { :preview => :put, :new_journal => :post, :edit_journal => [:get, :post] }
map.metrics '/projects/:project_id/metrics/:action', :controller => 'metrics'
end
View
@@ -23,8 +23,8 @@
project_module :cmiplugin do
# permission :view_cmi, {:cmi => [:projects, :groups, :show]}
permission :view_metrics, {:metrics => [:show, :info],
- :checkpoints => [:index, :new, :create, :show, :edit, :update, :destroy, :preview, :new_journal],
- :expenditures => [:index, :new, :create, :show, :edit, :update, :destroy, :preview, :new_journal]}
+ :checkpoints => [:index, :new, :create, :show, :edit, :update, :destroy, :preview, :new_journal, :edit_journal],
+ :expenditures => [:index, :new, :create, :show, :edit, :update, :destroy, :preview, :new_journal, :edit_journal]}
end
menu :project_menu, :metrics, {:controller => 'metrics', :action => 'show' }, :caption => :'cmi.caption_metrics', :after => :settings, :param => :project_id
@@ -20,7 +20,7 @@ module ClassMethods
module InstanceMethods
def after_create_with_cmi(journal)
- unless journal.journalized_type == 'CmiCheckpoint'
+ unless [ 'CmiCheckpoint', 'CmiExpenditure'].include? journal.journalized_type
after_create_without_cmi(journal)
end
end

0 comments on commit 1a40874

Please sign in to comment.