From 9cc519ea0c21f77f42cf214ec60408491f36cfac Mon Sep 17 00:00:00 2001 From: Ladislav Gallay Date: Sat, 7 Oct 2023 12:41:29 +0200 Subject: [PATCH] Unify the form (add-general-agenda-app) --- .../general_agenda_controller.rb | 38 +++++++++------- .../general_agenda/application_form.rb | 35 +++++++-------- .../general_agenda/_hidden_fields.html.erb | 3 -- .../general_agenda/fill_message.erb | 45 ------------------- .../general_agenda/index.html.erb | 33 +++++++++++--- config/routes.rb | 5 +-- 6 files changed, 64 insertions(+), 95 deletions(-) delete mode 100644 app/views/apps/general_agenda_app/general_agenda/_hidden_fields.html.erb delete mode 100644 app/views/apps/general_agenda_app/general_agenda/fill_message.erb diff --git a/app/controllers/apps/general_agenda_app/general_agenda_controller.rb b/app/controllers/apps/general_agenda_app/general_agenda_controller.rb index ee7cc142..0a4d466d 100644 --- a/app/controllers/apps/general_agenda_app/general_agenda_controller.rb +++ b/app/controllers/apps/general_agenda_app/general_agenda_controller.rb @@ -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 @@ -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 diff --git a/app/models/apps/general_agenda_app/general_agenda/application_form.rb b/app/models/apps/general_agenda_app/general_agenda/application_form.rb index 83c375e8..8ce1ec2f 100644 --- a/app/models/apps/general_agenda_app/general_agenda/application_form.rb +++ b/app/models/apps/general_agenda_app/general_agenda/application_form.rb @@ -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 jan.novak@firma.sk') 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 diff --git a/app/views/apps/general_agenda_app/general_agenda/_hidden_fields.html.erb b/app/views/apps/general_agenda_app/general_agenda/_hidden_fields.html.erb deleted file mode 100644 index 1c8d95c2..00000000 --- a/app/views/apps/general_agenda_app/general_agenda/_hidden_fields.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form.hidden_field :recipient_name, value: @application_form.recipient_name %> -<%= form.hidden_field :recipient_uri, value: @application_form.recipient_uri %> -<%= form.hidden_field :current_step, value: current_step %> diff --git a/app/views/apps/general_agenda_app/general_agenda/fill_message.erb b/app/views/apps/general_agenda_app/general_agenda/fill_message.erb deleted file mode 100644 index 4888cdfe..00000000 --- a/app/views/apps/general_agenda_app/general_agenda/fill_message.erb +++ /dev/null @@ -1,45 +0,0 @@ -<%= render partial: 'header' %> - -
-
- <%= form_for @application_form, :builder => AppFormBuilder, url: fill_message_apps_general_agenda_app_general_agenda_path do |f| %> - <%= link_to 'Späť', apps_general_agenda_app_general_agenda_path, class: 'govuk-back-link button-back or-sr-app-back' %> - - -

Vaša správa

-
-
- -

Zadajte text správy a vyberte prílohy.

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

- Predmet -

- -
-
- <%= f.text_field :subject %> -
-
- -

- Text -

- -
-
- <%= f.text_area :text, rows: 15 %> -
-
- - <%= render 'hidden_fields', form: f, current_step: 'fill_message' %> - - - <% end %> -
-
diff --git a/app/views/apps/general_agenda_app/general_agenda/index.html.erb b/app/views/apps/general_agenda_app/general_agenda/index.html.erb index 27a4619c..dd41a851 100644 --- a/app/views/apps/general_agenda_app/general_agenda/index.html.erb +++ b/app/views/apps/general_agenda_app/general_agenda/index.html.erb @@ -3,30 +3,51 @@
-

Vyhľadávanie prijímateľa

+

<%= @application_form.title %>


- <%= form_for @application_form, :builder => AppFormBuilder, url: fill_message_apps_general_agenda_app_general_agenda_path do |f| %> -

Táto aplikácia Vám umožní podať všeobecnú žiadosť na orgán verejnej moci.

-

Budete potrebovať prihlásiť sa cez eID alebo Slovensko v mobile. Začnite s vyhľadaním prijímateľa, komu chcete správu poslať.

+ <%= form_for @application_form, builder: AppFormBuilder, url: apps_general_agenda_app_general_agenda_path do |f| %> +

<%= @application_form.description %>


<%= render 'components/error_summary', form: @application_form %> + <%= f.hidden_field :recipient_name %> + <%= f.hidden_field :recipient_uri %> + <%= f.hidden_field :is_submitted, value: 1 %> +

Prijímateľ

- <%= f.inputs_set :corporate_body do %> + <%= f.inputs_set :recipient_body do %>
<% end %>
- <%= render 'hidden_fields', form: f, current_step: 'recipient_selection' %> +

+ Predmet +

+ +
+
+ <%= f.text_field :subject %> +
+
+ +

+ Text +

+ +
+
+ <%= f.text_area :text, rows: 15 %> +
+

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.

diff --git a/config/routes.rb b/config/routes.rb index 6b92f5e3..7aadb6fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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