aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Form/Waste.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
committerMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
commit09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch)
tree7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /perllib/FixMyStreet/App/Form/Waste.pm
parent585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff)
parentcea89fb87a96943708a1db0f646492fbfaaf000f (diff)
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/App/Form/Waste.pm')
-rw-r--r--perllib/FixMyStreet/App/Form/Waste.pm52
1 files changed, 52 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Form/Waste.pm b/perllib/FixMyStreet/App/Form/Waste.pm
new file mode 100644
index 000000000..c430506c7
--- /dev/null
+++ b/perllib/FixMyStreet/App/Form/Waste.pm
@@ -0,0 +1,52 @@
+package FixMyStreet::App::Form::Waste;
+
+use HTML::FormHandler::Moose;
+extends 'FixMyStreet::App::Form::Wizard';
+
+has c => ( is => 'ro' );
+
+has default_page_type => ( is => 'ro', isa => 'Str', default => 'Waste' );
+
+has finished_action => ( is => 'ro' );
+
+before _process_page_array => sub {
+ my ($self, $pages) = @_;
+ foreach my $page (@$pages) {
+ $page->{type} = $self->default_page_type
+ unless $page->{type};
+ }
+};
+
+# Add some functions to the form to pass through to the current page
+has '+current_page' => (
+ handles => {
+ title => 'title',
+ template => 'template',
+ }
+);
+
+sub wizard_finished {
+ my ($form, $action) = @_;
+ my $c = $form->c;
+ my $success = $c->forward($action, [ $form ]);
+ if (!$success) {
+ $form->add_form_error('Something went wrong, please try again');
+ foreach (keys %{$c->stash->{field_errors}}) {
+ $form->add_form_error("$_: " . $c->stash->{field_errors}{$_});
+ }
+ }
+ return $success;
+}
+
+# Make sure we can have pre-ticked things on the first page
+before after_build => sub {
+ my $self = shift;
+
+ my $saved_data = $self->previous_form ? $self->previous_form->saved_data : $self->saved_data;
+
+ my $c = $self->c;
+
+ map { $saved_data->{$_} = 1 } grep { /^(service|container)-/ && $c->req->params->{$_} } keys %{$c->req->params};
+};
+
+1;