Skip to content

Commit

Permalink
Unify the form (add-general-agenda-app)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laykou committed Oct 7, 2023
1 parent a8c103c commit 9cc519e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
module Apps
module GeneralAgendaApp
class GeneralAgendaController < ApplicationController
before_action :load_application_form, only: [:fill_message]
def index
@application_form = Apps::GeneralAgendaApp::GeneralAgenda::ApplicationForm.new

render :index
end

def fill_message
return render action: :index unless @application_form.valid?(:recipient_uri)

redirect_to_upvs_submission if @application_form.should_redirect_to_upvs_submission?
def index
attributes = {
title: params[:title].presence || 'Všeobecná agenda',
description: params[:description].presence || 'Formulár pre odoslanie podania pre všeobecnú agendu',
subject: params[:subject_placeholder],
text: params[:text_placeholder],
signed_required: params[:signed_required],
text_hint: params[:text_hint],
attachments_template: params[:attachments],
}.merge(general_agenda_params || {})

@application_form = Apps::GeneralAgendaApp::GeneralAgenda::ApplicationForm.new(attributes)

redirect_to_upvs_submission if @application_form.is_submitted && @application_form.valid?
end

def callback
Expand All @@ -25,17 +29,17 @@ def redirect_to_upvs_submission
render :redirect_to_upvs_submission
end

def load_application_form
@application_form = GeneralAgendaApp::GeneralAgenda::ApplicationForm.new(message_form_params)
end

def message_form_params
params.require(:apps_general_agenda_app_general_agenda_application_form).permit(
def general_agenda_params
params[:apps_general_agenda_app_general_agenda_application_form]&.permit(
:title,
:description,
:attachments_template,
:subject,
:text,
:attachments,
:recipient_name,
:recipient_uri,
:current_step
:is_submitted
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,30 @@ class ApplicationForm
include ActiveModel::Validations

validate :recipient_present?
validates :subject, presence: true, if: -> { current_step == 'fill_message' }
validates :text, presence: true, if: -> { current_step == 'fill_message' }
validates :subject, presence: true
validates :text, presence: true

attr_accessor(
:subject,
:text,
# Static/template attributes
:title,
:description,
:attachments_template,

# Submitted through form
:recipient_name,
:recipient_uri,
:current_step,
:subject,
:text,
:text_hint,
:signed_required,
:attachments,
:is_submitted
)

def should_redirect_to_upvs_submission?
current_step == 'fill_message' && valid?
end

private

def recipient_present?
errors.add(:recipient, 'Zvoľte prijímateľa') if recipient_uri.blank?
end

def subject_present?
return unless (@current_step == 'email')

if @email.present?
errors.add(:email, 'Zadajte emailovú adresu v platnom tvare, napríklad [email protected]') unless @email.match?(URI::MailTo::EMAIL_REGEXP)
else
errors.add(:email, 'Zadajte emailovú adresu')
end
errors.add(:recipient_name, 'Zvoľte prijímateľa') if recipient_name.blank? || recipient_uri.blank?
end
end
end
Expand Down

This file was deleted.

45 changes: 0 additions & 45 deletions app/views/apps/general_agenda_app/general_agenda/fill_message.erb

This file was deleted.

33 changes: 27 additions & 6 deletions app/views/apps/general_agenda_app/general_agenda/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,51 @@
<div id="acts-submission" class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h2 class="govuk-fieldset__heading">Vyhľadávanie prijímateľa</h2>
<h2 class="govuk-fieldset__heading"><%= @application_form.title %></h2>
</legend>
<br />

<%= form_for @application_form, :builder => AppFormBuilder, url: fill_message_apps_general_agenda_app_general_agenda_path do |f| %>
<p>Táto aplikácia Vám umožní podať všeobecnú žiadosť na orgán verejnej moci.</p>
<p><b>Budete potrebovať prihlásiť sa cez eID alebo Slovensko v mobile</b>. Začnite s vyhľadaním prijímateľa, komu chcete správu poslať.</p>
<%= form_for @application_form, builder: AppFormBuilder, url: apps_general_agenda_app_general_agenda_path do |f| %>
<p><%= @application_form.description %></p>
<br />

<%= render 'components/error_summary', form: @application_form %>

<%= f.hidden_field :recipient_name %>
<%= f.hidden_field :recipient_uri %>
<%= f.hidden_field :is_submitted, value: 1 %>

<p class="govuk-label-wrapper">
<b>Prijímateľ</b>
</p>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.inputs_set :corporate_body do %>
<%= f.inputs_set :recipient_body do %>
<div id="corporate_bodies_results"></div>
<% end %>
</div>
</div>

<%= render 'hidden_fields', form: f, current_step: 'recipient_selection' %>
<p class="govuk-label-wrapper">
<b>Predmet</b>
</p>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.text_field :subject %>
</div>
</div>

<p class="govuk-label-wrapper">
<b>Text</b>
</p>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.text_area :text, rows: 15 %>
</div>
</div>

<p class="govuk-body-xs">Používaním tejto služby súhlasíte so spracovaním osobných údajov v rozsahu nevyhnutnom na odoslanie podania. Vaše údaje neukladáme, sú použité výlučne na vyplnenie podania.</p>

Expand Down
5 changes: 1 addition & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@

namespace :general_agenda_app, path: 'vseobecna-agenda' do
resource :general_agenda, controller: 'general_agenda', path: '' do
get :index
get :create
post :fill_message, path: 'vyplnenie'
post :fill_message, path: 'vyplnenie'
match :index, via: [:get, :post]
get :callback, path: 'odoslane'
end
end
Expand Down

0 comments on commit 9cc519e

Please sign in to comment.