diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2014-07-04 09:51:05 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2014-07-04 09:51:05 +0100 |
commit | b930a578244addf0afd72439a5762ed7679ca59e (patch) | |
tree | abbe13763e31c7b5dae57654b9371918f2ec5496 | |
parent | 258fe80abdda33fdc3cdff41923e99617b5c3562 (diff) | |
parent | 1877bf4e4ae679c70c2349d6b9ad15ea610e3dc9 (diff) |
Merge branch '571-show-local-deploys-banner'
Conflicts:
web/cobrands/fixmystreet/base.scss
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Location.pm | 16 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 8 | ||||
-rw-r--r-- | templates/web/default/front/international_banner.html | 0 | ||||
-rw-r--r-- | templates/web/fixmystreet/front/international_banner.html | 15 | ||||
-rw-r--r-- | templates/web/fixmystreet/header_extra.html | 3 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/base.scss | 7 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 18 | ||||
-rw-r--r-- | web/cobrands/sass/_base.scss | 1 | ||||
-rw-r--r-- | web/js/jquery.cookie.min.js | 13 |
10 files changed, 84 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm index 4312b6911..8a68b2b3d 100644 --- a/perllib/FixMyStreet/App/Controller/Location.pm +++ b/perllib/FixMyStreet/App/Controller/Location.pm @@ -131,6 +131,22 @@ sub check_location : Private { return 1; } +=head2 country_message + +Displays the country_message template, used for displaying a message to +people using the site from outside the host country. + +=cut + +sub country_message : Path('/country_message') : Args(0) { + my ( $self, $c ) = @_; + + # we do not want to cache this as we always want to check if displaying this + # is the right thing to do. + $c->res->header( 'Cache_Control' => 'max-age=0' ); + $c->stash->{template} = 'front/international_banner.html'; +} + # Utility function for if someone (rarely) enters a grid reference sub gridref_to_latlon { my ( $a, $b, $num ) = @_; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index c8bae90e6..34ad5790f 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -878,5 +878,9 @@ sub updates_as_hashref { return {}; } +sub get_country_for_ip_address { + return 0; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index ce62e206e..36f381085 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -1,5 +1,6 @@ package FixMyStreet::Cobrand::FixMyStreet; use base 'FixMyStreet::Cobrand::UK'; +use mySociety::Gaze; use constant COUNCIL_ID_BROMLEY => 2482; @@ -39,5 +40,12 @@ sub extra_contact_validation { return %errors; } +sub get_country_for_ip_address { + my $self = shift; + my $ip = shift; + + return mySociety::Gaze::get_country_from_ip($ip); +} + 1; diff --git a/templates/web/default/front/international_banner.html b/templates/web/default/front/international_banner.html new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/templates/web/default/front/international_banner.html diff --git a/templates/web/fixmystreet/front/international_banner.html b/templates/web/fixmystreet/front/international_banner.html new file mode 100644 index 000000000..a4cf990fb --- /dev/null +++ b/templates/web/fixmystreet/front/international_banner.html @@ -0,0 +1,15 @@ +[% IF c.cobrand.moniker == 'fixmystreet' -%] + [%- country = c.cobrand.get_country_for_ip_address(c.req.address) -%] + [%- IF country AND country != 'GB' -%] + <div id="country_banner"> + <a href="#" id="message_close">Close</a> + <p id="international_message"> + <span id="message"> + This site is for reporting <strong>problems in the UK</strong>. There are FixMyStreet sites + <a href="http://www.fixmystreet.org/sites/">all over the world</a>, or you + could set up your own using the <a href="http://www.fixmystreet.org/">FixMyStreet Platform</a>. + </span> + </p> + </div> + [%- END -%] +[% END -%] diff --git a/templates/web/fixmystreet/header_extra.html b/templates/web/fixmystreet/header_extra.html new file mode 100644 index 000000000..8242c0479 --- /dev/null +++ b/templates/web/fixmystreet/header_extra.html @@ -0,0 +1,3 @@ +[% IF c.cobrand.moniker == 'fixmystreet' %] +<script src="[% start %][% version('/js/jquery.cookie.min.js') %]" type="text/javascript" charset="utf-8"></script> +[% END %] diff --git a/web/cobrands/fixmystreet/base.scss b/web/cobrands/fixmystreet/base.scss index c21087303..381864d58 100644 --- a/web/cobrands/fixmystreet/base.scss +++ b/web/cobrands/fixmystreet/base.scss @@ -13,3 +13,10 @@ #footer-nav { display: none; } + +#country_banner { + display: none; + color: $primary_text; background: $primary; + p#international_message { margin: auto; padding: 0.5em 2em; max-width: 40em; text-align: center; } + #message_close { float: right; } +} diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index ef74ebff4..073f745dd 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -421,7 +421,25 @@ $.fn.drawer = function(id, ajax) { }).fadeOut(500); }); + $('#message_close').live('click', function() { + $('#country_banner').hide(); + $.cookie('has_seen_country_message', 1, {expires: 365, path: '/'}); + }); + if ( cobrand == 'fixmystreet' && $('body.frontpage').length ) { + if (!$.cookie('has_seen_country_message')) { + $.ajax({ + url: '/country_message', + success: function(data) { + if ( data ) { + $('#site-header').css('position', 'relative'); + $('body').prepend(data); + $('#country_banner').slideDown('slow'); + } + } + }); + } + } /* * Fancybox fullscreen images diff --git a/web/cobrands/sass/_base.scss b/web/cobrands/sass/_base.scss index eb4901c1c..df44a3af2 100644 --- a/web/cobrands/sass/_base.scss +++ b/web/cobrands/sass/_base.scss @@ -1543,4 +1543,3 @@ table.nicetable { float: right; } } - diff --git a/web/js/jquery.cookie.min.js b/web/js/jquery.cookie.min.js new file mode 100644 index 000000000..3fa82b82b --- /dev/null +++ b/web/js/jquery.cookie.min.js @@ -0,0 +1,13 @@ + +(function(factory){if(typeof define==='function'&&define.amd){define(['jquery'],factory);}else if(typeof exports==='object'){factory(require('jquery'));}else{factory(jQuery);}}(function($){var pluses=/\+/g;function encode(s){return config.raw?s:encodeURIComponent(s);} +function decode(s){return config.raw?s:decodeURIComponent(s);} +function stringifyCookieValue(value){return encode(config.json?JSON.stringify(value):String(value));} +function parseCookieValue(s){if(s.indexOf('"')===0){s=s.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,'\\');} +try{s=decodeURIComponent(s.replace(pluses,' '));return config.json?JSON.parse(s):s;}catch(e){}} +function read(s,converter){var value=config.raw?s:parseCookieValue(s);return $.isFunction(converter)?converter(value):value;} +var config=$.cookie=function(key,value,options){if(value!==undefined&&!$.isFunction(value)){options=$.extend({},config.defaults,options);if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setTime(+t+days*864e+5);} +return(document.cookie=[encode(key),'=',stringifyCookieValue(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''));} +var result=key?undefined:{};var cookies=document.cookie?document.cookie.split('; '):[];for(var i=0,l=cookies.length;i<l;i++){var parts=cookies[i].split('=');var name=decode(parts.shift());var cookie=parts.join('=');if(key&&key===name){result=read(cookie,value);break;} +if(!key&&(cookie=read(cookie))!==undefined){result[name]=cookie;}} +return result;};config.defaults={};$.removeCookie=function(key,options){if($.cookie(key)===undefined){return false;} +$.cookie(key,'',$.extend({},options,{expires:-1}));return!$.cookie(key);};}));
\ No newline at end of file |