Updated to svn tags/tracks-1.6

This commit is contained in:
bsag 2008-06-03 19:40:22 +01:00
parent 103fcb8049
commit 02496f2d44
2274 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,147 @@
# The methods added to this helper will be available to all templates in the
# application.
module ApplicationHelper
def user_time
current_user.time
end
# Replicates the link_to method but also checks request.request_uri to find
# current page. If that matches the url, the link is marked id = "current"
#
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)
date.to_date - user_time.to_date
end
# Check due date in comparison to today's date Flag up date appropriately with
# a 'traffic light' colour code
#
def due_date(due)
if due == nil
return ""
end
days = days_from_today(due)
case days
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> "
# due 2-7 days away
when 2..7
if prefs.due_style == Preference.due_styles[:due_on]
"<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
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> "
else
# more than a week away - relax
"<a title='#{format_date(due)}'><span class=\"green\">Due in #{pluralize(days, 'day')}</span></a> "
end
end
end
# Check due date in comparison to today's date Flag up date appropriately with
# a 'traffic light' colour code Modified method for mobile screen
#
def due_date_mobile(due)
if due == nil
return ""
end
days = days_from_today(due)
case days
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
# overdue or due very soon! sound the alarm!
if days < 0
"<span class=\"red\">" + format_date(due) +"</span>"
else
# more than a week away - relax
"<span class=\"green\">" + format_date(due) + "</span>"
end
end
end
# Returns a count of next actions in the given context or project. The result
# is count and a string descriptor, correctly pluralised if there are no
# actions or multiple actions
#
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("&nbsp;"," ")
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
def link_to_project_mobile(project, accesskey, descriptor = sanitize(project.name))
link_to( descriptor, formatted_project_path(project, :m), {:title => "View project: #{project.name}", :accesskey => accesskey} )
end
def item_link_to_context(item)
descriptor = "[C]"
descriptor = "[#{item.context.name}]" if prefs.verbose_action_descriptors
link_to_context( item.context, descriptor )
end
def item_link_to_project(item)
descriptor = "[P]"
descriptor = "[#{item.project.name}]" if prefs.verbose_action_descriptors
link_to_project( item.project, descriptor )
end
def render_flash
render :partial => 'shared/flash', :locals => { :flash => flash }
end
# Display a flash message in RJS templates Usage: page.notify :warning, "This
# is the message", 5.0 Puts the message into a flash of type 'warning', fades
# over 5 secs
def notify(type, message, fade_duration)
type = type.to_s # symbol to string
page.replace 'flash', "<h4 id='flash' class='alert #{type}'>#{message}</h4>"
page.visual_effect :fade, 'flash', :duration => fade_duration
end
end

View file

@ -0,0 +1,2 @@
module BackendHelper
end

View file

@ -0,0 +1,12 @@
module ContextsHelper
def get_listing_sortable_options
{
:tag => 'div',
:handle => 'handle',
:complete => visual_effect(:highlight, 'list-contexts'),
:url => order_contexts_path
}
end
end

View file

@ -0,0 +1,2 @@
module DataHelper
end

View file

@ -0,0 +1,29 @@
module FeedlistHelper
def rss_formatted_link(options = {})
image_tag = image_tag("feed-icon.png", :size => "16X16", :border => 0, :class => "rss-icon")
linkoptions = merge_hashes( {:format => 'rss'}, user_token_hash, options)
link_to(image_tag, linkoptions, :title => "RSS feed")
end
def text_formatted_link(options = {})
linkoptions = merge_hashes( {:format => 'txt'}, user_token_hash, options)
link_to('<span class="feed">TXT</span>', linkoptions, :title => "Plain text feed" )
end
def ical_formatted_link(options = {})
linkoptions = merge_hashes( {:format => 'ics'}, user_token_hash, options)
link_to('<span class="feed">iCal</span>', linkoptions, :title => "iCal feed" )
end
protected
def merge_hashes(*hashes)
hashes.inject(Hash.new){ |result, h| result.merge(h) }
end
def user_token_hash
{ :token => current_user.token }
end
end

View file

@ -0,0 +1,2 @@
module IntegrationsHelper
end

View file

@ -0,0 +1,3 @@
module LoginHelper
end

View file

@ -0,0 +1,2 @@
module MobileHelper
end

View file

@ -0,0 +1,5 @@
module NotesHelper
def truncated_note(note, characters = 50)
sanitize(textilize_without_paragraph(truncate(note.body, characters, "...")))
end
end

View file

@ -0,0 +1,2 @@
module PreferencesHelper
end

View file

