From 4532ad8c0a949ec8376a7f9c269772af0132006e Mon Sep 17 00:00:00 2001 From: differentreality Date: Fri, 12 Jul 2013 17:40:27 +0300 Subject: [PATCH 01/13] new registration --- .../admin/registrations_controller.rb | 49 +++++++++++- app/controllers/admin/users_controller.rb | 47 +----------- app/views/admin/registrations/new.html.haml | 75 +++++++++++++++++++ app/views/admin/registrations/show.html.haml | 2 +- app/views/admin/users/new.html.haml | 20 ----- config/routes.rb | 3 +- 6 files changed, 127 insertions(+), 69 deletions(-) create mode 100644 app/views/admin/registrations/new.html.haml delete mode 100644 app/views/admin/users/new.html.haml diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 3a5fd03c..31105521 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -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}" diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 124bc5eb..b30b1598 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -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 \ No newline at end of file diff --git a/app/views/admin/registrations/new.html.haml b/app/views/admin/registrations/new.html.haml new file mode 100644 index 00000000..55dd7665 --- /dev/null +++ b/app/views/admin/registrations/new.html.haml @@ -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) + } + }); \ No newline at end of file diff --git a/app/views/admin/registrations/show.html.haml b/app/views/admin/registrations/show.html.haml index 7a395458..3253e999 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/show.html.haml @@ -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 diff --git a/app/views/admin/users/new.html.haml b/app/views/admin/users/new.html.haml deleted file mode 100644 index cddf0c1c..00000000 --- a/app/views/admin/users/new.html.haml +++ /dev/null @@ -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"} diff --git a/config/routes.rb b/config/routes.rb index 9d6a5485..2b78d62a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" From c7f326765c9b5c5891663997ab5e543b24b4ba5a Mon Sep 17 00:00:00 2001 From: differentreality Date: Fri, 12 Jul 2013 17:43:37 +0300 Subject: [PATCH 02/13] move attended field left before edit --- app/controllers/admin/registrations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 31105521..540c7f54 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -13,7 +13,7 @@ class Admin::RegistrationsController < ApplicationController 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] + @headers = %w[name email social_events attending_with_partner need_access other_needs arrival departure attended] end def change_field From 80fe0e234b83f98ce2276da40bf8b8fa7ebf1632 Mon Sep 17 00:00:00 2001 From: differentreality Date: Fri, 12 Jul 2013 19:11:47 +0300 Subject: [PATCH 03/13] make attended a button --- app/views/admin/registrations/show.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/admin/registrations/show.html.haml b/app/views/admin/registrations/show.html.haml index 3253e999..67fceb92 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/show.html.haml @@ -31,6 +31,8 @@ - if field == "name" #{registration.last_name} #{registration.first_name} (#{registration.public_name}) + -elsif field == 'attended' + = 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), :class => "btn btn-primary" -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' From 90bda0f140f582178576a39ec317198edb374d2e Mon Sep 17 00:00:00 2001 From: differentreality Date: Fri, 12 Jul 2013 20:24:08 +0300 Subject: [PATCH 04/13] fix --- app/views/admin/registrations/edit.html.haml | 77 ++++++++++++++++---- app/views/admin/registrations/new.html.haml | 8 +- app/views/admin/registrations/show.html.haml | 5 +- 3 files changed, 70 insertions(+), 20 deletions(-) diff --git a/app/views/admin/registrations/edit.html.haml b/app/views/admin/registrations/edit.html.haml index bc06d775..6d6e8821 100644 --- a/app/views/admin/registrations/edit.html.haml +++ b/app/views/admin/registrations/edit.html.haml @@ -2,24 +2,71 @@ .row-fluid .span12 %h3 - Edit registration of #{@person.public_name} for #{@conference.title} + Edit registration of #{@person.public_name} (#{@person.email}) 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.inputs "Personal Information" do + = f.fields_for :person 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 => "Edit Registration", :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) + } + }); \ No newline at end of file diff --git a/app/views/admin/registrations/new.html.haml b/app/views/admin/registrations/new.html.haml index 55dd7665..1567f3ea 100644 --- a/app/views/admin/registrations/new.html.haml +++ b/app/views/admin/registrations/new.html.haml @@ -5,8 +5,9 @@ .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| + = f.fields_for :users do |u| = u.input :email = u.input :password, :hint => "Password must be at least 6 characters" = f.inputs "Personal Information" do @@ -41,9 +42,8 @@ = 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 = ""; @@ -72,4 +72,4 @@ onSelect: function(selected) { $("#registration-arrival-datepicker").datepicker("option","maxDate", selected) } - }); \ No newline at end of file + }); \ No newline at end of file diff --git a/app/views/admin/registrations/show.html.haml b/app/views/admin/registrations/show.html.haml index 67fceb92..ed980237 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/show.html.haml @@ -32,11 +32,14 @@ #{registration.last_name} #{registration.first_name} (#{registration.public_name}) -elsif field == 'attended' - = 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), :class => "btn btn-primary" + = 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), :class => "btn btn-success" + -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 From a46ca6707bb7f568fb3ccaa05be07a0135d49b2b Mon Sep 17 00:00:00 2001 From: differentreality Date: Fri, 12 Jul 2013 20:27:36 +0300 Subject: [PATCH 05/13] fix --- app/views/admin/registrations/edit.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/registrations/edit.html.haml b/app/views/admin/registrations/edit.html.haml index 6d6e8821..67377654 100644 --- a/app/views/admin/registrations/edit.html.haml +++ b/app/views/admin/registrations/edit.html.haml @@ -19,7 +19,7 @@ = f.inputs "Registration Information" do - if @conference.use_supporter_levels? - = f.semantic_fields_for :supporter_registrations do |reg| + = 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 From 4fd6512af0d692fd81433cc9d28d7e8f6428dc1d Mon Sep 17 00:00:00 2001 From: differentreality Date: Fri, 12 Jul 2013 20:30:49 +0300 Subject: [PATCH 06/13] minor fix --- app/views/admin/registrations/new.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/registrations/new.html.haml b/app/views/admin/registrations/new.html.haml index 1567f3ea..4ad08782 100644 --- a/app/views/admin/registrations/new.html.haml +++ b/app/views/admin/registrations/new.html.haml @@ -7,7 +7,7 @@ = 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 :users do |u| + = 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 From 6a951f1f21fec4b7883c73f5376a46996bf935e4 Mon Sep 17 00:00:00 2001 From: differentreality Date: Fri, 12 Jul 2013 20:37:57 +0300 Subject: [PATCH 07/13] wording in message --- app/controllers/admin/registrations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 540c7f54..9de63749 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -44,7 +44,7 @@ class Admin::RegistrationsController < ApplicationController @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}" + 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") From 6fc6e924ef4c9c48e5c34265056d713d9b997944 Mon Sep 17 00:00:00 2001 From: differentreality Date: Sat, 13 Jul 2013 10:59:02 +0300 Subject: [PATCH 08/13] show supporter level below name in registrations list (if other than free) --- app/helpers/application_helper.rb | 9 +++++++++ app/views/admin/registrations/show.html.haml | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c5adfc14..70ae48d0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -14,6 +14,15 @@ module ApplicationHelper var.strftime("%a, %d %b") end end + + def get_supporter_level(registration) + @conference.supporter_registrations.find_by_sql("SELECT *, supporter_levels.title as title + FROM supporter_registrations + INNER JOIN supporter_levels + ON supporter_registrations.supporter_level_id = supporter_levels.id + WHERE supporter_registrations.conference_id = #{@conference.id} + AND supporter_registrations.registration_id = #{registration.id}").first + end def add_association_link(association_name, form_builder, div_class, html_options = {}) link_to_add_association "Add " + association_name.to_s.singularize, form_builder, div_class, html_options.merge(:class => "assoc btn btn-success") diff --git a/app/views/admin/registrations/show.html.haml b/app/views/admin/registrations/show.html.haml index ed980237..c33ce7d6 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/show.html.haml @@ -30,6 +30,11 @@ %td - if field == "name" #{registration.last_name} #{registration.first_name} (#{registration.public_name}) + - supp_reg = get_supporter_level(registration) + - if supp_reg + %br + %p{:style => "color:red"} + = supp_reg.title unless supp_reg.title == "Free" -elsif field == 'attended' = 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), :class => "btn btn-success" From e4cc6f158fe98af8cb9bb77f7a5aaf5075dca70c Mon Sep 17 00:00:00 2001 From: differentreality Date: Sun, 14 Jul 2013 14:39:40 +0300 Subject: [PATCH 09/13] fix new registration, add check if user/person exists but is not registered --- .../admin/registrations_controller.rb | 86 +++++++++++-------- app/views/admin/registrations/new.html.haml | 13 ++- 2 files changed, 56 insertions(+), 43 deletions(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 9de63749..ffc92d2d 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -41,8 +41,10 @@ class Admin::RegistrationsController < ApplicationController 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 + if params[:registration][:supporter_registration] + @registration.supporter_registration.update_attributes(params[:registration][:supporter_registration_attributes]) + params[:registration].delete :supporter_registration_attributes + end @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)) @@ -54,50 +56,62 @@ class Admin::RegistrationsController < ApplicationController end def new - @registration = Registration.new + @user = User.new + @person = Person.new + @registration = @person.registrations.new + @supporter_registration = @conference.supporter_registrations.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 + person = Person.where("email LIKE ?", params[:registration][:user][:email]).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 - + if !person.nil? + reg = @conference.registrations.where("person_id = ?", person.id).first + if reg.nil? 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! - + else 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 + flash[:notice] = "#{person.email} is already registred!" + return + end + else + if params[:registration][:person][:first_name].blank? || params[:registration][:person][: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 = rand(36**6).to_s(36) + begin user.save! + user.skip_confirmation! + person = Person.where("user_id = ?", user.id).first + person.update_attributes(params[:registration][:person]) + begin + registration = person.registrations.new + if params[:registration][:supporter_registration] + registration.supporter_registration = @conference.supporter_registrations.new(:supporter_level_id => params[:registration][:supporter_registration][:supporter_level_id], :code => params[:registration][:supporter_registration][:code], :email => person.email, :name => person.public_name) + end + 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 -# rescue Exception => e -# redirect_to(:back, :alert => "Did not create new user/person. #{e.message}") -# return end + params[:registration].delete :person + params[:registration].delete :user + params[:registration].delete :supporter_registration + 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}." end def delete diff --git a/app/views/admin/registrations/new.html.haml b/app/views/admin/registrations/new.html.haml index 4ad08782..20cdbe05 100644 --- a/app/views/admin/registrations/new.html.haml +++ b/app/views/admin/registrations/new.html.haml @@ -6,14 +6,13 @@ .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.inputs "Your details" 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| + = u.input :email, :hint => "Please enter a valid email address. You will need it to log in to OSEM later." + = f.fields_for @person do |p| = p.input :first_name = p.input :last_name + = p.input :public_name = p.label :Nickname = p.text_field :irc_nickname = p.label :Affiliation @@ -21,7 +20,7 @@ = f.inputs "Registration Information" do - if @conference.use_supporter_levels? - = f.semantic_fields_for :supporter_registrations do |reg| + = 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 @@ -72,4 +71,4 @@ onSelect: function(selected) { $("#registration-arrival-datepicker").datepicker("option","maxDate", selected) } - }); \ No newline at end of file + }); \ No newline at end of file From 8f34baecf65257ebb2b4c0b1454b69d1d6a52af4 Mon Sep 17 00:00:00 2001 From: differentreality Date: Mon, 15 Jul 2013 06:45:32 +0300 Subject: [PATCH 10/13] add nickname and affiliation in registrations list --- app/controllers/admin/registrations_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index ffc92d2d..9dd8c06d 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -10,10 +10,10 @@ class Admin::RegistrationsController < ApplicationController people.last_name AS last_name, people.first_name AS first_name, people.public_name AS public_name, - people.email AS email") + people.email AS email, people.company as affiliation, people.irc_nickname as nickname") @attended = @conference.registrations.where("attended = ?", true) - @headers = %w[name email social_events attending_with_partner need_access other_needs arrival departure attended] + @headers = %w[name email nickname affiliation social_events attending_with_partner need_access other_needs arrival departure attended] end def change_field From 79ba3c5ea6f41fe5e9931065ba33a99164ffe7ec Mon Sep 17 00:00:00 2001 From: differentreality Date: Mon, 15 Jul 2013 12:29:37 +0300 Subject: [PATCH 11/13] as string --- app/views/admin/registrations/edit.html.haml | 10 +++++----- app/views/admin/registrations/new.html.haml | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/admin/registrations/edit.html.haml b/app/views/admin/registrations/edit.html.haml index 67377654..f93341de 100644 --- a/app/views/admin/registrations/edit.html.haml +++ b/app/views/admin/registrations/edit.html.haml @@ -10,12 +10,12 @@ = f.inputs "Personal Information" do = f.fields_for :person do |p| - = p.input :first_name - = p.input :last_name - = p.label :Nickname - = p.text_field :irc_nickname + = p.input :first_name, :as => :string + = p.input :last_name, :as => :string + = p.label :Nickname, :as => :string + = p.text_field :irc_nickname, :as => :string = p.label :Affiliation - = p.text_field :company, :placeholder => "Company/User Group/nothing" + = p.text_field :company, :placeholder => "Company/User Group/nothing", :as => :string = f.inputs "Registration Information" do - if @conference.use_supporter_levels? diff --git a/app/views/admin/registrations/new.html.haml b/app/views/admin/registrations/new.html.haml index 20cdbe05..1d81f757 100644 --- a/app/views/admin/registrations/new.html.haml +++ b/app/views/admin/registrations/new.html.haml @@ -8,15 +8,15 @@ = f.inputs "Your details" do = f.fields_for :user do |u| - = u.input :email, :hint => "Please enter a valid email address. You will need it to log in to OSEM later." + = u.input :email, :as => :string, :hint => "Please enter a valid email address. You will need it to log in to OSEM later." = f.fields_for @person do |p| - = p.input :first_name - = p.input :last_name - = p.input :public_name + = p.input :first_name, :as => :string + = p.input :last_name, :as => :string + = p.input :public_name, :as => :string = p.label :Nickname - = p.text_field :irc_nickname + = p.text_field :irc_nickname, :as => :string = p.label :Affiliation - = p.text_field :company, :placeholder => "Company/User Group/nothing" + = p.text_field :company, :placeholder => "Company/User Group/nothing", :as => :string = f.inputs "Registration Information" do - if @conference.use_supporter_levels? From 7c834347f9edcc861896948843f0bc05e9de2d82 Mon Sep 17 00:00:00 2001 From: differentreality Date: Mon, 15 Jul 2013 13:11:18 +0300 Subject: [PATCH 12/13] fixes --- app/controllers/admin/registrations_controller.rb | 6 ++++-- app/helpers/application_helper.rb | 9 --------- app/models/registration.rb | 2 ++ app/views/admin/registrations/show.html.haml | 8 +++----- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 9dd8c06d..92b7a598 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -13,7 +13,7 @@ class Admin::RegistrationsController < ApplicationController people.email AS email, people.company as affiliation, people.irc_nickname as nickname") @attended = @conference.registrations.where("attended = ?", true) - @headers = %w[name email nickname affiliation social_events attending_with_partner need_access other_needs arrival departure attended] + @headers = %w[name email social_events attending_with_partner need_access other_needs arrival departure attended] end def change_field @@ -28,7 +28,7 @@ class Admin::RegistrationsController < ApplicationController 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 @@ -131,4 +131,6 @@ class Admin::RegistrationsController < ApplicationController redirect_to(admin_conference_registrations_path(@conference.short_title), :alert => 'You must be an admin to delete a registration.') end end + + helper_method :get_supporter_level end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 70ae48d0..c5adfc14 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -14,15 +14,6 @@ module ApplicationHelper var.strftime("%a, %d %b") end end - - def get_supporter_level(registration) - @conference.supporter_registrations.find_by_sql("SELECT *, supporter_levels.title as title - FROM supporter_registrations - INNER JOIN supporter_levels - ON supporter_registrations.supporter_level_id = supporter_levels.id - WHERE supporter_registrations.conference_id = #{@conference.id} - AND supporter_registrations.registration_id = #{registration.id}").first - end def add_association_link(association_name, form_builder, div_class, html_options = {}) link_to_add_association "Add " + association_name.to_s.singularize, form_builder, div_class, html_options.merge(:class => "assoc btn btn-success") diff --git a/app/models/registration.rb b/app/models/registration.rb index 3c65d6c8..626b6022 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -4,6 +4,7 @@ class Registration < ActiveRecord::Base belongs_to :dietary_choice has_one :supporter_registration + has_one :supporter_level, :through => :supporter_registration has_and_belongs_to_many :social_events has_and_belongs_to_many :events @@ -20,4 +21,5 @@ class Registration < ActiveRecord::Base 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/show.html.haml b/app/views/admin/registrations/show.html.haml index c33ce7d6..3c7078d6 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/show.html.haml @@ -29,12 +29,10 @@ - @headers.each do |field| %td - if field == "name" - #{registration.last_name} #{registration.first_name} (#{registration.public_name}) - - supp_reg = get_supporter_level(registration) - - if supp_reg - %br + #{registration.last_name} #{registration.first_name} (#{registration.nickname}) #{registration.affiliation} + - if registration.supporter_level %p{:style => "color:red"} - = supp_reg.title unless supp_reg.title == "Free" + = registration.supporter_level.title unless registration.supporter_level.title == 'Free' -elsif field == 'attended' = 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), :class => "btn btn-success" From 094e0bb0d04760d753a4e6569d41303662137111 Mon Sep 17 00:00:00 2001 From: differentreality Date: Mon, 15 Jul 2013 13:20:28 +0300 Subject: [PATCH 13/13] fix --- app/views/admin/registrations/show.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/registrations/show.html.haml b/app/views/admin/registrations/show.html.haml index 3c7078d6..b78efa98 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/show.html.haml @@ -30,9 +30,9 @@ %td - if field == "name" #{registration.last_name} #{registration.first_name} (#{registration.nickname}) #{registration.affiliation} - - if registration.supporter_level + - if registration.supporter_level && registration.supporter_level.title != 'Free' %p{:style => "color:red"} - = registration.supporter_level.title unless registration.supporter_level.title == 'Free' + = registration.supporter_level.title -elsif field == 'attended' = 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), :class => "btn btn-success"