add second guardian fields

This commit is contained in:
bilal
2020-06-19 15:01:30 +02:00
parent 6b0ea5b7df
commit a6104b4563
11 changed files with 187 additions and 0 deletions

View File

@@ -57,4 +57,7 @@ $(document).on("turbolinks:load", function() {
$("[data-behavior=take-guardian-photo]").click(function(e) { $("[data-behavior=take-guardian-photo]").click(function(e) {
$("[data-ujs-target=guardian-photo-input]").trigger("click"); $("[data-ujs-target=guardian-photo-input]").trigger("click");
}); });
$("[data-behavior=take-guardian-2-photo]").click(function(e) {
$("[data-ujs-target=guardian-2-photo-input]").trigger("click");
});
}); });

View File

@@ -71,8 +71,25 @@ class Public::AppearanceReleasesController < Public::BaseController
] ]
end end
def second_guardian_params
%i[
guardian_2_first_name
guardian_2_last_name
guardian_2_phone
guardian_2_email
guardian_2_photo
guardian_2_address_street1
guardian_2_address_street2
guardian_2_address_city
guardian_2_address_state
guardian_2_address_zip
guardian_2_address_country
]
end
def appearance_release_params def appearance_release_params
params.require(:appearance_release).permit(person_params, guardian_params, params.require(:appearance_release).permit(person_params, guardian_params,
second_guardian_params,
:minor, :signature_base64, :minor, :signature_base64,
:person_date_of_birth, :person_date_of_birth,
:locale, :contract_template) :locale, :contract_template)

View File

@@ -12,7 +12,9 @@ class AppearanceRelease < ApplicationRecord
include Taggable include Taggable
include PersonName include PersonName
include GuardianPhotoable include GuardianPhotoable
include SecondGuardianPhotoable
include GuardianName include GuardianName
include SecondGuardianName
has_one_attached :person_photo has_one_attached :person_photo
@@ -38,6 +40,17 @@ class AppearanceRelease < ApplicationRecord
%w[guardian_address_country country] %w[guardian_address_country country]
] ]
composed_of :guardian_2_address,
class_name: 'Address',
mapping: [
%w[guardian_2_address_street1 street1],
%w[guardian_2_address_street2 street2],
%w[guardian_2_address_city city],
%w[guardian_2_address_state state],
%w[guardian_2_address_zip zip],
%w[guardian_2_address_country country]
]
# These validations apply to all releases # These validations apply to all releases
validates :person_email, email: true, allow_blank: true validates :person_email, email: true, allow_blank: true
@@ -132,6 +145,10 @@ class AppearanceRelease < ApplicationRecord
true true
end end
def second_guardian_present?
self.guardian_2_first_name.present?
end
def contract_file_name def contract_file_name
"#{project.name.parameterize}_#{contract_template.release_type}_#{(signed_at || created_at).strftime('%Y.%m.%d')}_#{release_number}_#{filename_suffix.parameterize}" "#{project.name.parameterize}_#{contract_template.release_type}_#{(signed_at || created_at).strftime('%Y.%m.%d')}_#{release_number}_#{filename_suffix.parameterize}"
end end

View File

@@ -0,0 +1,20 @@
module SecondGuardianName
extend ActiveSupport::Concern
included do
def guardian_2_name
"#{guardian_2_first_name} #{guardian_2_last_name}".titleize
end
def guardian_2_name=(value)
if value.include?(' ')
split = value.split(" ", 2)
self.guardian_2_first_name = split.first
self.guardian_2_last_name = split.last
else
self.guardian_2_first_name = value
self.guardian_2_last_name = "(Not Given)"
end
end
end
end

View File

@@ -0,0 +1,9 @@
module SecondGuardianPhotoable
extend ActiveSupport::Concern
included do
has_one_attached :guardian_2_photo
validates :guardian_2_photo, content_type: ["image/png", "image/jpeg"]
end
end

View File