@ -0,0 +1,48 @@
module ProjectsHelper
def get_listing_sortable_options(list_container_id)
{
:tag => 'div',
:handle => 'handle',
:complete => visual_effect(:highlight, list_container_id),
:url => order_projects_path
}
end
def set_element_visible(id,test)
if (test)
page.show id
else
page.hide id
end
end
def project_next_prev
html = ''
unless @previous_project.nil?
project_name = truncate(@previous_project.name, 40, "...")
html << link_to_project(@previous_project, "&laquo; #{project_name}")
end
html << ' | ' if @previous_project && @next_project
unless @next_project.nil?
project_name = truncate(@next_project.name, 40, "...")
html << link_to_project(@next_project, "#{project_name} &raquo;")
end
html
end
def project_next_prev_mobile
html = ''
unless @previous_project.nil?
project_name = truncate(@previous_project.name, 40, "...")
html << link_to_project_mobile(@previous_project, "5", "&laquo; 5-#{project_name}")
end
html << ' | ' if @previous_project && @next_project
unless @next_project.nil?
project_name = truncate(@next_project.name, 40, "...")
html << link_to_project_mobile(@next_project, "6", "6-#{project_name} &raquo;")
end
html
end
end

View file

@ -0,0 +1,3 @@
module SearchHelper
end

2
app/helpers/stats_helper.rb Executable file
View file

@ -0,0 +1,2 @@
module StatsHelper
end

284
app/helpers/todos_helper.rb Normal file
View file

