Skip to content

Commit

Permalink
Refactor: Extract inline rjs to template
Browse files Browse the repository at this point in the history
  • Loading branch information
edavis10 committed Feb 16, 2010
1 parent 7f0ecbc commit 0eaf4ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
19 changes: 3 additions & 16 deletions app/controllers/bulk_time_entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,10 @@ def load_assigned_issues
def save
if request.post?
@time_entries = params[:time_entries]

render :update do |page|
@time_entries.each_pair do |html_id, entry|
@time_entry = TimeEntry.create_bulk_time_entry(entry)
if @time_entry.new_record?
page.replace "entry_#{html_id}", :partial => 'time_entry', :object => @time_entry
else
time_entry_target = if @time_entry.issue
"#{h(@time_entry.project.name)} - #{h(@time_entry.issue.subject)}"
else
"#{h(@time_entry.project.name)}"
end
page.replace_html "entry_#{html_id}", "<div class='flash notice'>#{l(:text_time_added_to_project, :count => @time_entry.hours, :target => time_entry_target)}#{" (#{@time_entry.comments})" unless @time_entry.comments.blank?}.</div>"
end
end
respond_to do |format|
format.js {}
end
end
end
end

def add_entry
Expand Down
13 changes: 13 additions & 0 deletions app/views/bulk_time_entries/save.js.rjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@time_entries.each_pair do |html_id, entry|
@time_entry = TimeEntry.create_bulk_time_entry(entry)
if @time_entry.new_record?
page.replace "entry_#{html_id}", :partial => 'time_entry', :object => @time_entry
else
time_entry_target = if @time_entry.issue
"#{h(@time_entry.project.name)} - #{h(@time_entry.issue.subject)}"
else
"#{h(@time_entry.project.name)}"
end
page.replace_html "entry_#{html_id}", "<div class='flash notice'>#{l(:text_time_added_to_project, :count => @time_entry.hours, :target => time_entry_target)}#{" (#{@time_entry.comments})" unless @time_entry.comments.blank?}.</div>"
end
end

0 comments on commit 0eaf4ba

Please sign in to comment.