aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm72
-rw-r--r--templates/web/base/report/new/category.html4
-rw-r--r--templates/web/base/report/new/category_extras.html6
-rw-r--r--templates/web/base/report/new/councils_text_all.html2
-rw-r--r--templates/web/fixamingata/report/new/top_message_none.html6
5 files changed, 47 insertions, 43 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 1e0dff9d9..cee72244f 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -228,6 +228,13 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
$c->forward('check_for_category');
my $category = $c->stash->{category} || "";
+ $category = '' if $category eq _('-- Pick a category --');
+
+ my $bodies = $c->forward('contacts_to_bodies', [ $category ]);
+ my $vars = {
+ $category ? (list_of_names => [ map { $_->name } @$bodies ]) : (),
+ };
+
my $category_extra = '';
my $generate;
if ( $c->stash->{category_extras}->{$category} && @{ $c->stash->{category_extras}->{$category} } >= 1 ) {
@@ -238,11 +245,10 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
$generate = 1;
}
if ($generate) {
- $c->stash->{report} = { category => $category };
- $category_extra = $c->render_fragment( 'report/new/category_extras.html');
+ $category_extra = $c->render_fragment('report/new/category_extras.html', $vars);
}
- my $councils_text = $c->render_fragment( 'report/new/councils_text.html');
+ my $councils_text = $c->render_fragment( 'report/new/councils_text.html', $vars);
my $councils_text_private = $c->render_fragment( 'report/new/councils_text_private.html');
my $body = encode_json({
@@ -621,7 +627,7 @@ sub setup_categories_and_bodies : Private {
my %seen;
foreach my $contact (@contacts) {
- $bodies_to_list{ $contact->body_id } = 1;
+ $bodies_to_list{ $contact->body_id } = $contact->body;
unless ( $seen{$contact->category} ) {
push @category_options, $contact->category;
@@ -651,9 +657,9 @@ sub setup_categories_and_bodies : Private {
# put results onto stash for display
$c->stash->{bodies} = \%bodies;
$c->stash->{contacts} = \@contacts;
- $c->stash->{all_body_names} = [ map { $_->name } values %bodies ];
- $c->stash->{all_body_urls} = [ map { $_->external_url } values %bodies ];
$c->stash->{bodies_to_list} = [ keys %bodies_to_list ];
+ $c->stash->{bodies_to_list_names} = [ map { $_->name } values %bodies_to_list ];
+ $c->stash->{bodies_to_list_urls} = [ map { $_->external_url } values %bodies_to_list ];
$c->stash->{category_options} = \@category_options;
$c->stash->{category_extras} = \%category_extras;
$c->stash->{non_public_categories} = \%non_public_categories;
@@ -833,34 +839,14 @@ sub process_report : Private {
return 1;
}
- if ($c->stash->{unresponsive}{$report->category} || $c->stash->{unresponsive}{ALL}) {
- # Unresponsive, don't try and send a report.
- $report->bodies_str(-1);
- } else {
- # construct the bodies string:
- my $body_string = do {
- if ( $c->cobrand->can('singleton_bodies_str') && $c->cobrand->singleton_bodies_str ) {
- # Cobrands like Zurich can only ever have a single body: 'x', because some functionality
- # relies on string comparison against bodies_str.
- if (@contacts) {
- $contacts[0]->body_id;
- }
- else {
- '';
- }
- }
- else {
- # 'x,x' - x are body IDs that have this category
- my $bs = join( ',', map { $_->body_id } @contacts );
- $bs;
- };
- };
- $report->bodies_str($body_string);
- # Record any body IDs which might have meant to match, but had no contact
- if ($body_string && @{ $c->stash->{missing_details_bodies} }) {
- my $missing = join( ',', map { $_->id } @{ $c->stash->{missing_details_bodies} } );
- $report->bodies_missing($missing);
- }
+ my $bodies = $c->forward('contacts_to_bodies', [ $report->category ]);
+ my $body_string = join(',', map { $_->id } @$bodies) || '-1';
+
+ $report->bodies_str($body_string);
+ # Record any body IDs which might have meant to match, but had no contact
+ if ($body_string ne '-1' && @{ $c->stash->{missing_details_bodies} }) {
+ my $missing = join( ',', map { $_->id } @{ $c->stash->{missing_details_bodies} } );
+ $report->bodies_missing($missing);
}
my @extra;
@@ -923,6 +909,24 @@ sub process_report : Private {
return 1;
}
+sub contacts_to_bodies : Private {
+ my ($self, $c, $category) = @_;
+
+ my @contacts = grep { $_->category eq $category } @{$c->stash->{contacts}};
+
+ if ($c->stash->{unresponsive}{$category} || $c->stash->{unresponsive}{ALL}) {
+ [];
+ } else {
+ if ( $c->cobrand->can('singleton_bodies_str') && $c->cobrand->singleton_bodies_str ) {
+ # Cobrands like Zurich can only ever have a single body: 'x', because some functionality
+ # relies on string comparison against bodies_str.
+ [ $contacts[0]->body ];
+ } else {
+ [ map { $_->body } @contacts ];
+ }
+ }
+}
+
=head2 check_for_errors
Examine the user and the report for errors. If found put them on stash and
diff --git a/templates/web/base/report/new/category.html b/templates/web/base/report/new/category.html
index 65bc485ab..d63649083 100644
--- a/templates/web/base/report/new/category.html
+++ b/templates/web/base/report/new/category.html
@@ -1,6 +1,6 @@
[% IF category_options.size ~%]
[% IF category;
- category = category | lower;
+ category_lc = category | lower;
END; ~%]
<label for='form_category' id="form_category_label">
[%~ loc('Category') ~%]
@@ -8,7 +8,7 @@
<select class="form-control" name='category' id='form_category'>
[%~ FOREACH cat_op IN category_options ~%]
[% cat_op_lc = cat_op | lower =%]
- <option value='[% cat_op | html %]'[% ' selected' IF report.category == cat_op || category == cat_op_lc || (category_options.size == 2 AND loop.last) ~%]
+ <option value='[% cat_op | html %]'[% ' selected' IF report.category == cat_op || category_lc == cat_op_lc || (category_options.size == 2 AND loop.last) ~%]
>[% IF loop.first %][% cat_op %][% ELSE %][% cat_op | html %][% END %]</option>
[%~ END =%]
</select>
diff --git a/templates/web/base/report/new/category_extras.html b/templates/web/base/report/new/category_extras.html
index 6d43d125a..6b01f93e0 100644
--- a/templates/web/base/report/new/category_extras.html
+++ b/templates/web/base/report/new/category_extras.html
@@ -1,6 +1,6 @@
-<div id="category_meta">
- [%- category = report.category -%]
+[% DEFAULT list_of_names = bodies_to_list_names %]
+<div id="category_meta">
[%- IF unresponsive.$category %]
[%# Note: this is only shown on FMS.com %]
[% INCLUDE "report/new/unresponsive_body.html" body_id = unresponsive.$category %]
@@ -12,7 +12,7 @@
<p class="form-section-description">
[% tprintf(
loc('Help <strong>%s</strong> resolve your problem quicker, by providing some extra detail. This extra information will not be published online.'),
- all_body_names.join( '</strong>' _ loc(' or ') _ '<strong>' )
+ list_of_names.join( '</strong>' _ loc(' or ') _ '<strong>' )
); %]
</p>
[%- FOR meta IN category_extras.$category %]
diff --git a/templates/web/base/report/new/councils_text_all.html b/templates/web/base/report/new/councils_text_all.html
index e856e5a09..9a11eaae6 100644
--- a/templates/web/base/report/new/councils_text_all.html
+++ b/templates/web/base/report/new/councils_text_all.html
@@ -1,4 +1,4 @@
-[% DEFAULT list_of_names = all_body_names %]
+[% DEFAULT list_of_names = bodies_to_list_names %]
<p>
[%
diff --git a/templates/web/fixamingata/report/new/top_message_none.html b/templates/web/fixamingata/report/new/top_message_none.html
index 78220d6b2..9a9141b33 100644
--- a/templates/web/fixamingata/report/new/top_message_none.html
+++ b/templates/web/fixamingata/report/new/top_message_none.html
@@ -1,15 +1,15 @@
<p>
-[% IF all_body_names.size == 1 %]
+[% IF bodies_to_list_names.size == 1 %]
[%
tprintf(
"%s har valt att inte ta emot rapporter från FixaMinGata, utan hänvisar fel- &amp; synpunktsrapportering till <a href='%s'>kommunens egen webbplats</a>.",
- all_body_names.first, all_body_urls.first);
+ bodies_to_list_names.first, bodies_to_list_urls.first);
%]
[% END %]
[%
loc("If you submit a problem here the problem will <strong>not</strong> be reported to the council.");
%]
-[% IF all_body_names.size != 1 %]
+[% IF bodies_to_list_names.size != 1 %]
[%
tprintf(
loc("You can help us by finding a contact email address for local problems for %s and emailing it to us at <a href='mailto:%s'>%s</a>."),