2009-03-24 21:06:53 +01:00
|
|
|
module TodosHelper
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def remote_star_icon(todo=@todo)
|
|
|
|
|
link_to( image_tag_for_star(todo),
|
|
|
|
|
toggle_star_todo_path(todo),
|
|
|
|
|
:class => "icon star_item", :title => t('todos.star_action_with_description', :description => todo.description))
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
2009-03-30 21:21:53 +02:00
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def remote_edit_button(todo=@todo)
|
2010-03-07 16:54:17 -05:00
|
|
|
link_to(
|
2011-02-03 16:59:59 +01:00
|
|
|
image_tag("blank.png", :alt => t('todos.edit'), :align => "absmiddle", :id => 'edit_icon_todo_'+todo.id.to_s, :class => 'edit_item'),
|
|
|
|
|
{:controller => 'todos', :action => 'edit', :id => todo.id},
|
2010-03-07 16:54:17 -05:00
|
|
|
:class => "icon edit_item",
|
2011-02-03 16:59:59 +01:00
|
|
|
:title => t('todos.edit_action_with_description', :description => todo.description))
|
2009-03-30 21:21:53 +02:00
|
|
|
end
|
|
|
|
|
|
2010-12-20 18:20:37 +01:00
|
|
|
def remote_delete_menu_item(todo)
|
|
|
|
|
return link_to(
|
2010-10-31 21:27:13 +08:00
|
|
|
image_tag("delete_off.png", :mouseover => "delete_on.png", :alt => t('todos.delete'), :align => "absmiddle")+" "+t('todos.delete'),
|
2010-12-20 18:20:37 +01:00
|
|
|
{:controller => 'todos', :action => 'destroy', :id => todo.id},
|
|
|
|
|
:class => "icon_delete_item",
|
|
|
|
|
:id => "delete_#{dom_id(todo)}",
|
2011-02-09 20:41:34 +01:00
|
|
|
:x_confirm_message => t('todos.confirm_delete', :description => todo.description),
|
|
|
|
|
:title => t('todos.delete_action'));
|
2009-03-30 21:21:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def remote_defer_menu_item(days, todo)
|
2009-04-07 19:31:49 +02:00
|
|
|
url = {:controller => 'todos', :action => 'defer', :id => todo.id, :days => days,
|
|
|
|
|
:_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")}
|
|
|
|
|
url[:_tag_name] = @tag_name if @source_view == 'tag'
|
2011-01-06 23:01:17 +01:00
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
futuredate = (todo.show_from || todo.user.date) + days.days
|
2011-01-06 23:01:17 +01:00
|
|
|
options = {:x_defer_alert => false, :class => "icon_defer_item" }
|
2011-02-03 16:59:59 +01:00
|
|
|
if todo.due && futuredate > todo.due
|
2011-01-06 23:01:17 +01:00
|
|
|
options[:x_defer_alert] = true
|
|
|
|
|
options[:x_defer_date_after_due_date] = t('todos.defer_date_after_due_date')
|
2009-04-15 23:09:55 -04:00
|
|
|
end
|
2011-01-06 23:01:17 +01:00
|
|
|
|
|
|
|
|
return link_to(image_tag_for_defer(days), url, options)
|
2009-03-30 21:21:53 +02:00
|
|
|
end
|
2009-12-20 13:36:05 -05:00
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def remote_delete_dependency(todo, predecessor)
|
|
|
|
|
link_to(
|
|
|
|
|
image_tag("blank.png", :title => t('todos.remove_dependency'), :align => "absmiddle", :class => "delete_item"),
|
|
|
|
|
url_for({:controller => 'todos', :action => 'remove_predecessor', :id => todo.id}),
|
|
|
|
|
{:class => "delete_dependency_button", :x_predecessors_id => predecessor.id}
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2009-12-20 13:36:05 -05:00
|
|
|
def remote_promote_to_project_menu_item(todo)
|
|
|
|
|
url = {:controller => 'todos', :action => 'convert_to_project', :id => todo.id,
|
|
|
|
|
:_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")}
|
|
|
|
|
url[:_tag_name] = @tag_name if @source_view == 'tag'
|
|
|
|
|
|
2010-10-31 21:27:13 +08:00
|
|
|
return link_to(image_tag("to_project_off.png", :align => "absmiddle")+" " + t('todos.convert_to_project'), url)
|
2009-12-20 13:36:05 -05:00
|
|
|
end
|
2010-12-25 16:28:53 +01:00
|
|
|
|
2011-01-06 23:01:17 +01:00
|
|
|
def image_tag_for_defer(days)
|
|
|
|
|
image_tag("defer_#{days}_off.png", :mouseover => "defer_#{days}.png", :alt => t('todos.defer_x_days', :count => days), :align => "absmiddle")+" "+t('todos.defer_x_days', :count => days)
|
|
|
|
|
end
|
|
|
|
|
|
2011-01-10 17:20:40 +01:00
|
|
|
# waiting stuff can be deleted after migration of defer and dependencies
|
2009-11-29 20:00:54 -05:00
|
|
|
def successor_start_waiting_js(successor)
|
|
|
|
|
return "$('##{dom_id(successor, "successor")}').block({message: null})"
|
2009-03-30 21:21:53 +02:00
|
|
|
end
|
|
|
|
|
|
2011-01-10 17:20:40 +01:00
|
|
|
def collapsed_notes_image(todo)
|
|
|
|
|
link = link_to(image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ), "#", {:class => 'show_notes', :title => 'Show notes'})
|
|
|
|
|
notes = content_tag(:div, {:class => "todo_notes", :id => dom_id(todo, 'notes'), :style => "display:none"}) { format_note(todo.notes) }
|
|
|
|
|
return link+notes
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def collapsed_successors_image(todo)
|
|
|
|
|
link = link_to(image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ), "#", {:class => 'show_successors', :title => 'Show successors'})
|
|
|
|
|
successors = content_tag(:div, {:class => "todo_successors", :id => dom_id(todo, 'successors'), :style => "display:none"}) do
|
|
|
|
|
render :partial => "todos/successor", :collection => todo.pending_successors,
|
|
|
|
|
:locals => { :parent_container_type => parent_container_type, :suppress_dependencies => true, :predecessor => todo }
|
|
|
|
|
end
|
|
|
|
|
return link+successors
|
2009-03-30 21:21:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def image_tag_for_recurring_todo(todo)
|
|
|
|
|
return link_to(
|
|
|
|
|
image_tag("recurring16x16.png"),
|
|
|
|
|
{:controller => "recurring_todos", :action => "index"},
|
|
|
|
|
:class => "recurring_icon", :title => recurrence_pattern_as_text(todo.recurring_todo))
|
|
|
|
|
end
|
2009-03-24 21:06:53 +01:00
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def remote_toggle_checkbox(todo=@todo)
|
|
|
|
|
check_box_tag('item_id', toggle_check_todo_path(todo), todo.completed?, :class => 'item-checkbox',
|
|
|
|
|
:title => todo.pending? ? t('todos.blocked_by', :predecessors => todo.uncompleted_predecessors.map(&:description).join(', ')) : "", :readonly => todo.pending?)
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def date_span(todo=@todo)
|
|
|
|
|
if todo.completed?
|
|
|
|
|
"<span class=\"grey\">#{format_date( todo.completed_at )}</span>"
|
|
|
|
|
elsif todo.pending?
|
|
|
|
|
"<a title='#{t('todos.depends_on')}: #{todo.uncompleted_predecessors.map(&:description).join(', ')}'><span class=\"orange\">#{t('todos.pending')}</span></a> "
|
|
|
|
|
elsif todo.deferred?
|
|
|
|
|
show_date( todo.show_from )
|
2009-03-24 21:06:53 +01:00
|
|
|
else
|
2011-02-03 16:59:59 +01:00
|
|
|
due_date( todo.due )
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def successors_span(todo=@todo)
|
|
|
|
|
unless todo.pending_successors.empty?
|
|
|
|
|
pending_count = todo.pending_successors.length
|
|
|
|
|
title = "#{t('todos.has_x_pending', :count => pending_count)}: #{todo.pending_successors.map(&:description).join(', ')}"
|
2009-06-08 23:42:46 +02:00
|
|
|
image_tag( 'successor_off.png', :width=>'10', :height=>'16', :border=>'0', :title => title )
|
2009-11-04 22:45:02 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def grip_span(todo=@todo)
|
|
|
|
|
unless todo.completed?
|
2009-06-10 00:07:23 +02:00
|
|
|
image_tag('grip.png', :width => '7', :height => '16', :border => '0',
|
2010-10-31 21:27:13 +08:00
|
|
|
:title => t('todos.drag_action_title'),
|
2010-05-09 18:57:56 -04:00
|
|
|
:class => 'grip')
|
2009-06-10 00:07:23 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def tag_list_text(todo=@todo)
|
|
|
|
|
todo.tags.collect{|t| t.name}.join(', ')
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def tag_list(todo=@todo)
|
|
|
|
|
tags_except_starred = todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME}
|
2009-03-24 21:06:53 +01:00
|
|
|
tag_list = tags_except_starred.collect{|t| "<span class=\"tag #{t.name.gsub(' ','-')}\">" + link_to(t.name, :controller => "todos", :action => "tag", :id => t.name) + "</span>"}.join('')
|
|
|
|
|
"<span class='tags'>#{tag_list}</span>"
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def tag_list_mobile(todo=@todo)
|
|
|
|
|
tags_except_starred = todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME}
|
2009-03-24 21:06:53 +01:00
|
|
|
# removed the link. TODO: add link to mobile view of tagged actions
|
|
|
|
|
tag_list = tags_except_starred.collect{|t|
|
|
|
|
|
"<span class=\"tag\">" +
|
|
|
|
|
link_to(t.name, {:action => "tag", :controller => "todos", :id => t.name+".m"}) +
|
2009-03-30 21:21:53 +02:00
|
|
|
"</span>"}.join('')
|
2009-03-24 21:06:53 +01:00
|
|
|
if tag_list.empty? then "" else "<span class=\"tags\">#{tag_list}</span>" end
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def predecessor_list_text(todo=@todo)
|
|
|
|
|
todo.predecessors.map{|t| t.specification}.join(', ')
|
2009-11-04 22:39:19 -05:00
|
|
|
end
|
2009-08-19 22:15:38 +02:00
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def deferred_due_date(todo=@todo)
|
|
|
|
|
if todo.deferred? && todo.due
|
|
|
|
|
t('todos.action_due_on', :date => format_date(todo.due))
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def project_and_context_links(todo, parent_container_type, opts = {})
|
2009-03-24 21:06:53 +01:00
|
|
|
str = ''
|
2011-02-03 16:59:59 +01:00
|
|
|
if todo.completed?
|
|
|
|
|
str += todo.context.name unless opts[:suppress_context]
|
|
|
|
|
should_suppress_project = opts[:suppress_project] || todo.project.nil?
|
2009-03-24 21:06:53 +01:00
|
|
|
str += ", " unless str.blank? || should_suppress_project
|
2011-02-03 16:59:59 +01:00
|
|
|
str += todo.project.name unless should_suppress_project
|
2009-03-24 21:06:53 +01:00
|
|
|
str = "(#{str})" unless str.blank?
|
|
|
|
|
else
|
|
|
|
|
if (['project', 'tag', 'stats', 'search'].include?(parent_container_type))
|
2011-02-03 16:59:59 +01:00
|
|
|
str << item_link_to_context( todo )
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
2011-02-03 19:30:48 +01:00
|
|
|
if (['context', 'tickler', 'tag', 'stats', 'search'].include?(parent_container_type)) && todo.project_id
|
2011-02-03 16:59:59 +01:00
|
|
|
str << item_link_to_project( todo )
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return str
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Uses the 'staleness_starts' value from settings.yml (in days) to colour the
|
|
|
|
|
# background of the action appropriately according to the age of the creation
|
|
|
|
|
# date:
|
|
|
|
|
# * l1: created more than 1 x staleness_starts, but < 2 x staleness_starts
|
|
|
|
|
# * l2: created more than 2 x staleness_starts, but < 3 x staleness_starts
|
|
|
|
|
# * l3: created more than 3 x staleness_starts
|
2009-03-30 21:21:53 +02:00
|
|
|
#
|
2009-03-24 21:06:53 +01:00
|
|
|
def staleness_class(item)
|
|
|
|
|
if item.due || item.completed?
|
|
|
|
|
return ""
|
2009-04-07 21:34:15 +02:00
|
|
|
elsif item.created_at < current_user.time - (prefs.staleness_starts * 3).days
|
2009-03-24 21:06:53 +01:00
|
|
|
return " stale_l3"
|
2009-04-07 21:34:15 +02:00
|
|
|
elsif item.created_at < current_user.time - (prefs.staleness_starts * 2).days
|
2009-03-24 21:06:53 +01:00
|
|
|
return " stale_l2"
|
2009-04-07 21:34:15 +02:00
|
|
|
elsif item.created_at < current_user.time - (prefs.staleness_starts).days
|
2009-03-24 21:06:53 +01:00
|
|
|
return " stale_l1"
|
|
|
|
|
else
|
|
|
|
|
return ""
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Check show_from date in comparison to today's date Flag up date
|
|
|
|
|
# appropriately with a 'traffic light' colour code
|
2009-03-30 21:21:53 +02:00
|
|
|
#
|
2009-03-24 21:06:53 +01:00
|
|
|
def show_date(d)
|
|
|
|
|
if d == nil
|
|
|
|
|
return ""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
days = days_from_today(d)
|
|
|
|
|
|
|
|
|
|
case days
|
|
|
|
|
# overdue or due very soon! sound the alarm!
|
|
|
|
|
when -1000..-1
|
2010-10-31 21:27:13 +08:00
|
|
|
"<a title=\"" + format_date(d) + "\"><span class=\"red\">#{t('todos.scheduled_overdue', :days => (days * -1).to_s)}</span></a> "
|
2009-03-24 21:06:53 +01:00
|
|
|
when 0
|
2010-10-31 21:27:13 +08:00
|
|
|
"<a title=\"" + format_date(d) + "\"><span class=\"amber\">#{t('todos.show_today')}</span></a> "
|
2009-03-24 21:06:53 +01:00
|
|
|
when 1
|
2010-10-31 21:27:13 +08:00
|
|
|
"<a title=\"" + format_date(d) + "\"><span class=\"amber\">#{t('todos.show_tomorrow')}</span></a> "
|
2009-03-24 21:06:53 +01:00
|
|
|
# due 2-7 days away
|
|
|
|
|
when 2..7
|
|
|
|
|
if prefs.due_style == Preference.due_styles[:due_on]
|
2010-10-31 21:27:13 +08:00
|
|
|
"<a title=\"" + format_date(d) + "\"><span class=\"orange\">#{t('todos.show_on_date', :date => d.strftime("%A"))}</span></a> "
|
2009-03-24 21:06:53 +01:00
|
|
|
else
|
2010-10-31 21:27:13 +08:00
|
|
|
"<a title=\"" + format_date(d) + "\"><span class=\"orange\">#{t('todos.show_in_days', :days => days.to_s)}</span></a> "
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
|
|
|
|
# more than a week away - relax
|
|
|
|
|
else
|
2010-10-31 21:27:13 +08:00
|
|
|
"<a title=\"" + format_date(d) + "\"><span class=\"green\">#{t('todos.show_in_days', :days => days.to_s)}</span></a> "
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def should_show_new_item
|
2011-01-08 19:50:19 +01:00
|
|
|
source_view do |page|
|
|
|
|
|
page.todo { return !@todo.hidden? }
|
|
|
|
|
page.deferred { return @todo.deferred? || @todo.pending? }
|
|
|
|
|
page.context {
|
2011-02-08 17:37:14 +01:00
|
|
|
logger.debug "ci=#{@todo.context_id} dci=#{@default_context.id} th=#{@todo.hidden?} tch=#{@todo.context.hidden?}"
|
|
|
|
|
return @todo.context_id==@default_context.id && ( (@todo.hidden? && @todo.context.hidden?) || (!@todo.hidden?) )
|
2011-01-08 19:50:19 +01:00
|
|
|
}
|
|
|
|
|
page.tag {
|
|
|
|
|
return ( (@todo.pending? && @todo.has_tag?(@tag_name)) ||
|
|
|
|
|
(@todo.has_tag?(@tag_name)) ||
|
|
|
|
|
(@todo.starred? && @tag_name == Todo::STARRED_TAG_NAME)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
page.project {
|
|
|
|
|
return (@todo.active? && @todo.project && @todo.project.id == @default_project.id) ||
|
|
|
|
|
(@todo.project.hidden? && @todo.project_hidden?) || @todo.deferred? || @todo.pending?
|
|
|
|
|
}
|
|
|
|
|
end
|
2010-07-14 23:34:47 +02:00
|
|
|
|
2009-03-24 21:06:53 +01:00
|
|
|
return false
|
|
|
|
|
end
|
2011-01-08 09:12:37 +01:00
|
|
|
|
2011-01-11 02:47:29 +01:00
|
|
|
def should_make_context_visible
|
|
|
|
|
return @todo.active? && (!@todo.hidden? && !source_view_is(:project) )
|
|
|
|
|
end
|
|
|
|
|
|
2011-01-08 09:12:37 +01:00
|
|
|
def should_add_new_context
|
|
|
|
|
return @new_context_created && !source_view_is(:project)
|
|
|
|
|
end
|
2009-03-24 21:06:53 +01:00
|
|
|
|
|
|
|
|
def parent_container_type
|
|
|
|
|
return 'tickler' if source_view_is :deferred
|
|
|
|
|
return 'project' if source_view_is :project
|
|
|
|
|
return 'stats' if source_view_is :stats
|
2011-01-01 18:55:53 +01:00
|
|
|
return 'tag' if source_view_is :tag
|
2009-03-24 21:06:53 +01:00
|
|
|
return 'context'
|
|
|
|
|
end
|
|
|
|
|
|
2010-12-20 18:20:37 +01:00
|
|
|
def todo_container_is_empty
|
|
|
|
|
default_container_empty = ( @down_count == 0 )
|
2011-01-01 18:55:53 +01:00
|
|
|
deferred_container_empty = ( @todo.deferred? && @remaining_deferred_count == 0)
|
2010-12-20 18:20:37 +01:00
|
|
|
return default_container_empty || deferred_container_empty
|
|
|
|
|
end
|
2009-03-24 21:06:53 +01:00
|
|
|
|
2009-10-02 15:48:24 -04:00
|
|
|
def default_contexts_for_autocomplete
|
|
|
|
|
projects = current_user.projects.find(:all, :conditions => ['default_context_id is not null'])
|
|
|
|
|
Hash[*projects.map{ |p| [p.name, p.default_context.name] }.flatten].to_json
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def default_tags_for_autocomplete
|
2009-11-25 10:08:38 +08:00
|
|
|
projects = current_user.projects.find(:all, :conditions => ["default_tags != ''"])
|
2009-10-02 15:48:24 -04:00
|
|
|
Hash[*projects.map{ |p| [p.name, p.default_tags] }.flatten].to_json
|
|
|
|
|
end
|
2009-03-24 21:06:53 +01:00
|
|
|
|
|
|
|
|
def format_ical_notes(notes)
|
2011-02-08 23:03:05 +01:00
|
|
|
unless notes.nil? || notes.blank?
|
2010-10-14 22:56:09 +08:00
|
|
|
split_notes = notes.split(/\n/)
|
|
|
|
|
joined_notes = split_notes.join("\\n")
|
|
|
|
|
end
|
|
|
|
|
joined_notes || ""
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def formatted_pagination(total)
|
|
|
|
|
s = will_paginate(@todos)
|
|
|
|
|
(s.gsub(/(<\/[^<]+>)/, '\1 ')).chomp(' ')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def date_field_tag(name, id, value = nil, options = {})
|
|
|
|
|
text_field_tag name, value, {"size" => 12, "id" => id, "class" => "Date", "onfocus" => "Calendar.setup", "autocomplete" => "off"}.update(options.stringify_keys)
|
|
|
|
|
end
|
2010-12-25 16:28:53 +01:00
|
|
|
|
|
|
|
|
def update_needs_to_hide_context
|
2011-01-06 23:01:17 +01:00
|
|
|
return (@remaining_in_context == 0 && (@todo_hidden_state_changed && @todo.hidden?)) ||
|
2011-01-11 02:47:29 +01:00
|
|
|
(@remaining_in_context == 0 && @todo_was_deferred_from_active_state) ||
|
|
|
|
|
(@remaining_in_context == 0 && @todo.completed? && !(@original_item_was_deferred || @original_item_was_hidden)) if source_view_is(:tag)
|
|
|
|
|
|
|
|
|
|
return false if source_view_is(:project)
|
|
|
|
|
|
2010-12-25 16:28:53 +01:00
|
|
|
return (@remaining_in_context == 0) && !source_view_is(:context)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_needs_to_remove_todo_from_container
|
|
|
|
|
source_view do |page|
|
2011-01-06 10:51:58 +01:00
|
|
|
page.context { return @context_changed || @todo.deferred? || @todo.pending? }
|
2011-02-03 16:59:59 +01:00
|
|
|
page.project { return @todo_deferred_state_changed || @todo_pending_state_changed }
|
2010-12-25 16:28:53 +01:00
|
|
|
page.deferred { return @context_changed || !(@todo.deferred? || @todo.pending?) }
|
|
|
|
|
page.calendar { return @due_date_changed || !@todo.due }
|
2011-01-01 18:55:53 +01:00
|
|
|
page.stats { return @todo.completed? }
|
|
|
|
|
page.tag { return (@context_changed && !@todo.hidden?) || @tag_was_removed || @todo_hidden_state_changed || @todo_deferred_state_changed }
|
2011-01-06 10:51:58 +01:00
|
|
|
page.todo { return @context_changed || @todo.hidden? || @todo.deferred? || @todo.pending?}
|
2010-12-25 16:28:53 +01:00
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def replace_with_updated_todo
|
|
|
|
|
source_view do |page|
|
|
|
|
|
page.context { return !update_needs_to_remove_todo_from_container }
|
2011-02-03 16:59:59 +01:00
|
|
|
page.project { return !update_needs_to_remove_todo_from_container }
|
2010-12-25 16:28:53 +01:00
|
|
|
page.deferred { return !@context_changed && (@todo.deferred? || @todo.pending?) }
|
|
|
|
|
page.calendar { return !@due_date_changed && @todo.due }
|
2011-01-01 18:55:53 +01:00
|
|
|
page.stats { return !@todo.completed? }
|
|
|
|
|
page.tag { return !update_needs_to_remove_todo_from_container && !@tag_was_removed }
|
2011-01-06 10:51:58 +01:00
|
|
|
page.todo { return !update_needs_to_remove_todo_from_container }
|
2010-12-25 16:28:53 +01:00
|
|
|
end
|
2011-01-01 18:55:53 +01:00
|
|
|
return false
|
2010-12-25 16:28:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def append_updated_todo
|
|
|
|
|
source_view do |page|
|
2011-01-01 18:55:53 +01:00
|
|
|
page.context { return false }
|
2011-02-03 16:59:59 +01:00
|
|
|
page.project { return @todo_deferred_state_changed || @todo_pending_state_changed }
|
2010-12-25 16:28:53 +01:00
|
|
|
page.deferred { return @context_changed && (@todo.deferred? || @todo.pending?) }
|
|
|
|
|
page.calendar { return @due_date_changed && @todo.due }
|
2011-01-01 18:55:53 +01:00
|
|
|
page.stats { return false }
|
|
|
|
|
page.tag { return update_needs_to_remove_todo_from_container && !@tag_was_removed}
|
2011-01-06 10:51:58 +01:00
|
|
|
page.todo { return @context_changed && !(@todo.deferred? || @todo.pending? || @todo.hidden?) }
|
2010-12-25 16:28:53 +01:00
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
2011-01-01 18:55:53 +01:00
|
|
|
def item_container_id (todo)
|
|
|
|
|
return "hiddenitems" if source_view_is(:tag) && todo.hidden?
|
|
|
|
|
return "c#{todo.context_id}items" if source_view_is :deferred
|
|
|
|
|
return @new_due_id if source_view_is :calendar
|
2011-01-06 10:51:58 +01:00
|
|
|
return "tickleritems" if !source_view_is(:todo) && (todo.deferred? || todo.pending?)
|
2011-01-06 23:01:17 +01:00
|
|
|
return "completed_containeritems" if todo.completed?
|
2011-01-01 18:55:53 +01:00
|
|
|
return "p#{todo.project_id}items" if source_view_is :project
|
|
|
|
|
return "c#{todo.context_id}items"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def empty_container_msg_div_id(todo = @todo || @successor)
|
|
|
|
|
raise Exception.new, "no @todo or @successor set" if !todo
|
|
|
|
|
|
|
|
|
|
source_view do |page|
|
|
|
|
|
page.project {
|
2011-02-03 16:59:59 +01:00
|
|
|
return "tickler-empty-nd" if @todo_was_deferred_from_active_state || @todo_was_blocked_from_active_state
|
2011-01-01 18:55:53 +01:00
|
|
|
return "p#{todo.project_id}empty-nd"
|
|
|
|
|
}
|
|
|
|
|
page.tag {
|
|
|
|
|
return "tickler-empty-nd" if @todo_was_deferred_from_active_state
|
|
|
|
|
return "hidden-empty-nd" if @todo.hidden?
|
|
|
|
|
return "c#{todo.context_id}empty-nd"
|
|
|
|
|
}
|
|
|
|
|
page.calendar {
|
|
|
|
|
return "empty_#{@new_due_id}"
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return "c#{todo.context_id}empty-nd"
|
2010-12-25 16:28:53 +01:00
|
|
|
end
|
|
|
|
|
|
2011-01-06 10:51:58 +01:00
|
|
|
def show_empty_message_in_source_container
|
|
|
|
|
container_id = ""
|
|
|
|
|
source_view do |page|
|
|
|
|
|
page.project {
|
|
|
|
|
container_id = "p#{@original_item_project_id}empty-nd" if @remaining_in_context == 0
|
2011-02-03 16:59:59 +01:00
|
|
|
container_id = "tickler-empty-nd" if (
|
|
|
|
|
( (@todo_was_activated_from_deferred_state || @todo_was_activated_from_pending_state) && @remaining_deferred_or_pending_count == 0) ||
|
|
|
|
|
(@original_item_was_deferred && @remaining_deferred_or_pending_count == 0 && @todo.completed?) )
|
2011-01-11 02:47:29 +01:00
|
|
|
container_id = "empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
|
2011-01-06 10:51:58 +01:00
|
|
|
}
|
|
|
|
|
page.deferred { container_id = "c#{@original_item_context_id}empty-nd" if @remaining_in_context == 0 }
|
|
|
|
|
page.calendar { container_id = "empty_#{@original_item_due_id}" if @old_due_empty }
|
|
|
|
|
page.tag {
|
2011-01-11 02:47:29 +01:00
|
|
|
container_id = "hidden-empty-nd" if (@remaining_hidden_count == 0 && !@todo.hidden? && @todo_hidden_state_changed) ||
|
|
|
|
|
(@remaining_hidden_count == 0 && @todo.completed? && @original_item_was_hidden)
|
2011-01-06 23:01:17 +01:00
|
|
|
container_id = "tickler-empty-nd" if (@todo_was_activated_from_deferred_state && @remaining_deferred_or_pending_count == 0) ||
|
2011-01-11 02:47:29 +01:00
|
|
|
(@original_item_was_deferred && @remaining_deferred_or_pending_count == 0 && @todo.completed?)
|
2011-01-06 23:01:17 +01:00
|
|
|
container_id = "empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
|
2011-01-06 10:51:58 +01:00
|
|
|
}
|
|
|
|
|
page.context { container_id = "c#{@original_item_context_id}empty-nd" if @remaining_in_context == 0 }
|
|
|
|
|
page.todo { container_id = "c#{@original_item_context_id}empty-nd" if @remaining_in_context == 0 }
|
|
|
|
|
end
|
|
|
|
|
return container_id.blank? ? "" : "$(\"##{container_id}\").slideDown(100);"
|
|
|
|
|
end
|
|
|
|
|
|
2010-12-25 16:28:53 +01:00
|
|
|
def render_animation(animation)
|
|
|
|
|
html = ""
|
|
|
|
|
animation.each do |step|
|
|
|
|
|
unless step.blank?
|
|
|
|
|
html += step + "({ go: function() {\r\n"
|
|
|
|
|
end
|
|
|
|
|
end
|
2011-01-01 18:55:53 +01:00
|
|
|
html += "}}) " * animation.count
|
2010-12-25 16:28:53 +01:00
|
|
|
return html
|
|
|
|
|
end
|
|
|
|
|
|
2009-03-24 21:06:53 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def image_tag_for_star(todo)
|
|
|
|
|
class_str = todo.starred? ? "starred_todo" : "unstarred_todo"
|
2010-12-04 22:28:31 +01:00
|
|
|
image_tag("blank.png", :title =>t('todos.star_action'), :class => class_str, :id => "star_img_"+todo.id.to_s)
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|
2009-08-19 22:15:38 +02:00
|
|
|
|
2009-03-24 21:06:53 +01:00
|
|
|
end
|