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

Prezidentské voľby 2024 #635

Merged
merged 21 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
13 changes: 13 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@
margin-bottom: 0;
}

.light-button {
border: 2px solid #3a67e8;
color: #3a67e8;
background-color: inherit;
border-radius: 3px;
margin-bottom: 0;
}

.light-button:hover {
background-color: #3a67e8;
color: white;
}

.active-topic {
background-color: #F3F2F1;
padding: 20px 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class Apps::PresidentVoteApp::ApplicationFormsController < ApplicationController
helper FormatDaysHelper
before_action :set_metadata, :check_inactive_president_application
before_action :disable_feedback, only: [:show, :delivery, :create]

def show
render_step('start')
end

def delivery
return render_self if request.post?
render_step('delivery')
end

def permanent_resident
return render_self if request.post?
render_step('permanent_resident')
end

def create
render_self
end

private def render_self
@application_form = Apps::PresidentVoteApp::ApplicationForm.new(form_params)
@application_form.run(self)
end

private def render_step(step)
@application_form = Apps::PresidentVoteApp::ApplicationForm.new(step: step)
render step
end

private def form_params
params.require(:apps_president_vote_app_application_form).permit(
:step,
:place_first_round,
:place_second_round,
:sk_citizen,
:delivery,
:full_name, :pin, :nationality, :maiden_name,
:authorized_person_full_name, :authorized_person_pin,
:street, :pobox, :municipality,
:same_delivery_address,
:delivery_street, :delivery_pobox, :delivery_municipality, :delivery_country,
:municipality_email,
:municipality_email_verified,
:permanent_resident,
:back
)
end

private def set_metadata
@metadata.og.title = 'Žiadosť o hlasovací preukaz'
@metadata.og.image = 'facebook_share_2020.png'
@metadata.og.description = 'Aj keď budete počas volieb mimo trvalého pobytu, voliť sa dá. Stačí požiadať.'
end

private def check_inactive_president_application
return if Apps::PresidentVoteApp::ApplicationForm.active?
return redirect_to apps_president_vote_app_application_forms_path if action_name != "show"
render 'inactive'
end
end
14 changes: 12 additions & 2 deletions app/helpers/format_days_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ def format_remaining_days(remaining_days)
"Dnes je posledný možný termín."
end
end
end


def format_remaining_days_count(remaining_days)
if remaining_days > 4
"#{remaining_days} dní"
elsif remaining_days > 1
"#{remaining_days} dni"
elsif remaining_days == 1
"1 deň"
elsif remaining_days == 0
"posledný deň"
end
end
end
43 changes: 40 additions & 3 deletions app/models/apps/parliament_vote_app/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ApplicationForm
on: [:identity, :world_sk_permanent_resident, :world_abroad_permanent_resident, :authorized_person]
validates_presence_of :pin, message: 'Rodné číslo je povinná položka',
on: [:identity, :world_sk_permanent_resident, :world_abroad_permanent_resident, :authorized_person]
# validate :pin_is_ok, on: [:identity, :world_sk_permanent_resident, :world_abroad_permanent_resident, :authorized_person]
validates_presence_of :street, message: 'Zadajte ulicu alebo názov obce ak obec nemá ulice',
on: [:identity, :world_sk_permanent_resident, :authorized_person]
validates_presence_of :pobox, message: 'Zadajte poštové smerové čislo',
Expand Down Expand Up @@ -155,6 +156,33 @@ def world_sk_resident_email_body
)
end

private def pin_is_ok
return errors.add(:pin, 'Rodné číslo je pocinná položka') if pin.blank?

begin
pin.to_i
rescue ArgumentError
return errors.add(:pin, 'Rodné číslo obsahuje neplatné znaky')
end

pin = self.pin.gsub(%r{/}, '')
return errors.add(:pin, 'Rodné číslo nie je deliteľné číslom 11') if pin.length == 10 and pin.to_i % 11 != 0
return errors.add(:pin, 'Rodné číslo má nesprávnu dĺžku') if pin.length != 10 and pin.length != 9

case pin[2..3].to_i
when 0, 13..50, 63..99
return errors.add(:pin, 'Rodné číslo obsahuje neplatný mesiac')
end

month = pin[2..3].to_i % 50
year = pin[0..1].to_i + (pin[2..3].to_i > 12 ? 1900 : 2000)
begin
Date.new(year, month, pin[4..5].to_i)
rescue ArgumentError
errors.add(:pin, 'Rodné číslo obsahuje neplatný dátum')
end
end

def run(listener)
case step
when 'start'
Expand Down Expand Up @@ -192,7 +220,10 @@ def run(listener)
end

private def sk_citizen_step(listener)
if valid?(:sk_citizen)
if go_back?
self.step = 'start'
listener.render :start
elsif valid?(:sk_citizen)
case sk_citizen
when 'yes'
self.step = 'permanent_resident'
Expand All @@ -206,7 +237,10 @@ def run(listener)
end

private def permanent_resident_step(listener)
if valid?(:permanent_resident)
if go_back?
self.step = 'sk_citizen'
listener.render :sk_citizen
elsif valid?(:permanent_resident)
case permanent_resident
when 'yes'
self.step = 'place'
Expand Down Expand Up @@ -241,7 +275,10 @@ def run(listener)

# Home flow
private def delivery_step(listener)
if valid?(:delivery)
if go_back?
self.step = 'place'
listener.render :place
elsif valid?(:delivery)
case delivery
when 'post'
self.step = 'identity'
Expand Down
Loading
Loading