Working on the backend interface for supporter registrations
This commit is contained in:
parent
e0f134bb34
commit
152e8a345d
66 changed files with 12860 additions and 17 deletions
|
|
@ -8,6 +8,7 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
has_one :email_settings, :dependent => :destroy
|
||||
has_one :call_for_papers, :dependent => :destroy
|
||||
has_many :supporter_registrations, :dependent => :destroy
|
||||
has_many :supporter_levels, :dependent => :destroy
|
||||
has_many :dietary_choices, :dependent => :destroy
|
||||
has_many :events, :dependent => :destroy
|
||||
|
|
|
|||
99
app/models/datatable.rb
Normal file
99
app/models/datatable.rb
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
# derived from http://railscasts.com/episodes/340-datatables
|
||||
# handles server side multi-column searching and sorting
|
||||
|
||||
class Datatable
|
||||
delegate :params, :h, :raw, :link_to, :number_to_currency, to: :@view
|
||||
|
||||
def initialize(klass, view)
|
||||
@klass = klass
|
||||
@view = view
|
||||
end
|
||||
|
||||
def as_json(options = {})
|
||||
{
|
||||
sEcho: params[:sEcho].to_i,
|
||||
iTotalRecords: @klass.count,
|
||||
iTotalDisplayRecords: items.total_entries,
|
||||
aaData: data
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def data
|
||||
[]
|
||||
end
|
||||
|
||||
def columns
|
||||
[]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def items
|
||||
@items ||= fetch_items
|
||||
end
|
||||
|
||||
def fetch_items
|
||||
items = filtered_list
|
||||
items = selected_columns(items)
|
||||
items = items.order(sort_order)
|
||||
items = items.page(page).per_page(per_page)
|
||||
if params[:sSearch].present?
|
||||
items = items.where(quick_search)
|
||||
end
|
||||
items
|
||||
end
|
||||
|
||||
def filtered_list
|
||||
@klass.scoped
|
||||
end
|
||||
|
||||
def selected_columns items
|
||||
items
|
||||
end
|
||||
|
||||
def quick_search
|
||||
search_for = params[:sSearch].split(' ')
|
||||
terms = {}
|
||||
which_one = -1
|
||||
criteria = search_for.inject([]) do |criteria,atom|
|
||||
which_one += 1
|
||||
terms["search#{which_one}".to_sym] = "%#{atom}%"
|
||||
criteria << "(#{search_cols.map{|col| "#{col} like :search#{which_one}"}.join(' or ')})"
|
||||
end.join(' and ')
|
||||
[criteria, terms]
|
||||
end
|
||||
|
||||
def page
|
||||
params[:iDisplayStart].to_i/per_page + 1
|
||||
end
|
||||
|
||||
def per_page
|
||||
params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
|
||||
end
|
||||
|
||||
def sort_order
|
||||
colnum = 0
|
||||
sort_by = []
|
||||
while true
|
||||
break if !sorted?(colnum)
|
||||
sort_by << "#{sort_column(colnum)} #{sort_direction(colnum)}"
|
||||
colnum += 1
|
||||
end
|
||||
sort_by.join(", ")
|
||||
end
|
||||
|
||||
def sorted? index=0
|
||||
!params["iSortCol_#{index}"].nil?
|
||||
end
|
||||
|
||||
def sort_column index=0
|
||||
index = "iSortCol_#{index}"
|
||||
columns[params[index].to_i]
|
||||
end
|
||||
|
||||
def sort_direction index=0
|
||||
index = "sSortDir_#{index}"
|
||||
params[index] == "desc" ? "desc" : "asc"
|
||||
end
|
||||
end
|
||||
30
app/models/datatable_supporters.rb
Normal file
30
app/models/datatable_supporters.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
class DatatableSupporters < Datatable
|
||||
def data
|
||||
arr = []
|
||||
items.each do |i|
|
||||
item = []
|
||||
if i.name.blank?
|
||||
item << i.registration.person.public_name
|
||||
else
|
||||
item << i.name
|
||||
end
|
||||
|
||||
if i.email.blank?
|
||||
item << i.registration.person.email
|
||||
else
|
||||
item << i.email
|
||||
end
|
||||
|
||||
item << i.supporter_level.title
|
||||
item << i.code
|
||||
item << i.code_is_valid
|
||||
arr << item
|
||||
end
|
||||
|
||||
arr
|
||||
end
|
||||
|
||||
def columns
|
||||
["name", "email", "name", "name", "name"]
|
||||
end
|
||||
end
|
||||
|
|
@ -2,5 +2,6 @@ class SupporterRegistration < ActiveRecord::Base
|
|||
belongs_to :supporter_level
|
||||
belongs_to :registration
|
||||
|
||||
attr_accessible :registration, :supporter_level_id, :code, :code_is_valid
|
||||
attr_accessible :registration, :supporter_level_id, :name, :email, :supporter_level, :code, :code_is_valid, :conference_id
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue