diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 18 | ||||
-rw-r--r-- | perllib/Open311.pm | 2 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 8 | ||||
-rw-r--r-- | t/open311.t | 92 | ||||
-rw-r--r-- | templates/web/bromley/report/new/fill_in_details_form.html | 31 | ||||
-rw-r--r-- | templates/web/default/js/validation_strings.html | 5 | ||||
-rw-r--r-- | templates/web/default/report/new/extra_name.html | 12 | ||||
-rw-r--r-- | web/js/fixmystreet.js | 9 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 3 |
10 files changed, 169 insertions, 31 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 9baee5eb4..ac462e293 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -398,6 +398,13 @@ sub initialize_report : Private { } + if ( $c->req->param('first_name') && $c->req->param('last_name') ) { + $c->stash->{first_name} = $c->req->param('first_name'); + $c->stash->{last_name} = $c->req->param('last_name'); + + $c->req->param( 'name', sprintf( '%s %s', $c->req->param('first_name'), $c->req->param('last_name') ) ); + } + # Capture whether the map was used $report->used_map( $c->req->param('skipped') ? 0 : 1 ); @@ -791,13 +798,22 @@ sub process_report : Private { } if ( $contacts[0]->area_id == 2482 ) { - for my $field ( qw/ fms_extra_title / ) { + for my $field ( qw/ fms_extra_title first_name last_name / ) { + my $value = $c->request->param( $field ); + if ( !$value ) { + $c->stash->{field_errors}->{ $field } = _('This information is required'); + } push @extra, { name => $field, description => uc( $field), - value => $c->request->param( $field ) || '', + value => $value || '', }; } + + if ( $c->request->param('fms_extra_title') ) { + $c->stash->{fms_extra_title} = $c->request->param('fms_extra_title'); + $c->stash->{extra_name_info} = 1; + } } if ( @extra ) { diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 56d726a8d..7b0ffca73 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -172,4 +172,22 @@ sub belongs_to_council { return 0; } +=head2 split_name + + $name = $user->split_name; + printf( 'Welcome %s %s', $name->{first}, $name->{last} ); + +Returns a hashref with first and last keys with first name(s) and last name. +NB: the spliting algorithm is extremely basic. + +=cut + +sub split_name { + my $self = shift; + + my ($first, $last) = $self->name =~ /^(\S*)(?: (.*))?$/; + + return { first => $first, last => $last }; +} + 1; diff --git a/perllib/Open311.pm b/perllib/Open311.pm index 2d50ed91f..a6810d448 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -43,7 +43,7 @@ sub send_service_request { my $service_code = shift; my $description = <<EOT; -title: @{[$problem->title()]} +title: @{[$problem->title()]} detail: @{[$problem->detail()]} diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 625c7531f..0d9a45c40 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -293,7 +293,7 @@ foreach my $test ( is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; # click through to the report page - $mech->follow_link_ok( { text => 'skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); # submit the main form @@ -473,7 +473,7 @@ subtest "test password errors for a user who is signing in as they report" => su "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( @@ -520,7 +520,7 @@ subtest "test report creation for a user who is signing in as they report" => su "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( @@ -614,7 +614,7 @@ foreach my $test ( "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); # check that the fields are correctly prefilled diff --git a/t/open311.t b/t/open311.t index 2a5e5d11c..bec03f49e 100644 --- a/t/open311.t +++ b/t/open311.t @@ -53,8 +53,66 @@ my $problem = FixMyStreet::App->model('DB::Problem')->new( { id => 80, external_id => 81, state => 'confirmed', + title => 'a problem', + detail => 'problem detail', + category => 'pothole', + latitude => 1, + longitude => 2, + user => $user, } ); +subtest 'posting service request' => sub { + my $extra = { + url => 'http://example.com/report/1', + }; + + my $results = make_service_req( $problem, $extra, $problem->category, '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>' ); + + is $results->{ res }, 248, 'got request id'; + + my $req = $o->test_req_used; + + my $description = <<EOT; +title: a problem + +detail: problem detail + +url: http://example.com/report/1 + +Submitted via FixMyStreet +EOT +; + + my $c = CGI::Simple->new( $results->{ req }->content ); + + is $c->param('email'), $user->email, 'correct email'; + is $c->param('first_name'), 'Test', 'correct first name'; + is $c->param('last_name'), 'User', 'correct last name'; + is $c->param('lat'), 1, 'latitide correct'; + is $c->param('long'), 2, 'longitude correct'; + is $c->param('description'), $description, 'descritpion correct'; + is $c->param('service_code'), 'pothole', 'service code correct'; +}; + +subtest 'extra values in service request' => sub { + $problem->extra([ + { + name => 'title', + value => 'A title', + } + ]); + + my $extra = { + url => 'http://example.com/report/1', + }; + + my $results = make_service_req( $problem, $extra, $problem->category, '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>' ); + my $req = $o->test_req_used; + my $c = CGI::Simple->new( $results->{ req }->content ); + + is $c->param('attribute[title]'), 'A title', 'extra parameter used correctly'; +}; + my $comment = FixMyStreet::App->model('DB::Comment')->new( { id => 38362, user => $user, @@ -191,18 +249,36 @@ sub make_update_req { my $comment = shift; my $xml = shift; - my $o = Open311->new( test_mode => 1, end_point => 'http://localhost/o311' ); + return make_req( $comment, $xml, 'post_service_request_update', 'update.xml' ); +} + +sub make_service_req { + my $problem = shift; + my $extra = shift; + my $service_code = shift; + my $xml = shift; + + return make_req( $problem, $xml, 'send_service_request', 'requests.xml', $extra, $service_code ); +} + +sub make_req { + my $object = shift; + my $xml = shift; + my $method = shift; + my $path = shift; + my @args = @_; + + my $o = + Open311->new( test_mode => 1, end_point => 'http://localhost/o311' ); my $test_res = HTTP::Response->new(); - $test_res->code( 200 ); - $test_res->message( 'OK' ); - $test_res->content( $xml ); + $test_res->code(200); + $test_res->message('OK'); + $test_res->content($xml); - $o->test_get_returns( { - 'update.xml' => $test_res - } ); + $o->test_get_returns( { $path => $test_res } ); - my $res = $o->post_service_request_update( $comment ); + my $res = $o->$method($object, @args); my $req = $o->test_req_used; diff --git a/templates/web/bromley/report/new/fill_in_details_form.html b/templates/web/bromley/report/new/fill_in_details_form.html index ac08de5a9..5729f1637 100644 --- a/templates/web/bromley/report/new/fill_in_details_form.html +++ b/templates/web/bromley/report/new/fill_in_details_form.html @@ -111,11 +111,21 @@ [% IF c.user_exists %] <div class="form-box"> - <label for="form_may_show_nameme">[% loc('Name') %]</label> - [% IF field_errors.name %] - <p class='form-error'>[% field_errors.name %]</p> + [% INCLUDE 'report/new/extra_name.html' %] + + [% names = c.user.split_name %] + <label for="form_first_name">[% loc('First Name') %]</label> + [% IF field_errors.first_name %] + <p class='form-error'>[% field_errors.first_name %]</p> + [% END %] + <input type="text" value="[% ( first_name || names.first ) | html %]" name="first_name" id="form_first_name" placeholder="[% loc('Your first name') %]"> + + <label for="form_last_name">[% loc('Last Name') %]</label> + [% IF field_errors.last_name %] + <p class='form-error'>[% field_errors.last_name %]</p> [% END %] - <input type="text" class="validName" value="[% report.name | html %]" name="name" id="form_name" placeholder="[% loc('Your name') %]"> + <input type="text" value="[% ( last_name || names.last ) | html %]" name="last_name" id="form_last_name" placeholder="[% loc('Your last name') %]"> + [%# if there is nothing in the name field then set check box as default on form %] <div class="checkbox-group"> @@ -151,12 +161,17 @@ [% INCLUDE 'report/new/extra_name.html' %] - <label for="form_may_show_nameme">[% loc('Name') %]</label> - [% IF field_errors.name %] - <p class='form-error'>[% field_errors.name %]</p> + <label for="form_first_name">[% loc('First Name') %]</label> + [% IF field_errors.first_name %] + <p class='form-error'>[% field_errors.first_name %]</p> [% END %] + <input type="text" class="form-focus-trigger" value="[% first_name | html %]" name="first_name" id="form_first_name" placeholder="[% loc('Your first name') %]"> - <input type="text" class="form-focus-trigger validName" value="[% report.name | html %]" name="name" id="form_name" placeholder="[% loc('Your name') %]"> + <label for="form_last_name">[% loc('Last Name') %]</label> + [% IF field_errors.last_name %] + <p class='form-error'>[% field_errors.last_name %]</p> + [% END %] + <input type="text" class="form-focus-trigger" value="[% last_name | html %]" name="last_name" id="form_last_name" placeholder="[% loc('Your last name') %]"> [%# if there is nothing in the name field then set check box as default on form %] <div class="checkbox-group"> diff --git a/templates/web/default/js/validation_strings.html b/templates/web/default/js/validation_strings.html index 70a0ed41c..71637877a 100644 --- a/templates/web/default/js/validation_strings.html +++ b/templates/web/default/js/validation_strings.html @@ -14,5 +14,8 @@ email: { required: '[% loc('Please enter your email') %]', email: '[% loc('Please enter a valid email') %]' - } + }, + fms_extra_title: '[% loc('Please enter your title') %]', + first_name: '[% loc('Please enter your first name') %]', + last_name: '[% loc('Please enter your second name') %]' }; diff --git a/templates/web/default/report/new/extra_name.html b/templates/web/default/report/new/extra_name.html index 7b057a831..ea523410b 100644 --- a/templates/web/default/report/new/extra_name.html +++ b/templates/web/default/report/new/extra_name.html @@ -4,12 +4,12 @@ <p class='form-error'>[% field_errors.fms_extra_title %]</p> [% END %] <select class="form-focus-trigger" id="form_fms_extra_title" - name="fms_extra_title" required> + name="fms_extra_title"> <option></option> - <option value="Mr">Mr</option> - <option value="Miss">Miss</option> - <option value="Mrs">Mrs</option> - <option value="Ms">Ms</option> - <option value="Dr">Dr</option> + <option value="Mr"[% ' selected' IF fms_extra_title == 'Mr' %]>Mr</option> + <option value="Miss"[% ' selected' IF fms_extra_title == 'Miss' %]>Miss</option> + <option value="Mrs"[% ' selected' IF fms_extra_title == 'Mrs' %]>Mrs</option> + <option value="Ms"[% ' selected' IF fms_extra_title == 'Ms' %]>Ms</option> + <option value="Dr"[% ' selected' IF fms_extra_title == 'Dr' %]>Dr</option> </select> [% END %] diff --git a/web/js/fixmystreet.js b/web/js/fixmystreet.js index 75546baff..36d47b5b2 100644 --- a/web/js/fixmystreet.js +++ b/web/js/fixmystreet.js @@ -101,16 +101,25 @@ $(function(){ $('#submit_sign_in').click( function(e) { $('#form_category').addClass('required validCategory').removeClass('valid'); $('#form_name').removeClass(); + $('#form_first_name').removeClass(); + $('#form_last_name').removeClass(); + $('#form_fms_extra_title').removeClass(); } ); $('#submit_register').click( function(e) { $('#form_category').addClass('required validCategory').removeClass('valid'); $('#form_name').addClass('required validName'); + $('#form_first_name').addClass('required'); + $('#form_last_name').addClass('required'); + $('#form_fms_extra_title').addClass('required'); } ); $('#problem_submit > input[type="submit"]').click( function(e) { $('#form_category').addClass('required validCategory').removeClass('valid'); $('#form_name').addClass('required validName'); + $('#form_first_name').addClass('required'); + $('#form_last_name').addClass('required'); + $('#form_fms_extra_title').addClass('required'); } ); $('#update_post').click( function(e) { diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index e4859b590..8ea54cac3 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -443,7 +443,8 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { $('#councils_text').html(data.councils_text); $('#form_category_row').html(data.category); if ( data.extra_name_info ) { - var lb = $('#form_name').prev(); + // there might be a first name field on some cobrands + var lb = $('#form_first_name').prev() || $('#form_name').prev(); lb.before(data.extra_name_info); } }); |