@@ -5,6 +5,9 @@
<% if release.respond_to? :guardian_photo %> <% if release.respond_to? :guardian_photo %>
<% @total_photos_count += release.guardian_photo.attached? ? 1 : 0 %> <% @total_photos_count += release.guardian_photo.attached? ? 1 : 0 %>
<% end %> <% end %>
<% if release.respond_to? :guardian_2_photo %>
<% @total_photos_count += release.guardian_2_photo.attached? ? 1 : 0 %>
<% end %>
<p class="heading"><strong><u><%= t '.heading', count: @total_photos_count %></u></strong></p> <p class="heading"><strong><u><%= t '.heading', count: @total_photos_count %></u></strong></p>
<ul> <ul>
@@ -29,6 +32,14 @@
<%= release.guardian_photo.filename.to_s %> <%= release.guardian_photo.filename.to_s %>
</li> </li>
<% end %> <% end %>
<% if release.respond_to?(:guardian_2_photo) && release.guardian_2_photo.attached? %>
<br>
<p class="heading"><strong><%= t '.guardian_2_photo_heading' %></strong></p>
<li>
<%= image_tag release.guardian_2_photo.variant(auto_orient: true, resize: "200x200") %><br />
<%= release.guardian_2_photo.filename.to_s %>
</li>
<% end %>
<% end %> <% end %>
</ul> </ul>

View File

@@ -69,4 +69,19 @@
<%= description_list_pair_for releasable, :signed_on, append: ":" %> <%= description_list_pair_for releasable, :signed_on, append: ":" %>
</dl> </dl>
<% if releasable.respond_to?(:second_guardian_present?) && releasable.second_guardian_present? %>
<br/>
<p class="text-left"><strong>Second guardian Information</strong></p>
<% # Second guardian information %>
<dl>
<%= description_list_pair_for releasable, :guardian_2_name, append: ":" %>
<%= description_list_pair_for releasable, :guardian_2_address, append: ":" %>
<%= description_list_pair_for releasable, :guardian_2_phone, append: ":" %>
<%= description_list_pair_for releasable, :guardian_2_email, append: ":" %>
</dl>
<% end %>
<% end %> <% end %>

View File

@@ -113,6 +113,49 @@
<hr> <hr>
<%= card_field_set_tag t(".guardian_2_info.heading") do %>
<div class="form-row">
<%= form.text_field :guardian_2_first_name, required: @appearance_release.minor?, wrapper_class: "col-sm-3" %>
<%= form.text_field :guardian_2_last_name, required: @appearance_release.minor?, wrapper_class: "col-sm-3" %>
<%= form.phone_field :guardian_2_phone, required: @appearance_release.minor?, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.text_field :guardian_2_email, required: @appearance_release.minor?, wrapper_class: "col-sm-6" %>
</div>
<%= render "shared/address_fields", form: form, subject: "guardian_2", required: @appearance_release.minor? %>
<% end %>
<hr>
<%= card_field_set_tag t(".guardian_2_photo.heading") do %>
<div class="alert alert-warning font-weight-bold"><%= t ".guardian_2_photo.instructions" %></div>
<div class="text-center">
<div class="d-inline-block mb-2" data-behavior="guardian-photo-preview" data-file-input="[data-ujs-target=guardian-2-photo-input]">
<div class="align-items-center d-flex photo-preview img-thumbnail justify-content-center">
<span><%= t ".photo.no_photo" %></span>
</div>
</div>
<div class="d-inline-block text-left">
<% if @appearance_release.guardian_2_photo.attached? %>
<%= javascript_tag nonce: true do %>
App.PhotoPreview.set("[data-behavior=guardian-photo-preview]", "<%= url_for(@appearance_release.guardian_2_photo.variant(auto_orient: true, resize: '200x200')) %>");
<% end %>
<% end %>
<div class="hidden-file-input">
<%= form.hidden_field :guardian_2_photo, value: form.object.guardian_2_photo.signed_id if @appearance_release.guardian_2_photo.attached? %>
<%= form.file_field :guardian_2_photo, required: @appearance_release.minor?, hide_label: true, data: { ujs_target: "guardian-2-photo-input" }, accept: @appearance_release.class.face_photo_acceptable_content_types.join(","), direct_upload: true %>
</div>
<%= button_tag t(".photo.take_photo"), type: "button", class: "btn btn-lg btn-primary take-photo-button", data: { behavior: "take-guardian-2-photo" } %>
</div>
<p class="p-2 font-weight-bold">
<%= fa_icon "arrow-up", text: t(".photo.camera_instructions_html") %><br>
<small class="text-muted"><%= t ".photo.warning" %></small>
</p>
</div>
<% end %>
<hr>
</div> </div>
<% end %> <% end %>

