Merge pull request #5 from ZeusWPI/transaction_form

Transaction form
This commit is contained in:
benji 2015-09-10 15:44:41 +02:00
commit e593d0fda0
10 changed files with 52 additions and 21 deletions

View file

@ -18,7 +18,11 @@
//= require_tree .
ready = function() {
$(".select2-selector").select2();
$(".select2-selector").select2({
width: 'resolve',
allowClear: true,
placeholder: "Ontvanger"
});
}
$(document).ready(ready)

View file

@ -43,3 +43,23 @@
background-color: rgb(83, 180, 79);
color: #fff;
}
fieldset.pure-group-inline {
display: inline-block;
.pure-group-addon {
padding: .5em .6em;
box-shadow: inset 0 1px 3px #ddd;
border: 1px solid #ccc;
white-space: nowrap;
border-collapse: separate;
margin-left: -4px;
&:last-child {
border-radius: 0 4px 4px 0;
}
&:first-child {
margin-left: 0;
border-radius: 4px 0 0 4px;
border-right: 0;
}
}
}

View file

@ -1,3 +1,6 @@
// Place all the styles related to the transactions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.price {
width: 100px;
}

View file

@ -1,3 +1,4 @@
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.euro:before { content:"\20AC"; }

View file

@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base
end
def current_client
@current_client ||= Client.find_by key: request.headers["X_API_KEY"]
@current_client ||= Client.find_by key: (request.headers["X_API_KEY"] || request.headers["HTTP_X_API_KEY"])
end
def current_ability

View file

@ -11,19 +11,16 @@ class TransactionsController < ApplicationController
@transactions = Transaction.all
end
def new
@transaction = Transaction.new
end
def create
@transaction = Transaction.new(transaction_params)
respond_to do |format|
format.html do
@user = current_user
if @transaction.save
flash[:success] = "Transaction created"
redirect_to new_transaction_path
redirect_to current_user
else
render 'new'
render "users/show"
end
end

View file

@ -3,6 +3,7 @@ class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@transaction = Transaction.new
respond_to do |format|
format.html
format.json { render json: TransactionDatatable.new(

View file

@ -0,0 +1,17 @@
= render 'partials/form_errors', object: @transaction
= form_for @transaction, html: { class: "pure-form" } do |f|
- if current_user.penning
= f.collection_select :debtor, User.all, :name, :name,
{ selected: @transaction.debtor.try(:name) || current_user.name }, { class: 'select2-selector'}
- else
= f.hidden_field :debtor, value: current_user.name
= f.select :creditor,
options_from_collection_for_select(User.all.order(:name), :name, :name),
{ include_blank: true },
{ class: 'select2-selector', size: 50, required: true }
= f.text_field :message, required: true, placeholder: "Message", size: 75
%fieldset.pure-group-inline
%span.euro.pure-group-addon
= f.number_field :euros, value: (@transaction.amount.zero? ? nil : @transaction.amount/100),
placeholder: "Bedrag", step: 0.01, min: 0.01, class: "pure-group-addon price", size: 20, required: true
= f.submit "Send it!", class: "pure-button pure-button-primary"

View file

@ -1,13 +0,0 @@
= render 'partials/form_errors', object: @transaction
= simple_form_for @transaction do |f|
- if current_user.penning
= f.collection_select :debtor, User.all, :name, :name,
{ selected: @transaction.debtor.try(:name) || current_user.name }, { class: 'select2-selector'}
- else
= f.hidden_field :debtor, value: current_user.name
= f.collection_select :creditor, User.all, :name, :name,
{ selected: @transaction.creditor.try(:name) || User.zeus.name }, { class: 'select2-selector' }
= f.input :message, required: true
= f.input :euros, input_html: { value: @transaction.amount/100}
.pure-controls
= f.button :submit, "Send it!"

View file

@ -1,4 +1,5 @@
%h2= @user.name
= render 'transactions/new'
%table#transactions.display{data: { source: user_path(@user) }}
%thead
%tr