aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Bodies.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm72
-rw-r--r--perllib/FixMyStreet/Cobrand/Bexley.pm1
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm7
4 files changed, 65 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
index 2ff69b3b5..67177fcbd 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
@@ -241,7 +241,7 @@ sub update_contacts : Private {
my $email = $c->get_param('email');
$email =~ s/\s+//g;
- my $send_method = $c->get_param('send_method') || $contact->send_method || $contact->body->send_method || "";
+ my $send_method = $c->get_param('send_method') || $contact->body->send_method || "";
unless ( $send_method eq 'Open311' ) {
$errors{email} = _('Please enter a valid email') unless is_valid_email_list($email) || $email eq 'REFUSED';
}
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index c41b65e2a..554fbc3b7 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -143,6 +143,7 @@ sub report_new_ajax : Path('mobile') : Args(0) {
$c->forward('setup_categories_and_bodies');
$c->forward('setup_report_extra_fields');
+ $c->forward('check_for_category');
$c->forward('process_report');
$c->forward('process_user');
$c->forward('/photo/process_photo');
@@ -253,10 +254,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
$c->forward('setup_report_extra_fields');
$c->forward('check_for_category');
- my $category = $c->stash->{category} || "";
- $category = '' if $category eq _('-- Pick a category --');
-
- $c->stash->{json_response} = $c->forward('by_category_ajax_data', [ 'one', $category ]);
+ $c->stash->{json_response} = $c->forward('by_category_ajax_data', [ 'one', $c->stash->{category} ]);
$c->forward('send_json_response');
}
@@ -949,12 +947,12 @@ sub process_report : Private {
'title', 'detail', 'pc', #
'detail_size',
'may_show_name', #
- 'category', #
'subcategory', #
'partial', #
'service', #
'non_public',
);
+ $params{category} = $c->stash->{category};
# load the report
my $report = $c->stash->{report};
@@ -1025,7 +1023,16 @@ sub process_report : Private {
my $body_string = do {
if (my $single_body_only = $c->get_param('single_body_only')) {
my $body = $c->model('DB::Body')->search({ name => $single_body_only })->first;
- $body ? $body->id : '-1';
+ if ($body) {
+ # Drop the contacts down to those in this body
+ # (potentially none for e.g. Highways England)
+ # so that set_report_extras doesn't error when
+ # there are 'missing' extra fields
+ @contacts = grep { $_->body->id == $body->id } @contacts;
+ $body->id;
+ } else {
+ '-1';
+ }
} else {
my $contact_options = {};
$contact_options->{do_not_send} = [ $c->get_param_list('do_not_send', 1) ];
@@ -1133,7 +1140,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');
}
@@ -1520,9 +1527,56 @@ sub generate_map : Private {
sub check_for_category : Private {
my ( $self, $c ) = @_;
- $c->stash->{category} = $c->get_param('category') || $c->stash->{report}->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;
- return 1;
+ # 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
diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm
index 26470617a..a395543bd 100644
--- a/perllib/FixMyStreet/Cobrand/Bexley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bexley.pm
@@ -9,6 +9,7 @@ sub council_area { 'Bexley' }
sub council_name { 'London Borough of Bexley' }
sub council_url { 'bexley' }
sub get_geocoder { 'OSM' }
+sub map_type { 'OSM' }
sub disambiguate_location {
my $self = shift;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 09c6cb06d..8159d7251 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -376,13 +376,6 @@ sub check_for_errors {
$errors{name} = _('Please enter your name');
}
- if ( $self->category
- && $self->category eq _('-- Pick a category --') )
- {
- $errors{category} = _('Please choose a category');
- $self->category(undef);
- }
-
return \%errors;
}