2007-03-30 04:36:52 +00:00
|
|
|
module ApplicationHelper
|
2013-03-05 14:04:01 +01:00
|
|
|
|
|
|
|
|
def group_view_by_menu_entry
|
|
|
|
|
# not set, no menu entry
|
|
|
|
|
return "" if @group_view_by.nil?
|
|
|
|
|
|
|
|
|
|
# if view == context, the menu shows Order By Project
|
|
|
|
|
menu_name = @group_view_by == 'context' ? 'project' : 'context'
|
|
|
|
|
|
|
|
|
|
content_tag(:li) do
|
2014-08-14 21:05:05 -05:00
|
|
|
link_to(
|
|
|
|
|
t("layouts.navigation.group_view_by_#{menu_name}"),
|
|
|
|
|
'#',
|
2013-03-05 14:04:01 +01:00
|
|
|
{:id => "group_view_by_link", :accesskey => "g", :title => t('layouts.navigation.group_view_by_title'), :x_current_group_by => @group_view_by} )
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def container_toggle(id)
|
|
|
|
|
link_to(
|
|
|
|
|
image_tag("blank.png", :alt => t('common.collapse_expand')),
|
2014-08-14 21:05:05 -05:00
|
|
|
"#",
|
2013-03-05 14:04:01 +01:00
|
|
|
{:class => "container_toggle", :id => id} )
|
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
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)
|
2014-07-17 15:19:17 +02:00
|
|
|
return DateLabelHelper::DueDateView.new(due, prefs).due_date_html
|
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 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)
|
2014-07-17 15:19:17 +02:00
|
|
|
return DateLabelHelper::DueDateView.new(due, prefs).due_date_mobile_html
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
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
|
|
|
#
|
2012-04-16 13:17:59 +02:00
|
|
|
def count_undone_todos_phrase(todos_parent)
|
2012-05-01 09:39:53 +02:00
|
|
|
controller.count_undone_todos_phrase(todos_parent).html_safe
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2012-04-16 13:17:59 +02:00
|
|
|
def count_undone_todos_phrase_text(todos_parent)
|
2012-05-01 09:39:53 +02:00
|
|
|
count_undone_todos_phrase(todos_parent).gsub(" "," ").html_safe
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2012-04-16 13:17:59 +02:00
|
|
|
def count_undone_todos_and_notes_phrase(project)
|
|
|
|
|
s = count_undone_todos_phrase(project)
|
|
|
|
|
s += ", #{t('common.note', :count => project.note_count)}" unless project.note_count == 0
|
2012-05-01 09:39:53 +02:00
|
|
|
s.html_safe
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def link_to_context(context, descriptor = sanitize(context.name))
|
2010-11-29 11:04:15 +01:00
|
|
|
link_to( descriptor, context, :title => "View context: #{context.name}" )
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def link_to_project(project, descriptor = sanitize(project.name))
|
2010-11-29 11:04:15 +01:00
|
|
|
link_to( descriptor, project, :title => "View project: #{project.name}" )
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
2010-10-07 23:24:50 +02:00
|
|
|
|
2010-11-11 22:14:14 +01:00
|
|
|
def link_to_edit_note (note, descriptor = sanitize(note.id.to_s))
|
2012-07-12 23:33:36 +02:00
|
|
|
link_to(descriptor, edit_note_path(note),
|
2010-11-11 22:14:14 +01:00
|
|
|
{:id => "link_edit_#{dom_id(note)}", :class => "note_edit_settings"})
|
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
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
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def item_link_to_context(item)
|
2012-07-12 13:14:21 +02:00
|
|
|
link_to_context( item.context, prefs.verbose_action_descriptors ? "[#{item.context.name}]" : "[C]" )
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def item_link_to_project(item)
|
2012-07-12 13:14:21 +02:00
|
|
|
link_to_project( item.project, prefs.verbose_action_descriptors ? "[#{item.project.name}]" : "[P]" )
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def render_flash
|
2012-01-27 10:55:39 +01:00
|
|
|
render :partial => 'shared/flash', :object => flash
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
2008-12-08 16:59:10 +01:00
|
|
|
|
2012-07-12 13:14:21 +02:00
|
|
|
def time_span_text(date, i18n_text)
|
|
|
|
|
return (date ? "#{i18n_text} #{format_date(date)}" : "").html_safe
|
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2008-12-08 16:59:10 +01:00
|
|
|
def recurrence_time_span(rt)
|
|
|
|
|
case rt.ends_on
|
|
|
|
|
when "no_end_date"
|
2012-07-12 13:14:21 +02:00
|
|
|
return time_span_text(rt.start_from, I18n.t("todos.recurrence.pattern.from"))
|
2008-12-08 16:59:10 +01:00
|
|
|
when "ends_on_number_of_times"
|
2015-02-10 15:49:13 +01:00
|
|
|
return I18n.t("todos.recurrence.pattern.times", :number => rt.number_of_occurrences)
|
2008-12-08 16:59:10 +01:00
|
|
|
when "ends_on_end_date"
|
2012-07-12 13:14:21 +02:00
|
|
|
starts = time_span_text(rt.start_from, I18n.t("todos.recurrence.pattern.from"))
|
|
|
|
|
ends = time_span_text(rt.end_date, I18n.t("todos.recurrence.pattern.until"))
|
2008-12-08 16:59:10 +01:00
|
|
|
return starts+ends
|
|
|
|
|
else
|
|
|
|
|
raise Exception.new, "unknown recurrence time span selection (#{rt.ends_on})"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def recurrence_pattern_as_text(recurring_todo)
|
2015-05-09 19:06:08 +02:00
|
|
|
recurring_target = recurring_todo.recurring_target_as_text
|
|
|
|
|
|
|
|
|
|
recurrence_pattern = recurring_todo.recurrence_pattern
|
|
|
|
|
recurrence_pattern = ' ' + recurrence_pattern unless recurrence_pattern.nil?
|
|
|
|
|
|
|
|
|
|
recurrence_time_span = recurrence_time_span(recurring_todo)
|
|
|
|
|
recurrence_time_span = ' ' + recurrence_time_span unless recurrence_time_span.empty?
|
|
|
|
|
|
|
|
|
|
recurring_target + recurrence_pattern + recurrence_time_span
|
2008-12-08 16:59:10 +01:00
|
|
|
end
|
|
|
|
|
|
2009-10-30 15:37:40 -04:00
|
|
|
def date_format_for_date_picker()
|
2012-07-12 13:14:21 +02:00
|
|
|
[
|
2009-10-30 15:37:40 -04:00
|
|
|
['%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']
|
2012-07-12 13:14:21 +02:00
|
|
|
].inject(current_user.prefs.date_format) { |str, translation| str.gsub(*translation) }
|
2009-10-30 15:37:40 -04:00
|
|
|
end
|
|
|
|
|
|
2010-11-24 22:01:23 +01:00
|
|
|
def sidebar_html_for_titled_list (list, title)
|
2012-05-01 17:25:45 +02:00
|
|
|
return content_tag(:h3, title+" (#{list.size})") + content_tag(:ul, sidebar_html_for_list(list))
|
2010-11-24 22:01:23 +01:00
|
|
|
end
|
|
|
|
|
|
2012-07-12 13:14:21 +02:00
|
|
|
def link_to_sidebar_item(item)
|
|
|
|
|
item.is_a?(Project) ? link_to_project( item ) : link_to_context( item )
|
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2012-07-12 13:14:21 +02:00
|
|
|
def sidebar_html_for_item(item)
|
|
|
|
|
content_tag(:li, link_to_sidebar_item(item) + " (" + count_undone_todos_phrase(item)+")")
|
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2010-11-24 22:01:23 +01:00
|
|
|
def sidebar_html_for_list(list)
|
2012-07-12 13:14:21 +02:00
|
|
|
return content_tag(:li, t('sidebar.list_empty')).html_safe if list.empty?
|
|
|
|
|
return list.inject("") { |html, item| html << sidebar_html_for_item(item) }.html_safe
|
2010-11-24 22:01:23 +01:00
|
|
|
end
|
|
|
|
|
|
2011-02-09 20:41:34 +01:00
|
|
|
def generate_i18n_strings
|
2011-02-25 17:10:33 +01:00
|
|
|
js = "i18n_locale='#{I18n.locale}';\n"
|
2011-02-09 20:41:34 +01:00
|
|
|
js << "i18n = new Array();\n"
|
|
|
|
|
%w{
|
|
|
|
|
shared.toggle_multi shared.toggle_multi_title
|
|
|
|
|
shared.hide_form shared.hide_action_form_title
|
|
|
|
|
shared.toggle_single shared.toggle_single_title
|
|
|
|
|
projects.hide_form projects.hide_form_title
|
|
|
|
|
projects.show_form projects.show_form_title
|
|
|
|
|
contexts.hide_form contexts.hide_form_title
|
|
|
|
|
contexts.show_form contexts.show_form_title
|
|
|
|
|
contexts.new_context_pre contexts.new_context_post
|
|
|
|
|
common.cancel common.ok
|
2012-04-11 20:21:28 +02:00
|
|
|
common.update common.create
|
2011-04-30 20:46:47 +02:00
|
|
|
common.ajaxError todos.unresolved_dependency
|
2011-02-09 20:41:34 +01:00
|
|
|
}.each do |s|
|
2011-02-12 22:58:58 +01:00
|
|
|
js << "i18n['#{s}'] = '#{ t(s).gsub(/'/, "\\\\'") }';\n"
|
2011-02-09 20:41:34 +01:00
|
|
|
end
|
2012-08-11 23:54:05 +02:00
|
|
|
return js.html_safe
|
2011-02-09 20:41:34 +01:00
|
|
|
end
|
|
|
|
|
|
2016-02-16 22:08:15 -05:00
|
|
|
def javascript_tag_for_i18n_datepicker
|
|
|
|
|
locale = I18n.locale
|
|
|
|
|
# do not include en as locale since this the available by default
|
|
|
|
|
if locale && locale != :en
|
|
|
|
|
javascript_include_tag("jquery-ui/datepicker-#{locale}")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-05-05 20:32:32 +02:00
|
|
|
def done_path(controller_name, type)
|
|
|
|
|
case controller_name
|
2011-06-17 14:30:32 +02:00
|
|
|
when "contexts"
|
2013-05-05 20:54:12 +02:00
|
|
|
send("#{type}_todos_context_path",@context)
|
2011-06-17 14:30:32 +02:00
|
|
|
when "projects"
|
2013-05-05 20:32:32 +02:00
|
|
|
send("#{type}_todos_project_path", @project)
|
2011-06-26 23:05:33 +02:00
|
|
|
when "todos"
|
2014-01-11 14:33:14 +01:00
|
|
|
if @tag_name
|
2013-05-05 20:32:32 +02:00
|
|
|
send("#{type}_tag_path",@tag_name)
|
2011-06-26 23:05:33 +02:00
|
|
|
else
|
2013-05-05 20:32:32 +02:00
|
|
|
send("#{type}_todos_path")
|
2012-01-27 10:55:39 +01:00
|
|
|
end
|
2011-06-17 14:30:32 +02:00
|
|
|
else
|
2013-05-05 20:32:32 +02:00
|
|
|
send("#{type}_todos_path")
|
2011-06-17 14:30:32 +02:00
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
end
|
|
|
|
|
|
2013-05-05 20:32:32 +02:00
|
|
|
def determine_done_path
|
|
|
|
|
done_path(controller.controller_name, :done)
|
2011-06-17 14:30:32 +02:00
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2011-06-17 14:30:32 +02:00
|
|
|
def determine_all_done_path
|
2013-05-05 20:32:32 +02:00
|
|
|
done_path(controller.controller_name, :all_done)
|
2011-06-17 14:30:32 +02:00
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2012-04-19 00:02:42 +02:00
|
|
|
def get_list_of_error_messages_for(model)
|
|
|
|
|
if model.errors.any?
|
2012-12-16 15:20:43 +01:00
|
|
|
content_tag(:div, {:id=>"errorExplanation"}) do
|
|
|
|
|
content_tag(:ul) do
|
|
|
|
|
model.errors.full_messages.collect { |msg| concat(content_tag(:li, msg)) }
|
|
|
|
|
end
|
2012-08-25 17:27:38 +02:00
|
|
|
end
|
2012-04-19 00:02:42 +02:00
|
|
|
end
|
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2013-05-05 20:32:32 +02:00
|
|
|
def link_to_delete(type, object, descriptor = sanitize(object.name))
|
|
|
|
|
link_to(
|
|
|
|
|
descriptor,
|
|
|
|
|
self.send("#{type}_path", object, :format => 'js'),
|
|
|
|
|
{
|
|
|
|
|
:id => "delete_#{type}_#{object.id}",
|
|
|
|
|
:class => "delete_#{type}_button icon",
|
|
|
|
|
:x_confirm_message => t("#{type}s.delete_#{type}_confirmation", :name => object.name),
|
|
|
|
|
:title => t("#{type}s.delete_#{type}_title")
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def link_to_edit(type, object, descriptor)
|
|
|
|
|
link_to(descriptor, self.send("edit_#{type}_path", object),
|
|
|
|
|
{
|
|
|
|
|
:id => "link_edit_#{dom_id(object)}",
|
|
|
|
|
:class => "#{type}_edit_settings icon"
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2013-06-19 17:47:51 +02:00
|
|
|
def source_view_key
|
|
|
|
|
# uses @project.id or @context.id depending on source_view
|
|
|
|
|
source_view_is_one_of(:project, :context) ? "#{@source_view}-#{eval("@#{@source_view}.id")}" : @source_view
|
|
|
|
|
end
|
2013-05-05 20:32:32 +02:00
|
|
|
|
2014-08-10 13:18:33 +02:00
|
|
|
# create a unique object name which can be used in ajax calls returning js
|
|
|
|
|
# to prevent concurrent calls with same functions to overwrite each other functions
|
|
|
|
|
def unique_object_name_for(name)
|
2014-08-14 21:05:05 -05:00
|
|
|
"#{name}_#{SecureRandom.hex(5)}"
|
2014-08-10 13:18:33 +02:00
|
|
|
end
|
|
|
|
|
|
2014-08-10 20:43:27 +02:00
|
|
|
def js_render(partial, locals = {}, object=nil)
|
|
|
|
|
if object
|
2014-08-14 21:05:05 -05:00
|
|
|
escape_javascript(render(partial: partial, locals: locals, object: object))
|
2014-08-10 20:43:27 +02:00
|
|
|
else
|
2014-08-14 21:05:05 -05:00
|
|
|
escape_javascript(render(partial: partial, locals: locals))
|
2014-08-10 20:43:27 +02:00
|
|
|
end
|
2014-08-10 15:57:37 +02:00
|
|
|
end
|
|
|
|
|
|
2014-08-10 20:43:27 +02:00
|
|
|
def js_error_messages_for(object)
|
|
|
|
|
escape_javascript(get_list_of_error_messages_for(object))
|
2014-08-14 21:05:05 -05:00
|
|
|
end
|
2014-08-10 20:43:27 +02:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|