Edit registration for admin

This commit is contained in:
differentreality 2013-07-12 11:43:31 +03:00
parent 463430b3e8
commit 19b11a79ff
5 changed files with 113 additions and 2 deletions

View file

@ -29,6 +29,30 @@ class Admin::RegistrationsController < ApplicationController
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

View file

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

View file

@ -38,7 +38,8 @@
- else
= registration.send(field.to_sym)
%td
= link_to "Edit", "#", :class => "btn btn-primary"
= link_to "Edit", admin_conference_registrations_edit_path(@conference.short_title, :id => registration.id), :method => :get, :class => "btn btn-primary"
%td
= 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}?"

View file

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

View file

@ -10,8 +10,10 @@ 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 "/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"