diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index cfd795c5..3a5fd03c 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -5,11 +5,69 @@ 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 + + def edit + @registration = @conference.registrations.where("id = ?", params[:id]).first + @person = Person.where("id = ?", @registration.person_id).first + end + + def update + reg_id = params[:format] + @registration = @conference.registrations.where("id = ?", reg_id).first + @person = Person.where("id = ?", @registration.person_id).first + begin + @person.update_attributes!(params[:registration][:person_attributes]) + params[:registration].delete :person_attributes + @registration.supporter_registration = @conference.supporter_registrations.new(params[:registration][:supporter_registration_attributes]) + params[:registration].delete :supporter_registration_attributes + @registration.update_attributes!(params[:registration]) + flash[:notice] = "Successfully updated Registration for #{@person.public_name} #{@person.email}" + redirect_to(admin_conference_registrations_path(@conference.short_title)) + rescue Exception => e + Rails.logger.debug e.backtrace.join("\n") + redirect_to(admin_conference_registrations_path(@conference.short_title), :alert => 'Failed to update registration:' + e.message) + return + end + end + + def delete + if has_role?(current_user, "Admin") + registration = @conference.registrations.where(:id => params[:id]).first + person = Person.where("id = ?", registration.person_id).first + + begin registration.destroy + redirect_to admin_conference_registrations_path + flash[:notice] = "Deleted registration for #{person.public_name} #{person.email}" + rescue Exception => e + Rails.logger.debug e.backtrace.join("\n") + redirect_to(admin_conference_registrations_path(@conference.short_title), :alert => 'Failed to delete registration:' + e.message) + return + end + else + redirect_to(admin_conference_registrations_path(@conference.short_title), :alert => 'You must be an admin to delete a registration.') + end end end \ No newline at end of file diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index a3126ab6..124bc5eb 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -16,4 +16,49 @@ class Admin::UsersController < ApplicationController user.update_attributes!(params[:user]) redirect_to admin_users_path, :notice => "Updated #{user.email}" end -end + + def new + @user = User.new + @person = Person.where("user_id =?", @user.id) + @conferences = Conference.where("end_date >= ?", Time.now) + @conference = Conference.find_all_by_short_title(params[:format]).first + end + + def create + @conference = Conference.find_all_by_short_title(params[:id]).first + + if params[:user][:people][:first_name].blank? || params[:user][:people][:last_name].blank? + redirect_to(:back, :alert => "Please fill in your first and last name before registering.") + return + end + + params[:user][:conferences].shift + if !params[:user][:conferences].empty? + user = User.new + user.email = params[:user][:email] + user.password = params[:user][:password] + begin + user.save! + user.skip_confirmation! + person = Person.where("user_id = ?", user.id).first + person.update_attributes(params[:user][:people]) + begin + params[:user][:conferences].each do |r| + registration = person.registrations.new(:conference_id => r, :attended => 't') + registration.save! + end + redirect_to admin_conference_registrations_path(@conference.short_title) + flash[:notice] = "Successfully created new registration for #{person.email}." + rescue Exception => e + redirect_to(:back, :alert => "Did not create registration. #{e.message}") + return + end + rescue Exception => e + redirect_to(:back, :alert => "Did not create new user/person. #{e.message}") + return + end + else + redirect_to(:back, :alert => "Please select at least one conference to register.") + end + end +end \ No newline at end of file diff --git a/app/models/registration.rb b/app/models/registration.rb index ca0c5f67..3c65d6c8 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -10,9 +10,14 @@ class Registration < ActiveRecord::Base attr_accessible :person_id, :conference_id, :attending_social_events, :attending_with_partner, :using_affiliated_lodging, :arrival, :departure, :person_attributes, :other_dietary_choice, :dietary_choice_id, :handicapped_access_required, :supporter_registration_attributes, :social_event_ids, :other_special_needs, - :event_ids + :event_ids, :attended accepts_nested_attributes_for :person accepts_nested_attributes_for :supporter_registration accepts_nested_attributes_for :social_events + + 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/edit.html.haml b/app/views/admin/registrations/edit.html.haml new file mode 100644 index 00000000..bc06d775 --- /dev/null +++ b/app/views/admin/registrations/edit.html.haml @@ -0,0 +1,25 @@ +.container-fluid + .row-fluid + .span12 + %h3 + Edit registration of #{@person.public_name} for #{@conference.title} + %br + .row-fluid + .span12 + = semantic_form_for(@registration, :url => admin_conference_registrations_edit_path(@conference.short_title, @registration.id), :html => { :method => :put }) do |f| + .span6 + = f.inputs :name => "Personal Data" do + = f.fields_for :person do |p| + = p.label :first_name + = p.text_field :first_name + = p.label :last_name + = p.text_field :last_name + = p.label :email + = p.text_field :email + = p.label :affiliation + = p.text_field :company + = p.label :Nickname + = p.text_field :irc_nickname + = render :partial => 'shared/conference_registration', :locals => { :f => f } + + = f.action :submit, :button_html => { :value => "Edit Registration", :class => "btn btn-primary" } diff --git a/app/views/admin/registrations/show.html.haml b/app/views/admin/registrations/show.html.haml index 4ba9f67b..7a395458 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/show.html.haml @@ -1,6 +1,7 @@ .row-fluid .span12 .pull-right{:style=>"margin-top:20px; margin-bottom:20px;"} + = link_to "New", admin_users_new_path(@conference.short_title), :class => "btn btn-primary" = link_to "Export PDF", admin_conference_registrations_path(@conference.short_title, :format => :pdf), :class => "btn btn-success" .row-fluid .span12 @@ -8,45 +9,44 @@ 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 + = 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 - = registration.first_name + = link_to "Edit", admin_conference_registrations_edit_path(@conference.short_title, :id => registration.id), :method => :get, :class => "btn btn-primary" + %td - = registration.public_name - %td - = registration.email - %td - = registration.attending_social_events - %td - = registration.attending_with_partner - %td - = registration.arrival - %td - = registration.departure - %td - = link_to "Edit", "#", :class => "btn btn-primary" - %td - = link_to "Delete", "#", :class => "btn btn-danger", :confirm => "Really delete registration for #{registration.public_name}?" + = link_to "Delete", admin_conference_registrations_path(@conference.short_title, :id => registration.id), :method => :delete, :class => "btn btn-danger", :confirm => "Really delete registration for #{registration.public_name} #{registration.email}?" + +:javascript + $(document).ready(function() { + $('#registrations').dataTable( { + "bPaginate": false, + "bLengthChange": false + } ); + } ); \ No newline at end of file diff --git a/app/views/admin/users/new.html.haml b/app/views/admin/users/new.html.haml new file mode 100644 index 00000000..cddf0c1c --- /dev/null +++ b/app/views/admin/users/new.html.haml @@ -0,0 +1,20 @@ +.row + .span12 + %h3 + Create new account and registration +.row + .span12 + = semantic_form_for(@user, :url => admin_users_new_path(:id => @conference.short_title), :html => { :method => :put }) do |f| + = f.inputs "Account Information" do + = f.input :email + = f.input :password, :hint => "Password must be at least 6 characters" + = f.inputs "Personal Information" do + = f.fields_for :people do |p| + = p.input :first_name + = p.input :last_name + = p.label :Nickname + = p.text_field :irc_nickname + = p.label :Affiliation + = p.text_field :company, :placeholder => "Company/User Group/nothing" + = f.input :conferences, :as => :check_boxes, :label => true, :collection => @conferences + = f.action :submit, :button_html => { :value => "Create", :class => "btn btn-primary"} diff --git a/app/views/shared/_conference_registration.html.haml b/app/views/shared/_conference_registration.html.haml new file mode 100644 index 00000000..424a9def --- /dev/null +++ b/app/views/shared/_conference_registration.html.haml @@ -0,0 +1,59 @@ += f.inputs :name => "Your Details" do + %br + Your public name (required) + %br + = f.fields_for :person do |p| + = p.text_field :public_name, :for => :person + - if @conference.use_supporter_levels? + = f.semantic_fields_for :supporter_registration do |reg| + = reg.input :supporter_level, :as => :select, :collection => @conference.supporter_levels + = reg.input :code, :label => "Confirmation or registration code (if applicable)" + %span#supporter-link.help-block + + = f.input :attending_with_partner, :label => false + = f.input :using_affiliated_lodging, :label => false + = f.input :handicapped_access_required, :label => false + = f.input :other_special_needs, :label => "Any other special needs?", :input_html => {:rows => 2, :class => "span6"} += f.inputs "Travel Info" do + = f.input :arrival, :as => :string, :input_html => {:value => (f.object.arrival.to_formatted_s(:db_without_seconds) unless f.object.arrival.nil?), :id => "registration-arrival-datepicker", :readonly => "readonly" } + = f.input :departure, :as => :string, :input_html => {:value => (f.object.departure.to_formatted_s(:db_without_seconds) unless f.object.departure.nil?), :id => "registration-departure-datepicker", :readonly => "readonly" } +- if @conference.social_events.count > 0 + = f.inputs "Are you planning to attend any of the parties?" do + %br Yes, I'll be attending... + %br + = f.input :social_events, :as => :check_boxes, :label => false, :collection => @conference.social_events +- if @conference.use_dietary_choices? + = f.inputs "Food" do + = f.input :dietary_choice, :collection => [["None", nil]] + @conference.dietary_choices.map {|x| [x.title, x.id]}, + :include_blank => false, :label => "Special Dietary Restriction" + = f.input :other_dietary_choice, :input_html => {:rows => "2", :class => "span6"}, :label => "Other Dietary Restictions (please describe)" + +:javascript + $("#registration_supporter_registration_attributes_supporter_level_id").change(function () { + var str = ""; + #{generate_supporter_level_js @conference} + $("#supporter-link").html(str); + }) + .trigger('change'); + + $("#registration-arrival-datepicker").datetimepicker({ + dateFormat: "yy-mm-dd", + timeFormat: "HH:mm", + showSecond: false, + numberOfMonths: 1, + defaultDate: '#{@conference.start_date.yesterday.strftime('%Y-%m-%d')}', + onSelect: function(selected) { + $("#registration-departure-datepicker").datepicker("option","minDate", selected) + } + }); + + $("#registration-departure-datepicker").datetimepicker({ + dateFormat: "yy-mm-dd", + timeFormat: "HH:mm", + showSecond: false, + numberOfMonths: 1, + defaultDate: '#{@conference.end_date.tomorrow.strftime('%Y-%m-%d')}', + onSelect: function(selected) { + $("#registration-arrival-datepicker").datepicker("option","maxDate", selected) + } + }); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 4fc2797d..2ad20c78 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,12 +3,17 @@ Osem::Application.routes.draw do devise_for :users, :controllers => { :registrations => :registrations }, :path => 'accounts' namespace :admin do + put "/users/new" => "users#create" resources :users resources :people resources :conference do get "/schedule" => "schedule#show" put "/schedule" => "schedule#update" get "/registrations" => "registrations#show" + get "/registrations/edit" => "registrations#edit" + put "/registrations/edit" => "registrations#update" + delete "/registrations" => "registrations#delete" + 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" diff --git a/db/migrate/20130712072609_add_attended_to_registrations.rb b/db/migrate/20130712072609_add_attended_to_registrations.rb new file mode 100644 index 00000000..c7420f04 --- /dev/null +++ b/db/migrate/20130712072609_add_attended_to_registrations.rb @@ -0,0 +1,5 @@ +class AddAttendedToRegistrations < ActiveRecord::Migration + def change + add_column :registrations, :attended, :boolean, :default => 0 + end +end