@ -0,0 +1,284 @@
module TodosHelper
# #require 'users_controller' Counts the number of incomplete items in the
# specified context
#
def count_items(context)
count = Todo.find_all("done=0 AND context_id=#{context.id}").length
end
def form_remote_tag_edit_todo( &block )
form_tag(
todo_path(@todo), {
:method => :put,
:id => dom_id(@todo, 'form'),
:class => dom_id(@todo, 'form') + " inline-form edit_todo_form" },
&block )
apply_behavior 'form.edit_todo_form', make_remote_form(
:method => :put,
:before => "this.down('button.positive').startWaiting()",
:loaded => "this.down('button.positive').stopWaiting()",
:condition => "!(this.down('button.positive').isWaiting())"),
:prevent_default => true
end
def set_behavior_for_delete_icon
parameters = "_source_view=#{@source_view}"
parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
apply_behavior '.item-container a.delete_icon:click', :prevent_default => true do |page|
page.confirming "'Are you sure that you want to ' + this.title + '?'" do
page << "itemContainer = this.up('.item-container'); itemContainer.startWaiting();"
page << remote_to_href(:method => 'delete', :with => "'#{parameters}'", :complete => "itemContainer.stopWaiting();")
end
end
end
def remote_delete_icon
str = link_to( image_tag_for_delete,
todo_path(@todo), :id => "delete_icon_"+@todo.id.to_s,
:class => "icon delete_icon", :title => "delete the action '#{@todo.description}'")
set_behavior_for_delete_icon
str
end
def set_behavior_for_star_icon
apply_behavior '.item-container a.star_item:click',
remote_to_href(:method => 'put', :with => "{ _source_view : '#{@source_view}' }"),
:prevent_default => true
end
def remote_star_icon
str = link_to( image_tag_for_star(@todo),
toggle_star_todo_path(@todo),
:class => "icon star_item", :title => "star the action '#{@todo.description}'")
set_behavior_for_star_icon
str
end
def set_behavior_for_edit_icon
parameters = "_source_view=#{@source_view}"
parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
apply_behavior '.item-container a.edit_icon:click', :prevent_default => true do |page|
page << "Effect.Pulsate(this);"
page << remote_to_href(:method => 'get', :with => "'#{parameters}'")
end
end
def remote_edit_icon
if !@todo.completed?
str = link_to( image_tag_for_edit,
edit_todo_path(@todo),
:class => "icon edit_icon")
set_behavior_for_edit_icon
else
str = '<a class="icon">' + image_tag("blank.png") + "</a> "
end
str
end
def set_behavior_for_toggle_checkbox
parameters = "_source_view=#{@source_view}"
parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
apply_behavior '.item-container input.item-checkbox:click',
remote_function(:url => javascript_variable('this.value'), :method => 'put',
:with => "'#{parameters}'")
end
def remote_toggle_checkbox
str = check_box_tag('item_id', toggle_check_todo_path(@todo), @todo.completed?, :class => 'item-checkbox')
set_behavior_for_toggle_checkbox
str
end
def date_span
if @todo.completed?
"<span class=\"grey\">#{format_date( @todo.completed_at )}</span>"
elsif @todo.deferred?
show_date( @todo.show_from )
else
due_date( @todo.due )
end
end
def tag_list_text
@todo.tags.collect{|t| t.name}.join(', ')
end
def tag_list
tags_except_starred = @todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME}
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
def tag_list_mobile
tags_except_starred = @todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME}
# removed the link. TODO: add link to mobile view of tagged actions
tag_list = tags_except_starred.collect{|t|
"<span class=\"tag #{t.name.gsub(' ','-')}\">" +
link_to(t.name, {:action => "tag", :controller => "todos", :id => t.name+".m"}) +
# link_to(t.name, formatted_tag_path(t, :m)) +
"</span>"}.join('')
"<span class='tags'>#{tag_list}</span>"
end
def deferred_due_date
if @todo.deferred? && @todo.due
"(action due on #{format_date(@todo.due)})"
end
end
def project_and_context_links(parent_container_type, opts = {})
str = ''
if @todo.completed?
str += @todo.context.name unless opts[:suppress_context]
should_suppress_project = opts[:suppress_project] || @todo.project.nil?
str += ", " unless str.blank? || should_suppress_project
str += @todo.project.name unless should_suppress_project
str = "(#{str})" unless str.blank?
else
if (['project', 'tag', 'stats', 'search'].include?(parent_container_type))
str << item_link_to_context( @todo )
end
if (['context', 'tickler', 'tag', 'stats', 'search'].include?(parent_container_type)) && @todo.project_id
str << item_link_to_project( @todo )
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
#
def staleness_class(item)
if item.due || item.completed?
return ""
elsif item.created_at < user_time - (prefs.staleness_starts * 3).days
return " stale_l3"
elsif item.created_at < user_time - (prefs.staleness_starts * 2).days
return " stale_l2"
elsif item.created_at < user_time - (prefs.staleness_starts).days
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
#
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
"<a title=\"" + format_date(d) + "\"><span class=\"red\">Scheduled to show " + (days * -1).to_s + " days ago</span></a> "
when 0
"<a title=\"" + format_date(d) + "\"><span class=\"amber\">Show Today</span></a> "
when 1
"<a title=\"" + format_date(d) + "\"><span class=\"amber\">Show Tomorrow</span></a> "
# due 2-7 days away
when 2..7
if prefs.due_style == Preference.due_styles[:due_on]
"<a title=\"" + format_date(d) + "\"><span class=\"orange\">Show on " + d.strftime("%A") + "</span></a> "
else
"<a title=\"" + format_date(d) + "\"><span class=\"orange\">Show in " + days.to_s + " days</span></a> "
end
# more than a week away - relax
else
"<a title=\"" + format_date(d) + "\"><span class=\"green\">Show in " + days.to_s + " days</span></a> "
end
end
def calendar_setup( input_field )
str = "Calendar.setup({ ifFormat:\"#{prefs.date_format}\""
str << ",firstDay:#{prefs.week_starts},showOthers:true,range:[2004, 2010]"
str << ",step:1,inputField:\"" + input_field + "\",cache:true,align:\"TR\" })\n"
javascript_tag str
end
def item_container_id
if source_view_is :project
return "p#{@todo.project_id}" if @todo.active?
return "tickler" if @todo.deferred?
end
return "c#{@todo.context_id}"
end
def should_show_new_item
if @todo.project.nil? == false
# do not show new actions that were added to hidden or completed projects
# on home page and context page
return false if source_view_is(:todo) && (@todo.project.hidden? || @todo.project.completed?)
return false if source_view_is(:context) && (@todo.project.hidden? || @todo.project.completed?)
end
return true if source_view_is(:deferred) && @todo.deferred?
return true if source_view_is(:project) && @todo.project.hidden? && @todo.project_hidden?
return true if source_view_is(:project) && @todo.deferred?
return true if !source_view_is(:deferred) && @todo.active?
return false
end
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
return 'context'
end
def empty_container_msg_div_id
return "tickler-empty-nd" if source_view_is(:project) && @todo.deferred?
return "p#{@todo.project_id}empty-nd" if source_view_is :project
return "c#{@todo.context_id}empty-nd"
end
def project_names_for_autocomplete
array_or_string_for_javascript( ['None'] + @projects.select{ |p| p.active? }.collect{|p| escape_javascript(p.name) } )
end
def context_names_for_autocomplete
# #return array_or_string_for_javascript(['Create a new context']) if
# @contexts.empty?
array_or_string_for_javascript( @contexts.collect{|c| escape_javascript(c.name) } )
end
def format_ical_notes(notes)
split_notes = notes.split(/\n/)
joined_notes = split_notes.join("\\n")
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
private
def image_tag_for_delete
image_tag("blank.png", :title =>"Delete action", :class=>"delete_item")
end
def image_tag_for_edit
image_tag("blank.png", :title =>"Edit action", :class=>"edit_item", :id=> dom_id(@todo, 'edit_icon'))
end
def image_tag_for_star(todo)
class_str = todo.starred? ? "starred_todo" : "unstarred_todo"
image_tag("blank.png", :title =>"Star action", :class => class_str)
end
end

View file

@ -0,0 +1,2 @@
module UsersHelper
end