aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2017-09-12 15:22:29 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-12-13 16:42:34 +0000
commit5b49ba7aa2ba707bd7d157db6ef0bcfc6c00cf78 (patch)
treeaac67ffcbe35a7e7c1fe03739d18b046e3394184
parent36d62c1bd83aa9e164edcc8a7e6c344cc7b07fda (diff)
Include JSON of extra fields in category_extras.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm21
2 files changed, 22 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3020a15c7..3302a79f2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -57,6 +57,7 @@
Open311 updates. #1924
- Development improvements:
- Add hook for pre-wrapper content.
+ - Include JSON representation of extra fields in category_extras output
- UK:
- Use SVG logo, inlined on front page. #1887
- Inline critical CSS on front page.
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 951f6f2be..ca4fa2fd2 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -257,6 +257,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
};
my $category_extra = '';
+ my $category_extra_json = [];
my $generate;
if ( $c->stash->{category_extras}->{$category} && @{ $c->stash->{category_extras}->{$category} } >= 1 ) {
$c->stash->{category_extras} = { $category => $c->stash->{category_extras}->{$category} };
@@ -270,6 +271,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
}
if ($generate) {
$category_extra = $c->render_fragment('report/new/category_extras.html', $vars);
+ $category_extra_json = $c->forward('generate_category_extra_json');
}
my $councils_text = $c->render_fragment( 'report/new/councils_text.html', $vars);
@@ -279,6 +281,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
category_extra => $category_extra,
councils_text => $councils_text,
councils_text_private => $councils_text_private,
+ category_extra_json => $category_extra_json,
});
$c->res->content_type('application/json; charset=utf-8');
@@ -1457,6 +1460,24 @@ sub redirect_to_around : Private {
return $c->res->redirect($around_uri);
}
+sub generate_category_extra_json : Private {
+ my ( $self, $c ) = @_;
+
+ my $true = JSON->true;
+ my $false = JSON->false;
+
+ my @fields = map {
+ {
+ %$_,
+ required => $_->{required} eq "true" ? $true : $false,
+ variable => $_->{variable} eq "true" ? $true : $false,
+ order => int($_->{order}),
+ }
+ } @{ $c->stash->{category_extras}->{$c->stash->{category}} };
+
+ return \@fields;
+}
+
__PACKAGE__->meta->make_immutable;
1;