new registration

This commit is contained in:
differentreality 2013-07-12 17:40:27 +03:00
parent 84d30e13f0
commit 4532ad8c0a
6 changed files with 127 additions and 69 deletions

View file

@ -53,11 +53,58 @@ class Admin::RegistrationsController < ApplicationController
end
end
def new
@registration = Registration.new
@conference = Conference.find_all_by_short_title(params[:conference_id]).first
end
def create
@conference = Conference.find_all_by_short_title(params[:conference_id]).first
if params[:registration][:people][:first_name].blank? || params[:registration][:people][:last_name].blank?
redirect_to(:back, :alert => "Please fill in your first and last name before registering.")
return
end
user = User.new
user.email = params[:registration][:user][:email]
user.password = params[:registration][:user][:password]
begin
user.save!
user.skip_confirmation!
person = Person.where("user_id = ?", user.id).first
person.update_attributes(params[:registration][:people])
begin
params[:registration].delete :people
params[:registration].delete :user
registration = person.registrations.new
registration.supporter_registration = @conference.supporter_registrations.new(:supporter_level_id => params[:registration][:supporter_registrations][:supporter_level], :code => params[:registration][:supporter_registrations][:code], :email => person.email, :name => person.public_name)
params[:registration].delete :supporter_registrations
registration.update_attributes(params[:registration])
registration.update_attributes(:conference_id => @conference.id, :attended => true)
registration.save!
redirect_to admin_conference_registrations_path(@conference.short_title)
flash[:notice] = "Successfully created new registration for #{person.email}."
# rescue Exception => e
# user.destroy
# person.destroy
# 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
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}"

View file

@ -15,50 +15,5 @@ class Admin::UsersController < ApplicationController
user = User.find(params[:id])
user.update_attributes!(params[:user])
redirect_to admin_users_path, :notice => "Updated #{user.email}"
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
end

View file

@ -0,0 +1,75 @@
.row
.span12
%h3
Create new account and registration
.row
.span12
= semantic_form_for(@registration, :url => admin_conference_registrations_new_path(@conference.short_title), :html => { :method => :put }) do |f|
= f.inputs "Account Information" do
= f.fields_for :user do |u|
= u.input :email
= u.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.inputs "Registration Information" do
- if @conference.use_supporter_levels?
= f.semantic_fields_for :supporter_registrations 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"}
- 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)"
= f.action :submit, :button_html => { :value => "Create", :class => "btn btn-primary"}
: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)
}
});

View file

@ -1,7 +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 "New", admin_conference_registrations_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

View file

@ -1,20 +0,0 @@
.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"}

View file

@ -3,7 +3,6 @@ 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
@ -11,6 +10,8 @@ Osem::Application.routes.draw do
put "/schedule" => "schedule#update"
get "/stats" => "stats#index"
get "/registrations" => "registrations#show"
get "/registrations/new" => "registrations#new"
put "/registrations/new" => "registrations#create"
get "/registrations/edit" => "registrations#edit"
put "/registrations/edit" => "registrations#update"
delete "/registrations" => "registrations#delete"