diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/application_helper.rb | 15 | ||||
-rw-r--r-- | app/helpers/config_helper.rb | 4 | ||||
-rwxr-xr-x | app/helpers/link_to_helper.rb | 27 |
3 files changed, 35 insertions, 11 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ec56566a9..d12238582 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -94,5 +94,20 @@ module ApplicationHelper block.call end end + # (unfortunately) ugly way of getting id of generated form element + # ids + # see http://chrisblunt.com/2009/10/12/rails-getting-the-id-of-form-fields-inside-a-fields_for-block/ + def sanitized_object_name(object_name) + object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") + end + + def sanitized_method_name(method_name) + method_name.sub(/\?$/, "") + end + + def form_tag_id(object_name, method_name) + return "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}" + end + end diff --git a/app/helpers/config_helper.rb b/app/helpers/config_helper.rb index 80f2deed2..b0381a2f5 100644 --- a/app/helpers/config_helper.rb +++ b/app/helpers/config_helper.rb @@ -2,4 +2,8 @@ module ConfigHelper def site_name MySociety::Config.get('SITE_NAME', 'Alaveteli') end + + def force_registration_on_new_request + MySociety::Config.get('FORCE_REGISTRATION_ON_NEW_REQUEST', false) + end end
\ No newline at end of file diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 444129052..54b8d69d0 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -61,7 +61,7 @@ module LinkToHelper # Public bodies def public_body_url(public_body) - return show_public_body_url(:url_name => public_body.url_name, :only_path => true) + public_body.url_name.nil? ? '' : show_public_body_url(:url_name => public_body.url_name, :only_path => true) end def public_body_link_short(public_body) link_to h(public_body.short_or_long_name), public_body_url(public_body) @@ -79,7 +79,7 @@ module LinkToHelper link_to(h(public_body.name), main_url(public_body_url(public_body))) + " (" + link_to("admin", public_body_admin_url(public_body)) + ")" end def list_public_bodies_default - list_public_bodies_url(:tag => 'a') + list_public_bodies_url(:tag => 'all') end # Users @@ -135,11 +135,10 @@ module LinkToHelper end end - # General pages. postfix is either the sort order, or 'bodies' to show you - # came from the front page and are looking for public bodies - def search_url(query, postfix = nil) + # General pages. + def search_url(query, variety_postfix = nil, sort_postfix = nil, advanced = nil) + query = query - ["", nil] if query.kind_of?(Array) url = search_general_url(:combined => query) - # Here we can't escape the slashes, as RFC 2396 doesn't allow slashes # within a path component. Rails is assuming when generating URLs that # either there aren't slashes, or we are in a query part where you can @@ -151,13 +150,19 @@ module LinkToHelper # http://rails.lighthouseapp.com/projects/8994/tickets/144-patch-bug-in-rails-route-globbing url = url.gsub("%2F", "/") - if !postfix.nil? && !postfix.empty? - url = url + "/" + postfix + if !variety_postfix.nil? && !variety_postfix.empty? + url = url + "/" + variety_postfix + end + if !sort_postfix.nil? && !sort_postfix.empty? + url = url + "/" + sort_postfix + end + if !advanced.nil? && (advanced) + url = url + "/advanced" end return url end - def search_link(query, postfix = nil) - link_to h(query), search_url(query, postfix) + def search_link(query, variety_postfix = nil, sort_postfix = nil, advanced = nil) + link_to h(query), search_url(query, variety_postfix, sort_postfix, advanced) end # Admin pages @@ -187,7 +192,7 @@ module LinkToHelper # Basic date format def simple_date(date) - return date.strftime("%e %B %Y").strip + return I18n.l(date, :format => "%e %B %Y") end def simple_time(date) |