2008-04-05 14:04:28 +00:00
|
|
|
# The methods added to this helper will be available to all templates in the
|
|
|
|
|
# application.
|
2007-03-30 04:36:52 +00:00
|
|
|
module ApplicationHelper
|
|
|
|
|
|
|
|
|
|
# Replicates the link_to method but also checks request.request_uri to find
|
2008-04-05 14:04:28 +00:00
|
|
|
# current page. If that matches the url, the link is marked id = "current"
|
2008-12-08 16:59:10 +01:00
|
|
|
#
|
2007-03-30 04:36:52 +00:00
|
|
|
def navigation_link(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
|
|
|
|
if html_options
|
|
|
|
|
html_options = html_options.stringify_keys
|
|
|
|
|
convert_options_to_javascript!(html_options)
|
|
|
|
|
tag_options = tag_options(html_options)
|
|
|
|
|
else
|
|
|
|
|
tag_options = nil
|
|
|
|
|
end
|
|
|
|
|
url = options.is_a?(String) ? options : self.url_for(options, *parameters_for_method_reference)
|
|
|
|
|
id_tag = (request.request_uri == url) ? " id=\"current\"" : ""
|
|
|
|
|
|
|
|
|
|
"<a href=\"#{url}\"#{tag_options}#{id_tag}>#{name || url}</a>"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def days_from_today(date)
|
2009-04-07 21:34:15 +02:00
|
|
|
date.in_time_zone.to_date - current_user.time.to_date
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2008-04-05 14:04:28 +00:00
|
|
|
# Check due date in comparison to today's date Flag up date appropriately with
|
|
|
|
|
# a 'traffic light' colour code
|
2008-12-08 16:59:10 +01:00
|
|
|
#
|
2007-03-30 04:36:52 +00:00
|
|
|
def due_date(due)
|
|
|
|
|
if due == nil
|
|
|
|
|
return ""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
days = days_from_today(due)
|
|
|
|
|
|
|
|
|
|
case days
|
2008-04-05 14:04:28 +00:00
|
|
|
when 0
|
|
|
|
|
"<a title='#{format_date(due)}'><span class=\"amber\">Due Today</span></a> "
|
|
|
|
|
when 1
|
|
|
|
|
"<a title='#{format_date(due)}'><span class=\"amber\">Due Tomorrow</span></a> "
|
2007-03-30 04:36:52 +00:00
|
|
|
# due 2-7 days away
|
2008-04-05 14:04:28 +00:00
|
|
|
when 2..7
|
2007-09-26 12:05:21 +00:00
|
|
|
if prefs.due_style == Preference.due_styles[:due_on]
|
2007-03-30 04:36:52 +00:00
|
|
|
"<a title='#{format_date(due)}'><span class=\"orange\">Due on #{due.strftime("%A")}</span></a> "
|
|
|
|
|
else
|
|
|
|
|
"<a title='#{format_date(due)}'><span class=\"orange\">Due in #{pluralize(days, 'day')}</span></a> "
|
|
|
|
|
end
|
2008-04-05 14:04:28 +00:00
|
|
|
else
|
|
|
|
|
# overdue or due very soon! sound the alarm!
|
|
|
|
|
if days < 0
|
|
|
|
|
"<a title='#{format_date(due)}'><span class=\"red\">Overdue by #{pluralize(days * -1, 'day')}</span></a> "
|
2007-03-30 04:36:52 +00:00
|
|
|
else
|
2008-04-05 14:04:28 +00:00
|
|
|
# more than a week away - relax
|
2007-03-30 04:36:52 +00:00
|
|
|
"<a title='#{format_date(due)}'><span class=\"green\">Due in #{pluralize(days, 'day')}</span></a> "
|
2008-04-05 14:04:28 +00:00
|
|
|
end
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2008-04-05 14:04:28 +00:00
|
|
|
# Check due date in comparison to today's date Flag up date appropriately with
|
|
|
|
|
# a 'traffic light' colour code Modified method for mobile screen
|
2008-12-08 16:59:10 +01:00
|
|
|
#
|
2007-03-30 04:36:52 +00:00
|
|
|
def due_date_mobile(due)
|
|
|
|
|
if due == nil
|
|
|
|
|
return ""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
days = days_from_today(due)
|
|
|
|
|
|
|
|
|
|
case days
|
2008-04-05 14:04:28 +00:00
|
|
|
when 0
|
|
|
|
|
"<span class=\"amber\">"+ format_date(due) + "</span>"
|
|
|
|
|
when 1
|
|
|
|
|
"<span class=\"amber\">" + format_date(due) + "</span>"
|
|
|
|
|
# due 2-7 days away
|
|
|
|
|
when 2..7
|
|
|
|
|
"<span class=\"orange\">" + format_date(due) + "</span>"
|
|
|
|
|
else
|
2007-03-30 04:36:52 +00:00
|
|
|
# overdue or due very soon! sound the alarm!
|
2008-04-05 14:04:28 +00:00
|
|
|
if days < 0
|
2007-03-30 04:36:52 +00:00
|
|
|
"<span class=\"red\">" + format_date(due) +"</span>"
|
|
|
|
|
else
|
2008-04-05 14:04:28 +00:00
|
|
|
# more than a week away - relax
|
2007-03-30 04:36:52 +00:00
|
|
|
"<span class=\"green\">" + format_date(due) + "</span>"
|
2008-04-05 14:04:28 +00:00
|
|
|
end
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2008-05-16 14:32:42 +00:00
|
|
|
# Returns a count of next actions in the given context or project. The result
|
2008-04-05 14:04:28 +00:00
|
|
|
# is count and a string descriptor, correctly pluralised if there are no
|
2007-03-30 04:36:52 +00:00
|
|
|
# actions or multiple actions
|
2008-12-08 16:59:10 +01:00
|
|
|
#
|
2007-03-30 04:36:52 +00:00
|
|
|
def count_undone_todos_phrase(todos_parent, string="actions")
|
|
|
|
|
@controller.count_undone_todos_phrase(todos_parent, string)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def count_undone_todos_phrase_text(todos_parent, string="actions")
|
|
|
|
|
count_undone_todos_phrase(todos_parent, string).gsub(" "," ")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def count_undone_todos_and_notes_phrase(project, string="actions")
|
|
|
|
|
s = count_undone_todos_phrase(project, string)
|
|
|
|
|
s += ", #{pluralize(project.note_count, 'note')}" unless project.note_count == 0
|
|
|
|
|
s
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def link_to_context(context, descriptor = sanitize(context.name))
|
|
|
|
|
link_to( descriptor, context_path(context), :title => "View context: #{context.name}" )
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def link_to_project(project, descriptor = sanitize(project.name))
|
|
|
|
|
link_to( descriptor, project_path(project), :title => "View project: #{project.name}" )
|
|
|
|
|
end
|
2010-10-07 23:24:50 +02:00
|
|
|
|
|
|
|
|
def link_to_edit_project (project, descriptor = sanitize(project.name))
|
|
|
|
|
link_to(descriptor,
|
|
|
|
|
url_for({:controller => 'projects', :action => 'edit', :id => project.id}),
|
|
|
|
|
{:id => "link_edit_#{dom_id(project)}", :class => "project_edit_settings"})
|
|
|
|
|
end
|
2010-10-24 22:31:57 +02:00
|
|
|
|
|
|
|
|
def link_to_edit_context (context, descriptor = sanitize(context.name))
|
|
|
|
|
link_to(descriptor,
|
|
|
|
|
url_for({:controller => 'contexts', :action => 'edit', :id => context.id}),
|
|
|
|
|
{:id => "link_edit_#{dom_id(context)}", :class => "context_edit_settings"})
|
|
|
|
|
end
|
2010-11-11 22:14:14 +01:00
|
|
|
|
|
|
|
|
def link_to_edit_note (note, descriptor = sanitize(note.id.to_s))
|
|
|
|
|
link_to(descriptor,
|
|
|
|
|
url_for({:controller => 'notes', :action => 'edit', :id => note.id}),
|
|
|
|
|
{:id => "link_edit_#{dom_id(note)}", :class => "note_edit_settings"})
|
|
|
|
|
end
|
2007-03-30 04:36:52 +00:00
|
|
|
|
2010-10-07 23:37:39 +02:00
|
|
|
def link_to_delete_project(project, descriptor = sanitize(project.name))
|
|
|
|
|
link_to(
|
|
|
|
|
descriptor,
|
|
|
|
|
project_path(project, :format => 'js'),
|
|
|
|
|
{:id => "delete_project_#{project.id}", :class => "delete_project_button", :title => "#{t('projects.delete_project_title')} '#{project.name}'"}
|
|
|
|
|
)
|
|
|
|
|
end
|
2010-10-23 17:52:50 +02:00
|
|
|
|
|
|
|
|
def link_to_delete_context(context, descriptor = sanitize(context.name))
|
|
|
|
|
link_to(
|
|
|
|
|
descriptor,
|
|
|
|
|
context_path(context, :format => 'js'),
|
|
|
|
|
{:id => "delete_context_#{context.id}", :class => "delete_context_button", :title => t('contexts.delete_context_confirmation', :name => context.name)}
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2010-11-11 22:14:14 +01:00
|
|
|
def link_to_delete_note(note, descriptor = sanitize(note.id.to_s))
|
|
|
|
|
link_to(
|
|
|
|
|
descriptor,
|
|
|
|
|
note_path(note, :format => 'js'),
|
|
|
|
|
{:id => "delete_note_#{note.id}", :class => "delete_note_button", :title => "delete the note '#{note.id}'"}
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2008-04-25 19:06:45 +00:00
|
|
|
def link_to_project_mobile(project, accesskey, descriptor = sanitize(project.name))
|
2009-12-07 23:16:21 -05:00
|
|
|
link_to( descriptor, project_path(project, :format => 'm'), {:title => "View project: #{project.name}", :accesskey => accesskey} )
|
2008-04-19 19:15:07 +00:00
|
|
|
end
|
|
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def item_link_to_context(item)
|
|
|
|
|
descriptor = "[C]"
|
2007-07-30 05:29:18 +00:00
|
|
|
descriptor = "[#{item.context.name}]" if prefs.verbose_action_descriptors
|
2007-03-30 04:36:52 +00:00
|
|
|
link_to_context( item.context, descriptor )
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def item_link_to_project(item)
|
|
|
|
|
descriptor = "[P]"
|
2007-07-30 05:29:18 +00:00
|
|
|
descriptor = "[#{item.project.name}]" if prefs.verbose_action_descriptors
|
2007-03-30 04:36:52 +00:00
|
|
|
link_to_project( item.project, descriptor )
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def render_flash
|
|
|
|
|
render :partial => 'shared/flash', :locals => { :flash => flash }
|
|
|
|
|
end
|
2008-12-08 16:59:10 +01:00
|
|
|
|
|
|
|
|
def recurrence_time_span(rt)
|
|
|
|
|
case rt.ends_on
|
|
|
|
|
when "no_end_date"
|
|
|
|
|
return rt.start_from.nil? ? "" : "from " + format_date(rt.start_from)
|
|
|
|
|
when "ends_on_number_of_times"
|
|
|
|
|
return "for "+rt.number_of_occurences.to_s + " times"
|
|
|
|
|
when "ends_on_end_date"
|
|
|
|
|
starts = rt.start_from.nil? ? "" : "from " + format_date(rt.start_from)
|
|
|
|
|
ends = rt.end_date.nil? ? "" : " until " + format_date(rt.end_date)
|
|
|
|
|
return starts+ends
|
|
|
|
|
else
|
|
|
|
|
raise Exception.new, "unknown recurrence time span selection (#{rt.ends_on})"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def recurrence_pattern_as_text(recurring_todo)
|
|
|
|
|
rt = recurring_todo.recurring_target_as_text
|
|
|
|
|
rp = recurring_todo.recurrence_pattern
|
|
|
|
|
# only add space if recurrence_pattern has content
|
|
|
|
|
rp = " " + rp if !rp.nil?
|
|
|
|
|
rts = recurrence_time_span(recurring_todo)
|
|
|
|
|
# only add space if recurrence_time_span has content
|
|
|
|
|
rts = " " + rts if !(rts == "")
|
|
|
|
|
return rt+rp+rts
|
|
|
|
|
end
|
|
|
|
|
|
2009-10-30 15:37:40 -04:00
|
|
|
def date_format_for_date_picker()
|
|
|
|
|
standard_format = current_user.prefs.date_format
|
|
|
|
|
translations = [
|
|
|
|
|
['%m', 'mm'],
|
2009-12-16 17:54:29 -05:00
|
|
|
['%b', 'M'],
|
|
|
|
|
['%B', 'MM'],
|
2009-10-30 15:37:40 -04:00
|
|
|
['%d', 'dd'],
|
2009-12-16 17:54:29 -05:00
|
|
|
['%a', 'D'],
|
|
|
|
|
['%A', 'DD'],
|
|
|
|
|
['%y', 'y'],
|
|
|
|
|
['%Y', 'yy']
|
2009-10-30 15:37:40 -04:00
|
|
|
]
|
|
|
|
|
translations.inject(standard_format) do |str, translation|
|
|
|
|
|
str.gsub(*translation)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-01-13 20:45:09 +01:00
|
|
|
AUTO_LINK_MESSAGE_RE = %r{message://<[^>]+>} unless const_defined?(:AUTO_LINK_MESSAGE_RE)
|
|
|
|
|
|
|
|
|
|
# Converts message:// links to href. This URL scheme is used on Mac OS X
|
|
|
|
|
# to link to a mail message in Mail.app.
|
|
|
|
|
def auto_link_message(text)
|
|
|
|
|
text.gsub(AUTO_LINK_MESSAGE_RE) do
|
|
|
|
|
href = $&
|
|
|
|
|
left, right = $`, $'
|
|
|
|
|
# detect already linked URLs and URLs in the middle of a tag
|
|
|
|
|
if left =~ /<[^>]+$/ && right =~ /^[^>]*>/
|
|
|
|
|
# do not change string; URL is alreay linked
|
|
|
|
|
href
|
|
|
|
|
else
|
2010-04-09 09:34:57 -04:00
|
|
|
content = content_tag(:a, h(href), :href => h(href))
|
2010-01-13 20:45:09 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def format_note(note)
|
|
|
|
|
note = auto_link_message(note)
|
2010-04-09 09:34:57 -04:00
|
|
|
note = markdown(note)
|
|
|
|
|
note = auto_link(note, :link => :urls)
|
2010-04-07 10:06:46 -04:00
|
|
|
|
|
|
|
|
# add onenote and message protocols
|
|
|
|
|
Sanitize::Config::RELAXED[:protocols]['a']['href'] << 'onenote'
|
|
|
|
|
Sanitize::Config::RELAXED[:protocols]['a']['href'] << 'message'
|
|
|
|
|
|
|
|
|
|
note = Sanitize.clean(note, Sanitize::Config::RELAXED)
|
2010-04-02 12:53:29 -04:00
|
|
|
return note
|
2010-01-13 20:45:09 +01:00
|
|
|
end
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|