aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Bodies.pm6
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm11
-rw-r--r--t/app/controller/admin/bodies.t4
-rw-r--r--t/cobrand/zurich.t16
-rw-r--r--templates/web/base/admin/bodies/open311-form-fields.html2
-rw-r--r--templates/web/zurich/admin/bodies/form.html12
6 files changed, 43 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
index 67177fcbd..8ca6bbc22 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
@@ -380,9 +380,13 @@ sub body_params : Private {
);
my %params = map { $_ => $c->get_param($_) || $defaults{$_} } keys %defaults;
$c->forward('check_body_params', [ \%params ]);
+
my @extras = qw/fetch_all_problems/;
+ my $cobrand_extras = $c->cobrand->call_hook('body_extra_fields');
+ push @extras, @$cobrand_extras if $cobrand_extras;
+
%defaults = map { $_ => '' } @extras;
- my %extras = map { $_ => $c->get_param($_) || $defaults{$_} } @extras;
+ my %extras = map { $_ => $c->get_param("extra[$_]") || $defaults{$_} } @extras;
return { params => \%params, extras => \%extras };
}
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 53d86ddbc..03f76aa67 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -522,7 +522,8 @@ sub admin {
}
sub category_options {
- my ($self, $c) = @_;
+ my $self = shift;
+ my $c = $self->{c};
my @categories = $c->model('DB::Contact')->not_deleted->all;
$c->stash->{category_options} = [ map { {
category => $_->category, category_display => $_->category,
@@ -553,7 +554,7 @@ sub admin_report_edit {
$c->stash->{bodies} = \@bodies;
# Can change category to any other
- $self->category_options($c);
+ $self->category_options;
} elsif ($type eq 'dm') {
@@ -567,7 +568,7 @@ sub admin_report_edit {
$c->stash->{bodies} = \@bodies;
# Can change category to any other
- $self->category_options($c);
+ $self->category_options;
}
@@ -1135,7 +1136,7 @@ sub admin_stats {
}
# Can change category to any other
- $self->category_options($c);
+ $self->category_options;
# Total reports (non-hidden)
my $total = $c->model('DB::Problem')->search( \%params )->count;
@@ -1305,6 +1306,8 @@ sub reports_per_page { return 20; }
sub singleton_bodies_str { 1 }
+sub body_extra_fields { [ 'category' ] };
+
sub contact_extra_fields { [ 'abbreviation' ] };
sub default_problem_state { 'submitted' }
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index 6fb13f0ff..a07f19494 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -162,7 +162,7 @@ subtest 'check open311 configuring' => sub {
jurisdiction => 'open311',
send_comments => 0,
send_method => 'Open311',
- fetch_all_problems => 1,
+ 'extra[fetch_all_problems]' => 1,
}
}
);
@@ -181,7 +181,7 @@ subtest 'check open311 configuring' => sub {
jurisdiction => 'open311',
send_comments => 0,
send_method => 'Open311',
- fetch_all_problems => 0,
+ 'extra[fetch_all_problems]' => 0,
can_be_devolved => 1, # for next test
}
}
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index fbdcc3236..60ccfde14 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -745,6 +745,22 @@ subtest "phone number is not mandatory for reports from mobile apps" => sub {
$mech->clear_emails_ok;
};
+subtest "link external body to category" => sub {
+ $mech->log_in_ok( 'super@example.org' );
+ $mech->get_ok( '/admin/body/' . $zurich->id );
+ $mech->content_lacks('extra[category]');
+ $mech->get_ok( '/admin/body/' . $division->id );
+ $mech->content_lacks('extra[category]');
+ $mech->get_ok( '/admin/body/' . $subdivision->id );
+ $mech->content_lacks('extra[category]');
+ $mech->get_ok( '/admin/body/' . $external_body->id );
+ $mech->content_contains('extra[category]');
+ $mech->submit_form_ok({ with_fields => { 'extra[category]' => 'Cat1' } });
+ $mech->content_contains('<option value="Cat1" selected>');
+ $external_body->discard_changes;
+ is $external_body->get_extra_metadata('category'), 'Cat1';
+};
+
subtest "problems can't be assigned to deleted bodies" => sub {
$user = $mech->log_in_ok( 'dm1@example.org' );
$user->from_body( $zurich->id );
diff --git a/templates/web/base/admin/bodies/open311-form-fields.html b/templates/web/base/admin/bodies/open311-form-fields.html
index bdd4ad935..be2f13af0 100644
--- a/templates/web/base/admin/bodies/open311-form-fields.html
+++ b/templates/web/base/admin/bodies/open311-form-fields.html
@@ -161,7 +161,7 @@
</p>
</div>
<p>
- <input type="checkbox" id="fetch_all_problems" name="fetch_all_problems"[% ' checked' IF object.get_extra_metadata('fetch_all_problems') %]>
+ <input type="checkbox" id="fetch_all_problems" name="extra[fetch_all_problems]"[% ' checked' IF object.get_extra_metadata('fetch_all_problems') %]>
<label for="fetch_all_problems" class="inline">[% loc('Always fetch all problems') %]</label>
</p>
</div>
diff --git a/templates/web/zurich/admin/bodies/form.html b/templates/web/zurich/admin/bodies/form.html
index b625efc44..f9cd4f812 100644
--- a/templates/web/zurich/admin/bodies/form.html
+++ b/templates/web/zurich/admin/bodies/form.html
@@ -20,6 +20,18 @@
</select>
</p>
+ [% IF body AND NOT body.parent AND NOT body.bodies %]
+ <p>
+ <label for="category">[% loc('Category') %]</label>
+ <select class="form-control" name="extra[category]" id="category">
+ <option value="">[% loc('-- Pick a category --') %]</option>
+ [% FOR cat IN c.cobrand.category_options %]
+ <option value="[% cat.category %]"[% ' selected' IF cat.category == body.get_extra_metadata('category') %]>[% cat.category_display | html %]</option>
+ [% END %]
+ </select>
+ </p>
+ [% END %]
+
<p>
<label for="area_ids">[% loc('Area covered') %]</label>
<select class="form-control js-multiple" name="area_ids" id="area_ids" multiple data-none="-- [% loc('Select an area') %] --">