Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add validations to project setup form

  • Loading branch information...
commit 04ee67d0967d3b52385aac03d4b8bb1c3531a196 1 parent 86ba1bf
Paul Strong lapluviosilla authored
4 app/controllers/projects_setup_controller.rb
View
@@ -12,6 +12,7 @@ def show
@project.build_field_host unless @project.field_host
@project.build_organization unless @project.organization
end
+ @project.wizard_status = step.to_s # For client-side validations
render_wizard
end
@@ -28,6 +29,9 @@ def update
end
end
+ params[:project][:wizard_status] = step.to_s
+ params[:project][:wizard_status] = 'complete' if step == steps.last
+
@project.update_attributes params[:project]
render_wizard @project
session[:project_id] = @project.id
2  app/models/field_host.rb
View
@@ -32,7 +32,7 @@ class FieldHost < ActiveRecord::Base
belongs_to :organization
has_many :projects
- validates_presence_of :first_name, :last_name, :email, :preferred_phone, :phone_type
+ validates_presence_of :first_name, :last_name, :email, :preferred_phone, :phone_type, :overall_education
validates :years_associated_with_organization, :numericality => {:allow_nil => true}
end
42 app/models/project.rb
View
@@ -22,7 +22,7 @@ class Project < ActiveRecord::Base
:address, :internet_distance, :location_private, :location_type, :transportation_available,
:location_description, :culture_description, :housing_type, :dining_location, :housing_description,
:safety_level, :challenges_description, :typical_attire, :guidelines_description, :agree_memo, :agree_to_transport,
- :field_host_attributes, :organization_attributes, :organization_id
+ :field_host_attributes, :organization_attributes, :organization_id, :wizard_status
accepts_nested_attributes_for :field_host
accepts_nested_attributes_for :organization
@@ -41,6 +41,46 @@ class Project < ActiveRecord::Base
alias_method_chain f, :deserialize
end
+ # -- About You
+ validates :field_host, :organization, :associated => true, :if => :complete_or_about_you?
+ # -- The Project
+ validates :name, :student_educational_requirement, :presence => true, :if => :complete_or_the_project?
+ validates :team_mode, inclusion: {in: [true, false]}, :if => :complete_or_the_project?
+ validates :min_students, :max_students, :numericality => true, :if => :complete_or_the_project?
+ # -- Location
+ validates :location_private, :address, :internet_distance,
+ :location_description, :culture_description, :presence => true, :if => :complete_or_location?
+ # -- Content
+ validates :description, :housing_type, :dining_location, :housing_description, :safety_level, :challenges_description,
+ :typical_attire, :guidelines_description, :presence => true, :if => :complete_or_content?
+ # -- Agreement
+ validates :agree_memo, :agree_to_transport, inclusion: { in: [true, 1, 'true', 'T', '1'] }, :if => :complete_or_agreement?
+
+
+ def complete?
+ wizard_status == 'complete'
+ end
+
+ def complete_or_about_you?
+ wizard_status.include?('about_you') || complete?
+ end
+
+ def complete_or_the_project?
+ wizard_status.include?('the_project') || complete?
+ end
+
+ def complete_or_location?
+ wizard_status.include?('location') || complete?
+ end
+
+ def complete_or_content?
+ wizard_status.include?('content') || complete?
+ end
+
+ def complete_or_agreement?
+ wizard_status.include?('agreement') || complete?
+ end
+
# TODO: Partial validations with wizard steps
# validates_presence_of :name, :description
# validates_uniqueness_of :name
2  app/views/projects_setup/about_you.html.haml
View
@@ -36,7 +36,7 @@
= f_organization.input :website
%fieldset
- = f.fields_for :field_host do |f_field_host|
+ = f.fields_for :field_host, validate: true do |f_field_host|
= f_field_host.input :role_title
= f_field_host.input :years_associated_with_organization
= f_field_host.input :overall_education
16 app/views/projects_setup/content.html.haml
View
@@ -21,23 +21,23 @@
%fieldset
%h4 Internship Project, Community, and Personal Overview
- = f.input :description, as: :text, label: false, placeholder: 'Describe the project, the project facilities, organization, and project personnel here...'
+ = f.input :description, as: :text, label: false, placeholder: 'Describe the project, the project facilities, organization, and project personnel here...', validate: true
%fieldset
%h4 Housing & Meals
- = f.input :housing_type, label: "Student housing type."
- = f.input :dining_location, label: "Student dining location."
- = f.input :housing_description, as: :text, label: false, placeholder: 'Describe the housing, diet, and any health concerns here...'
+ = f.input :housing_type, label: "Student housing type.", validate: true
+ = f.input :dining_location, label: "Student dining location.", validate: true
+ = f.input :housing_description, as: :text, label: false, placeholder: 'Describe the housing, diet, and any health concerns here...', validate: true
%fieldset
%h4 Challenges at your location
- = f.input :safety_level, label: "Describe the level of safety in your area:"
- = f.input :challenges_description, as: :text, label: false, placeholder: 'Describe the specific cultural, safety, and lifestyle challenges at your location...'
+ = f.input :safety_level, label: "Describe the level of safety in your area:", validate: true
+ = f.input :challenges_description, as: :text, label: false, placeholder: 'Describe the specific cultural, safety, and lifestyle challenges at your location...', validate: true
%fieldset
%h4 What are your community guidelines (Dress, schedule, etc...)
- = f.input :typical_attire, label: "Describe a students typical attire:"
- = f.input :guidelines_description, as: :text, label: false, placeholder: 'Describe your project and/or organization guidelines (such as dress, for personal/interns)...'
+ = f.input :typical_attire, label: "Describe a students typical attire:", validate: true
+ = f.input :guidelines_description, as: :text, label: false, placeholder: 'Describe your project and/or organization guidelines (such as dress, for personal/interns)...', validate: true
= f.submit "Save & Continue to Step #5", class: "button button-orange"
10 app/views/projects_setup/location.html.haml
View
@@ -10,20 +10,20 @@
= button 'Project location must be private', :grey, id: "private-location"
= f.input :location_private, as: :boolean, label: false, input_html: {style:"display:none;"}
- = f.input :address, label: "Street Address (include Street Address, City, Province, Country)"
+ = f.input :address, label: "Street Address (include Street Address, City, Province, Country)", validate: true
%article
%h3.center Describe Your Region
- .location-col1= f.input :internet_distance, label: "How far away is the internet?"
+ .location-col1= f.input :internet_distance, label: "How far away is the internet?", validate: true
.location-col2
%label Is your location urban, surburban or rural?
= f.input :location_type, label: false, as: :button_group
-# = f.input :location_type, label: false, input_html: {style: "display:none;"}
- = f.input :transportation_available, label: 'Describe the type(s) of transportation available in your area'
+ = f.input :transportation_available, label: 'Describe the type(s) of transportation available in your area', validate: true
- = f.input :location_description, as: :text, label: "Describe Your City/Area", placeholder: 'Enter a few sentences on your area, region or city. What will students experience while they\'re at your location?'
- = f.input :culture_description, as: :text, label: "Describe the Culture of the Area", placeholder: 'Enter a few sentences on your culture, events, the people, history, art, people\'s interests, their living, etc...'
+ = f.input :location_description, as: :text, label: "Describe Your City/Area", placeholder: 'Enter a few sentences on your area, region or city. What will students experience while they\'re at your location?', validate: true
+ = f.input :culture_description, as: :text, label: "Describe the Culture of the Area", placeholder: 'Enter a few sentences on your culture, events, the people, history, art, people\'s interests, their living, etc...', validate: true
= f.submit "Save & Continue to Step #4", class: "button button-orange"
18 app/views/projects_setup/the_project.html.haml
View
@@ -2,7 +2,7 @@
= simple_form_for @project, url: wizard_path, method: :put, validate: true do |f|
%h3.center The Project
- = f.input :name, label: 'Internship Project Name:'
+ = f.input :name, label: 'Internship Project Name:', validate: true
%h4.center.teams-individuals Are you interested in teams or individuals?
#team-select.button-group.block-center
@@ -11,8 +11,8 @@
= f.input :team_mode, as: :boolean, label: false, input_html: {style:"display:none;"}
-# = f.input :min_stay_duration
- = f.input :min_students, label: 'Min. number of students to make this project worthwhile?'
- = f.input :max_students, label: 'Max. number of students you can house at any one time?'
+ = f.input :min_students, label: 'Min. number of students to make this project worthwhile?', validate: true
+ = f.input :max_students, label: 'Max. number of students you can house at any one time?', validate: true
%h3.center Project Sessions
@@ -22,8 +22,8 @@
%li This weekly cost will include all housing and all meal costs for student
%li Please include any additional costs for gear or equipment the student will need for the program
- = f.input :per_week_cost, label: 'Per Week Cost for Each Student:'
- = f.input :per_week_cost_final, as: :boolean, label: "Is this final?"
+ = f.input :per_week_cost, label: 'Per Week Cost for Each Student:', validate: true
+ = f.input :per_week_cost_final, as: :boolean, label: "Is this final?", validate: true
%h3.center Student Requirements
@@ -31,9 +31,9 @@
%h4 Define the Right Students
%img(src="http://placehold.it/350x300")
.student-requirements-fields
- = f.input :required_languages, label: 'Select Required Languages Students Must Speak'
- = f.input :related_student_passions, label: 'Tag All Related Student Passions'
- = f.input :related_fields_of_study, label: 'Tag all related fields of study that would benefit this project'
- = f.input :student_educational_requirement, label: 'Student Educational Requirement'
+ = f.input :required_languages, label: 'Select Required Languages Students Must Speak', validate: true
+ = f.input :related_student_passions, label: 'Tag All Related Student Passions', validate: true
+ = f.input :related_fields_of_study, label: 'Tag all related fields of study that would benefit this project', validate: true
+ = f.input :student_educational_requirement, label: 'Student Educational Requirement', validate: true
= f.submit "Save & Continue to Step #3", class: "button button-orange"
Please sign in to comment.
Something went wrong with that request. Please try again.