Skip to content
Browse files

implemented in_place editing for account view

  • Loading branch information...
1 parent d11e539 commit 8a2746d948f58a844da5955682c53ca4ea6fa97b @huerlisi committed Sep 24, 2007
View
5 app/controllers/accounts_controller.rb
@@ -1,4 +1,9 @@
class AccountsController < ApplicationController
+ # inplace editor declarations
+ in_place_edit_for :booking, :title
+ in_place_edit_for :booking, :comments
+ in_place_edit_for :booking, :in_place_amount
+
def index
list
render :action => 'list'
View
4 app/helpers/application_helper.rb
@@ -4,4 +4,8 @@ def sort_header(column, label = nil)
label ||= column.humanize
content_tag('th', label + ' ' + link_to(image_tag('up'), :order => column) + link_to(image_tag('down'), :order => column + ' DESC'))
end
+
+ def currency_fmt(value)
+ sprintf("%.2f", value)
+ end
end
View
8 app/models/booking.rb
@@ -12,6 +12,14 @@ def rounded_amount
end
end
+ def in_place_amount
+ sprintf("%.2f", self.amount)
+ end
+
+ def in_place_amount=(value)
+ self.amount=value
+ end
+
def value_date=(value)
if value.is_a?(String)
day, month, year = value.split('.')
View
19 app/views/accounts/show.rhtml
@@ -29,33 +29,34 @@
</tr>
<% total_debit = 0; total_credit = 0 %>
<% for booking in @account.bookings %>
+ <% @booking = booking %>
<% total_debit += booking.amount if booking.debit_account == @account %>
<% total_credit += booking.amount if booking.credit_account == @account %>
<tr style="border-top: 2px">
<td style="border: 0 none; border-top: 2px solid"><%=h booking.value_date.strftime('%d.%m.%Y') %></td>
<td style="border: 0 none; border-top: 2px solid">
- <%=h booking.title %>
+ <%= in_place_editor_field :booking, :title %>
<%= "<hr/>" unless booking.comments.empty? %>
- <%=h booking.comments %>
+ <%= in_place_editor_field :booking, :comments %>
</td>
- <td style="border: 0 none; border-top: 2px solid"><%= booking.amount if booking.debit_account == @account %></td>
- <td style="border: 0 none; border-top: 2px solid"><%= booking.amount if booking.credit_account == @account %></td>
- <td style="border: 0 none; border-top: 2px solid"><%= total_credit - total_debit %></td>
+ <td style="border: 0 none; border-top: 2px solid; text-align: right"><%= in_place_editor_field :booking, :in_place_amount if booking.debit_account == @account %></td>
+ <td style="border: 0 none; border-top: 2px solid; text-align: right"><%= in_place_editor_field :booking, :in_place_amount if booking.credit_account == @account %></td>
+ <td style="border: 0 none; border-top: 2px solid; text-align: right"><%= currency_fmt(total_credit - total_debit) %></td>
<td style="border: 0 none; border-top: 2px solid"><%= link_to h(booking.value_date.strftime("%d.%m.%Y")), :controller => :bookings, :action => :show, :id => booking unless booking.value_date.nil? %></td>
</tr>
<% end %>
<tr style="border-top: double 2px black; background-color: grey">
<td style="border: 0 none; border-top: 2px solid">Umsatz</td>
<td style="border: 0 none; border-top: 2px solid" />
- <td style="border: 0 none; border-top: 2px solid"><%= total_credit %></td>
- <td style="border: 0 none; border-top: 2px solid"><%= total_debit %></td>
+ <td style="border: 0 none; border-top: 2px solid; text-align: right"><%= total_credit %></td>
+ <td style="border: 0 none; border-top: 2px solid; text-align: right"><%= total_debit %></td>
<td style="border: 0 none; border-top: 2px solid" />
<td style="border: 0 none; border-top: 2px solid" /> </tr>
<tr style="border-top: double 2px black; background-color: grey">
- <td colspan="2" style="border: 0 none; border-top: 2px solid">Aktueller Kontostand (per <%= DateTime.now.strftime("%d.%m.%Y %H.%M") %></td>
+ <td colspan="2" style="border: 0 none; border-top: 2px solid">Aktueller Kontostand (per <%= DateTime.now.strftime("%d.%m.%Y %H:%M") %>)</td>
<td style="border: 0 none; border-top: 2px solid" />
<td style="border: 0 none; border-top: 2px solid" />
- <td style="border: 0 none; border-top: 2px solid"><%= total_credit - total_debit %></td>
+ <td style="border: 0 none; border-top: 2px solid; text-align: right"><%= total_credit - total_debit %></td>
<td style="border: 0 none; border-top: 2px solid" />
</tr>
</table>
View
4 config/environment.rb
@@ -50,4 +50,6 @@
# inflect.uncountable %w( fish sheep )
# end
-# Include your application configuration below
+# Include your application configuration below
+require 'float.rb'
+
View
17 lib/float.rb
@@ -0,0 +1,17 @@
+class Float
+ def size
+ to_s.size
+ end
+
+ def strip
+ to_s
+ end
+
+ def currency_round
+ (self * 20).round / 20.0
+ end
+
+ def currency_fmt
+ sprintf("%.2f", self.currency_round)
+ end
+end

0 comments on commit 8a2746d

Please sign in to comment.
Something went wrong with that request. Please try again.