bsag / tracks

Tracks is a GTD(TM) web application, built with Ruby on Rails

This URL has Read+Write access

tracks / app / helpers / todos_helper.rb
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 1 module TodosHelper
2
ab2f0f82 » lrbalt 2008-03-16 fixes #660. New todos that ... 3 # #require 'users_controller' Counts the number of incomplete items in the
4 # specified context
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 5 #
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 6 def count_items(context)
7 count = Todo.find_all("done=0 AND context_id=#{context.id}").length
8 end
9
10 def form_remote_tag_edit_todo( &block )
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 11 form_tag(
12 todo_path(@todo), {
13 :method => :put,
14 :id => dom_id(@todo, 'form'),
15 :class => dom_id(@todo, 'form') + " inline-form edit_todo_form" },
16 &block )
ab2f0f82 » lrbalt 2008-03-16 fixes #660. New todos that ... 17 apply_behavior 'form.edit_todo_form', make_remote_form(
18 :method => :put,
19 :before => "this.down('button.positive').startWaiting()",
20 :loaded => "this.down('button.positive').stopWaiting()",
21 :condition => "!(this.down('button.positive').isWaiting())"),
22 :prevent_default => true
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 23 end
24
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 25 def set_behavior_for_delete_icon
f3529e78 » lukemelia 2008-04-28 Fix #704, todo items failin... 26 parameters = "_source_view=#{@source_view}"
27 parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 28 apply_behavior '.item-container a.delete_icon:click', :prevent_default => true do |page|
4b3ba0dd » lukemelia 2007-12-02 AJAX spinners are now conte... 29 page.confirming "'Are you sure that you want to ' + this.title + '?'" do
30 page << "itemContainer = this.up('.item-container'); itemContainer.startWaiting();"
f3529e78 » lukemelia 2008-04-28 Fix #704, todo items failin... 31 page << remote_to_href(:method => 'delete', :with => "'#{parameters}'", :complete => "itemContainer.stopWaiting();")
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 32 end
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 33 end
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 34 end
35
36 def remote_delete_icon
37 str = link_to( image_tag_for_delete,
38 todo_path(@todo), :id => "delete_icon_"+@todo.id.to_s,
39 :class => "icon delete_icon", :title => "delete the action '#{@todo.description}'")
40 set_behavior_for_delete_icon
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 41 str
42 end
43
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 44 def set_behavior_for_star_icon
45 apply_behavior '.item-container a.star_item:click',
46 remote_to_href(:method => 'put', :with => "{ _source_view : '#{@source_view}' }"),
47 :prevent_default => true
48 end
49
8bc41e2c » lrbalt 2008-07-19 add recurring todos to tracks 50 def remote_star_icon
1cce7f07 » lukemelia 2007-05-25 This changeset is larger th... 51 str = link_to( image_tag_for_star(@todo),
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 52 toggle_star_todo_path(@todo),
53 :class => "icon star_item", :title => "star the action '#{@todo.description}'")
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 54 set_behavior_for_star_icon
4b3ba0dd » lukemelia 2007-12-02 AJAX spinners are now conte... 55 str
1cce7f07 » lukemelia 2007-05-25 This changeset is larger th... 56 end
57
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 58 def set_behavior_for_edit_icon
f3529e78 » lukemelia 2008-04-28 Fix #704, todo items failin... 59 parameters = "_source_view=#{@source_view}"
60 parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 61 apply_behavior '.item-container a.edit_icon:click', :prevent_default => true do |page|
62 page << "Effect.Pulsate(this);"
63 page << remote_to_href(:method => 'get', :with => "'#{parameters}'")
64 end
65 end
66
67 def remote_edit_icon
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 68 if !@todo.completed?
8bc41e2c » lrbalt 2008-07-19 add recurring todos to tracks 69 str = link_to( image_tag_for_edit(@todo),
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 70 edit_todo_path(@todo),
71 :class => "icon edit_icon")
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 72 set_behavior_for_edit_icon
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 73 else
74 str = '<a class="icon">' + image_tag("blank.png") + "</a> "
75 end
76 str
77 end
78
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 79 def set_behavior_for_toggle_checkbox
f3529e78 » lukemelia 2008-04-28 Fix #704, todo items failin... 80 parameters = "_source_view=#{@source_view}"
81 parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 82 apply_behavior '.item-container input.item-checkbox:click',
8c7afc4c » lukemelia 2007-12-02 Whoops. The last changeset ... 83 remote_function(:url => javascript_variable('this.value'), :method => 'put',
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 84 :with => "'#{parameters}'")
85 end
86
87 def remote_toggle_checkbox
88 str = check_box_tag('item_id', toggle_check_todo_path(@todo), @todo.completed?, :class => 'item-checkbox')
89 set_behavior_for_toggle_checkbox
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 90 str
91 end
92
93 def date_span
94 if @todo.completed?
95 "<span class=\"grey\">#{format_date( @todo.completed_at )}</span>"
96 elsif @todo.deferred?
97 show_date( @todo.show_from )
98 else
b440e2b2 » lukemelia 2007-11-04 Fixed #581, "Empty tickler ... 99 due_date( @todo.due )
100 end
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 101 end
102
71db7bc2 » lukemelia 2007-05-28 Fixed a bug where tags were... 103 def tag_list_text
104 @todo.tags.collect{|t| t.name}.join(', ')
105 end
106
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 107 def tag_list
7728ea00 » lukemelia 2007-09-20 Applied patch from Jeremy H... 108 tags_except_starred = @todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME}
1dff683e » lrbalt 2007-10-06 Fixes the 500 error when cl... 109 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('')
1cce7f07 » lukemelia 2007-05-25 This changeset is larger th... 110 "<span class='tags'>#{tag_list}</span>"
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 111 end
112
39a64989 » lrbalt 2008-04-19 merge new mobile interface ... 113 def tag_list_mobile
114 tags_except_starred = @todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME}
115 # removed the link. TODO: add link to mobile view of tagged actions
116 tag_list = tags_except_starred.collect{|t|
db86df54 » lrbalt 2008-08-04 fixes for mobile view and f... 117 "<span class=\"tag\">" +
39a64989 » lrbalt 2008-04-19 merge new mobile interface ... 118 link_to(t.name, {:action => "tag", :controller => "todos", :id => t.name+".m"}) +
119 "</span>"}.join('')
a0d23629 » Jakub A.Tesinsky 2008-12-01 Optimalized mobile pages - ... 120 if not tag_list.empty? then "<span class=\"tags\">#{tag_list}</span>" end
39a64989 » lrbalt 2008-04-19 merge new mobile interface ... 121 end
122
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 123 def deferred_due_date
124 if @todo.deferred? && @todo.due
125 "(action due on #{format_date(@todo.due)})"
126 end
127 end
128
0f823a8a » lukemelia 2007-11-26 Fix issue where completed i... 129 def project_and_context_links(parent_container_type, opts = {})
130 str = ''
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 131 if @todo.completed?
0f823a8a » lukemelia 2007-11-26 Fix issue where completed i... 132 str += @todo.context.name unless opts[:suppress_context]
133 should_suppress_project = opts[:suppress_project] || @todo.project.nil?
134 str += ", " unless str.blank? || should_suppress_project
135 str += @todo.project.name unless should_suppress_project
136 str = "(#{str})" unless str.blank?
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 137 else
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 138 if (['project', 'tag', 'stats', 'search'].include?(parent_container_type))
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 139 str << item_link_to_context( @todo )
140 end
c1109b3f » bsag 2008-06-15 Merge branch 'svn-tracking' 141 if (['context', 'tickler', 'tag', 'stats', 'search'].include?(parent_container_type)) && @todo.project_id
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 142 str << item_link_to_project( @todo )
143 end
144 end
0f823a8a » lukemelia 2007-11-26 Fix issue where completed i... 145 return str
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 146 end
147
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 148 # Uses the 'staleness_starts' value from settings.yml (in days) to colour the
149 # background of the action appropriately according to the age of the creation
150 # date:
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 151 # * l1: created more than 1 x staleness_starts, but < 2 x staleness_starts
152 # * l2: created more than 2 x staleness_starts, but < 3 x staleness_starts
153 # * l3: created more than 3 x staleness_starts
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 154 #
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 155 def staleness_class(item)
156 if item.due || item.completed?
157 return ""
30c23fc5 » lukemelia 2007-07-29 Introduce current_user and ... 158 elsif item.created_at < user_time - (prefs.staleness_starts * 3).days
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 159 return " stale_l3"
30c23fc5 » lukemelia 2007-07-29 Introduce current_user and ... 160 elsif item.created_at < user_time - (prefs.staleness_starts * 2).days
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 161 return " stale_l2"
30c23fc5 » lukemelia 2007-07-29 Introduce current_user and ... 162 elsif item.created_at < user_time - (prefs.staleness_starts).days
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 163 return " stale_l1"
164 else
165 return ""
166 end
167 end
168
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 169 # Check show_from date in comparison to today's date Flag up date
170 # appropriately with a 'traffic light' colour code
171 #
b440e2b2 » lukemelia 2007-11-04 Fixed #581, "Empty tickler ... 172 def show_date(d)
173 if d == nil
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 174 return ""
175 end
176
b440e2b2 » lukemelia 2007-11-04 Fixed #581, "Empty tickler ... 177 days = days_from_today(d)
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 178
179 case days
180 # overdue or due very soon! sound the alarm!
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 181 when -1000..-1
b440e2b2 » lukemelia 2007-11-04 Fixed #581, "Empty tickler ... 182 "<a title=\"" + format_date(d) + "\"><span class=\"red\">Scheduled to show " + (days * -1).to_s + " days ago</span></a> "
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 183 when 0
b440e2b2 » lukemelia 2007-11-04 Fixed #581, "Empty tickler ... 184 "<a title=\"" + format_date(d) + "\"><span class=\"amber\">Show Today</span></a> "
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 185 when 1
b440e2b2 » lukemelia 2007-11-04 Fixed #581, "Empty tickler ... 186 "<a title=\"" + format_date(d) + "\"><span class=\"amber\">Show Tomorrow</span></a> "
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 187 # due 2-7 days away
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 188 when 2..7
17a880d2 » lukemelia 2007-09-26 The recent changeset to the... 189 if prefs.due_style == Preference.due_styles[:due_on]
b440e2b2 » lukemelia 2007-11-04 Fixed #581, "Empty tickler ... 190 "<a title=\"" + format_date(d) + "\"><span class=\"orange\">Show on " + d.strftime("%A") + "</span></a> "
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 191 else
b440e2b2 » lukemelia 2007-11-04 Fixed #581, "Empty tickler ... 192 "<a title=\"" + format_date(d) + "\"><span class=\"orange\">Show in " + days.to_s + " days</span></a> "
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 193 end
194 # more than a week away - relax
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 195 else
b440e2b2 » lukemelia 2007-11-04 Fixed #581, "Empty tickler ... 196 "<a title=\"" + format_date(d) + "\"><span class=\"green\">Show in " + days.to_s + " days</span></a> "
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 197 end
198 end
199
200 def calendar_setup( input_field )
30c23fc5 » lukemelia 2007-07-29 Introduce current_user and ... 201 str = "Calendar.setup({ ifFormat:\"#{prefs.date_format}\""
202 str << ",firstDay:#{prefs.week_starts},showOthers:true,range:[2004, 2010]"
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 203 str << ",step:1,inputField:\"" + input_field + "\",cache:true,align:\"TR\" })\n"
204 javascript_tag str
205 end
206
8bc41e2c » lrbalt 2008-07-19 add recurring todos to tracks 207 def item_container_id (todo)
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 208 if source_view_is :project
8bc41e2c » lrbalt 2008-07-19 add recurring todos to tracks 209 return "p#{todo.project_id}" if todo.active?
210 return "tickler" if todo.deferred?
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 211 end
8bc41e2c » lrbalt 2008-07-19 add recurring todos to tracks 212 return "c#{todo.context_id}"
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 213 end
214
215 def should_show_new_item
ab2f0f82 » lrbalt 2008-03-16 fixes #660. New todos that ... 216
217 if @todo.project.nil? == false
218 # do not show new actions that were added to hidden or completed projects
219 # on home page and context page
220 return false if source_view_is(:todo) && (@todo.project.hidden? || @todo.project.completed?)
221 return false if source_view_is(:context) && (@todo.project.hidden? || @todo.project.completed?)
222 end
223
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 224 return true if source_view_is(:deferred) && @todo.deferred?
225 return true if source_view_is(:project) && @todo.project.hidden? && @todo.project_hidden?
226 return true if source_view_is(:project) && @todo.deferred?
227 return true if !source_view_is(:deferred) && @todo.active?
228 return false
229 end
230
231 def parent_container_type
232 return 'tickler' if source_view_is :deferred
233 return 'project' if source_view_is :project
1abacfbd » lrbalt 2008-02-29 this patch add 'down-drilli... 234 return 'stats' if source_view_is :stats
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 235 return 'context'
236 end
237
238 def empty_container_msg_div_id
239 return "tickler-empty-nd" if source_view_is(:project) && @todo.deferred?
240 return "p#{@todo.project_id}empty-nd" if source_view_is :project
241 return "c#{@todo.context_id}empty-nd"
242 end
243
244 def project_names_for_autocomplete
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 245 array_or_string_for_javascript( ['None'] + @projects.select{ |p| p.active? }.collect{|p| escape_javascript(p.name) } )
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 246 end
247
248 def context_names_for_autocomplete
0703253a » lrbalt 2007-10-21 Fixes #554 by adding a spin... 249 # #return array_or_string_for_javascript(['Create a new context']) if
250 # @contexts.empty?
251 array_or_string_for_javascript( @contexts.collect{|c| escape_javascript(c.name) } )
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 252 end
253
254 def format_ical_notes(notes)
255 split_notes = notes.split(/\n/)
256 joined_notes = split_notes.join("\\n")
257 end
ba0b52ff » lukemelia 2007-04-01 Merged mobile_controller in... 258
8c587a0d » lukemelia 2007-12-10 Updated to latest will_pagi... 259 def formatted_pagination(total)
260 s = will_paginate(@todos)
ba0b52ff » lukemelia 2007-04-01 Merged mobile_controller in... 261 (s.gsub /(<\/[^<]+>)/, '\1 ').chomp(' ')
262 end
bd519165 » lukemelia 2007-05-20 Added an XML representation... 263
264 def date_field_tag(name, id, value = nil, options = {})
265 text_field_tag name, value, {"size" => 12, "id" => id, "class" => "Date", "onfocus" => "Calendar.setup", "autocomplete" => "off"}.update(options.stringify_keys)
266 end
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 267
268 private
269
270 def image_tag_for_delete
271 image_tag("blank.png", :title =>"Delete action", :class=>"delete_item")
272 end
273
8bc41e2c » lrbalt 2008-07-19 add recurring todos to tracks 274 def image_tag_for_edit(todo)
275 image_tag("blank.png", :title =>"Edit action", :class=>"edit_item", :id=> dom_id(todo, 'edit_icon'))
06f14dd3 » lukemelia 2007-03-29 And here's the copy step. 276 end
277
1cce7f07 » lukemelia 2007-05-25 This changeset is larger th... 278 def image_tag_for_star(todo)
279 class_str = todo.starred? ? "starred_todo" : "unstarred_todo"
280 image_tag("blank.png", :title =>"Star action", :class => class_str)
281 end
282
8bc41e2c » lrbalt 2008-07-19 add recurring todos to tracks 283 end