diff options
author | Struan Donald <struan@exo.org.uk> | 2011-08-22 11:22:33 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-08-22 11:22:33 +0100 |
commit | 44c31ab8efbd97086e17d26c819b1d5b4946ce43 (patch) | |
tree | 5a509a5006afd50f4c48f52fdf45ac9ac86ac054 /perllib/FixMyStreet/App/Controller/Report | |
parent | f93ff062c986847f97aef76673c2ca7742f1f125 (diff) | |
parent | a9a4fed583d7467c9c1f1fa56d42bcb75b4b488c (diff) |
Merge branch 'master' of ssh://git.mysociety.org/data/git/public/fixmystreet into open311-consumer
Conflicts:
t/app/model/problem.t
templates/web/default/report/new/fill_in_details.html
web/css/core.css
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 29 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 34 |
2 files changed, 60 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index aa919d882..3c63d5c07 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -99,6 +99,33 @@ sub report_new : Path : Args(0) { $c->forward('redirect_or_confirm_creation'); } +sub report_form_ajax : Path('ajax') : Args(0) { + my ( $self, $c ) = @_; + + $c->forward('initialize_report'); + + # work out the location for this report and do some checks + # XXX We don't want to do this here if this actually happens! + return $c->forward('redirect_to_around') + unless $c->forward('determine_location'); + + $c->forward('setup_categories_and_councils'); + + # render templates to get the html + my $category = $c->view('Web')->render( $c, 'report/new/category.html'); + my $councils_text = $c->view('Web')->render( $c, 'report/new/councils_text.html'); + + my $body = JSON->new->utf8(1)->encode( + { + councils_text => $councils_text, + category => $category, + } + ); + + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); +} + =head2 report_import Action to accept report creations from iPhones and other mobile apps. URL is @@ -935,7 +962,7 @@ sub generate_map : Private { ( $c->stash->{latitude}, $c->stash->{longitude} ); # Don't do anything if the user skipped the map - unless ( $c->req->param('skipped') ) { + if ( $c->stash->{report}->used_map ) { $c->stash->{page} = 'new'; FixMyStreet::Map::display_map( $c, diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 501dd2b41..add9d1371 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -51,8 +51,11 @@ sub update_problem : Private { my $update = $c->stash->{update}; my $problem = $c->stash->{problem} || $update->problem; + # we may need this if we display the questionnaire + my $old_state = $problem->state; + if ( $update->mark_fixed ) { - $problem->state('fixed'); + $problem->state('fixed - user'); if ( $update->user->id == $problem->user->id ) { $problem->send_questionnaire(0); @@ -65,6 +68,10 @@ sub update_problem : Private { } } + if ( $update->problem_state ) { + $problem->state( $update->problem_state ); + } + if ( $update->mark_open && $update->user->id == $problem->user->id ) { $problem->state('confirmed'); } @@ -75,6 +82,7 @@ sub update_problem : Private { $c->stash->{problem_id} = $problem->id; if ($display_questionnaire) { + $c->flash->{old_state} = $old_state; $c->detach('/questionnaire/creator_fixed'); } @@ -145,7 +153,7 @@ sub process_update : Private { my ( $self, $c ) = @_; my %params = - map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'reopen' ); + map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'state', 'reopen' ); $params{update} = Utils::cleanup_text( $params{update}, { allow_multiline => 1 } ); @@ -170,6 +178,12 @@ sub process_update : Private { } ); + if ( $params{state} ) { + $params{state} = 'fixed - council' + if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_council( $update->problem->council ); + $update->problem_state( $params{state} ); + } + $c->stash->{update} = $update; $c->stash->{add_alert} = $c->req->param('add_alert'); @@ -187,6 +201,22 @@ return false. sub check_for_errors : Private { my ( $self, $c ) = @_; + # they have to be an authority user to update the state + if ( $c->req->param('state') ) { + my $error = 0; + $error = 1 unless $c->user && $c->user->belongs_to_council( $c->stash->{update}->problem->council ); + + my $state = $c->req->param('state'); + $error = 1 unless ( grep { $state eq $_ } ( qw/confirmed closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) ); + + if ( $error ) { + $c->stash->{errors} ||= []; + push @{ $c->stash->{errors} }, _('There was a problem with your update. Please try again.'); + return; + } + + } + # let the model check for errors $c->stash->{field_errors} ||= {}; my %field_errors = ( |