From f53af55a741830718967a2928d0d36b5b557baa6 Mon Sep 17 00:00:00 2001 From: differentreality Date: Fri, 12 Jul 2013 10:45:40 +0300 Subject: [PATCH] add pagination, re-arrange view --- .../admin/registrations_controller.rb | 18 +++++- app/models/registration.rb | 7 ++- app/views/admin/registrations/show.html.haml | 60 +++++++++---------- config/routes.rb | 1 + 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index cfd795c5..a0768411 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -5,11 +5,27 @@ class Admin::RegistrationsController < ApplicationController session[:return_to] ||= request.referer @pdf_filename = "#{@conference.title}.pdf" @registrations = @conference.registrations.all(:joins => :person, - :order => "people.last_name ASC", + :order => "registrations.created_at ASC", :select => "registrations.*, people.last_name AS last_name, people.first_name AS first_name, people.public_name AS public_name, people.email AS email") + + @attended = @conference.registrations.where("attended = ?", true) + @headers = %w[attended name email social_events attending_with_partner need_access other_needs arrival departure] + end + + def change_field + @registration = Registration.find(params[:id]) + field = params[:view_field] + if @registration.send(field.to_sym) + @registration.update_attribute(:"#{field}",0) + else + @registration.update_attribute(:"#{field}",1) + end + + redirect_to admin_conference_registrations_path(@conference.short_title, @registration) + flash[:notice] = "Updated '#{params[:view_field]}' for #{(Person.where("id = ?", @registration.person_id).first).email}" end end \ No newline at end of file diff --git a/app/models/registration.rb b/app/models/registration.rb index adfa244b..3c65d6c8 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -15,4 +15,9 @@ class Registration < ActiveRecord::Base accepts_nested_attributes_for :person accepts_nested_attributes_for :supporter_registration accepts_nested_attributes_for :social_events -end + + alias_attribute :with_partner, :attending_with_partner + alias_attribute :social_events, :attending_social_events + alias_attribute :need_access, :handicapped_access_required + alias_attribute :other_needs, :other_special_needs +end \ No newline at end of file diff --git a/app/views/admin/registrations/show.html.haml b/app/views/admin/registrations/show.html.haml index 9e88fe84..cb2535bc 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/show.html.haml @@ -9,45 +9,43 @@ Registrations - if @registrations = "(#{@registrations.length})" - %table.table.table-striped.table-bordered.table-hover + - if @attended + = " - Attended (#{@attended.length})" + %table.table.table-striped.table-bordered.table-hover#registrations %thead %th - %b Last Name - %th - %b First Name - %th - %b Public Name - %th - %b Email - %th - %b Attending Social Events - %th - %b Attending With Partner - %th - %b Arrival Date - %th - %b Departure Date + No + - @headers.each do |h| + - h = h.gsub("_", " ") + %th + = h.capitalize %th %th + - counter = 0 - @registrations.each do |registration| %tr %td - = registration.last_name - %td - = registration.first_name - %td - = registration.public_name - %td - = registration.email - %td - = registration.attending_social_events - %td - = registration.attending_with_partner - %td - = registration.arrival - %td - = registration.departure + = counter +=1 + - @headers.each do |field| + %td + - if field == "name" + #{registration.last_name} #{registration.first_name} (#{registration.public_name}) + + -elsif (registration.send(field.to_sym).class == TrueClass || registration.send(field.to_sym).class == FalseClass) + = link_to "#{registration.send(field.to_sym)}", admin_conference_registrations_change_field_path(@conference.short_title, :id => registration.id, :view_field => "#{field}"), :method => :put, ":#{field}" => registration.send(field.to_sym) + - elsif field == 'arrival' || field == 'departure' + = registration.send(field.to_sym).strftime("%d %b %H:%M") if registration.send(field.to_sym) + - else + = registration.send(field.to_sym) %td = link_to "Edit", "#", :class => "btn btn-primary" %td = link_to "Delete", "#", :class => "btn btn-danger", :confirm => "Really delete registration for #{registration.public_name}?" + +:javascript + $(document).ready(function() { + $('#registrations').dataTable( { + "bPaginate": false, + "bLengthChange": false + } ); + } ); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f21d1781..3713964d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,7 @@ Osem::Application.routes.draw do get "/schedule" => "schedule#show" put "/schedule" => "schedule#update" get "/registrations" => "registrations#show" + put "/registrations/change_field" => "registrations#change_field" get "/emailsettings" => "emails#show", :as => "email_settings" put "/emailsettings" => "emails#update", :as => "email_settings" get "/supporter_levels" => "SupporterLevels#show"