Skip to content

Commit

Permalink
Merge branch 'master' of github.com:medwezys/lazy_acc
Browse files Browse the repository at this point in the history
  • Loading branch information
tadast committed Apr 11, 2010
2 parents 6cd5e07 + 320f78b commit 6c9b93a
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 31 deletions.
29 changes: 19 additions & 10 deletions app/controllers/transactions_controller.rb
Expand Up @@ -3,14 +3,13 @@ class TransactionsController < ApplicationController
# GET /transactions
# GET /transactions.xml
def index
@transactions = current_user.transactions.current.group_by(&:bucket_id)
@buckets = current_user.buckets.debet
end

# GET /transactions/1
# GET /transactions/1.xml
def show
@transaction = Transaction.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @transaction }
Expand All @@ -37,19 +36,29 @@ def edit
# POST /transactions.xml
def create
@transaction = Transaction.new(params[:transaction])

respond_to do |format|
if @transaction.save
flash[:notice] = 'Transaction was successfully created.'
format.html { redirect_to(@transaction) }
format.xml { render :xml => @transaction, :status => :created, :location => @transaction }
else
format.html { render :action => "new" }
if @transaction.save
#flash[:notice] = 'Transaction was successfully created.'
render :update do |page|
page.insert_html :bottom, "bucket_#{@transaction.bucket_id}", :partial => "transaction_line", :object => @transaction
page.visual_effect :highlight, "bucket_#{@transaction.bucket_id}_name", :duration => 2.0
page.visual_effect :highlight, "transaction_#{@transaction.id}", :duration => 2.0
end
else
respond_to do |format|
format.html { render :action => "index" }
format.xml { render :xml => @transaction.errors, :status => :unprocessable_entity }
end
end
end

def update_transaction_status
t = Transaction.find(params[:id].to_i)
t.update_attributes(:status => params['status'])
render :update do |page|
page.replace_html "tstatus_#{t.id}", :partial => "tstatus", :object => t
end
end

# PUT /transactions/1
# PUT /transactions/1.xml
def update
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/transactions_helper.rb
@@ -1,2 +1,10 @@
module TransactionsHelper
def toggle_value(id, status)
remote_function(:url => {:action => :update_transaction_status},
:method => :put,
:before => "$('spinner-#{id}').show();$('tstatus_button_#{id}').hide();",
:complete => "$('spinner-#{id}').hide();$('tstatus_button_#{id}').show();",
:with => "this.status + '=' + #{status} + '&id=' + #{id}"
)
end
end
24 changes: 24 additions & 0 deletions app/views/transactions/_form.html.erb
@@ -0,0 +1,24 @@
<% remote_form_for(:transaction, :url => {:action => :create}) do |f| %>
<%= f.error_messages %>
<table>
<tr>
<td>
<%= f.label :bucket_id %><br />
<%= f.select :bucket_id, current_user.buckets.map{ |x| [x.title, x.id]} %>
</td>
<td>
<%= f.label :title %><br />
<%= f.text_field :title %>
</td>
<td>
<%= f.label :amount %><br />
<%= f.text_field :amount %>
</td>
<td>
<br />
<%= f.submit 'Create' %>
</td>
</tr>
</table>
<% end %>

5 changes: 5 additions & 0 deletions app/views/transactions/_transaction_line.html.erb
@@ -0,0 +1,5 @@
<tr id="transaction_<%= object.id %>" class="<%= Transaction::STATUS_NAME[object.status] %>">
<td width="40%"><%= object.title %></td>
<td width="5%"><%= object.amount %></td>
<%= render :partial => "tstatus", :object => object %>
</tr>
8 changes: 8 additions & 0 deletions app/views/transactions/_tstatus.html.erb
@@ -0,0 +1,8 @@
<td id="tstatus_<%= object.id %>">
<% if object.status == Transaction::STATUS[:unconfirmed] %>
<button type="button" id="tstatus_button_<%= object.id %>" onclick="<%= toggle_value(object.id, Transaction::STATUS[:confirmed]) %>">Confirm!</button>
<%= image_tag("spinner.gif", :style => "display:none", :id => "spinner-#{object.id}") %>
<% else %>
<%= image_tag("confirm.png", {:style => "width:15px;height15px;"}) %>
<% end %>
</td>
32 changes: 17 additions & 15 deletions app/views/transactions/index.html.erb
@@ -1,23 +1,25 @@
<h1>Listing transactions</h1>
<% @transactions.each do |bucket_id, transactions| %>
<% if transactions.present? %>

<div id="new_transaction">
<%= render :partial => "form" %>
</div>

<% @buckets.each do |bucket| %>
<div>
<div><h2><%= transactions.first.bucket.title %></h2></div>
<div id="bucket_<%= bucket.id %>_name"><h2><%= bucket.title %></h2></div>
<div>
<table>
<% transactions.each do |t| %>
<tr class="<%= Transaction::STATUS_NAME[t.status] %>">
<td><%= t.title %></td>
<td><%= t.amount %></td>
<td><%= image_tag "confirm.png", {:style => "width:30px;height30px;"}%></td>
</tr>
<% if bucket.transactions.current.empty? %>
&nbsp;&nbsp;&nbsp;<i>None</i>
<p></p>
<% else %>
<table id="bucket_<%= bucket.id %>">
<% bucket.transactions.current.each do |t| %>
<%= render :partial => "transaction_line", :object => t %>
<% end %>
</table>
<% end %>
</table>
</div>
</div>
<% end %>
<% end %>

<br />

<%= link_to 'New transaction', new_transaction_path %>
<br />
6 changes: 1 addition & 5 deletions app/views/transactions/new.html.erb
@@ -1,6 +1,6 @@
<h1>New transaction</h1>

<% form_for(@transaction) do |f| %>
<% form_for(@transaction, :url => {:action => :create}) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :bucket_id %><br />
Expand All @@ -10,10 +10,6 @@
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :description %><br />
<%= f.text_area :description %>
</p>
<p>
<%= f.label :amount %><br />
<%= f.text_field :amount %>
Expand Down
5 changes: 4 additions & 1 deletion config/routes.rb
@@ -1,5 +1,5 @@
ActionController::Routing::Routes.draw do |map|
map.resources :transactions
map.resources :transactions, :collection => {:update_transaction_status => :put}

map.resources :bills

Expand All @@ -9,6 +9,9 @@
map.resource :account, :controller => "users"
map.resources :users
map.resource :user_session



map.root :controller => "user_sessions", :action => "new"
map.resource :tours, :collection => {:step1 => :get, :step2 => :get }
end
Binary file added public/images/spinner.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6c9b93a

Please sign in to comment.