aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Report/New.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report/New.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm33
1 files changed, 33 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index a8d5b995e..00fe7dd7a 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -99,6 +99,7 @@ sub report_new : Path : Args(0) {
# create a problem from the submitted details
$c->stash->{template} = "report/new/fill_in_details.html";
$c->forward('setup_categories_and_bodies');
+ $c->forward('setup_report_extra_fields');
$c->forward('generate_map');
$c->forward('check_for_category');
@@ -138,6 +139,7 @@ sub report_new_ajax : Path('mobile') : Args(0) {
}
$c->forward('setup_categories_and_bodies');
+ $c->forward('setup_report_extra_fields');
$c->forward('process_user');
$c->forward('process_report');
$c->forward('/photo/process_photo');
@@ -185,6 +187,7 @@ sub report_form_ajax : Path('ajax') : Args(0) {
}
$c->forward('setup_categories_and_bodies');
+ $c->forward('setup_report_extra_fields');
# render templates to get the html
my $category = $c->render_fragment( 'report/new/category.html');
@@ -235,6 +238,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
return 1;
}
$c->forward('setup_categories_and_bodies');
+ $c->forward('setup_report_extra_fields');
$c->forward('check_for_category');
my $category = $c->stash->{category} || "";
@@ -254,6 +258,9 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
if ($c->stash->{unresponsive}->{$category}) {
$generate = 1;
}
+ if ($c->stash->{report_extra_fields}) {
+ $generate = 1;
+ }
if ($generate) {
$category_extra = $c->render_fragment('report/new/category_extras.html', $vars);
}
@@ -689,6 +696,15 @@ sub setup_categories_and_bodies : Private {
$c->stash->{missing_details_body_names} = \@missing_details_body_names;
}
+sub setup_report_extra_fields : Private {
+ my ( $self, $c ) = @_;
+
+ return unless $c->cobrand->allow_report_extra_fields;
+
+ my @extras = $c->model('DB::ReportExtraFields')->for_cobrand($c->cobrand)->for_language($c->stash->{lang_code})->all;
+ $c->stash->{report_extra_fields} = \@extras;
+}
+
=head2 check_form_submitted
$bool = $c->forward('check_form_submitted');
@@ -946,6 +962,23 @@ sub set_report_extras : Private {
}
}
+ foreach my $extra_fields (@{ $c->stash->{report_extra_fields} }) {
+ my $metas = $extra_fields->get_extra_fields;
+ $param_prefix = "extra[" . $extra_fields->id . "]";
+ foreach my $field ( @$metas ) {
+ if ( lc( $field->{required} ) eq 'true' && !$c->cobrand->category_extra_hidden($field->{code})) {
+ unless ( $c->get_param($param_prefix . $field->{code}) ) {
+ $c->stash->{field_errors}->{ $field->{code} } = _('This information is required');
+ }
+ }
+ push @extra, {
+ name => $field->{code},
+ description => $field->{description},
+ value => $c->get_param($param_prefix . $field->{code}) || '',
+ };
+ }
+ }
+
$c->cobrand->process_open311_extras( $c, @$contacts[0]->body, \@extra )
if ( scalar @$contacts );