diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 28 |
1 files changed, 28 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; } |