diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-08-30 15:53:31 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-09-05 12:00:09 +0100 |
commit | b8916dcf8e8eeefea426a4725601bbd22263848e (patch) | |
tree | 397e6d5e7626a49f8f051ec7286ff02183dfaa9d /perllib/FixMyStreet/App/Controller/Report/New.pm | |
parent | cd405cc208bd1efa36c0ab6e7d5af7e4e56be733 (diff) |
Improve user flow when JavaScript is not available
This improves the reporting journey to only ask for category,
and then category extra questions if appropriate, first, so that
if the choice would lead to the form being disabled, this can
be shown immediately.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report/New.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index dd7f3f5fa..bc19d9c8b 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -1131,7 +1131,7 @@ sub set_report_extras : Private { foreach my $item (@metalist) { my ($metas, $param_prefix) = @$item; foreach my $field ( @$metas ) { - if ( lc( $field->{required} ) eq 'true' && !$c->cobrand->category_extra_hidden($field)) { + if ( lc( $field->{required} || '' ) eq 'true' && !$c->cobrand->category_extra_hidden($field)) { unless ( $c->get_param($param_prefix . $field->{code}) ) { $c->stash->{field_errors}->{ 'x' . $field->{code} } = _('This information is required'); } @@ -1518,10 +1518,56 @@ sub generate_map : Private { sub check_for_category : Private { my ( $self, $c ) = @_; - my $category = $c->get_param('category') || ''; + my $category = $c->get_param('category') || $c->stash->{report}->category || ''; $category = '' if $category eq _('Loading...') || $category eq _('-- Pick a category --'); - $c->stash->{category} = $category || $c->stash->{report}->category || ''; + $c->stash->{category} = $category; + # Bit of a copy of set_report_extras, because we need the results here, but + # don't want to run all of that fn until later as it e.g. alters field + # errors at that point. Also, the report might already have some answers in + # too if e.g. gone via social login... TODO Improve this? + my $extra = $c->stash->{report}->get_extra_fields; + my %current = map { $_->{name} => $_ } @$extra; + + my @contacts = grep { $_->category eq $category } @{$c->stash->{contacts}}; + my @metalist = map { @{$_->get_metadata_for_storage} } @contacts; + my @extra; + foreach my $field (@metalist) { + push @extra, { + name => $field->{code}, + description => $field->{description}, + value => $c->get_param($field->{code}) || $current{$field->{code}}{value} || '', + }; + } + $c->stash->{report}->set_extra_fields( @extra ); + + # Work out if the selected category (or category extra question answer) should lead + # to a message being shown not to use the form + if ( $c->stash->{category_extras}->{$category} && @{ $c->stash->{category_extras}->{$category} } >= 1 ) { + my $disable_form_messages = $c->forward('disable_form_message'); + if ($disable_form_messages->{all}) { + $c->stash->{disable_form_message} = $disable_form_messages->{all}; + } elsif (my $code = $disable_form_messages->{code}) { + my $answer = $c->get_param($code); + my $message = $disable_form_messages->{message}; + if ($answer) { + foreach (@{$disable_form_messages->{answers}}) { + if ($answer eq $_) { + $c->stash->{disable_form_message} = $message; + } + } + } else { + $c->stash->{have_disable_qn_to_answer} = 1; + } + } + } + + if ($c->get_param('submit_category_part_only') || $c->stash->{disable_form_message}) { + # If we've clicked the first-part category button (no-JS only probably), + # or the category submitted will be showing a disabled form message, + # we only want to reshow the form + $c->stash->{force_form_not_submitted} = 1; + } } =head2 redirect_or_confirm_creation |