From 638a0402fe2cc38a5ffab367805916353f7caa7b Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Mon, 30 Mar 2009 21:21:53 +0200 Subject: [PATCH] tidy up _todo for readability --- app/helpers/todos_helper.rb | 53 ++++++++++++++++++++++++++++++---- app/views/todos/_todo.html.erb | 13 ++++----- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index d77a9cd4..c534eb68 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -2,7 +2,7 @@ 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 @@ -35,7 +35,50 @@ module TodosHelper set_behavior_for_star_icon str end - + + def remote_edit_menu_item(parameters, todo) + return link_to_remote( + image_tag("edit_off.png", :mouseover => "edit_on.png", :alt => "", :align => "absmiddle")+" Edit", + :url => {:controller => 'todos', :action => 'edit', :id => todo.id}, + :method => 'get', + :with => "'#{parameters}'", + :before => todo_start_waiting_js(todo), + :complete => todo_stop_waiting_js) + end + + def remote_delete_menu_item(parameters, todo) + return link_to_remote( + image_tag("delete_off.png", :mouseover => "delete_on.png", :alt => "", :align => "absmiddle")+" Delete", + :url => {:controller => 'todos', :action => 'destroy', :id => todo.id}, + :method => 'delete', + :with => "'#{parameters}'", + :before => todo_start_waiting_js(todo), + :complete => todo_stop_waiting_js) + end + + def remote_defer_menu_item(days, todo) + return link_to_remote( + image_tag("defer_#{days}_off.png", :mouseover => "defer_#{days}.png", :alt => "", :align => "absmiddle")+" Defer #{pluralize(days, "day")}", + :url => {:controller => 'todos', :action => 'defer', :id => todo.id, :days => days, :_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")}, + :before => todo_start_waiting_js(todo), + :complete => todo_stop_waiting_js) + end + + def todo_start_waiting_js(todo) + return "$('ul#{dom_id(todo)}').hide(); itemContainer = $('#{dom_id(todo)}'); itemContainer.startWaiting()" + end + + def todo_stop_waiting_js + return "itemContainer.stopWaiting();" + 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 + def set_behavior_for_toggle_checkbox parameters = "_source_view=#{@source_view}" parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag' @@ -76,7 +119,7 @@ module TodosHelper tag_list = tags_except_starred.collect{|t| "" + link_to(t.name, {:action => "tag", :controller => "todos", :id => t.name+".m"}) + - ""}.join('') + ""}.join('') if tag_list.empty? then "" else "#{tag_list}" end end @@ -111,7 +154,7 @@ module TodosHelper # * 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 "" @@ -128,7 +171,7 @@ module TodosHelper # 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 "" diff --git a/app/views/todos/_todo.html.erb b/app/views/todos/_todo.html.erb index 3c344ab9..629273e6 100644 --- a/app/views/todos/_todo.html.erb +++ b/app/views/todos/_todo.html.erb @@ -13,21 +13,18 @@ parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag' <%= remote_toggle_checkbox unless source_view_is :deferred %>
<%= date_span -%> <%= h sanitize(todo.description) %> - <%= link_to( - image_tag("recurring16x16.png"), - {:controller => "recurring_todos", :action => "index"}, - :class => "recurring_icon", :title => recurrence_pattern_as_text(@todo.recurring_todo)) if @todo.from_recurring_todo? %> + <%= image_tag_for_recurring_todo(todo) if @todo.from_recurring_todo? %> <%= tag_list %> <%= deferred_due_date %> <%= project_and_context_links( parent_container_type, :suppress_context => suppress_context, :suppress_project => suppress_project ) %>