From 522f0b31d95efb5d38ee126729a542f6795896ca Mon Sep 17 00:00:00 2001 From: raluka Date: Mon, 6 Jul 2015 18:36:46 +0200 Subject: [PATCH] created action for attendance-button --- .../admin/registrations_controller.rb | 18 ++++++++++++++++++ app/views/admin/registrations/index.html.haml | 6 ++++-- config/routes.rb | 3 +-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 27dacfa4..fd4a02be 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -36,6 +36,7 @@ module Admin end end +=begin def present @registration.attended = true if @registration.save @@ -59,6 +60,22 @@ module Admin redirect_to admin_conference_registrations_path(@conference.short_title) end end +=end + + def toggle_attendance + if params[:attended] == "true" + flash[:notice] = "#{@user.email} is attended." + @registration.attended = true + elsif params[:attended] == "false" + flash[:notice] = "#{@user.email} is not attended." + @registration.attended = false + end + unless @registration.save + flash[:notice] = "Update Attended for #{@user.email} failed!" \ + "#{@registration.errors.full_messages.join('. ')}" + end + render json: {attended: @registration.attended} + end protected @@ -77,5 +94,6 @@ module Admin :id, :name, :tshirt, :mobile, :volunteer_experience, :languages, :nickname, :affiliation ]) end + end end diff --git a/app/views/admin/registrations/index.html.haml b/app/views/admin/registrations/index.html.haml index a60dd3fc..fdad2aa4 100644 --- a/app/views/admin/registrations/index.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -43,13 +43,15 @@ -if @conference.questions.any? %td = link_to 'Questions','#', class: 'btn btn-success question-btn', 'data-id' => index, 'data-name' => registration.name - %td - = check_box_tag @conference.short_title, registration.id, true, class: 'switch-checkbox', method: :patch, + %td{'data-order' => "#{registration.attended}"} + = check_box_tag "#{@conference.short_title}_#{registration.id}", registration.id, registration.attended, class: 'switch-checkbox', + method: :patch, url: toggle_attendance_admin_conference_registration_path(@conference.short_title, id: registration.id)+"?attended=", data: { size: "large", on_color: 'success', off_color: 'warning', on_text: 'Present', off_text: 'Absent' } + %td .btn-group .btn-group = link_to 'Edit', edit_admin_conference_registration_path(@conference.short_title, id: registration), diff --git a/config/routes.rb b/config/routes.rb index 2a5cbcd0..17c74bcc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,8 +35,7 @@ Osem::Application.routes.draw do resources :registrations, except: [:create, :new] do member do - patch :present - patch :absent + patch :toggle_attendance end end