View File

@@ -66,6 +66,10 @@ en:
person_phone: Phone person_phone: Phone
person_photo: Photo person_photo: Photo
signed_on: Date signed_on: Date
guardian_2_address: Second guardian address
guardian_2_name: Second guardian name
guardian_2_phone: Second guardian phone
guardian_2_email: Second guardian email
location_release: location_release:
person_company: Company person_company: Company
person_email: Email person_email: Email
@@ -244,6 +248,7 @@ en:
minor_photos_heading: minor_photos_heading:
one: Minor photo one: Minor photo
other: Minor photos other: Minor photos
guardian_2_photo_heading: Second guardian photo
signature_page: signature_page:
heading: Signature Page heading: Signature Page
instructions: "By signing this signature page, as of the date listed below, I hereby agree, acknowledge and accept the terms and conditions listed in this %{releasable_name}." instructions: "By signing this signature page, as of the date listed below, I hereby agree, acknowledge and accept the terms and conditions listed in this %{releasable_name}."
@@ -334,6 +339,16 @@ en:
guardian_address_street1: Guardian address guardian_address_street1: Guardian address
guardian_address_street2: Guardian address (Line 2) guardian_address_street2: Guardian address (Line 2)
guardian_address_zip: Guardian zip code guardian_address_zip: Guardian zip code
guardian_2_address_city: Second guardian city
guardian_2_address_country: Second guardian country
guardian_2_address_state: Second guardian state
guardian_2_address_street1: Second guardian address
guardian_2_address_street2: Second guardian address (Line 2)
guardian_2_address_zip: Second guardian zip code
guardian_2_first_name: Second guardian first name
guardian_2_last_name: Second guardian last name
guardian_2_phone: Second guardian phone
guardian_2_email: Second guardian email
minor: Is the person a minor? minor: Is the person a minor?
person_address_city: City person_address_city: City
person_address_country: Country person_address_country: Country
@@ -806,10 +821,16 @@ en:
heading: Guardian Clause heading: Guardian Clause
guardian_info: guardian_info:
heading: Guardian Information heading: Guardian Information
guardian_2_info:
heading: Second Guardian Information
guardian_photo: guardian_photo:
heading: Guardian Photo heading: Guardian Photo
instructions: > instructions: >
Lastly, it's time for guardian to take a selfie photo! Please remove your hat and sunglasses (regular eyewear is ok), make sure that you are the only person in the photo, look straight into the camera, and say Cheese! Lastly, it's time for guardian to take a selfie photo! Please remove your hat and sunglasses (regular eyewear is ok), make sure that you are the only person in the photo, look straight into the camera, and say Cheese!
guardian_2_photo:
heading: Second Guardian Photo
instructions: >
Lastly, it's time for second guardian to take a selfie photo! Please remove your hat and sunglasses (regular eyewear is ok), make sure that you are the only person in the photo, look straight into the camera, and say Cheese!
instructions_html: > instructions_html: >
Congrats on appearing in <em>%{name}</em>. After scrolling down and reading the appearance release form, please enter your personal information, take a selfie photo and press the "Submit Release" button. If the person appearing on camera is a minor, you will enter their personal information first, select the button noting this person is a minor, and then enter your own personal info under "Guardian Information" at the bottom. Congrats on appearing in <em>%{name}</em>. After scrolling down and reading the appearance release form, please enter your personal information, take a selfie photo and press the "Submit Release" button. If the person appearing on camera is a minor, you will enter their personal information first, select the button noting this person is a minor, and then enter your own personal info under "Guardian Information" at the bottom.
legal: legal:

