From 19b11a79ff9820d2f1e1b869efe35addb5e21428 Mon Sep 17 00:00:00 2001 From: differentreality Date: Fri, 12 Jul 2013 11:43:31 +0300 Subject: [PATCH] Edit registration for admin --- .../admin/registrations_controller.rb | 24 ++++++++ app/views/admin/registrations/edit.html.haml | 25 ++++++++ app/views/admin/registrations/show.html.haml | 3 +- .../shared/_conference_registration.html.haml | 59 +++++++++++++++++++ config/routes.rb | 4 +- 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 app/views/admin/registrations/edit.html.haml create mode 100644 app/views/shared/_conference_registration.html.haml diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index b948e960..3a5fd03c 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -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 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 136a286d..7a395458 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/show.html.haml @@ -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}?" 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 38074bfa..2ad20c78 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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"