diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Waste.pm | 72 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Form/Waste/Enquiry.pm | 48 |
2 files changed, 120 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Waste.pm b/perllib/FixMyStreet/App/Controller/Waste.pm index 667edad10..a31c359f1 100644 --- a/perllib/FixMyStreet/App/Controller/Waste.pm +++ b/perllib/FixMyStreet/App/Controller/Waste.pm @@ -10,6 +10,7 @@ use FixMyStreet::App::Form::Waste::UPRN; use FixMyStreet::App::Form::Waste::AboutYou; use FixMyStreet::App::Form::Waste::Request; use FixMyStreet::App::Form::Waste::Report; +use FixMyStreet::App::Form::Waste::Enquiry; sub auto : Private { my ( $self, $c ) = @_; @@ -226,6 +227,77 @@ sub process_report_data : Private { return 1; } +sub enquiry : Chained('uprn') : Args(0) { + my ($self, $c) = @_; + + if (my $template = $c->get_param('template')) { + $c->stash->{template} = "waste/enquiry-$template.html"; + $c->detach; + } + + $c->forward('setup_categories_and_bodies'); + + my $category = $c->get_param('category'); + my $service = $c->get_param('service_id'); + if (!$category || !$service || !$c->stash->{services}{$service}) { + $c->res->redirect('/waste/uprn/' . $c->stash->{uprn}); + $c->detach; + } + my ($contact) = grep { $_->category eq $category } @{$c->stash->{contacts}}; + if (!$contact) { + $c->res->redirect('/waste/uprn/' . $c->stash->{uprn}); + $c->detach; + } + + my $field_list = []; + foreach (@{$contact->get_metadata_for_input}) { + next if $_->{code} eq 'service_id' || $_->{code} eq 'uprn'; + my $type = 'Text'; + $type = 'TextArea' if 'text' eq ($_->{datatype} || ''); + my $required = $_->{required} eq 'true' ? 1 : 0; + push @$field_list, "extra_$_->{code}" => { + type => $type, label => $_->{description}, required => $required + }; + } + + $c->stash->{first_page} = 'enquiry'; + $c->stash->{form_class} = 'FixMyStreet::App::Form::Waste::Enquiry'; + $c->stash->{page_list} = [ + enquiry => { + fields => [ 'category', 'service_id', grep { ! ref $_ } @$field_list, 'continue' ], + title => $category, + next => 'about_you', + update_field_list => sub { + my $form = shift; + my $c = $form->c; + return { + category => { default => $c->get_param('category') }, + service_id => { default => $c->get_param('service_id') }, + } + } + }, + ]; + $c->stash->{field_list} = $field_list; + $c->forward('form'); +} + +sub process_enquiry_data : Private { + my ($self, $c, $form) = @_; + my $data = $form->saved_data; + my $address = $c->stash->{property}->{address}; + $data->{title} = $data->{category}; + $data->{detail} = "$data->{category}\n\n$address"; + # Read extra details in loop + foreach (grep { /^extra_/ } keys %$data) { + my ($id) = /^extra_(.*)/; + $c->set_param($id, $data->{$_}); + } + $c->set_param('service_id', $data->{service_id}); + $c->forward('add_report', [ $data ]) or return; + push @{$c->stash->{report_ids}}, $c->stash->{report}->id; + return 1; +} + sub load_form { my ($c, $previous_form) = @_; diff --git a/perllib/FixMyStreet/App/Form/Waste/Enquiry.pm b/perllib/FixMyStreet/App/Form/Waste/Enquiry.pm new file mode 100644 index 000000000..fa85d5d4c --- /dev/null +++ b/perllib/FixMyStreet/App/Form/Waste/Enquiry.pm @@ -0,0 +1,48 @@ +package FixMyStreet::App::Form::Waste::Enquiry; + +use utf8; +use HTML::FormHandler::Moose; +extends 'FixMyStreet::App::Form::Waste'; + +# First page has dynamic fields, so is set in code + +has_field category => ( type => 'Hidden' ); +has_field service_id => ( type => 'Hidden' ); + +has_page about_you => ( + fields => ['name', 'phone', 'email', 'continue'], + title => 'About you', + next => 'summary', +); + +with 'FixMyStreet::App::Form::Waste::AboutYou'; + +has_page summary => ( + fields => ['submit'], + title => 'Submit missed collection', + template => 'waste/summary_enquiry.html', + finished => sub { + return $_[0]->wizard_finished('process_enquiry_data'); + }, + next => 'done', +); + +has_page done => ( + title => 'Enquiry sent', + template => 'waste/confirmation.html', +); + +has_field continue => ( + type => 'Submit', + value => 'Continue', + element_attr => { class => 'govuk-button' }, + order => 999 +); + +has_field submit => ( + type => 'Submit', + value => 'Submit', + element_attr => { class => 'govuk-button' } +); + +1; |