Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
aoz-003
Commits
15a51c57
Commit
15a51c57
authored
Jun 02, 2017
by
Tugce Nur Tas
Committed by
Tuğçe Nur Taş
Jun 22, 2017
Browse files
integrate contact fields into volunteer
parent
5545589e
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/controllers/concerns/nested_attributes.rb
View file @
15a51c57
...
...
@@ -3,8 +3,7 @@ module NestedAttributes
included
do
def
volunteer_attributes
[
:first_name
,
:last_name
,
:date_of_birth
,
:gender
,
:avatar
,
:street
,
:zip
,
:city
,
:nationality
,
:additional_nationality
,
:email
,
:phone
,
[
:date_of_birth
,
:gender
,
:avatar
,
:nationality
,
:additional_nationality
,
:profession
,
:education
,
:motivation
,
:experience
,
:expectations
,
:strengths
,
:skills
,
:interests
,
:state
,
:rejection_type
,
:rejection_text
,
:duration
,
:man
,
:woman
,
:family
,
:kid
,
:sport
,
:creative
,
:music
,
:culture
,
...
...
app/controllers/volunteers_controller.rb
View file @
15a51c57
...
...
@@ -13,6 +13,7 @@ class VolunteersController < ApplicationController
def
new
@volunteer
=
Volunteer
.
new
@volunteer
.
schedules
<<
Schedule
.
build
@volunteer
.
build_contact
authorize
@volunteer
end
...
...
@@ -43,7 +44,8 @@ class VolunteersController < ApplicationController
private
def
invite_volunteer_user
new_user
=
User
.
new
(
email:
@volunteer
.
email
,
password:
Devise
.
friendly_token
,
role:
'volunteer'
)
new_user
=
User
.
new
(
email:
@volunteer
.
contact
.
contact_emails
.
first
.
body
,
password:
Devise
.
friendly_token
,
role:
'volunteer'
)
new_user
.
save
@volunteer
.
user
=
new_user
new_user
.
invite!
...
...
@@ -58,7 +60,16 @@ class VolunteersController < ApplicationController
def
volunteer_params
params
.
require
(
:volunteer
).
permit
(
volunteer_attributes
,
language_skills_attributes
,
relatives_attributes
,
schedules_attributes
language_skills_attributes
,
relatives_attributes
,
schedules_attributes
,
contact_attributes:
[
:id
,
:first_name
,
:last_name
,
:_destroy
,
:contactable_id
,
:contactable_type
,
:street
,
:extended
,
:city
,
:postal_code
,
contact_emails_attributes:
contact_point_attrs
,
contact_phones_attributes:
contact_point_attrs
]
)
end
def
contact_point_attrs
[
:id
,
:body
,
:label
,
:_destroy
,
:type
,
:contacts_id
]
end
end
app/models/volunteer.rb
View file @
15a51c57
...
...
@@ -3,6 +3,9 @@ class Volunteer < ApplicationRecord
include
FullName
include
GenderCollection
has_one
:contact
,
as: :contactable
accepts_nested_attributes_for
:contact
acts_as_paranoid
before_save
:default_state
...
...
@@ -22,7 +25,7 @@ class Volunteer < ApplicationRecord
validates_attachment
:avatar
,
content_type:
{
content_type:
/\Aimage\/.*\z/
}
validates
:first_name
,
:last_name
,
:email
,
presence:
true
validates
:email
,
uniqueness:
true
def
self
.
state_collection
...
...
app/views/clients/_form.html.slim
View file @
15a51c57
...
...
@@ -10,6 +10,7 @@
.col-xs-12.col-md-6
=
f
.
simple_fields_for
:contact
do
|
c
|
=
render
'contacts/fields'
,
f:
c
.row
.col-xs-12.col-md-6
=
f
.
input
:date_of_birth
,
as: :date
,
start_year:
Date
.
today
.
year
-
90
,
...
...
app/views/clients/show.html.slim
View file @
15a51c57
...
...
@@ -12,15 +12,15 @@
tr
td
=
t_attr
(
:date_of_birth
)
td
=
l
(
@client
.
date_of_birth
)
if
@client
.
date_of_birth
tr
td
=
t_attr
(
:gender
)
td
=
t
(
"gender.
#{
@client
.
gender
}
"
)
unless
@client
.
gender
.
blank?
tr
td
=
t_attr
(
:nationality
)
td
=
country
(
@client
.
nationality
)
tr
td
=
t_attr
(
:permit
)
td
=
@client
.
permit
tr
td
=
t_attr
(
:gender
)
td
=
t
(
"gender.
#{
@client
.
gender
}
"
)
unless
@client
.
gender
.
blank?
=
render
'language_skills/show'
,
speaker:
@client
...
...
app/views/volunteers/_form.html.slim
View file @
15a51c57
...
...
@@ -4,11 +4,11 @@
=
f
.
error_notification
.row
.col-xs-12
.col-md-6
=
f
.
input
:first_name
.col-xs-12.col-md-6
=
f
.
input
:last_name
.col-xs-12
.row
.col-xs-12.col-md-6
=
f
.
simple_fields_for
:contact
do
|
c
|
=
render
'contacts/fields'
,
f:
c
.row
.col-xs-12.col-md-6
...
...
@@ -28,23 +28,7 @@
.col-xs-12.col-md-6
=
f
.
input
:additional_nationality
,
as: :country
.row
.col-xs-12
=
f
.
input
:street
.col-xs-6
=
f
.
input
:zip
.col-xs-6
=
f
.
input
:city
.col-xs-12.col-md-6
=
f
.
input
:email
.col-xs-12.col-md-6
=
f
.
input
:phone
=
render
'language_skills/form'
,
f:
f
,
speaker:
f
.
object
=
render
'language_skills/form'
,
f:
f
,
speaker:
@volunteer
=
render
'relatives/form'
,
f:
f
,
relative:
f
.
object
...
...
app/views/volunteers/_volunteer.html.slim
View file @
15a51c57
tr
td
=
volunteer
.
full_name
td
=
l
(
volunteer
.
date_of_birth
)
if
volunteer
.
date_of_birth
.
present?
td
=
volunteer
.
contact
.
first_name
td
=
volunteer
.
contact
.
last_name
td
=
volunteer
.
date_of_birth
if
volunteer
.
date_of_birth
.
present?
td
=
country
(
volunteer
.
nationality
)
if
volunteer
.
nationality
.
present?
td
=
l
(
volunteer
.
created_at
)
td
=
t
(
"gender.
#{
volunteer
.
gender
}
"
)
unless
volunteer
.
gender
.
blank?
td
=
t
(
"state.
#{
volunteer
.
state
}
"
,
scope:
[
:simple_form
,
:options
,
:volunteer
])
td
-
if
volunteer
.
contact
.
contact_emails
.
any?
=
link_to
volunteer
.
contact
.
contact_emails
.
first
.
body
td
=
link_to
t_action
(
:show
),
volunteer
td
=
link_to
t_action
(
:edit
),
edit_volunteer_path
(
volunteer
)
td
=
link_to
t_action
(
:destroy
),
volunteer
,
data:
{
confirm:
t_confirm_delete
(
volunteer
)
},
method: :delete
app/views/volunteers/show.html.slim
View file @
15a51c57
h1
=
@volunteer
.
full_name
.row
.col-xs-12
h1
=
@volunteer
.
contact
.
full_name
.row
.col-xs-12
.table-responsive
table
.table.table-no-border-top
tbody
tr
td
=
t_attr
(
:date_of_birth
)
td
=
l
(
@volunteer
.
date_of_birth
)
if
@volunteer
.
date_of_birth
tr
td
=
t_attr
(
:gender
)
td
=
t
(
"gender.
#{
@volunteer
.
gender
}
"
)
unless
@volunteer
.
gender
.
blank?
tr
td
=
t_attr
(
:avatar
)
td
=
image_tag
@volunteer
.
avatar
.
url
(
:thumb
)
if
@volunteer
.
avatar
.
present?
tr
td
=
t_attr
(
:nationality
)
td
=
country
(
@volunteer
.
nationality
)
tr
td
=
t_attr
(
:additional_nationality
)
td
=
country
(
@volunteer
.
additional_nationality
)
=
render
'language_skills/show'
,
speaker:
@volunteer
=
render
'relatives/show'
,
relative:
@volunteer
tr
td
=
t_attr
(
:profession
)
td
=
@volunteer
.
profession
tr
td
=
t_attr
(
:education
)
td
=
@volunteer
.
education
tr
td
=
t_attr
(
:motivation
)
td
=
@volunteer
.
motivation
tr
td
=
t_attr
(
:experience
)
td
=
Volunteer
.
human_boolean
(
@volunteer
.
experience
)
tr
td
=
t_attr
(
:expectations
)
td
=
@volunteer
.
expectations
tr
td
=
t_attr
(
:strengths
)
td
=
@volunteer
.
strengths
tr
td
=
t_attr
(
:skills
)
td
=
@volunteer
.
skills
tr
td
=
t_attr
(
:interests
)
td
=
@volunteer
.
interests
-
if
policy
(
Volunteer
).
destroy?
tr
td
=
t_attr
(
:state
)
td
=
t
(
"state.
#{
@volunteer
.
state
}
"
)
-
if
@volunteer
.
rejected?
tr
td
=
t_attr
(
:rejection_type
)
td
=
t
(
"rejection_type.
#{
@volunteer
.
rejection_type
}
"
)
unless
@volunteer
.
rejection_type
.
blank?
tr
td
=
t_attr
(
:rejection_text
)
td
=
@volunteer
.
rejection_text
tr
td
=
t_attr
(
:duration
)
td
=
t
(
"duration.
#{
@volunteer
.
duration
}
"
)
unless
@volunteer
.
duration
.
blank?
tr
td
=
t_attr
(
:region
)
td
=
t
(
"region.
#{
@volunteer
.
region
}
"
)
unless
@volunteer
.
region
.
blank?
.table-responsive
table
.table.table-no-border-top
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment