Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark school fields as required and update their locations #332

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/javascript/packs/schools.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ let create_school = function (input, callback) {
selectizeCallback = null;
$('#teacher_school_id').val(original_school_id);
}
toggle_required(['name', 'city', 'state', 'website'], true);
// TODO: This list should match the model attributes.
toggle_required(['name', 'city', 'state', 'website', 'grade_level', 'school_type'], true);
$("#school_form").hide();
});
};
Expand Down
8 changes: 7 additions & 1 deletion app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class School < ApplicationRecord
validates :state, presence: true, if: -> { country == "US" }
validates :state, inclusion: { in: VALID_STATES }, if: -> { country == "US" }
validates_format_of :website, with: /.+\..+/, on: :create
validates :grade_level, presence: true
validates :school_type, presence: true

before_save :update_gps_data, if: -> { lat.nil? || lng.nil? }
before_save :update_gps_data, if: -> { lat.nil? || lng.nil? || location_changed? }

has_many :teachers
scope :validated, -> { where("teachers_count > 0") }
Expand Down Expand Up @@ -124,6 +126,10 @@ def self.all_maps_data
end

private
def location_changed?
city_changed? || state_changed? || country_changed?
end

def prefix_url(url)
return unless url
url.match?(/^https?:/) ? url : "https://#{url}"
Expand Down
Loading