Merge branch 'master' into datagrid

This commit is contained in:
Felix Van der Jeugt 2015-09-10 16:18:46 +02:00
commit 079c1ea4d0
10 changed files with 58 additions and 23 deletions

View file

@ -17,7 +17,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

@ -19,19 +19,16 @@ class TransactionsController < ApplicationController
end
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
@ -51,8 +48,13 @@ class TransactionsController < ApplicationController
debtor: User.find_by(name: t[:debtor]) || User.zeus,
creditor: User.find_by(name: t[:creditor]) || User.zeus,
issuer: current_client || current_user,
amount: (t[:euros].to_f*100 + t[:cents].to_f).to_i,
amount: (float(t[:euros]) * 100 + float(t[:cents])).to_i,
message: t[:message]
}
end
def float arg
if arg.is_a? String then arg.sub!(',', '.') end
arg.to_f
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
end

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,5 +1,5 @@
%h2= @user.name
= render 'transactions/new'
%table#transactions.pure-table.pure-table-striped{data: { source: user_path(@user) }}
%thead
%tr