diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 79 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 31 |
2 files changed, 89 insertions, 21 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 37ff1ae76..5bf184ae6 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -104,6 +104,68 @@ sub report_new : Path : Args(0) { $c->forward('redirect_or_confirm_creation'); } +# This is for the new phonegap versions of the app. It looks a lot like +# report_new but there's a few workflow differences as we only ever want +# to sent JSON back here + +sub report_new_ajax : Path('mobile') : Args(0) { + my ( $self, $c ) = @_; + + # create the report - loading a partial if available + $c->forward('initialize_report'); + + unless ( $c->forward('determine_location') ) { + $c->stash->{ json_response } = { errors => 'Unable to determine location' }; + $c->forward('send_json_response'); + return 1; + } + + $c->forward('setup_categories_and_councils'); + $c->forward('process_user'); + $c->forward('process_report'); + $c->forward('/photo/process_photo'); + + unless ($c->forward('check_for_errors')) { + $c->stash->{ json_response } = { errors => $c->stash->{field_errors} }; + $c->stash->{ json_response }->{check_name} = $c->user->name if $c->stash->{check_name}; + $c->forward('send_json_response'); + return 1; + } + + $c->forward('save_user_and_report'); + + my $report = $c->stash->{report}; + my $data = $c->stash->{token_data} || {}; + my $token = $c->model("DB::Token")->create( { + scope => 'problem', + data => { + %$data, + id => $report->id + } + } ); + if ( $report->confirmed ) { + $c->stash->{ json_response } = { success => 1, report => $report->id }; + } else { + $c->stash->{token_url} = $c->uri_for_email( '/P', $token->token ); + $c->send_email( 'problem-confirm.txt', { + to => [ [ $report->user->email, $report->name ] ], + } ); + $c->stash->{ json_response } = { success => 1 }; + } + + $c->forward('send_json_response'); +} + +sub send_json_response : Private { + my ( $self, $c ) = @_; + + my $body = JSON->new->utf8(1)->encode( + $c->stash->{json_response}, + ); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); +} + sub report_form_ajax : Path('ajax') : Args(0) { my ( $self, $c ) = @_; @@ -124,7 +186,6 @@ sub report_form_ajax : Path('ajax') : Args(0) { # render templates to get the html my $category = $c->render_fragment( 'report/new/category.html'); my $councils_text = $c->render_fragment( 'report/new/councils_text.html'); - my $has_open311 = keys %{ $c->stash->{category_extras} }; my $extra_name_info = $c->stash->{extra_name_info} ? $c->render_fragment('report/new/extra_name.html') : ''; @@ -133,7 +194,6 @@ sub report_form_ajax : Path('ajax') : Args(0) { { councils_text => $councils_text, category => $category, - has_open311 => $has_open311, extra_name_info => $extra_name_info, } ); @@ -579,10 +639,6 @@ sub setup_categories_and_councils : Private { $area_ids_to_list{ $contact->area_id } = 1; - next # TODO - move this to the cobrand - if $c->cobrand->moniker eq 'southampton' - && $contact->category =~ /Street lighting|Traffic lights/; - next if $contact->category eq _('Other'); unless ( $seen{$contact->category} ) { @@ -595,8 +651,9 @@ sub setup_categories_and_councils : Private { } if (@category_options) { - @category_options = - ( _('-- Pick a category --'), @category_options, _('Other') ); + @category_options = ( _('-- Pick a category --'), @category_options ); + push @category_options, _('Other') + unless $first_council->{id} == 2482; $category_label = _('Category'); } } @@ -679,6 +736,7 @@ sub process_user : Private { my $user = $c->user->obj; $report->user( $user ); $report->name( $user->name ); + $c->stash->{check_name} = 1; $c->stash->{field_errors}->{name} = _('You have successfully signed in; please check and confirm your details are accurate:'); $c->log->info($user->id . ' logged in during problem creation'); return 1; @@ -712,6 +770,7 @@ sub process_report : Private { ( 'title', 'detail', 'pc', # 'detail_size', 'detail_depth', + 'detail_offensive', 'may_show_name', # 'category', # 'partial', # @@ -732,7 +791,7 @@ sub process_report : Private { $report->title( Utils::cleanup_text( $params{title} ) ); my $detail = Utils::cleanup_text( $params{detail}, { allow_multiline => 1 } ); - for my $w ('depth', 'size') { + for my $w ('depth', 'size', 'offensive') { next unless $params{"detail_$w"}; next if $params{"detail_$w"} eq '-- Please select --'; $detail .= "\n\n\u$w: " . $params{"detail_$w"}; @@ -813,7 +872,7 @@ sub process_report : Private { }; } - $c->cobrand->process_extras( $c, \@contacts, \@extra ); + $c->cobrand->process_extras( $c, $contacts[0]->area_id, \@extra ); if ( @extra ) { $c->stash->{report_meta} = \@extra; diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 5b0dad170..3a2b40c2c 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -201,13 +201,16 @@ sub process_update : Private { $update->problem_state( $params{state} ); } + my @extra; # Next function fills this, but we don't need it here. + # This is just so that the error checkign for these extra fields runs. + # TODO Use extra here as it is used on reports. + $c->cobrand->process_extras( $c, $update->problem->council, \@extra ); + if ( $c->req->param('fms_extra_title') ) { my %extras = (); $extras{title} = $c->req->param('fms_extra_title'); - $extras{email_alerts_required} = $c->req->param('add_alert'); + $extras{email_alerts_requested} = $c->req->param('add_alert'); $update->extra( \%extras ); - - $c->stash->{fms_extra_title} = $c->req->param('fms_extra_title'); } if ( $c->stash->{ first_name } && $c->stash->{ last_name } ) { @@ -392,14 +395,20 @@ sub signup_for_alerts : Private { if ( $c->stash->{add_alert} ) { my $update = $c->stash->{update}; - my $alert = $c->model('DB::Alert')->find_or_create( - user => $update->user, - alert_type => 'new_updates', - parameter => $update->problem_id, - cobrand => $update->cobrand, - cobrand_data => $update->cobrand_data, - lang => $update->lang, - ); + my $options = { + user => $update->user, + alert_type => 'new_updates', + parameter => $update->problem_id, + }; + my $alert = $c->model('DB::Alert')->find($options); + unless ($alert) { + $alert = $c->model('DB::Alert')->create({ + %$options, + cobrand => $update->cobrand, + cobrand_data => $update->cobrand_data, + lang => $update->lang, + }); + } $alert->confirm(); } elsif ( $c->user && ( my $alert = $c->user->alert_for_problem($c->stash->{update}->problem_id) ) ) { |