From 5b922ceab5a4da788ac607a665f042ba0303cd50 Mon Sep 17 00:00:00 2001 From: benji Date: Wed, 28 Oct 2015 16:57:11 +0100 Subject: [PATCH] Add way to see changes in quickpay --- app/assets/javascripts/quickpay.js | 17 +++++++++++++++++ app/assets/stylesheets/last.css.scss | 3 +++ app/controllers/orders_controller.rb | 1 + app/controllers/users_controller.rb | 17 ++++++++++++++--- app/views/orders/overview.html.haml | 9 ++++++++- app/views/users/_user.html.haml | 2 +- 6 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/quickpay.js create mode 100644 app/assets/stylesheets/last.css.scss diff --git a/app/assets/javascripts/quickpay.js b/app/assets/javascripts/quickpay.js new file mode 100644 index 0000000..8a85451 --- /dev/null +++ b/app/assets/javascripts/quickpay.js @@ -0,0 +1,17 @@ +ready = function() { + $('[data-quickpay]').on("ajax:success", function (e, data, status, xhr) { + var img = $("", { + src: $(this).closest(".overviewthumbnail").find(".avatar").attr("src").replace("large", "small"), + class: [ "img-responsive img-circle img-thumbnail" ] + }) + $(img).hide().prependTo($("#last")).fadeIn(); + if ($("#last").find("img").size() > 10) { + $("#last").find("img").last().remove(); + } + }).on("ajax:error", function (e, xhr, status, error) { + alert("Error while using quickpay ... sorry."); + }); +} + +$(document).ready(ready); +$(document).on('page:load', ready); diff --git a/app/assets/stylesheets/last.css.scss b/app/assets/stylesheets/last.css.scss new file mode 100644 index 0000000..c53cb1a --- /dev/null +++ b/app/assets/stylesheets/last.css.scss @@ -0,0 +1,3 @@ +#last img { + margin-bottom: 10px; +} diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 8511919..ace4c01 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -25,6 +25,7 @@ class OrdersController < ApplicationController def overview @users = User.members.publik.order(:name) + @last = Order.order(:created_at).reverse_order.includes(:user).limit(10).map(&:user) end private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 468d86c..9321c72 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -29,11 +29,22 @@ class UsersController < ApplicationController order = @user.orders.build order.order_items.build(count: 1, product: @user.dagschotel) if order.save - flash[:success] = "Quick pay succeeded." + respond_to do |format| + format.js { head :ok } + format.html { + flash[:success] = "Quick pay succeeded." + redirect_to root_path + } + end else - flash[:error] = order.errors.full_messages.first + respond_to do |format| + format.js { head :unprocessable_entity } + format.html { + flash[:error] = order.errors.full_messages.first + redirect_to root_path + } + end end - redirect_to root_path end private diff --git a/app/views/orders/overview.html.haml b/app/views/orders/overview.html.haml index 28c453e..053fb78 100644 --- a/app/views/orders/overview.html.haml +++ b/app/views/orders/overview.html.haml @@ -1,4 +1,11 @@ .warning.center %h1 TESTFASE | GELIEVE STREEPJES TE BLIJVEN ZETTEN | TESTFASE .row - = render @users + .col-md-1 + %h5 Recent + #last + - @last.each do |user| + = image_tag user.avatar(:small), class: "img-responsive img-circle img-thumbnail" + .col-md-11 + .row + = render @users diff --git a/app/views/users/_user.html.haml b/app/views/users/_user.html.haml index 2fa23c3..f335514 100644 --- a/app/views/users/_user.html.haml +++ b/app/views/users/_user.html.haml @@ -1,6 +1,6 @@ .col-md-2.overviewthumbnail - unless user.dagschotel.nil? - = link_to quickpay_user_path(user) do + = link_to quickpay_user_path(user), remote: true, data: { quickpay: true } do = image_tag user.dagschotel.avatar(:dagschotel), class: "img-circle dagschotel" = link_to image_tag(user.avatar(:large) , class: "img-circle avatar"), new_user_order_path(user) = link_to user.name , new_user_order_path(user), class: "btn btn-info", style: get_color_style(user)