diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-09-25 18:11:54 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-09-30 11:46:56 +0100 |
commit | b36d053978ff90e2827c8c859f8c2b15af3b5ad1 (patch) | |
tree | 3f141cbf061fd052d16dfbbb36e9edf71aa3592a | |
parent | 9439346af7941134fd4b98a115cd936947783f0a (diff) |
Add top disable-form field to admin category form.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 16 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 21 | ||||
-rw-r--r-- | t/app/controller/admin/bodies.t | 18 | ||||
-rw-r--r-- | templates/web/base/admin/bodies/contact-form.html | 10 |
5 files changed, 64 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a171366e..4ddb95d9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Add new roles system, to group permissions and apply to users. #2483 - Contact form emails now include user admin links. - Allow categories/Open311 questions to disable the reporting form. #2599 + - Improve category edit form. #2469 - New features: - Categories can be listed under more than one group #2475 - OpenID Connect login support. #2523 diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm index 67177fcbd..3d5f1084d 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm @@ -288,6 +288,22 @@ sub update_contacts : Private { $c->forward('/admin/update_extra_fields', [ $contact ]); $c->forward('contact_cobrand_extra_fields', [ $contact ]); + # Special form disabling form + if ($c->get_param('disable')) { + my $msg = $c->get_param('disable_message'); + $errors{category} = _('Please enter a message') unless $msg; + my $meta = { + code => '_fms_disable_', + variable => 'false', + protected => 'true', + disable_form => 'true', + description => $msg, + }; + $contact->update_extra_field($meta); + } else { + $contact->remove_extra_field('_fms_disable_'); + } + if ( %errors ) { $c->stash->{updated} = _('Please correct the errors below'); $c->stash->{contact} = $contact; diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index 3ce0ec66f..bc91c84ee 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -98,7 +98,7 @@ sub category_display { $self->translate_column('category'); } -sub get_metadata_for_editing { +sub get_all_metadata { my $self = shift; my @metadata = @{$self->get_extra_fields}; @@ -111,9 +111,19 @@ sub get_metadata_for_editing { return \@metadata; } +sub get_metadata_for_editing { + my $self = shift; + my $metadata = $self->get_all_metadata; + + # Ignore the special admin-form-created entry + my @metadata = grep { $_->{code} ne '_fms_disable_' } @$metadata; + + return \@metadata; +} + sub get_metadata_for_input { my $self = shift; - my $metadata = $self->get_metadata_for_editing; + my $metadata = $self->get_all_metadata; # Also ignore any we have with a 'server_set' automated attribute my @metadata = grep { !$_->{automated} || $_->{automated} ne 'server_set' } @$metadata; @@ -136,4 +146,11 @@ sub id_field { return $self->get_extra_metadata('id_field') || 'fixmystreet_id'; } +sub disable_form_field { + my $self = shift; + my $metadata = $self->get_all_metadata; + my ($field) = grep { $_->{code} eq '_fms_disable_' } @$metadata; + return $field; +} + 1; diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t index adbb09293..c1072eb15 100644 --- a/t/app/controller/admin/bodies.t +++ b/t/app/controller/admin/bodies.t @@ -217,6 +217,24 @@ subtest 'check text output' => sub { $mech->content_lacks('<body'); }; +subtest 'disable form message editing' => sub { + $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->submit_form_ok( { with_fields => { + disable => 1, + disable_message => 'Please ring us!', + note => 'Adding emergency message', + } } ); + $mech->content_contains('Values updated'); + my $contact = $body->contacts->find({ category => 'test category' }); + is_deeply $contact->get_extra_fields, [{ + description => 'Please ring us!', + code => '_fms_disable_', + protected => 'true', + variable => 'false', + disable_form => 'true', + }], 'right message added'; +}; + }; # END of override wrap diff --git a/templates/web/base/admin/bodies/contact-form.html b/templates/web/base/admin/bodies/contact-form.html index d7cddd6b0..7a58644e5 100644 --- a/templates/web/base/admin/bodies/contact-form.html +++ b/templates/web/base/admin/bodies/contact-form.html @@ -67,6 +67,16 @@ </p> <p class="form-check"> + <input type="checkbox" name="disable" value="1" id="disable" data-toggle-visibility="#js-disable-form-message-box" [% ' checked' IF contact.disable_form_field %]> + <label for="disable">[% loc('Disable form when this category is selected') %]</label> + </p> + + <p class="form-group form-group--indented [% 'hidden-js' IF NOT contact.disable_form_field %]" id="js-disable-form-message-box"> + <label for="disabled-message">[% loc('Message to show when form is disabled (HTML permitted)') %]</label> + <textarea id="disabled-message" name="disable_message" class="form-control">[% contact.disable_form_field.description %]</textarea> + </p> + + <p class="form-check"> <input type="checkbox" name="inspection_required" value="1" id="inspection_required" data-toggle-visibility="#js-inspection-reputation-box" [% 'checked' IF contact.get_extra_metadata('inspection_required') %]> <label for="inspection_required">[% loc('Reports in this category must be inspected before being sent') %]</label> </p> |