diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e33c2a5..c56e3de 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -18,7 +18,11 @@ //= require_tree . ready = function() { - $(".select2-selector").select2(); + $(".select2-selector").select2({ + width: 'resolve', + allowClear: true, + placeholder: "Ontvanger" + }); } $(document).ready(ready) diff --git a/app/assets/stylesheets/purecss.css b/app/assets/stylesheets/purecss.css.scss similarity index 66% rename from app/assets/stylesheets/purecss.css rename to app/assets/stylesheets/purecss.css.scss index f6647f5..94150c8 100644 --- a/app/assets/stylesheets/purecss.css +++ b/app/assets/stylesheets/purecss.css.scss @@ -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; + } + } +} diff --git a/app/assets/stylesheets/transactions.scss b/app/assets/stylesheets/transactions.scss index c402390..25d4ef0 100644 --- a/app/assets/stylesheets/transactions.scss +++ b/app/assets/stylesheets/transactions.scss @@ -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; +} diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.css.scss similarity index 83% rename from app/assets/stylesheets/users.scss rename to app/assets/stylesheets/users.css.scss index 1efc835..994acd2 100644 --- a/app/assets/stylesheets/users.scss +++ b/app/assets/stylesheets/users.css.scss @@ -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"; } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 27bab4f..47d756c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb index c43728d..e4d1a0d 100644 --- a/app/controllers/transactions_controller.rb +++ b/app/controllers/transactions_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f11be9d..92861af 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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( diff --git a/app/views/transactions/_new.html.haml b/app/views/transactions/_new.html.haml new file mode 100644 index 0000000..b47bc7a --- /dev/null +++ b/app/views/transactions/_new.html.haml @@ -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" diff --git a/app/views/transactions/new.html.haml b/app/views/transactions/new.html.haml deleted file mode 100644 index bd46894..0000000 --- a/app/views/transactions/new.html.haml +++ /dev/null @@ -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!" diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 119b6ea..ee24535 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,4 +1,5 @@ %h2= @user.name += render 'transactions/new' %table#transactions.display{data: { source: user_path(@user) }} %thead %tr