diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-07-31 12:01:27 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-07-31 12:21:33 +0100 |
commit | 87543f78383eaab0d78d0fadc1655e39f9335517 (patch) | |
tree | 3b652a2bbd1c08118cd0ae06ba93de252f490abc | |
parent | 939c6d6de069654fcbcb82722de5d71fd8cb1622 (diff) |
Move Latin-char-specific name check to cobrand.
Also move some UK-specific code in the same function.
The specific code is still tested in report_new.t.
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 33 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 2 | ||||
-rw-r--r-- | t/app/model/problem.t | 24 | ||||
-rw-r--r-- | templates/web/barnet/header.html | 2 | ||||
-rw-r--r-- | templates/web/bromley/header.html | 2 | ||||
-rw-r--r-- | templates/web/fixmystreet-uk-councils/header_extra.html | 1 | ||||
-rw-r--r-- | templates/web/fixmystreet.com/header_extra.html | 3 | ||||
-rw-r--r-- | templates/web/harrogate/header.html | 2 | ||||
-rw-r--r-- | templates/web/hart/header.html | 2 | ||||
-rw-r--r-- | templates/web/oxfordshire/header.html | 1 | ||||
-rw-r--r-- | templates/web/stevenage/header.html | 1 | ||||
-rw-r--r-- | templates/web/warwickshire/header.html | 1 | ||||
-rw-r--r-- | web/cobrands/fixmystreet-uk-councils/js.js | 3 | ||||
-rw-r--r-- | web/cobrands/fixmystreet.com/js.js | 3 | ||||
-rw-r--r-- | web/js/fixmystreet.js | 4 |
16 files changed, 53 insertions, 51 deletions
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index b293c3568..2473f386f 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -302,5 +302,38 @@ sub council_rss_alert_options { return ( \@options, @reported_to_options ? \@reported_to_options : undef ); } +sub report_check_for_errors { + my $self = shift; + my $c = shift; + + my %errors = $self->next::method($c); + + my $report = $c->stash->{report}; + + if (!$errors{name} && (length($report->name) < 5 + || $report->name !~ m/\s/ + || $report->name =~ m/\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i)) + { + $errors{name} = _( +'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below' + ); + } + + # XXX Hardcoded body ID matching mapit area ID + if ( $report->bodies_str && $report->detail ) { + # Custom character limit: + # Bromley Council + if ( $report->bodies_str eq '2482' && length($report->detail) > 1750 ) { + $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1750 ); + } + # Oxfordshire + if ( $report->bodies_str eq '2237' && length($report->detail) > 1700 ) { + $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1700 ); + } + } + + return %errors; +} + 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index e55c26cd8..bed2f160a 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -405,14 +405,6 @@ sub check_for_errors { if ( !$self->name || $self->name !~ m/\S/ ) { $errors{name} = _('Please enter your name'); } - elsif (length( $self->name ) < 5 - || $self->name !~ m/\s/ - || $self->name =~ m/\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i ) - { - $errors{name} = _( -'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below' - ) unless $self->cobrand eq 'emptyhomes'; - } if ( $self->category && $self->category eq _('-- Pick a category --') ) @@ -427,18 +419,6 @@ sub check_for_errors { $self->category(undef); } - if ( $self->bodies_str && $self->detail ) { - # Custom character limit: - # Bromley Council - if ( $self->bodies_str eq '2482' && length($self->detail) > 1750 ) { - $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1750 ); - } - # Oxfordshire - if ( $self->bodies_str eq '2237' && length($self->detail) > 1700 ) { - $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1700 ); - } - } - return \%errors; } diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 6a93f97ec..f08b666c8 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -100,7 +100,7 @@ use mySociety::EmailUtil; =head2 check_for_errors - $error_hashref = $problem->check_for_errors(); + $error_hashref = $user->check_for_errors(); Look at all the fields and return a hashref with all errors found, keyed on the field name. This is intended to be passed back to the form to display the diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 1b6488fc7..ad82a62a5 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -67,30 +67,6 @@ for my $test ( } }, { - desc => 'name too short', - changed => { - name => 'xx', - }, - errors => { - title => 'Please enter a subject', - detail => 'Please enter some details', - bodies => 'No council selected', - name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below', - } - }, - { - desc => 'name is anonymous', - changed => { - name => 'anonymous', - }, - errors => { - title => 'Please enter a subject', - detail => 'Please enter some details', - bodies => 'No council selected', - name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below', - } - }, - { desc => 'correct name', changed => { name => 'A User', diff --git a/templates/web/barnet/header.html b/templates/web/barnet/header.html index 0227ceff8..101d444a7 100644 --- a/templates/web/barnet/header.html +++ b/templates/web/barnet/header.html @@ -33,6 +33,8 @@ [% INCLUDE 'common_header_tags.html', js_override = '/cobrands/fixmystreet/fixmystreet.js' %] <script src="[% version('/js/fancybox/jquery.fancybox-1.3.4.pack.js') %]" charset="utf-8"></script> + [% PROCESS 'header_extra.html' %] + </head> <body class="[% bodyclass | html IF bodyclass %]"> <div id="barnet-wrapper"> diff --git a/templates/web/bromley/header.html b/templates/web/bromley/header.html index 4f885f513..9559592ff 100644 --- a/templates/web/bromley/header.html +++ b/templates/web/bromley/header.html @@ -40,6 +40,8 @@ <link rel="Shortcut Icon" type="image/x-icon" href="/cobrands/bromley/favicon.ico"> + [% PROCESS 'header_extra.html' %] + </head> <body class="[% bodyclass | html IF bodyclass %]"> [%# ie_wrapper is to prevent a horizontal scrollbar in IE7, it appears (from Bromley site) %] diff --git a/templates/web/fixmystreet-uk-councils/header_extra.html b/templates/web/fixmystreet-uk-councils/header_extra.html new file mode 100644 index 000000000..9e614f177 --- /dev/null +++ b/templates/web/fixmystreet-uk-councils/header_extra.html @@ -0,0 +1 @@ +<script src="[% start %][% version('/cobrands/fixmystreet-uk-councils/js.js') %]"></script> diff --git a/templates/web/fixmystreet.com/header_extra.html b/templates/web/fixmystreet.com/header_extra.html index 1cce668a5..6d3474c23 100644 --- a/templates/web/fixmystreet.com/header_extra.html +++ b/templates/web/fixmystreet.com/header_extra.html @@ -1,5 +1,6 @@ <link rel="Shortcut Icon" type="image/x-icon" href="/cobrands/fixmystreet.com/favicon.ico"> -<script src="[% start %][% version('/js/jquery.cookie.min.js') %]" type="text/javascript" charset="utf-8"></script> +<script src="[% start %][% version('/js/jquery.cookie.min.js') %]"></script> +<script src="[% start %][% version('/cobrands/fixmystreet.com/js.js') %]"></script> [% INCLUDE 'tracking_code.html' %] diff --git a/templates/web/harrogate/header.html b/templates/web/harrogate/header.html index a1c0ba38a..e40a38d94 100644 --- a/templates/web/harrogate/header.html +++ b/templates/web/harrogate/header.html @@ -31,7 +31,7 @@ <link rel="canonical" href="https://www.fixmystreet.com[% c.req.uri.path_query %]"> [% END %] - [% TRY %][% PROCESS 'header_extra.html' %][% CATCH file %][% END %] + [% PROCESS 'header_extra.html' %] </head> [% TRY %][% PROCESS 'set_body_class.html' %][% CATCH file %][% END %] diff --git a/templates/web/hart/header.html b/templates/web/hart/header.html index dcc202b5a..c2d363010 100644 --- a/templates/web/hart/header.html +++ b/templates/web/hart/header.html @@ -42,6 +42,8 @@ <link rel="Shortcut Icon" type="image/x-icon" href="/cobrands/hart/favicon.ico"> + [% PROCESS 'header_extra.html' %] + </head> [% TRY %][% PROCESS 'set_body_class.html' %][% CATCH file %][% END %] <body class="[% bodyclass | html IF bodyclass %]"> diff --git a/templates/web/oxfordshire/header.html b/templates/web/oxfordshire/header.html index 0bbdaf353..bc52a0720 100644 --- a/templates/web/oxfordshire/header.html +++ b/templates/web/oxfordshire/header.html @@ -26,6 +26,7 @@ [% extra_js %] [% INCLUDE 'tracking_code.html' %] + [% PROCESS 'header_extra.html' %] </head> <body class="[% bodyclass | html IF bodyclass %]"> diff --git a/templates/web/stevenage/header.html b/templates/web/stevenage/header.html index 0b3171808..155b35b64 100644 --- a/templates/web/stevenage/header.html +++ b/templates/web/stevenage/header.html @@ -24,6 +24,7 @@ [% extra_js %] [% INCLUDE 'tracking_code.html' %] + [% PROCESS 'header_extra.html' %] </head> <body class="[% bodyclass | html IF bodyclass %]"> diff --git a/templates/web/warwickshire/header.html b/templates/web/warwickshire/header.html index 1d52b5546..274a78ce7 100644 --- a/templates/web/warwickshire/header.html +++ b/templates/web/warwickshire/header.html @@ -32,6 +32,7 @@ [% INCLUDE 'common_header_tags.html', js_override = '/cobrands/fixmystreet/fixmystreet.js' %] [% extra_js %] + [% PROCESS 'header_extra.html' %] </head> [% TRY %][% PROCESS 'set_body_class.html' %][% CATCH file %][% END %] diff --git a/web/cobrands/fixmystreet-uk-councils/js.js b/web/cobrands/fixmystreet-uk-councils/js.js new file mode 100644 index 000000000..3abba8e33 --- /dev/null +++ b/web/cobrands/fixmystreet-uk-councils/js.js @@ -0,0 +1,3 @@ +jQuery.validator.addMethod('validName', function(value, element) { + var validNamePat = /\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i; + return this.optional(element) || value.length > 5 && value.match( /\S/ ) && value.match( /\s/ ) && !value.match( validNamePat ); }, translation_strings.category ); diff --git a/web/cobrands/fixmystreet.com/js.js b/web/cobrands/fixmystreet.com/js.js new file mode 100644 index 000000000..3abba8e33 --- /dev/null +++ b/web/cobrands/fixmystreet.com/js.js @@ -0,0 +1,3 @@ +jQuery.validator.addMethod('validName', function(value, element) { + var validNamePat = /\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i; + return this.optional(element) || value.length > 5 && value.match( /\S/ ) && value.match( /\s/ ) && !value.match( validNamePat ); }, translation_strings.category ); diff --git a/web/js/fixmystreet.js b/web/js/fixmystreet.js index c8f1fe697..78372d68c 100644 --- a/web/js/fixmystreet.js +++ b/web/js/fixmystreet.js @@ -49,10 +49,6 @@ $(function(){ jQuery.validator.addMethod('validCategory', function(value, element) { return this.optional(element) || value != '-- Pick a category --'; }, translation_strings.category ); - jQuery.validator.addMethod('validName', function(value, element) { - var validNamePat = /\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i; - return this.optional(element) || value.length > 5 && value.match( /\S/ ) && value.match( /\s/ ) && !value.match( validNamePat ); }, translation_strings.category ); - var form_submitted = 0; var submitted = false; |