From 5118fa71351ad2dfb0578e823f837f6d141d6fe6 Mon Sep 17 00:00:00 2001 From: Godwin Date: Thu, 12 Jan 2017 18:22:37 -0800 Subject: [PATCH] Fixed registration status issues --- app/assets/javascripts/registrations.js | 8 ++++++-- .../conference_administration_controller.rb | 7 ++++++- app/models/city.rb | 10 +++++++++- app/models/conference_registration.rb | 7 ++++--- db/schema.rb | 2 +- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/registrations.js b/app/assets/javascripts/registrations.js index f22d9e1..f467202 100644 --- a/app/assets/javascripts/registrations.js +++ b/app/assets/javascripts/registrations.js @@ -69,9 +69,9 @@ } function editTableCell(cell) { - if (selectorMatches(cell, 'tr[data-key].editable td')) { + if (cell && selectorMatches(cell, 'tr[data-key].editable td')) { editTableRow(cell.parentElement, cell); - } else if (!selectorMatches(cell, 'tr[data-key].editable + tr, tr[data-key].editable + tr *')) { + } else if (!cell || !selectorMatches(cell, 'tr[data-key].editable + tr, tr[data-key].editable + tr *')) { var currentRow = document.querySelector('tr[data-key].editable.editing'); if (currentRow) { saveRow(currentRow); @@ -131,6 +131,10 @@ document.addEventListener("focus", function (event) { editTableCell(event.target); }, true); } + window.onbeforeunload = function() { + editTableCell(); + }; + searchControl.addEventListener('keyup', filterTable); searchControl.addEventListener('search', filterTable); diff --git a/app/controllers/conference_administration_controller.rb b/app/controllers/conference_administration_controller.rb index 2cd37d4..e64d547 100644 --- a/app/controllers/conference_administration_controller.rb +++ b/app/controllers/conference_administration_controller.rb @@ -867,7 +867,12 @@ class ConferenceAdministrationController < ApplicationController params.each do | key, value | case key.to_sym when :city - registration.city = value.present? ? view_context.location(Geocoder.search(value, language: @this_conference.locale).first, @this_conference.locale) : nil + if value.present? + city = City.search(value) + if city.present? + registration.city_id = city.id + end + end when :housing, :bike, :food, :allergies, :other registration.send("#{key.to_s}=", value) when :registration_fees_paid diff --git a/app/models/city.rb b/app/models/city.rb index e10d658..ed82ef8 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -50,6 +50,14 @@ class City < ActiveRecord::Base return translation end + def to_s + ([ + city, + territory.present? && country.present? ? I18n.t("geography.subregions.#{country}.#{territory}") : '', + country.present? ? I18n.t("geography.countries.#{country}") : '' + ] - ['', nil]).join(', ') + end + def self.search(str) cache = CityCache.search(str) @@ -66,7 +74,7 @@ class City < ActiveRecord::Base # if we didn't find a match by place id, collect the city, territory, and country from the result unless city.present? - # google nsames things differently than we do, we'll look for these itesm + # google names things differently than we do, we'll look for these items component_alises = { 'locality' => :city, 'administrative_area_level_1' => :territory, diff --git a/app/models/conference_registration.rb b/app/models/conference_registration.rb index c34ed0a..d7f7b2c 100644 --- a/app/models/conference_registration.rb +++ b/app/models/conference_registration.rb @@ -34,9 +34,10 @@ class ConferenceRegistration < ActiveRecord::Base end def status(was = false) - return :unregistered if user.nil? || user.firstname.blank? || self.send(was ? :city_was : :city).blank? - return :registered if self.send(was ? :housing_was : :housing).present? || (self.send(was ? :can_provide_housing_was : :can_provide_housing) && (self.send(was ? :housing_data_was : :housing_data) || {})['availability'].present?) - return :preregistered + return :unregistered if user.nil? + steps = ((was ? steps_completed_was : steps_completed) || []).map(&:to_sym) + return :registered if steps.include?(:hosting) || steps.include?(:questions) + return :preregistered if steps.include?(:contact_info) end around_update :check_status diff --git a/db/schema.rb b/db/schema.rb index 76c49c2..0edeb71 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170111013903) do +ActiveRecord::Schema.define(version: 20170111172147) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"