diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 16 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 21 |
2 files changed, 35 insertions, 2 deletions
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; |