aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/services_controller.rb32
-rw-r--r--app/views/help/_sidebar.rhtml1
-rw-r--r--app/views/help/alaveteli.rhtml30
-rw-r--r--app/views/layouts/default.rhtml6
-rw-r--r--config/environment.rb1
-rw-r--r--config/routes.rb5
-rw-r--r--lib/world_foi_websites.rb40
-rw-r--r--public/javascripts/general.js22
-rw-r--r--public/javascripts/jquery.cookie.js111
-rw-r--r--public/stylesheets/theme.css21
-rw-r--r--spec/controllers/services_controller_spec.rb31
11 files changed, 214 insertions, 86 deletions
diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb
new file mode 100644
index 000000000..6fb20336e
--- /dev/null
+++ b/app/controllers/services_controller.rb
@@ -0,0 +1,32 @@
+# controllers/application.rb:
+# Parent class of all controllers in FOI site. Filters added to this controller
+# apply to all controllers in the application. Likewise, all the methods added
+# will be available for all controllers.
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
+#
+# $Id: application.rb,v 1.59 2009-09-17 13:01:56 francis Exp $
+
+require 'open-uri'
+
+class ServicesController < ApplicationController
+ def other_country_message
+ text = ""
+ iso_country_code = MySociety::Config.get('ISO_COUNTRY_CODE').downcase
+ if country_from_ip.downcase != iso_country_code
+ found_country = WorldFOIWebsites.by_code(country_from_ip)
+ found_country_name = !found_country.nil? && found_country[:country_name]
+ if found_country_name
+ text = _("Hello! You can make Freedom of Information requests within {{country_name}} at {{link_to_website}}", :country_name => found_country_name, :link_to_website => "<a href=\"#{found_country[:url]}\">#{found_country[:name]}</a>")
+ else
+ current_country = WorldFOIWebsites.by_code(iso_country_code)[:country_name]
+ text = _("Hello! We have an <a href=\"/help/alaveteli?country_name=#{CGI.escape(current_country)}\">important message</a> for visitors outside {{country_name}}", :country_name => current_country)
+ end
+ end
+ if !text.empty?
+ text += ' <span class="close-button">X</span>'
+ end
+ render :text => text, :content_type => "text/plain" # XXX workaround the HTML validation in test suite
+ end
+end
diff --git a/app/views/help/_sidebar.rhtml b/app/views/help/_sidebar.rhtml
index b6d26271e..db69f283b 100644
--- a/app/views/help/_sidebar.rhtml
+++ b/app/views/help/_sidebar.rhtml
@@ -5,6 +5,7 @@
<li><%= link_to_unless_current "Making requests", "/help/requesting" %></li>
<li><%= link_to_unless_current "Your privacy", "/help/privacy" %></li>
<li><%= link_to_unless_current "FOI officers", "/help/officers" %></li>
+ <li><%= link_to_unless_current "About the software", "/help/alaveteli" %></li>
<li><%= link_to_unless_current "Credits", "/help/credits" %></li>
<li><%= link_to_unless_current "Programmers API", "/help/api" %></li>
<li><%= link_to_unless_current "Advanced search", "/search" %></li>
diff --git a/app/views/help/alaveteli.rhtml b/app/views/help/alaveteli.rhtml
new file mode 100644
index 000000000..f7accdd11
--- /dev/null
+++ b/app/views/help/alaveteli.rhtml
@@ -0,0 +1,30 @@
+<% @title = "Making requests" %>
+
+<%= render :partial => 'sidebar' %>
+<div id="left_column">
+ <% if params[:country_name] %>
+ <h1><%= _("Would you like to see a website like this in your country?") %></h1>
+ <% else %>
+ <h1>Powered by Alaveteli</h1>
+ <% end %>
+ <p>This website is powered by Alaveteli. Alaveteli is free software
+ for making Freedom of Information requests. It can easily be
+ translated into any language, and customised for variations of FOI
+ law.</p>
+
+ <p>The development of Alaveteli is sponsored and supported by a
+ number of foundataions and charities who are interested in
+ transparency across the world.</p>
+
+ <p>If you would like to set up an Alaveteli website in your own
+ country, we can help. You will need a few days to get the site
+ configured and ready to use, and will then have to spend at least an
+ hour a week moderating and managing the site (more for busy
+ websites).</p>
+
+ <p>Read more on the <a href="http://alaveteli.org">Alaveteli
+ website</a>, or <a href="mailto:hello@alaveteli.org">drop us an
+ email</a>.</p>
+
+ <div id="hash_link_padding"></div>
+</div>
diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml
index e21553d0e..c82d75ebe 100644
--- a/app/views/layouts/default.rhtml
+++ b/app/views/layouts/default.rhtml
@@ -20,7 +20,7 @@
<%= stylesheet_link_tag 'main', :title => "Main", :rel => "stylesheet" %>
<%= stylesheet_link_tag 'fonts', :rel => "stylesheet" %>
<%= stylesheet_link_tag 'theme', :rel => "stylesheet" %>
- <%= javascript_include_tag 'jquery.js', 'jquery-ui.min' %>
+ <%= javascript_include_tag 'jquery.js', 'jquery-ui.min','jquery.cookie.js', 'general.js' %>
<%= stylesheet_link_tag 'admin-theme/jquery-ui-1.8.15.custom.css', :rel => 'stylesheet'%>
<!--[if LT IE 7]>
<style type="text/css">@import url("/stylesheets/ie6.css");</style>
@@ -107,7 +107,7 @@
</div>
</div>
<div id="wrapper">
-
+
<div id="content">
<% if flash[:notice] %>
@@ -118,6 +118,8 @@
<% end %>
<div id="<%= controller.controller_name + "_" + controller.action_name %>" class="controller_<%= controller.controller_name %>">
+
+ <div id="other-country-notice"></div>
<%= yield :layout %>
</div>
</div>
diff --git a/config/environment.rb b/config/environment.rb
index c363e7fae..3abfd3d22 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -145,3 +145,4 @@ require 'sendmail_return_path.rb'
require 'tnef.rb'
require 'i18n_fixes.rb'
require 'rack_quote_monkeypatch.rb'
+require 'world_foi_websites.rb'
diff --git a/config/routes.rb b/config/routes.rb
index c1bbfc3b3..b6a3dc0de 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -105,6 +105,10 @@ ActionController::Routing::Routes.draw do |map|
comment.new_comment "/annotate/request/:url_title", :action => 'new', :type => 'request'
end
+ map.with_options :controller => 'services' do |service|
+ service.other_country_message "/country_message", :action => 'other_country_message'
+ end
+
map.with_options :controller => 'track' do |track|
# /track/ is for setting up an email alert for the item
# /feed/ is a direct RSS feed of the item
@@ -124,6 +128,7 @@ ActionController::Routing::Routes.draw do |map|
map.with_options :controller => 'help' do |help|
help.help_unhappy '/help/unhappy/:url_title', :action => 'unhappy'
help.help_about '/help/about', :action => 'about'
+ help.help_about '/help/alaveteli', :action => 'alaveteli'
help.help_contact '/help/contact', :action => 'contact'
help.help_officers '/help/officers', :action => 'officers'
help.help_requesting '/help/requesting', :action => 'requesting'
diff --git a/lib/world_foi_websites.rb b/lib/world_foi_websites.rb
new file mode 100644
index 000000000..24845437a
--- /dev/null
+++ b/lib/world_foi_websites.rb
@@ -0,0 +1,40 @@
+class WorldFOIWebsites
+ def self.world_foi_websites
+ world_foi_websites = [
+ {:name => "WhatDoTheyKnow?",
+ :country_name => _("United Kingdom"),
+ :country_iso_code => "GB",
+ :url => "http://www.whatdotheyknow.com"},
+ {:name => "Informata Zyrtare",
+ :country_name => _("Kosovo"),
+ :country_iso_code => "XK",
+ :url => "http://informatazyrtare.org"},
+ {:name => "Ask The EU",
+ :country_name => _("European Union"),
+ :country_iso_code => "",
+ :url => "http://asktheu.org"},
+ {:name => "MuckRock.com",
+ :country_name => _("United States of America"),
+ :country_iso_code => "US",
+ :url => "http://www.muckrock.com"},
+ {:name => "FYI",
+ :country_name => _("New Zealand"),
+ :country_iso_code => "NZ",
+ :url => "http://fyi.org.nz"},
+ {:name => "Frag den Staat",
+ :country_name => _("Germany"),
+ :country_iso_code => "DE",
+ :url => "http://fragdenstaat.de"},
+ {:name => "Acceso Intelligente",
+ :country_name => _("Chile"),
+ :country_iso_code => "CL",
+ :url => "accesointeligente.org"}]
+ return world_foi_websites
+ end
+
+ def self.by_code(code)
+ result = self.world_foi_websites.find{|x| x[:country_iso_code].downcase == code.downcase}
+ return result
+ end
+end
+
diff --git a/public/javascripts/general.js b/public/javascripts/general.js
new file mode 100644
index 000000000..ed5095f82
--- /dev/null
+++ b/public/javascripts/general.js
@@ -0,0 +1,22 @@
+$(document).ready(function() {
+ if(window.location.search.substring(1).search("country_name") == -1) {
+ if (!$.cookie('has_seen_country_message')) {
+ $.ajax({
+ url: "/country_message",
+ dataType: 'html',
+ success: function(country_message){
+ if (country_message != ''){
+ $('#other-country-notice').html(country_message);
+ $('body:not(.front) #other-country-notice').show()
+ }
+ }
+ })
+
+ }
+ }
+
+ $('#other-country-notice').click(function() {
+ $('#other-country-notice').hide();
+ $.cookie('has_seen_country_message', 1, {expires: 365, path: '/'});
+ })
+}) \ No newline at end of file
diff --git a/public/javascripts/jquery.cookie.js b/public/javascripts/jquery.cookie.js
index 6df1faca2..6a3e394b4 100644
--- a/public/javascripts/jquery.cookie.js
+++ b/public/javascripts/jquery.cookie.js
@@ -1,96 +1,41 @@
/**
- * Cookie plugin
+ * jQuery Cookie plugin
*
- * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
+ * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
+jQuery.cookie = function (key, value, options) {
-/**
- * Create a cookie with the given name and value and other optional parameters.
- *
- * @example $.cookie('the_cookie', 'the_value');
- * @desc Set the value of a cookie.
- * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
- * @desc Create a cookie with all available options.
- * @example $.cookie('the_cookie', 'the_value');
- * @desc Create a session cookie.
- * @example $.cookie('the_cookie', null);
- * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
- * used when the cookie was set.
- *
- * @param String name The name of the cookie.
- * @param String value The value of the cookie.
- * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
- * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
- * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
- * If set to null or omitted, the cookie will be a session cookie and will not be retained
- * when the the browser exits.
- * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
- * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
- * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
- * require a secure protocol (like HTTPS).
- * @type undefined
- *
- * @name $.cookie
- * @cat Plugins/Cookie
- * @author Klaus Hartl/klaus.hartl@stilbuero.de
- */
+ // key and at least value given, set cookie...
+ if (arguments.length > 1 && String(value) !== "[object Object]") {
+ options = jQuery.extend({}, options);
-/**
- * Get the value of a cookie with the given name.
- *
- * @example $.cookie('the_cookie');
- * @desc Get the value of a cookie.
- *
- * @param String name The name of the cookie.
- * @return The value of the cookie.
- * @type String
- *
- * @name $.cookie
- * @cat Plugins/Cookie
- * @author Klaus Hartl/klaus.hartl@stilbuero.de
- */
-jQuery.cookie = function(name, value, options) {
- if (typeof value != 'undefined') { // name and value given, set cookie
- options = options || {};
- if (value === null) {
- value = '';
+ if (value === null || value === undefined) {
options.expires = -1;
}
- var expires = '';
- if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
- var date;
- if (typeof options.expires == 'number') {
- date = new Date();
- date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
- } else {
- date = options.expires;
- }
- expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
- }
- // CAUTION: Needed to parenthesize options.path and options.domain
- // in the following expressions, otherwise they evaluate to undefined
- // in the packed version for some reason...
- var path = options.path ? '; path=' + (options.path) : '';
- var domain = options.domain ? '; domain=' + (options.domain) : '';
- var secure = options.secure ? '; secure' : '';
- document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
- } else { // only name given, get cookie
- var cookieValue = null;
- if (document.cookie && document.cookie != '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- // Does this cookie string begin with the name we want?
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
- break;
- }
- }
+
+ if (typeof options.expires === 'number') {
+ var days = options.expires, t = options.expires = new Date();
+ t.setDate(t.getDate() + days);
}
- return cookieValue;
+
+ value = String(value);
+
+ return (document.cookie = [
+ encodeURIComponent(key), '=',
+ options.raw ? value : encodeURIComponent(value),
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
+ options.path ? '; path=' + options.path : '',
+ options.domain ? '; domain=' + options.domain : '',
+ options.secure ? '; secure' : ''
+ ].join(''));
}
-}; \ No newline at end of file
+
+ // key and possibly options given, get cookie...
+ options = value || {};
+ var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
+ return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
+};
diff --git a/public/stylesheets/theme.css b/public/stylesheets/theme.css
index 6c71bb8cf..c84c11a32 100644
--- a/public/stylesheets/theme.css
+++ b/public/stylesheets/theme.css
@@ -602,7 +602,8 @@ form input.use-datepicker[type=text] {
form input[type=submit],
a.link_button_green,
-a.link_button_green_large {
+a.link_button_green_large,
+span.close-button {
background: url(/images/button-gradient.png);
color: white;
text-decoration: none;
@@ -615,6 +616,7 @@ a.link_button_green_large {
font-family: 'DeliciousRoman', Arial, sans-serif;
font-size: 18px;
cursor: pointer;
+ cursor: hand;
}
a.link_button_green_large {
@@ -897,6 +899,23 @@ body.front h3 {
cursor:pointer;
opacity: 1;
}
+
+#other-country-notice {
+ position: absolute;
+}
+
+span.close-button {
+ cursor: pointer;
+ font-size: 1em;
+ padding: 0 1px 0 1px;
+ line-height: 1.1em;
+ font-family: Arial;
+}
+body.front #other-country-notice,
+#other-country-notice {
+ display: none;
+}
+
p.public-body-name-prefix {
color: #DEB4D8;
margin-top: 15px;
diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb
new file mode 100644
index 000000000..1bafd0c8f
--- /dev/null
+++ b/spec/controllers/services_controller_spec.rb
@@ -0,0 +1,31 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe ServicesController, "when using web services" do
+ integrate_views
+
+ it "should show no alaveteli message when in the deployed country" do
+ config = MySociety::Config.load_default()
+ config['ISO_COUNTRY_CODE'] = "DE"
+ controller.stub!(:country_from_ip).and_return('DE')
+ get :other_country_message
+ response.body.should == ""
+ end
+
+ it "should show an alaveteli message when not in the deployed country and in a country with no FOI website" do
+ config = MySociety::Config.load_default()
+ config['ISO_COUNTRY_CODE'] = "DE"
+ controller.stub!(:country_from_ip).and_return('ZZ')
+ get :other_country_message
+ response.body.should match(/outside Germany/)
+ end
+
+ it "should show link to other FOI website when not in the deployed country" do
+ config = MySociety::Config.load_default()
+ config['ISO_COUNTRY_CODE'] = "ZZ"
+ controller.stub!(:country_from_ip).and_return('DE')
+ get :other_country_message
+ response.body.should match(/within Germany/)
+ end
+
+
+end