View File

@@ -73,6 +73,7 @@ es:
minor_photos_heading: minor_photos_heading:
one: Minor photo (ES) one: Minor photo (ES)
other: Minor photos (ES) other: Minor photos (ES)
guardian_2_photo_heading: Second guardian photo (ES)
signature_page: signature_page:
heading: Página de Firma de Autorización de Aparacimiento heading: Página de Firma de Autorización de Aparacimiento
instructions: Al firmar esta página de firma, a partir de la fecha indicada abajo, por la presente acepto, reconozco y acepto los términos y condiciones enumerados en esta autorización de aparacimiento. instructions: Al firmar esta página de firma, a partir de la fecha indicada abajo, por la presente acepto, reconozco y acepto los términos y condiciones enumerados en esta autorización de aparacimiento.
@@ -121,6 +122,16 @@ es:
guardian_address_street1: Dirección del tutor legal guardian_address_street1: Dirección del tutor legal
guardian_address_street2: Dirección del tutor legal (Línea 2) guardian_address_street2: Dirección del tutor legal (Línea 2)
guardian_address_zip: Guardian zip code (ES) guardian_address_zip: Guardian zip code (ES)
guardian_2_address_city: Second guardian city (ES)
guardian_2_address_country: Second guardian country (ES)
guardian_2_address_state: Second guardian state (ES)
guardian_2_address_street1: Second guardian address (ES)
guardian_2_address_street2: Second guardian address (Line 2) (ES)
guardian_2_address_zip: Second guardian zip code (ES)
guardian_2_first_name: Second guardian first name (ES)
guardian_2_last_name: Second guardian last name (ES)
guardian_2_phone: Second guardian phone (ES)
guardian_2_email: Second guardian email (ES)
guardian_name: Nómbre del tutor legal guardian_name: Nómbre del tutor legal
guardian_phone: Número de teléfono del tutor legal guardian_phone: Número de teléfono del tutor legal
minor: El firmante es un menor minor: El firmante es un menor
@@ -189,6 +200,12 @@ es:
clear: Despejar clear: Despejar
heading: Firma heading: Firma
instructions: 'Firma Abajo:' instructions: 'Firma Abajo:'
guardian_2_info:
heading: Second Guardian Information (ES)
guardian_2_photo:
heading: Second Guardian Photo (ES)
instructions: >
(ES) Lastly, it's time for second guardian to take a selfie photo! Please remove your hat and sunglasses (regular eyewear is ok), make sure that you are the only person in the photo, look straight into the camera, and say Cheese! (ES)
location_releases: location_releases:
new: new:
photos: photos:

View File

@@ -0,0 +1,14 @@
class AddSecondGuardianFieldsToAppearanceReleases < ActiveRecord::Migration[6.0]
def change
add_column :appearance_releases, :guardian_2_first_name, :string
add_column :appearance_releases, :guardian_2_last_name, :string
add_column :appearance_releases, :guardian_2_email, :string
add_column :appearance_releases, :guardian_2_phone, :string
add_column :appearance_releases, :guardian_2_address_street1, :string
add_column :appearance_releases, :guardian_2_address_street2, :string
add_column :appearance_releases, :guardian_2_address_city, :string
add_column :appearance_releases, :guardian_2_address_state, :string
add_column :appearance_releases, :guardian_2_address_zip, :string
add_column :appearance_releases, :guardian_2_address_country, :string
end
end