add pagination, re-arrange view

This commit is contained in:
differentreality 2013-07-12 10:45:40 +03:00
parent 3ec3944406
commit f53af55a74
4 changed files with 53 additions and 33 deletions

View file

@ -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

View file

@ -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

View file

@ -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
} );
} );

View file

@ -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"