diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Auth.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Contact.pm | 5 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Develop.pm | 122 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Questionnaire.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 109 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tokens.pm | 26 | ||||
-rw-r--r-- | t/app/controller/contact.t | 2 | ||||
-rw-r--r-- | t/app/controller/develop.t | 45 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 7 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 41 | ||||
-rw-r--r-- | templates/email/default/contact.txt | 2 | ||||
-rwxr-xr-x | templates/web/base/develop/index.html | 41 | ||||
-rw-r--r-- | templates/web/base/js/translation_strings.html | 2 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 41 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 77 |
16 files changed, 364 insertions, 171 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c4a570d99..1892c5bec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - “Report another problem here” button on report confirmation page #2198 - Button in nav bar now makes it easier to report again in the same location #2195 - Shrink OpenLayers library a bit. #2217 + - Remove need for separate per-category ajax call. #1201 - Admin improvements: - Mandatory defect type selection if defect raised. - Send login email button on user edit page #2041 @@ -42,6 +43,8 @@ - Add ability for client to set bodies not to be sent to. - Make it easier to prevent a form_detail_placeholder being printed. - Include user agent in contact form emails. #2206 + - Use site name in contact email subject line. + - Add /_dev endpoints for previewing confirmation/submission pages. - Allow cobrand to add extra ability to moderate. diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm index 41674e377..9f948e0f9 100644 --- a/perllib/FixMyStreet/App/Controller/Auth.pm +++ b/perllib/FixMyStreet/App/Controller/Auth.pm @@ -54,11 +54,6 @@ sub general : Path : Args(0) { } -sub general_test : Path('_test_') : Args(0) { - my ( $self, $c ) = @_; - $c->stash->{template} = 'auth/token.html'; -} - sub authenticate : Private { my ($self, $c, $type, $username, $password) = @_; return 1 if $type eq 'email' && $c->authenticate({ email => $username, email_verified => 1, password => $password }); diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index 3a37d9fa9..aabeb650e 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -42,11 +42,6 @@ Handle contact us form submission sub submit : Path('submit') : Args(0) { my ( $self, $c ) = @_; - if (my $testing = $c->get_param('_test_')) { - $c->stash->{success} = $c->get_param('success'); - return; - } - $c->res->redirect( '/contact' ) and return unless $c->req->method eq 'POST'; return diff --git a/perllib/FixMyStreet/App/Controller/Develop.pm b/perllib/FixMyStreet/App/Controller/Develop.pm index 0bc52883f..b73bbaf86 100755 --- a/perllib/FixMyStreet/App/Controller/Develop.pm +++ b/perllib/FixMyStreet/App/Controller/Develop.pm @@ -26,10 +26,21 @@ Makes sure this controller is only available when run in development. sub auto : Private { my ($self, $c) = @_; - $c->detach( '/page_error_404_not_found' ) unless $c->config->{STAGING_SITE}; + $c->detach( '/page_error_404_not_found' ) unless $c->user_exists && $c->user->is_superuser; return 1; } +=item index + +Shows a list of links to preview HTML emails. + +=cut + +sub index : Path('/_dev') : Args(0) { + my ( $self, $c ) = @_; + $c->stash->{problem} = $c->model('DB::Problem')->first; +} + =item email_list Shows a list of links to preview HTML emails. @@ -130,6 +141,115 @@ sub email_previewer : Path('/_dev/email') : Args(1) { $c->response->body($html); } +=item problem_confirm_previewer + +Displays the confirmation page for a given problem. + +=back + +=cut + +sub problem_confirm_previewer : Path('/_dev/confirm_problem') : Args(1) { + my ( $self, $c, $id ) = @_; + + $c->log->info('Previewing confirmation page for problem ' . $id); + + my $problem = $c->model('DB::Problem')->find( { id => $id } ) + || $c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] ); + $c->stash->{report} = $problem; + + $c->log->info('Problem ' . $id . ' found: ' . $problem->title); + $c->stash->{template} = 'tokens/confirm_problem.html'; +} + +=item update_confirm_previewer + +Displays the confirmation page for an update on the given problem. + +=back + +=cut + +sub update_confirm_previewer : Path('/_dev/confirm_update') : Args(1) { + my ( $self, $c, $id ) = @_; + + my $problem = $c->model('DB::Problem')->find( { id => $id } ) + || $c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] ); + $c->stash->{problem} = $problem; + + $c->stash->{template} = 'tokens/confirm_update.html'; +} + +=item alert_confirm_previewer + +Displays the confirmation page for an alert, with the supplied +confirmation type (ie: subscribed, or unsubscribed). + +=back + +=cut + +sub alert_confirm_previewer : Path('/_dev/confirm_alert') : Args(1) { + my ( $self, $c, $confirm_type ) = @_; + $c->stash->{confirm_type} = $confirm_type; + $c->stash->{template} = 'tokens/confirm_alert.html'; +} + +=item contact_submit_previewer + +Displays the contact submission page, with success based on the +truthyness of the supplied argument. + +=back + +=cut + +sub contact_submit_previewer : Path('/_dev/contact_submit') : Args(1) { + my ( $self, $c, $success ) = @_; + $c->stash->{success} = $success; + $c->stash->{template} = 'contact/submit.html'; +} + +=item questionnaire_completed_previewer + +Displays the questionnaire completed page, with content based on +the supplied ?new_state and ?been_fixed query params. + +=back + +=cut + +sub questionnaire_completed_previewer : Path('/_dev/questionnaire_completed') : Args(0) { + my ( $self, $c ) = @_; + $c->stash->{been_fixed} = $c->get_param('been_fixed'); + $c->stash->{new_state} = $c->get_param('new_state'); + $c->stash->{template} = 'questionnaire/completed.html'; +} + +=item questionnaire_creator_fixed_previewer + +Displays the page a user sees after they mark their own report as fixed. + +=back + +=cut + +sub questionnaire_creator_fixed_previewer : Path('/_dev/questionnaire_creator_fixed') : Args(0) { + my ( $self, $c ) = @_; + $c->stash->{template} = 'questionnaire/creator_fixed.html'; +} + +sub auth_preview : Path('/_dev/auth') : Args(0) { + my ( $self, $c ) = @_; + $c->stash->{template} = 'auth/token.html'; +} + +sub report_new_preview : Path('/_dev/report_new') : Args(0) { + my ( $self, $c ) = @_; + $c->stash->{template} = 'email_sent.html'; + $c->stash->{email_type} = $c->get_param('email_type'); +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 696529660..d2b0bf3f4 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -65,15 +65,8 @@ sub submit : Path('submit') { my ( $self, $c ) = @_; if (my $token = $c->get_param('token')) { - if ($token eq '_test_') { - $c->stash->{been_fixed} = $c->get_param('been_fixed'); - $c->stash->{new_state} = $c->get_param('new_state'); - $c->stash->{template} = 'questionnaire/completed.html'; - return; - } $c->forward('submit_standard'); } elsif (my $p = $c->get_param('problem')) { - $c->detach('creator_fixed') if $p eq '_test_'; $c->forward('submit_creator_fixed'); } else { $c->detach( '/page_error_404_not_found' ); diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index a1038e909..dfaf43ffb 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -118,12 +118,6 @@ sub report_new : Path : Args(0) { $c->forward('redirect_or_confirm_creation'); } -sub report_new_test : Path('_test_') : Args(0) { - my ( $self, $c ) = @_; - $c->stash->{template} = 'email_sent.html'; - $c->stash->{email_type} = $c->get_param('email_type'); -} - # 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 @@ -188,10 +182,8 @@ sub report_form_ajax : Path('ajax') : Args(0) { # work out the location for this report and do some checks if ( ! $c->forward('determine_location') ) { - my $body = encode_json({ error => $c->stash->{location_error} }); - $c->res->content_type('application/json; charset=utf-8'); - $c->res->body($body); - return; + $c->stash->{json_response} = { error => $c->stash->{location_error} }; + $c->detach('send_json_response'); } $c->forward('setup_categories_and_bodies'); @@ -220,22 +212,27 @@ sub report_form_ajax : Path('ajax') : Args(0) { $contribute_as->{body} = $ca_body if $ca_body; } - my $body = encode_json( - { - bodies => \@list_of_names, - councils_text => $councils_text, - councils_text_private => $councils_text_private, - category => $category, - extra_name_info => $extra_name_info, - titles_list => $extra_titles_list, - %$contribute_as ? (contribute_as => $contribute_as) : (), - $top_message ? (top_message => $top_message) : (), - unresponsive => $c->stash->{unresponsive}->{ALL} || '', - } - ); + my %by_category; + foreach my $contact (@{$c->stash->{category_options}}) { + next if ref $contact eq 'HASH'; # Ignore the 'Pick a category' line + my $cat = $c->stash->{category} = $contact->category; + my $body = $c->forward('by_category_ajax_data', [ 'all', $cat ]); + $by_category{$cat} = $body; + } - $c->res->content_type('application/json; charset=utf-8'); - $c->res->body($body); + $c->stash->{json_response} = { + bodies => \@list_of_names, + councils_text => $councils_text, + councils_text_private => $councils_text_private, + category => $category, + extra_name_info => $extra_name_info, + titles_list => $extra_titles_list, + %$contribute_as ? (contribute_as => $contribute_as) : (), + $top_message ? (top_message => $top_message) : (), + unresponsive => $c->stash->{unresponsive}->{ALL} || '', + by_category => \%by_category, + }; + $c->detach('send_json_response'); } sub category_extras_ajax : Path('category_extras') : Args(0) { @@ -243,29 +240,24 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { $c->forward('initialize_report'); if ( ! $c->forward('determine_location') ) { - my $body = encode_json({ error => _("Sorry, we could not find that location.") }); - $c->res->content_type('application/json; charset=utf-8'); - $c->res->body($body); - return 1; + $c->stash->{json_response} = { error => _("Sorry, we could not find that location.") }; + $c->detach('send_json_response'); } $c->forward('setup_categories_and_bodies'); $c->forward('setup_report_extra_fields'); - $c->forward('check_for_category'); + $c->forward('check_for_category'); my $category = $c->stash->{category} || ""; $category = '' if $category eq _('-- Pick a category --'); - my $bodies = $c->forward('contacts_to_bodies', [ $category ]); + $c->stash->{json_response} = $c->forward('by_category_ajax_data', [ 'one', $category ]); + $c->forward('send_json_response'); +} - my $list_of_names = [ map { $_->name } ($category ? @$bodies : values %{$c->stash->{bodies_to_list}}) ]; - my $vars = { - $category ? (list_of_names => $list_of_names) : (), - }; +sub by_category_ajax_data : Private { + my ($self, $c, $type, $category) = @_; - my $category_extra = ''; - my $category_extra_json = []; my $generate; - my $unresponsive = ''; if ( $c->stash->{category_extras}->{$category} && @{ $c->stash->{category_extras}->{$category} } >= 1 ) { $c->stash->{category_extras} = { $category => $c->stash->{category_extras}->{$category} }; $generate = 1; @@ -276,27 +268,36 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { if ($c->stash->{report_extra_fields}) { $generate = 1; } + + my $bodies = $c->forward('contacts_to_bodies', [ $category ]); + my $list_of_names = [ map { $_->name } ($category ? @$bodies : values %{$c->stash->{bodies_to_list}}) ]; + my $vars = { + $category ? (list_of_names => $list_of_names) : (), + }; + + my $body = { + bodies => $list_of_names, + }; + if ($generate) { - $category_extra = $c->render_fragment('report/new/category_extras.html', $vars); - $category_extra_json = $c->forward('generate_category_extra_json'); - } + $body->{category_extra} = $c->render_fragment('report/new/category_extras.html', $vars); + $body->{category_extra_json} = $c->forward('generate_category_extra_json'); - my $councils_text = $c->render_fragment( 'report/new/councils_text.html', $vars); - my $councils_text_private = $c->render_fragment( 'report/new/councils_text_private.html'); + } - $unresponsive = $c->stash->{unresponsive}->{$category} || $c->stash->{unresponsive}->{ALL} || ''; + my $unresponsive = $c->stash->{unresponsive}->{$category}; + $unresponsive ||= $c->stash->{unresponsive}->{ALL} || '' if $type eq 'one'; - my $body = encode_json({ - category_extra => $category_extra, - councils_text => $councils_text, - councils_text_private => $councils_text_private, - category_extra_json => $category_extra_json, - unresponsive => $unresponsive, - bodies => $list_of_names, - }); + # unresponsive must return empty string if okay, as that's what mobile app checks + if ($type eq 'one' || ($type eq 'all' && $unresponsive)) { + $body->{unresponsive} = $unresponsive; + if ($type eq 'all' && $unresponsive) { + $body->{councils_text} = $c->render_fragment( 'report/new/councils_text.html', $vars); + $body->{councils_text_private} = $c->render_fragment( 'report/new/councils_text_private.html'); + } + } - $c->res->content_type('application/json; charset=utf-8'); - $c->res->body($body); + return $body; } =head2 report_import diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index bb6140e0a..659d763de 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -28,17 +28,6 @@ problem but are not logged in. sub confirm_problem : Path('/P') { my ( $self, $c, $token_code ) = @_; - if ($token_code eq '_test_') { - $c->stash->{report} = { - id => 123, - title => 'Title of Report', - bodies_str => '1', - url => '/report/123', - service => $c->get_param('service'), - }; - return; - } - my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'problem' ] ); @@ -88,11 +77,6 @@ alert but are not logged in. sub confirm_alert : Path('/A') { my ( $self, $c, $token_code ) = @_; - if ($token_code eq '_test_') { - $c->stash->{confirm_type} = $c->get_param('confirm_type'); - return; - } - my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'alert' ] ); # Load the alert @@ -134,16 +118,6 @@ update but are not logged in. sub confirm_update : Path('/C') { my ( $self, $c, $token_code ) = @_; - if ($token_code eq '_test_') { - $c->stash->{problem} = { - id => 123, - title => 'Title of Report', - bodies_str => '1', - url => '/report/123', - }; - return; - } - my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'comment' ] ); diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index cb299d161..2cbdbc0da 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -305,7 +305,7 @@ for my $test ( my $email = $mech->get_email; - is $email->header('Subject'), 'FMS message: ' . $test->{fields}->{subject}, 'subject'; + is $email->header('Subject'), 'FixMyStreet message: ' . $test->{fields}->{subject}, 'subject'; is $email->header('From'), "\"$test->{fields}->{name}\" <$test->{fields}->{em}>", 'from'; my $body = $mech->get_text_body_from_email($email); like $body, qr/$test->{fields}->{message}/, 'body'; diff --git a/t/app/controller/develop.t b/t/app/controller/develop.t index 92aa86721..8f26a9f16 100644 --- a/t/app/controller/develop.t +++ b/t/app/controller/develop.t @@ -6,14 +6,20 @@ my ($problem) = $mech->create_problems_for_body(1, 2504, 'title'); my $update = $mech->create_comment_for_problem($problem, $problem->user, 'Name', 'Text', 'f', 'confirmed', 'confirmed'); subtest 'not visible on live site' => sub { - FixMyStreet::override_config { - STAGING_SITE => 0 - }, sub { - $mech->get('/_dev/email/'); - is $mech->res->code, 404; - $mech->get('/_dev/email/login'); - is $mech->res->code, 404; - }; + $mech->get('/_dev/'); + is $mech->res->code, 404; + $mech->get('/_dev/email'); + is $mech->res->code, 404; + $mech->get('/_dev/email/login'); + is $mech->res->code, 404; +}; + +$problem->user->update({ is_superuser => 1 }); +$mech->log_in_ok($problem->user->email); + +subtest 'dev index' => sub { + $mech->get_ok('/_dev/'); + $mech->content_contains('<h1>/_dev</h1>'); }; subtest 'dev email index page' => sub { @@ -30,4 +36,27 @@ subtest 'individual email previews' => sub { $mech->get_ok('/_dev/email/update-confirm?update=' . $update->id); }; +subtest 'problem confirmation page preview' => sub { + $mech->get_ok('/_dev/confirm_problem/' . $problem->id ); +}; + +subtest 'update confirmation page preview' => sub { + $mech->get_ok('/_dev/confirm_update/' . $problem->id); +}; + +subtest 'alert confirmation page preview' => sub { + $mech->get_ok('/_dev/confirm_alert/subscribe'); +}; + +subtest 'contact form submission page preview' => sub { + $mech->get_ok('/_dev/contact_submit/1'); +}; + +subtest 'questionnaire completion page previews' => sub { + $mech->get_ok('/_dev/questionnaire_completed?been_fixed=Yes'); + $mech->get_ok('/_dev/questionnaire_completed?been_fixed=Unknown'); + $mech->get_ok('/_dev/questionnaire_completed?new_state=confirmed'); + $mech->get_ok('/_dev/questionnaire_creator_fixed'); +}; + done_testing(); diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 048f2644e..94c7b1231 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -1669,10 +1669,9 @@ subtest "unresponsive body handling works" => sub { # Test body-level send method my $old_send = $contact1->body->send_method; $contact1->body->update( { send_method => 'Refused' } ); - $mech->get_ok('/report/new/ajax?latitude=55.952055&longitude=-3.189579'); # Edinburgh my $body_id = $contact1->body->id; - ok $mech->content_like( qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id} ); my $extra_details = $mech->get_ok_json('/report/new/ajax?latitude=55.952055&longitude=-3.189579'); + like $extra_details->{top_message}, qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id}; is $extra_details->{unresponsive}, $body_id, "unresponsive json set"; $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Street%20lighting&latitude=55.952055&longitude=-3.189579'); is $extra_details->{unresponsive}, $body_id, "unresponsive json set"; @@ -1749,8 +1748,8 @@ subtest "unresponsive body handling works" => sub { # And test per-category refusing my $old_email = $contact3->email; $contact3->update( { email => 'REFUSED' } ); - $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.896268&longitude=-2.093063'); - ok $mech->content_like( qr/Cheltenham.*Trees.*unresponsive.*category=Trees/ ); + $extra_details = $mech->get_ok_json('/report/new/ajax?latitude=51.896268&longitude=-2.093063'); + like $extra_details->{by_category}{$contact3->category}{category_extra}, qr/Cheltenham.*Trees.*unresponsive.*category=Trees/s; $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Trees&latitude=51.896268&longitude=-2.093063'); is $extra_details->{unresponsive}, $contact3->body->id, "unresponsive json set"; diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index 17b489447..7d4f5429f 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -249,13 +249,18 @@ subtest "Category extras omits description label when all fields are hidden" => ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], MAPIT_URL => 'http://mapit.uk/', }, sub { - my $json = $mech->get_ok_json('/report/new/category_extras?category=Pothole&latitude=55.952055&longitude=-3.189579'); - my $category_extra = $json->{category_extra}; - contains_string($category_extra, "usrn"); - contains_string($category_extra, "central_asset_id"); - lacks_string($category_extra, "USRN", "Lacks 'USRN' label"); - lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label"); - lacks_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Lacks description text"); + for ( + { url => '/report/new/ajax?' }, + { url => '/report/new/category_extras?category=Pothole' }, + ) { + my $json = $mech->get_ok_json($_->{url} . '&latitude=55.952055&longitude=-3.189579'); + my $category_extra = $json->{by_category} ? $json->{by_category}{Pothole}{category_extra} : $json->{category_extra}; + contains_string($category_extra, "usrn"); + contains_string($category_extra, "central_asset_id"); + lacks_string($category_extra, "USRN", "Lacks 'USRN' label"); + lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label"); + lacks_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Lacks description text"); + } }; }; @@ -266,15 +271,19 @@ subtest "Category extras includes description label for user" => sub { }, sub { $contact4->push_extra_fields({ description => 'Size?', code => 'size', required => 'true', automated => '', variable => 'true', order => '3' }); $contact4->update; - - my $json = $mech->get_ok_json('/report/new/category_extras?category=Pothole&latitude=55.952055&longitude=-3.189579'); - my $category_extra = $json->{category_extra}; - contains_string($category_extra, "usrn"); - contains_string($category_extra, "central_asset_id"); - lacks_string($category_extra, "USRN", "Lacks 'USRN' label"); - lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label"); - contains_string($category_extra, "Size?"); - contains_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Contains description text"); + for ( + { url => '/report/new/ajax?' }, + { url => '/report/new/category_extras?category=Pothole' }, + ) { + my $json = $mech->get_ok_json($_->{url} . '&latitude=55.952055&longitude=-3.189579'); + my $category_extra = $json->{by_category} ? $json->{by_category}{Pothole}{category_extra} : $json->{category_extra}; + contains_string($category_extra, "usrn"); + contains_string($category_extra, "central_asset_id"); + lacks_string($category_extra, "USRN", "Lacks 'USRN' label"); + lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label"); + contains_string($category_extra, "Size?"); + contains_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Contains description text"); + } }; }; diff --git a/templates/email/default/contact.txt b/templates/email/default/contact.txt index 545b1632c..bd97d17a6 100644 --- a/templates/email/default/contact.txt +++ b/templates/email/default/contact.txt @@ -1,4 +1,4 @@ -Subject: FMS message: [% subject %] +Subject: [% site_name %] message: [% subject %] [% message %] diff --git a/templates/web/base/develop/index.html b/templates/web/base/develop/index.html new file mode 100755 index 000000000..56af2319d --- /dev/null +++ b/templates/web/base/develop/index.html @@ -0,0 +1,41 @@ +[% INCLUDE 'header.html' %] + +<h1>/_dev</h1> + +<p><a href="/_dev/email">Email previews</a></p> + +<dl> + +<dt>Questionnaire responses</dt> +<dd><ul> +<li><a href="/_dev/questionnaire_completed?been_fixed=Yes">Yes</a> +<li><a href="/_dev/questionnaire_completed?new_state=confirmed">No</a> +<li><a href="/_dev/questionnaire_completed?been_fixed=Unknown">Unknown</a> +<li><a href="/_dev/questionnaire_creator_fixed">Mark fixed as part of update by reporter</a> +</ul></dd> + +<dt>Confirmation pages</dt> +<dd><ul> +<li><a href="/_dev/confirm_problem/[% problem.id %]">Problem</a> +<li><a href="/_dev/confirm_update/[% problem.id %]">Update</a> +<li><a href="/_dev/confirm_alert/subscribe">Alert</a> +<li><a href="/_dev/confirm_alert/unsubscribe">Alert unsubscribe</a> +</ul></dd> + +<dt>Contact form</dt> +<dd><ul> +<li><a href="/_dev/contact_submit/1">Success</a> +<li><a href="/_dev/contact_submit/0">Failure</a> +</ul></dd> + +<dt>Check email pages</dt> +<dd><ul> +<li><a href="/_dev/auth">Auth</a> + <li><a href="/_dev/report_new?email_type=problem">New report</a> + <li><a href="/_dev/report_new?email_type=update">New update</a> + <li><a href="/_dev/report_new?email_type=alert">New alert</a> +</ul></dd> + +</dl> + +[% INCLUDE 'footer.html' %] diff --git a/templates/web/base/js/translation_strings.html b/templates/web/base/js/translation_strings.html index f6e1e580b..bd8144a63 100644 --- a/templates/web/base/js/translation_strings.html +++ b/templates/web/base/js/translation_strings.html @@ -38,6 +38,8 @@ fixmystreet.password_minimum_length = [% c.cobrand.password_minimum_length %]; how_to_send: '[% loc('How to send successful reports') | replace("'", "\\'") %]', more_details: '[% loc('Details') | replace("'", "\\'") %]', + or: '[% loc(' or ') | replace("'", "\\'") %]', + geolocation_declined: '[% loc('You declined; please fill in the box above') | replace("'", "\\'") %]', geolocation_no_position: '[% loc('Could not look up location') | replace("'", "\\'") %]', geolocation_no_result: '[% loc('No result returned') | replace("'", "\\'") %]', diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 280fe001c..c27d19211 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -19,9 +19,7 @@ var fixmystreet = fixmystreet || {}; OpenLayers.Layer.VectorAsset = OpenLayers.Class(OpenLayers.Layer.Vector, { initialize: function(name, options) { OpenLayers.Layer.Vector.prototype.initialize.apply(this, arguments); - // Do in both locations so fixmystreet.bodies is up to date. Otherwise - // e.g. a layer can disappear the category change after it should. - $(fixmystreet).on('report_new:category_change:extras_received', this.update_layer_visibility.bind(this)); + // Update layer based upon new data from category change $(fixmystreet).on('report_new:category_change', this.update_layer_visibility.bind(this)); }, @@ -74,9 +72,7 @@ OpenLayers.Layer.VectorNearest = OpenLayers.Class(OpenLayers.Layer.VectorAsset, OpenLayers.Layer.VectorAsset.prototype.initialize.apply(this, arguments); $(fixmystreet).on('maps:update_pin', this.checkFeature.bind(this)); $(fixmystreet).on('assets:selected', this.checkFeature.bind(this)); - // Might only be able to fill in fields once they've been returned from the server - $(fixmystreet).on('report_new:category_change:extras_received', this.changeCategory.bind(this)); - // But also want to do it immediately in case it's hiding the form or something + // Update fields/etc from data now available from category change $(fixmystreet).on('report_new:category_change', this.changeCategory.bind(this)); }, @@ -332,6 +328,13 @@ function check_zoom_message_visibility() { } function layer_visibilitychanged() { + if (this.fixmystreet.road) { + if (!this.getVisibility()) { + this.road_not_found(); + } + return; + } + check_zoom_message_visibility.call(this); var layers = fixmystreet.map.getLayersBy('assets', true); var visible = 0; @@ -624,7 +627,8 @@ fixmystreet.assets = { } }); } - if (!options.always_visible) { + + if (!options.always_visible || options.road) { asset_layer.events.register( 'visibilitychanged', asset_layer, layer_visibilitychanged); } @@ -804,22 +808,25 @@ return { })(); $(fixmystreet).on('body_overrides:change', function() { - var councils_text = $('#js-councils_text').html(); + var single_body_only = $('#single_body_only').val(), + do_not_send = $('#do_not_send').val(), + bodies = fixmystreet.bodies; - var single_body_only = $('#single_body_only').val(); if (single_body_only) { - councils_text = councils_text.replace(/<strong>.*<\/strong>/, '<strong>' + single_body_only + '</strong>'); + bodies = [ single_body_only ]; } - var do_not_send = $('#do_not_send').val(); if (do_not_send) { do_not_send = fixmystreet.utils.csv_to_array(do_not_send); - for (var i=0; i<do_not_send.length; i++) { - // XXX Translations - councils_text = councils_text.replace(new RegExp('or <strong>' + do_not_send[i] + '</strong>'), ''); - councils_text = councils_text.replace(new RegExp('<strong>' + do_not_send[i] + '</strong> or '), ''); - } + var lookup = {}; + $.map(do_not_send, function(val) { + lookup[val] = 1; + }); + bodies = OpenLayers.Array.filter(bodies, function(b) { + return !lookup[b]; + }); } - $('#js-councils_text').html(councils_text); + fixmystreet.update_public_councils_text( + $('#js-councils_text').html(), bodies); }); diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index 63f4c16b4..b663d37ba 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -387,34 +387,49 @@ $.extend(fixmystreet.set_up, { // On the new report form, does this by asking for details from the server. // Delegation is necessary because #form_category may be replaced during the lifetime of the page $("#problem_form").on("change.category", "select#form_category", function(){ - var args = { - category: $(this).val(), - latitude: $('input[name="latitude"]').val(), - longitude: $('input[name="longitude"]').val() - }; - - $.getJSON('/report/new/category_extras', args, function(data) { - var $category_meta = $('#category_meta'); + // If we haven't got any reporting data (e.g. came straight to + // /report/new), fetch it first. That will then automatically call this + // function again, due to it calling change() on the category if set. + if (!fixmystreet.reporting_data) { + if (fixmystreet.map) { + fixmystreet.update_pin(fixmystreet.map.getCenter(), false); + } + return; + } + + var category = $(this).val(), + data = fixmystreet.reporting_data.by_category[category], + $category_meta = $('#category_meta'); + + if (!data) { + // The Pick a category option, or something gone wrong + return; + } + + fixmystreet.bodies = data.bodies || []; + if (fixmystreet.body_overrides) { + fixmystreet.body_overrides.clear(); + } + + if (data.councils_text) { fixmystreet.update_councils_text(data); - if ( data.category_extra ) { - if ( $category_meta.length ) { - $category_meta.replaceWith( data.category_extra ); - // Preserve any existing values - $category_meta.find("[name]").each(function() { - $('#category_meta').find("[name="+this.name+"]").val(this.value); - }); - } else { - $('#form_category_row').after( data.category_extra ); - } + } else { + // Use the original returned texts + fixmystreet.update_councils_text(fixmystreet.reporting_data); + } + if ( data.category_extra ) { + if ( $category_meta.length ) { + $category_meta.replaceWith( data.category_extra ); + // Preserve any existing values + $category_meta.find("[name]").each(function() { + $category_meta.find("[name="+this.name+"]").val(this.value); + }); } else { - $category_meta.empty(); - } - fixmystreet.bodies = data.bodies || []; - if (fixmystreet.body_overrides) { - fixmystreet.body_overrides.clear(); + $('#form_category_row').after( data.category_extra ); } - $(fixmystreet).trigger('report_new:category_change:extras_received'); - }); + } else { + $category_meta.empty(); + } $(fixmystreet).trigger('report_new:category_change', [ $(this) ]); }); @@ -940,8 +955,15 @@ fixmystreet.update_report_a_problem_btn = function() { $('.report-a-problem-btn').attr('href', href).text(text).toggle(visible); }; +fixmystreet.update_public_councils_text = function(text, bodies) { + bodies = bodies.join('</strong> ' + translation_strings.or + ' <strong>'); + text = text.replace(/<strong>.*<\/strong>/, '<strong>' + bodies + '</strong>'); + $('#js-councils_text').html(text); +}; + fixmystreet.update_councils_text = function(data) { - $('#js-councils_text').html(data.councils_text); + fixmystreet.update_public_councils_text( + data.councils_text, fixmystreet.bodies); $('#js-councils_text_private').html(data.councils_text_private); $(fixmystreet).trigger('body_overrides:change'); }; @@ -975,6 +997,9 @@ fixmystreet.update_pin = function(lonlat, savePushState) { } $('#side-form, #site-logo').show(); var old_category = $("select#form_category").val(); + + fixmystreet.reporting_data = data; + fixmystreet.update_councils_text(data); $('#js-top-message').html(data.top_message || ''); $('#form_category_row').html(data.category); |