diff options
author | Dave Arter <davea@mysociety.org> | 2016-09-23 14:45:24 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-04 10:37:53 +0100 |
commit | d8fdbf5d353238d9e4c334f06de251987f7e60cf (patch) | |
tree | 7929ce57958f9062be3265ee57d7513aff565eeb /perllib/FixMyStreet/App/Controller/Report.pm | |
parent | 68e154c90b5a0278c4ec87aa93b80947e8704630 (diff) |
Handle extra field updates on report inspect page
We want to make sure the extra metadata stored on a problem is kept in sync with
the requirements of the category the report is in. Thus, if a report is moved to
a category that collects extra metadata then the appropriate input fields should
be shown so the inspector can enter the data.
This commit shows the category extra HTML elements for every selectable category
on the inspector page hiding those that don't apply to the selected category. JS
is used to show/hide the extra fields when the category dropdown is changed.
A consequence of the implementation is that any extra metadata from the original
category is lost when the category is changed. Some thought was given to storing
the old values elsewhere in the problem's extra field but I decided against this
for the time being.
For mysociety/fixmystreetforcouncils#45
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index e68b7fda0..355a3f2a9 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -309,6 +309,7 @@ sub inspect : Private { my $problem = $c->stash->{problem}; $c->stash->{categories} = $c->forward('/admin/categories_for_point'); + $c->stash->{report_meta} = { map { $_->{name} => $_ } @{ $c->stash->{problem}->get_extra_fields() } }; if ( $c->get_param('save') ) { $c->forward('/auth/check_csrf_token'); @@ -359,6 +360,14 @@ sub inspect : Private { if ($permissions->{report_inspect} || $permissions->{report_edit_category}) { $c->forward( '/admin/report_edit_category', [ $problem ] ); + + # The new category might require extra metadata (e.g. pothole size), so + # we need to update the problem with the new values. + my $param_prefix = lc $problem->category; + $param_prefix =~ s/[^a-z]//g; + $param_prefix = "category_" . $param_prefix . "_"; + my @contacts = grep { $_->category eq $problem->category } @{$c->stash->{contacts}}; + $c->forward('/report/new/set_report_extras', [ \@contacts, $param_prefix ]); } if ($valid) { |