aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/link_to_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/link_to_helper.rb')
-rwxr-xr-xapp/helpers/link_to_helper.rb193
1 files changed, 99 insertions, 94 deletions
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index 030fab20b..dc5c8f34e 100755
--- a/app/helpers/link_to_helper.rb
+++ b/app/helpers/link_to_helper.rb
@@ -10,95 +10,93 @@ module LinkToHelper
# Links to various models
# Requests
- def request_url(info_request, extra_params={})
- params = {:url_title => info_request.url_title, :only_path => true}
- return show_request_url(params.merge(extra_params))
+ def request_url(info_request, options = {})
+ show_request_url({:url_title => info_request.url_title}.merge(options))
end
- def request_link(info_request, cls=nil )
- link_to h(info_request.title), request_url(info_request), :class => cls
+ def request_path(info_request, options = {})
+ request_url(info_request, {:only_path => true}.merge(options))
end
- def request_admin_url(info_request)
- return admin_url('request/show/' + info_request.id.to_s)
+ def request_link(info_request, cls=nil )
+ link_to h(info_request.title), request_path(info_request), :class => cls
end
- def request_admin_link(info_request, name="admin", cls=nil)
- link_to name, request_admin_url(info_request), :class => cls
+ def request_details_path(info_request)
+ details_request_path(:url_title => info_request.url_title)
end
- def request_both_links(info_request)
- link_to(h(info_request.title), main_url(request_url(info_request))) + " (" + link_to("admin", request_admin_url(info_request)) + ")"
+ # Incoming / outgoing messages
+ def incoming_message_url(incoming_message, options = {})
+ return request_url(incoming_message.info_request, options.merge(:anchor => "incoming-#{incoming_message.id}"))
end
- def request_similar_url(info_request)
- return similar_request_url(:url_title => info_request.url_title, :only_path => true)
+ def incoming_message_path(incoming_message)
+ incoming_message_url(incoming_message, :only_path => true)
end
- def request_details_url(info_request)
- return details_request_url(:url_title => info_request.url_title, :only_path => true)
+ def outgoing_message_url(outgoing_message, options = {})
+ return request_path(outgoing_message.info_request, options.merge(:anchor => "outgoing-#{outgoing_message.id}"))
end
- # Incoming / outgoing messages
- def incoming_message_url(incoming_message)
- return request_url(incoming_message.info_request)+"#incoming-"+incoming_message.id.to_s
+ def outgoing_message_path(outgoing_message)
+ outgoing_message_url(outgoing_message, :only_path => true)
end
- def outgoing_message_url(outgoing_message)
- return request_url(outgoing_message.info_request)+"#outgoing-"+outgoing_message.id.to_s
+ def comment_url(comment, options = {})
+ request_url(comment.info_request, options.merge(:anchor => "comment-#{comment.id}"))
end
- def comment_url(comment)
- return request_url(comment.info_request)+"#comment-"+comment.id.to_s
+ def comment_path(comment)
+ comment_url(comment, :only_path => true)
end
# Respond to request
- def respond_to_last_url(info_request)
+ def respond_to_last_url(info_request, options = {})
last_response = info_request.get_last_response
if last_response.nil?
- respond_url = show_response_no_followup_url(:id => info_request.id)
+ show_response_no_followup_url(options.merge(:id => info_request.id))
else
- respond_url = show_response_url(:id => info_request.id, :incoming_message_id => last_response.id)
+ show_response_url(options.merge(:id => info_request.id, :incoming_message_id => last_response.id))
end
- return respond_url
end
- # Public bodies
- def public_body_url(public_body)
- public_body.url_name.nil? ? '' : show_public_body_url(:url_name => public_body.url_name, :only_path => true)
+ def respond_to_last_path(info_request)
+ respond_to_last_url(info_request, :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)
+ # Public bodies
+ def public_body_url(public_body, options = {})
+ public_body.url_name.nil? ? '' : show_public_body_url(options.merge(:url_name => public_body.url_name))
end
- def public_body_link(public_body, cls=nil)
- link_to h(public_body.name), public_body_url(public_body), :class => cls
+ def public_body_path(public_body)
+ public_body_url(public_body, :only_path => true)
end
- def public_body_link_absolute(public_body) # e.g. for in RSS
- link_to h(public_body.name), main_url(public_body_url(public_body))
+ def public_body_link_short(public_body)
+ link_to h(public_body.short_or_long_name), public_body_path(public_body)
end
- def public_body_admin_url(public_body)
- return admin_url('body/show/' + public_body.id.to_s)
+ def public_body_link(public_body, cls=nil)
+ link_to h(public_body.name), public_body_path(public_body), :class => cls
end
- def public_body_both_links(public_body)
- link_to(h(public_body.name), main_url(public_body_url(public_body))) + " (" + link_to("admin", public_body_admin_url(public_body)) + ")"
+ def public_body_link_absolute(public_body) # e.g. for in RSS
+ link_to h(public_body.name), public_body_url(public_body)
end
- def list_public_bodies_default
- list_public_bodies_url(:tag => 'all')
+ # Users
+ def user_url(user, options = {})
+ show_user_url(options.merge(:url_name => user.url_name))
end
- # Users
- def user_url(user)
- return show_user_url(:url_name => user.url_name, :only_path => true)
+ def user_path(user)
+ user_url(user, :only_path => true)
end
def user_link(user, cls=nil)
- link_to h(user.name), user_url(user), :class => cls
+ link_to h(user.name), user_path(user), :class => cls
end
def user_link_for_request(request, cls=nil)
@@ -110,21 +108,24 @@ module LinkToHelper
user_name
end
else
- link_to h(request.user.name), user_url(request.user), :class => cls
+ link_to h(request.user.name), user_path(request.user), :class => cls
end
end
def user_admin_link_for_request(request, external_text=nil, internal_text=nil)
if request.is_external?
- text = external_text ? external_text : (request.external_user_name || _("Anonymous user")) + " (external)"
+ external_text || (request.external_user_name || _("Anonymous user")) + " (external)"
else
- text = internal_text ? internal_text : request.user.name
- link_to(h(text), user_admin_url(request.user))
+ link_to(h(internal_text || request.user.name), admin_user_show_url(request.user))
end
end
def user_link_absolute(user)
- link_to h(user.name), main_url(user_url(user))
+ link_to h(user.name), user_url(user)
+ end
+
+ def user_link(user)
+ link_to h(user.name), user_path(user)
end
def request_user_link_absolute(request)
@@ -135,11 +136,19 @@ module LinkToHelper
end
end
+ def request_user_link(request)
+ if request.is_external?
+ request.external_user_name || _("Anonymous user")
+ else
+ user_link(request.user)
+ end
+ end
+
def user_or_you_link(user)
if @user && user == @user
- link_to h("you"), user_url(user)
+ link_to h("you"), user_path(user)
else
- link_to h(user.name), user_url(user)
+ link_to h(user.name), user_path(user)
end
end
@@ -152,40 +161,36 @@ module LinkToHelper
end
def user_or_you_capital_link(user)
- link_to user_or_you_capital(user), user_url(user)
- end
-
- def user_admin_url(user)
- return admin_url('user/show/' + user.id.to_s)
+ link_to user_or_you_capital(user), user_path(user)
end
def user_admin_link(user, name="admin", cls=nil)
- link_to name, user_admin_url(user), :class => cls
- end
-
- def user_both_links(user)
- link_to(h(user.name), main_url(user_url(user))) + " (" + link_to("admin", user_admin_url(user)) + ")"
+ link_to name, admin_user_show_url(user), :class => cls
end
# Tracks. feed can be 'track' or 'feed'
- def do_track_url(track_thing, feed = 'track')
+ def do_track_url(track_thing, feed = 'track', options = {})
if track_thing.track_type == 'request_updates'
- track_request_url(:url_title => track_thing.info_request.url_title, :feed => feed)
+ track_request_url(options.merge(:url_title => track_thing.info_request.url_title, :feed => feed))
elsif track_thing.track_type == 'all_new_requests'
- track_list_url(:view => 'recent', :feed => feed)
+ track_list_url(options.merge(:view => 'recent', :feed => feed))
elsif track_thing.track_type == 'all_successful_requests'
- track_list_url(:view => 'successful', :feed => feed)
+ track_list_url(options.merge(:view => 'successful', :feed => feed))
elsif track_thing.track_type == 'public_body_updates'
- track_public_body_url(:url_name => track_thing.public_body.url_name, :feed => feed)
+ track_public_body_url(options.merge(:url_name => track_thing.public_body.url_name, :feed => feed))
elsif track_thing.track_type == 'user_updates'
- track_user_url(:url_name => track_thing.tracked_user.url_name, :feed => feed)
+ track_user_url(options.merge(:url_name => track_thing.tracked_user.url_name, :feed => feed))
elsif track_thing.track_type == 'search_query'
- track_search_url(:query_array => track_thing.track_query, :feed => feed)
+ track_search_url(options.merge(:query_array => track_thing.track_query, :feed => feed))
else
raise "unknown tracking type " + track_thing.track_type
end
end
+ def do_track_path(track_thing, feed = 'track')
+ do_track_url(track_thing, feed, :only_path => true)
+ end
+
# General pages.
def search_url(query, params = nil)
if query.kind_of?(Array)
@@ -213,31 +218,26 @@ module LinkToHelper
return url
end
- def search_link(query, variety_postfix = nil, sort_postfix = nil, advanced = nil)
- link_to h(query), search_url(query)
- end
- # Admin pages
- def admin_url(relative_path)
- admin_url_prefix = Configuration::admin_base_url
- (admin_url_prefix.empty? ? admin_general_index_url + '/' : admin_url_prefix) + relative_path
+ def search_path(query, options = {})
+ search_url(query, options.merge(:only_path => true))
end
- # About page URLs
- def about_url
- return help_general_url(:action => 'about')
+ def search_link(query)
+ link_to h(query), search_url(query)
end
- def unhappy_url(info_request = nil)
- if info_request.nil?
- return help_general_url(:action => 'unhappy')
- else
- return help_unhappy_url(:url_title => info_request.url_title)
- end
+ # Deprecated helper
+ # TODO: Remove in next release
+ def admin_url(relative_path)
+ warn "[DEPRECATION] admin_url is deprecated. Please remove it from your theme."
+ relative_path
end
-
+ # Deprecated helper
+ # TODO: Remove in next release
def main_url(relative_path, append = nil)
+ warn "[DEPRECATION] main_url is deprecated. Please remove it from your theme."
url_prefix = "http://" + Configuration::domain
url = url_prefix + relative_path
if !append.nil?
@@ -253,6 +253,19 @@ module LinkToHelper
return url
end
+ # About page URLs
+ def about_url
+ return help_general_url(:action => 'about')
+ end
+
+ def unhappy_url(info_request = nil)
+ if info_request.nil?
+ return help_general_url(:action => 'unhappy')
+ else
+ return help_unhappy_url(:url_title => info_request.url_title)
+ end
+ end
+
# Basic date format
def simple_date(date)
date = date.in_time_zone.to_date unless date.is_a? Date
@@ -269,13 +282,5 @@ module LinkToHelper
def year_from_date(date)
return date.strftime("%Y").strip
end
-
- #I18n locale switcher
-
- def locale_switcher(locale, params)
- params['locale'] = locale
- return url_for(params)
- end
-
end