diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 9 | ||||
-rw-r--r-- | t/app/controller/admin/bodies.t | 32 | ||||
-rw-r--r-- | templates/web/base/admin/bodies/contact-form.html | 14 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/admin.js | 10 |
5 files changed, 64 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f607e575..91c2773ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - Mobile users can now filter the pins on the `/around` map view. #2366 - Admin improvements: - Add new roles system, to group permissions and apply to users. + - New features: + - Categories can be listed under more than one group #2475 - Bugfixes: - Prevent creation of two templates with same title. - Fix bug going between report/new pages client side diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm index 0e47d2238..2ff69b3b5 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm @@ -273,8 +273,13 @@ sub update_contacts : Private { if ( $c->get_param('reputation_threshold') ) { $contact->set_extra_metadata( reputation_threshold => int($c->get_param('reputation_threshold')) ); } - if ( my $group = $c->get_param('group') ) { - $contact->set_extra_metadata( group => $group ); + if ( my @group = $c->get_param_list('group') ) { + @group = grep { $_ } @group; + if (scalar @group == 0) { + $contact->unset_extra_metadata( 'group' ); + } else { + $contact->set_extra_metadata( group => \@group ); + } } else { $contact->unset_extra_metadata( 'group' ); } diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t index d2ae28e9d..db53b7cda 100644 --- a/t/app/controller/admin/bodies.t +++ b/t/app/controller/admin/bodies.t @@ -224,7 +224,7 @@ FixMyStreet::override_config { } } ); my $contact = $body->contacts->find({ category => 'grouped category' }); - is $contact->get_extra_metadata('group'), 'group a', "group stored correctly"; + is_deeply $contact->get_extra_metadata('group'), ['group a'], "group stored correctly"; }; subtest 'group can be unset' => sub { @@ -246,5 +246,35 @@ FixMyStreet::override_config { }; +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + MAPIT_TYPES => [ 'UTA' ], + BASE_URL => 'http://www.example.org', + COBRAND_FEATURES => { + category_groups => { default => 1 }, + multiple_category_groups => { default => 1 }, + } +}, sub { + subtest 'multi group editing works' => sub { + $mech->get_ok('/admin/body/' . $body->id); + $mech->content_contains( 'group</strong> is used for the top-level category' ); + + # have to do this as a post as adding a second group requires + # javascript + $mech->post_ok( '/admin/body/' . $body->id, { + posted => 'new', + token => $mech->form_id('category_edit')->value('token'), + category => 'grouped category', + email => 'test@example.com', + note => 'test note', + 'group' => [ 'group a', 'group b'], + non_public => undef, + state => 'unconfirmed', + } ); + + my $contact = $body->contacts->find({ category => 'grouped category' }); + is_deeply $contact->get_extra_metadata('group'), ['group a', 'group b'], "group stored correctly"; + }; +}; done_testing(); diff --git a/templates/web/base/admin/bodies/contact-form.html b/templates/web/base/admin/bodies/contact-form.html index c55c5c036..efc576b24 100644 --- a/templates/web/base/admin/bodies/contact-form.html +++ b/templates/web/base/admin/bodies/contact-form.html @@ -132,7 +132,21 @@ as well.") %] <p> <label> [% loc('Group') %] + [% IF body.get_cobrand_handler.enable_multiple_category_groups %] + [% IF contact.extra.group %] + [% FOR group IN contact.extra.group %] + <input class="form-control" type="text" name="group" value="[% group | html %]" size="30"> + [% END %] + [% ELSE %] + <input class="form-control" type="text" name="group" value="" size="30"> + [% END %] + <input class="hidden-js js-group-item-template form-control" type="text" name="group" value="" size="30"> + <p class="hidden-nojs"> + <button class="btn btn--small js-group-item-add">[% loc('Add group') %]</button> + </p> + [% ELSE %] <input class="form-control" type="text" name="group" value="[% contact.extra.group | html %]" size="30"> + [% END %] </label> </p> [% END %] diff --git a/web/cobrands/fixmystreet/admin.js b/web/cobrands/fixmystreet/admin.js index 8bc956c57..25c7651eb 100644 --- a/web/cobrands/fixmystreet/admin.js +++ b/web/cobrands/fixmystreet/admin.js @@ -165,6 +165,16 @@ $(function(){ return true; }); + $(".js-group-item-add").on("click", function(e) { + e.preventDefault(); + var $template_item = $(".js-group-item-template"); + var $new_item = $template_item.clone(); + $new_item.removeClass("hidden-js js-group-item-template"); + $new_item.insertBefore($template_item); + $new_item.focus(); + return true; + }); + // Fields can be added/removed $(".js-metadata-item-add").on("click", function(e) { e.preventDefault(); |