aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm28
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm17
2 files changed, 45 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 4888a39f3..39d750562 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -51,6 +51,25 @@ sub display : Path('') : Args(1) {
return $c->res->redirect( $c->uri_for($1), 301 );
}
+ $c->forward( '_display', [ $id ] );
+}
+
+=head2 ajax
+
+Return JSON formatted details of a report
+
+=cut
+
+sub ajax : Path('ajax') : Args(1) {
+ my ( $self, $c, $id ) = @_;
+
+ $c->stash->{ajax} = 1;
+ $c->forward( '_display', [ $id ] );
+}
+
+sub _display : Private {
+ my ( $self, $c, $id ) = @_;
+
$c->forward( 'load_problem_or_display_error', [ $id ] );
$c->forward( 'load_updates' );
$c->forward( 'format_problem_for_display' );
@@ -151,6 +170,15 @@ sub format_problem_for_display : Private {
$c->forward('generate_map_tags');
+ if ( $c->stash->{ajax} ) {
+ $c->res->content_type('application/json; charset=utf-8');
+ my $content = JSON->new->utf8(1)->encode(
+ $problem->as_hashref( $c )
+ );
+ $c->res->body( $content );
+ return 1;
+ }
+
return 1;
}
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 20b79167f..c7fb37a84 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -731,6 +731,23 @@ sub update_send_failed {
} );
}
+sub as_hashref {
+ my $self = shift;
+ my $c = shift;
+
+ return {
+ id => $self->id,
+ title => $self->title,
+ category => $self->category,
+ detail => $self->detail,
+ latitude => $self->latitude,
+ longitude => $self->longitude,
+ postcode => $self->postcode,
+ photo => $self->get_photo_params,
+ meta => $self->meta_line( $c ),
+ };
+}
+
# we need the inline_constructor bit as we don't inherit from Moose
__PACKAGE__->meta->make_immutable( inline_constructor => 0 );