Fixed #436 (Show from not working). While debugging this issue, I renamed a lot of usages of "item" to "todo" to make the code easier to understand.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@435 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-02-08 05:47:14 +00:00
parent d012a3ab71
commit 08290efdf5
28 changed files with 304 additions and 258 deletions

View file

@ -108,7 +108,13 @@ class ApplicationController < ActionController::Base
def parse_date_per_user_prefs( s )
return nil if s.blank?
@user.prefs.tz.unadjust(Date.strptime(s, @user.prefs.date_format)).utc.to_date
#logger.info "Unadjusting user date #{s} from #{@user.prefs.tz} parsing with #{@user.prefs.date_format}"
time = Date.strptime(s, @user.prefs.date_format)
#logger.info "parsed = #{time}"
unadjusted = @user.prefs.tz.unadjust(time).utc
#logger.info "unadjusted = #{unadjusted}"
#logger.info "returning #{unadjusted.to_date}"
unadjusted.to_date
end
def init_data_for_sidebar

View file

@ -23,15 +23,15 @@ class MobileController < ApplicationController
def update
if params[:id]
@item = check_user_return_item
@item.update_attributes params[:item]
if params[:item][:state] == "1"
@item.update_attributes params[:todo]
if params[:todo][:state] == "1"
@item.state = "completed"
else
@item.state = "active"
end
else
params[:item][:user_id] = @user.id
@item = Todo.new(params[:item]) if params[:item]
params[:todo][:user_id] = @user.id
@item = Todo.new(params[:todo]) if params[:todo]
end
if @item.save

View file

@ -31,9 +31,14 @@ class TodosController < ApplicationController
end
def create
@item = @user.todos.build
@todo = @user.todos.build
p = params['request'] || params
@item.attributes = p['todo']
if p['todo']['show_from']
p['todo']['show_from'] = parse_date_per_user_prefs(p['todo']['show_from'])
end
@todo.attributes = p['todo']
if p['todo']['project_id'].blank? && !p['project_name'].blank? && p['project_name'] != 'None'
project = @user.projects.find_by_name(p['project_name'].strip)
@ -43,7 +48,7 @@ class TodosController < ApplicationController
project.save
@new_project_created = true
end
@item.project_id = project.id
@todo.project_id = project.id
end
if p['todo']['context_id'].blank? && !p['context_name'].blank?
@ -53,45 +58,39 @@ class TodosController < ApplicationController
context.name = p['context_name'].strip
context.save
@new_context_created = true
@not_done_todos = [@item]
@not_done_todos = [@todo]
end
@item.context_id = context.id
@todo.context_id = context.id
end
if @item.due?
@date = parse_date_per_user_prefs(p['todo']['due'])
@item.due = @date
if @todo.due?
@todo.due = parse_date_per_user_prefs(p['todo']['due'])
else
@item.due = ""
@todo.due = ""
end
if p['todo']['show_from']
@item.show_from = parse_date_per_user_prefs(p['todo']['show_from'])
@saved = @todo.save
@todo.tag_with(params[:tag_list],@user)
@todo.reload
respond_to do |wants|
wants.html { redirect_to :action => "index" }
wants.js do
if @saved
determine_down_count
end
render :action => 'create'
end
wants.xml { render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ) }
end
@item.save
@item.tag_with(params[:tag_list],@user)
@saved = @item.save
respond_to do |wants|
wants.html { redirect_to :action => "index" }
wants.js do
if @saved
determine_down_count
end
render :action => 'create'
end
wants.xml { render :xml => @item.to_xml( :root => 'todo', :except => :user_id ) }
end
end
def edit
@item = check_user_return_item
@todo = check_user_return_todo
end
def show
item = check_user_return_item
item = check_user_return_todo
respond_to do |wants|
wants.xml { render :xml => item.to_xml( :root => 'todo', :except => :user_id ) }
end
@ -100,13 +99,13 @@ class TodosController < ApplicationController
# Toggles the 'done' status of the action
#
def toggle_check
@item = check_user_return_item
@item.toggle_completion()
@saved = @item.save
@todo = check_user_return_todo
@todo.toggle_completion()
@saved = @todo.save
respond_to do |format|
format.js do
if @saved
@remaining_undone_in_context = @user.contexts.find(@item.context_id).not_done_todo_count
@remaining_undone_in_context = @user.contexts.find(@todo.context_id).not_done_todo_count
determine_down_count
determine_completed_count
end
@ -115,10 +114,10 @@ class TodosController < ApplicationController
format.html do
if @saved
# TODO: I think this will work, but can't figure out how to test it
notify :notice, "The action <strong>'#{@item.description}'</strong> was marked as <strong>#{@item.completed? ? 'complete' : 'incomplete' }</strong>"
notify :notice, "The action <strong>'#{@todo.description}'</strong> was marked as <strong>#{@todo.completed? ? 'complete' : 'incomplete' }</strong>"
redirect_to :action => "index"
else
notify :notice, "The action <strong>'#{@item.description}'</strong> was NOT marked as <strong>#{@item.completed? ? 'complete' : 'incomplete' } due to an error on the server.</strong>", "index"
notify :notice, "The action <strong>'#{@todo.description}'</strong> was NOT marked as <strong>#{@todo.completed? ? 'complete' : 'incomplete' } due to an error on the server.</strong>", "index"
redirect_to :action => "index"
end
end
@ -126,12 +125,12 @@ class TodosController < ApplicationController
end
def update
@item = check_user_return_item
@item.tag_with(params[:tag_list],@user)
@original_item_context_id = @item.context_id
@original_item_project_id = @item.project_id
@original_item_was_deferred = @item.deferred?
if params['item']['project_id'].blank? && !params['project_name'].blank?
@todo = check_user_return_todo
@todo.tag_with(params[:tag_list],@user)
@original_item_context_id = @todo.context_id
@original_item_project_id = @todo.project_id
@original_item_was_deferred = @todo.deferred?
if params['todo']['project_id'].blank? && !params['project_name'].blank?
if params['project_name'] == 'None'
project = Project.null_object
else
@ -143,10 +142,10 @@ class TodosController < ApplicationController
@new_project_created = true
end
end
params["item"]["project_id"] = project.id
params["todo"]["project_id"] = project.id
end
if params['item']['context_id'].blank? && !params['context_name'].blank?
if params['todo']['context_id'].blank? && !params['context_name'].blank?
context = @user.contexts.find_by_name(params['context_name'].strip)
unless context
context = @user.contexts.build
@ -154,33 +153,33 @@ class TodosController < ApplicationController
context.save
@new_context_created = true
end
params["item"]["context_id"] = context.id
params["todo"]["context_id"] = context.id
end
if params["item"].has_key?("due")
params["item"]["due"] = parse_date_per_user_prefs(params["item"]["due"])
if params["todo"].has_key?("due")
params["todo"]["due"] = parse_date_per_user_prefs(params["todo"]["due"])
else
params["item"]["due"] = ""
params["todo"]["due"] = ""
end
if params['item']['show_from']
params['item']['show_from'] = parse_date_per_user_prefs(params['item']['show_from'])
if params['todo']['show_from']
params['todo']['show_from'] = parse_date_per_user_prefs(params['todo']['show_from'])
end
@saved = @item.update_attributes params["item"]
@context_changed = @original_item_context_id != @item.context_id
@item_was_activated_from_deferred_state = @original_item_was_deferred && @item.active?
@saved = @todo.update_attributes params["todo"]
@context_changed = @original_item_context_id != @todo.context_id
@todo_was_activated_from_deferred_state = @original_item_was_deferred && @todo.active?
if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todo_count; end
@project_changed = @original_item_project_id != @item.project_id
@project_changed = @original_item_project_id != @todo.project_id
if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = @user.projects.find(@original_item_project_id).not_done_todo_count; end
determine_down_count
end
def destroy
@item = check_user_return_item
@context_id = @item.context_id
@project_id = @item.project_id
@saved = @item.destroy
@todo = check_user_return_todo
@context_id = @todo.context_id
@project_id = @todo.project_id
@saved = @todo.destroy
respond_to do |wants|
@ -258,12 +257,12 @@ class TodosController < ApplicationController
private
def check_user_return_item
item = Todo.find( params['id'].to_i )
if @user == item.user
return item
def check_user_return_todo
todo = Todo.find( params['id'].to_i )
if @user == todo.user
return todo
else
@error_message = 'Item and session user mis-match: #{item.user.name} and #{@user.name}!'
@error_message = 'Item and session user mis-match: #{todo.user.name} and #{@todo.name}!'
respond_to do |wants|
wants.html do
notify :error, @error_message, 8.0
@ -295,12 +294,12 @@ class TodosController < ApplicationController
@down_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'active', false])
end
from.context do
@down_count = @user.contexts.find(@item.context_id).not_done_todo_count
@down_count = @user.contexts.find(@todo.context_id).not_done_todo_count
end
from.project do
unless @item.project_id == nil
@down_count = @user.projects.find(@item.project_id).not_done_todo_count
@deferred_count = @user.projects.find(@item.project_id).deferred_todo_count
unless @todo.project_id == nil
@down_count = @user.projects.find(@todo.project_id).not_done_todo_count
@deferred_count = @user.projects.find(@todo.project_id).deferred_todo_count
end
end
from.deferred do
@ -315,11 +314,11 @@ class TodosController < ApplicationController
@completed_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'completed', false])
end
from.context do
@completed_count = @user.contexts.find(@item.context_id).done_todo_count
@completed_count = @user.contexts.find(@todo.context_id).done_todo_count
end
from.project do
unless @item.project_id == nil
@completed_count = @user.projects.find(@item.project_id).done_todo_count
unless @todo.project_id == nil
@completed_count = @user.projects.find(@todo.project_id).done_todo_count
end
end
end

View file

@ -11,6 +11,7 @@ module ApplicationHelper
else
formatted_date = ''
end
formatted_date
end
def user_time

View file

@ -7,15 +7,15 @@ module TodosHelper
count = Todo.find_all("done=0 AND context_id=#{context.id}").length
end
def form_remote_tag_edit_todo( item, &block )
form_tag( todo_path(item), {:method => :put, :id => dom_id(item, 'form'), :class => "edit_todo_form inline-form" }, &block )
def form_remote_tag_edit_todo( &block )
form_tag( todo_path(@todo), {:method => :put, :id => dom_id(@todo, 'form'), :class => "edit_todo_form inline-form" }, &block )
apply_behavior 'form.edit_todo_form', make_remote_form(:method => :put), :prevent_default => true
end
def remote_delete_icon(item)
str = link_to( image_tag("blank.png", :title =>"Delete action", :class=>"delete_item"),
todo_path(item),
:class => "icon delete_icon", :title => "delete the action '#{item.description}'")
def remote_delete_icon
str = link_to( image_tag_for_delete,
todo_path(@todo),
:class => "icon delete_icon", :title => "delete the action '#{@todo.description}'")
apply_behavior '.item-container a.delete_icon:click', :prevent_default => true do |page|
page << "if (confirm('Are you sure that you want to ' + this.title + '?')) {"
page << " new Ajax.Request(this.href, { asynchronous : true, evalScripts : true, method : 'delete', parameters : { '_source_view' : '#{@source_view}' }})"
@ -24,10 +24,10 @@ module TodosHelper
str
end
def remote_edit_icon(item)
if !item.completed?
str = link_to( image_tag_for_edit(item),
edit_todo_path(item),
def remote_edit_icon
if !@todo.completed?
str = link_to( image_tag_for_edit,
edit_todo_path(@todo),
:class => "icon edit_icon")
apply_behavior '.item-container a.edit_icon:click', :prevent_default => true do |page|
page << "new Ajax.Request(this.href, { asynchronous : true, evalScripts : true, method : 'get', parameters : { '_source_view' : '#{@source_view}' }, onLoading: function(request){ Effect.Pulsate(this)}});"
@ -38,44 +38,44 @@ module TodosHelper
str
end
def remote_toggle_checkbox(item)
str = check_box_tag('item_id', toggle_check_todo_path(item), item.completed?, :class => 'item-checkbox')
def remote_toggle_checkbox
str = check_box_tag('item_id', toggle_check_todo_path(@todo), @todo.completed?, :class => 'item-checkbox')
apply_behavior '.item-container input.item-checkbox:click',
remote_function(:url => javascript_variable('this.value'),
:with => "{ method : 'post', _source_view : '#{@source_view}' }")
str
end
def date_span(item)
if item.completed?
"<span class=\"grey\">#{format_date( item.completed_at )}</span>"
elsif item.deferred?
show_date( item.show_from )
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( item.due )
due_date( @todo.due )
end
end
def tag_list(item)
item.tags.collect{|t| "<span class=\"tag\">" + link_to(t.name, :action => "tag", :id => t.name) + "</span>"}.join('')
def tag_list
@todo.tags.collect{|t| "<span class=\"tag\">" + link_to(t.name, :action => "tag", :id => t.name) + "</span>"}.join('')
end
def deferred_due_date(item)
if item.deferred? && item.due
"(action due on #{format_date(item.due)})"
def deferred_due_date
if @todo.deferred? && @todo.due
"(action due on #{format_date(@todo.due)})"
end
end
def project_and_context_links(item, parent_container_type)
if item.completed?
"(#{item.context.name}#{", " + item.project.name unless item.project.nil?})"
def project_and_context_links(parent_container_type)
if @todo.completed?
"(#{@todo.context.name}#{", " + @todo.project.name unless @todo.project.nil?})"
else
str = ''
if (['project', 'tickler', 'tag'].include?(parent_container_type))
str << item_link_to_context( item )
str << item_link_to_context( @todo )
end
if (['context', 'tickler', 'tag'].include?(parent_container_type)) && item.project_id
str << item_link_to_project( item )
if (['context', 'tickler', 'tag'].include?(parent_container_type)) && @todo.project_id
str << item_link_to_project( @todo )
end
str
end
@ -145,17 +145,17 @@ module TodosHelper
def item_container_id
return "tickler-items" if source_view_is :deferred
if source_view_is :project
return "p#{@item.project_id}" if @item.active?
return "tickler" if @item.deferred?
return "p#{@todo.project_id}" if @todo.active?
return "tickler" if @todo.deferred?
end
return "c#{@item.context_id}"
return "c#{@todo.context_id}"
end
def should_show_new_item
return true if source_view_is(:deferred) && @item.deferred?
return true if source_view_is(:project) && @item.project.hidden? && @item.project_hidden?
return true if source_view_is(:project) && @item.deferred?
return true if !source_view_is(:deferred) && @item.active?
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
@ -166,10 +166,10 @@ module TodosHelper
end
def empty_container_msg_div_id
return "tickler-empty-nd" if source_view_is(:project) && @item.deferred?
return "p#{@item.project_id}empty-nd" if source_view_is :project
return "tickler-empty-nd" if source_view_is(:project) && @todo.deferred?
return "p#{@todo.project_id}empty-nd" if source_view_is :project
return "tickler-empty-nd" if source_view_is :deferred
return "c#{@item.context_id}empty-nd"
return "c#{@todo.context_id}empty-nd"
end
def project_names_for_autocomplete
@ -187,8 +187,8 @@ module TodosHelper
image_tag("blank.png", :title =>"Delete action", :class=>"delete_item")
end
def image_tag_for_edit(item)
image_tag("blank.png", :title =>"Edit action", :class=>"edit_item", :id=> dom_id(item, 'edit_icon'))
def image_tag_for_edit
image_tag("blank.png", :title =>"Edit action", :class=>"edit_item", :id=> dom_id(@todo, 'edit_icon'))
end
end

View file

@ -14,6 +14,6 @@
<div id="c<%= context.id %>empty-nd" style="display:<%= @not_done.empty? ? 'block' : 'none'%>;">
<div class="message"><p>Currently there are no uncompleted actions in this context</p></div>
</div>
<%= render :partial => "todos/item", :collection => @not_done, :locals => { :parent_container_type => "context" } %>
<%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "context" } %>
</div><!-- [end:items] -->
</div><!-- [end:c<%= context.id %>] -->

View file

@ -1,21 +1,21 @@
<span class="errors">
<%= error_messages_for("item") %>
<%= error_messages_for("todo") %>
</span>
<% this_year = user_time.to_date.strftime("%Y").to_i -%>
<p><label for="item_state">Done?</label></p>
<p><%= check_box( "item", "state", "tabindex" => 1) %></p>
<p><label for="item_description">Next action</label></p>
<p><%= text_field( "item", "description", "tabindex" => 2) %></p>
<p><label for="item_notes">Notes</label></p>
<p><%= text_area( "item", "notes", "cols" => 30, "rows" => 5, "tabindex" => 3) %></p>
<p><label for="item_context_id">Context</label></p>
<p><%= collection_select( "item", "context_id", @contexts, "id", "name", {"tabindex" => 4} ) %></p> <p><label for="item_project_id">Project</label></p>
<p><%= collection_select( "item", "project_id", @projects, "id", "name",
<p><label for="todo_state">Done?</label></p>
<p><%= check_box( "todo", "state", "tabindex" => 1) %></p>
<p><label for="todo_description">Next action</label></p>
<p><%= text_field( "todo", "description", "tabindex" => 2) %></p>
<p><label for="todo_notes">Notes</label></p>
<p><%= text_area( "todo", "notes", "cols" => 30, "rows" => 5, "tabindex" => 3) %></p>
<p><label for="todo_context_id">Context</label></p>
<p><%= collection_select( "todo", "context_id", @contexts, "id", "name", {"tabindex" => 4} ) %></p> <p><label for="todo_project_id">Project</label></p>
<p><%= collection_select( "todo", "project_id", @projects, "id", "name",
{:include_blank => true}, {"tabindex" => 5} ) %></p>
<p><label for="item_due">Due</label></p>
<p><%= date_select("item", "due", :order => [:day, :month, :year],
<p><label for="todo_due">Due</label></p>
<p><%= date_select("todo", "due", :order => [:day, :month, :year],
:start_year => this_year, :include_blank => true) %></p>
<p><label for="item_show_from">Show from</label></p>
<p><%= date_select("item", "show_from", :order => [:day, :month, :year],
<p><label for="todo_show_from">Show from</label></p>
<p><%= date_select("todo", "show_from", :order => [:day, :month, :year],
:start_year => this_year, :include_blank => true) %></p>
<p><input type="submit" value="Update" tabindex="6" /></p>

View file

@ -20,6 +20,6 @@
<div id="p<%= project.id %>empty-nd" style="display:<%= @not_done.empty? ? 'block' : 'none'%>;">
<div class="message"><p>Currently there are no uncompleted actions in this project</p></div>
</div>
<%= render :partial => "todos/item", :collection => @not_done, :locals => { :parent_container_type => "project" } %>
<%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "project" } %>
</div><!-- [end:items] -->
</div><!-- [end:p<%= project.id %>] -->

View file

@ -1,4 +1,5 @@
<%
@todo = nil
@initial_context_name = @context.name unless @context.nil?
@initial_context_name ||= @contexts[0].name unless @contexts[0].nil?
@initial_project_name = @project.name unless @project.nil?

View file

@ -12,6 +12,6 @@
<div class="message"><p>Currently there are no completed actions.</p></div>
</div>
<%= render :partial => "todos/item", :collection => done, :locals => { :parent_container_type => "completed" } %>
<%= render :partial => "todos/todo", :collection => done, :locals => { :parent_container_type => "completed" } %>
</div>
</div><!-- [end:next_actions] -->

View file

@ -12,7 +12,7 @@
<div class="message"><p>Currently there are no deferred actions</p></div>
</div>
<%= render :partial => "todos/item", :collection => deferred, :locals => { :parent_container_type => 'tickler' } %>
<%= render :partial => "todos/todo", :collection => deferred, :locals => { :parent_container_type => 'tickler' } %>
</div><!-- [end:items] -->
</div><!-- [end:tickler] -->

View file

@ -1,59 +1,59 @@
<div id="error_status"><%= error_messages_for("item") %></div>
<div id="error_status"><%= error_messages_for("todo") %></div>
<%= hidden_field( "item", "id" ) %>
<%= hidden_field( "todo", "id" ) %>
<%= source_view_tag( @source_view ) %>
<table>
<tr>
<td class="label"><label for="item_description">Next action</label></td>
<td><%= text_field( "item", "description", "tabindex" => 8) %></td>
<td class="label"><label for="todo_description">Next action</label></td>
<td><%= text_field( "todo", "description", "tabindex" => 8) %></td>
</tr>
<tr>
<td class="label"><label for="item_notes">Notes</label></td>
<td><%= text_area( "item", "notes", "cols" => 20, "rows" => 5, "tabindex" => 9) %></td>
<td class="label"><label for="todo_notes">Notes</label></td>
<td><%= text_area( "todo", "notes", "cols" => 20, "rows" => 5, "tabindex" => 9) %></td>
</tr>
<tr>
<td class="label"><label for="<%= dom_id(@item, 'context_name') %>">Context</label></td>
<td><input id="<%= dom_id(@item, 'context_name') %>" name="context_name" autocomplete="off" tabindex="10" size="25" type="text" value="<%= @item.context.name %>" />
<div class="page_name_auto_complete" id="<%= dom_id(@item, 'context_list') %>" style="display:none"></div></td>
<td class="label"><label for="<%= dom_id(@todo, 'context_name') %>">Context</label></td>
<td><input id="<%= dom_id(@todo, 'context_name') %>" name="context_name" autocomplete="off" tabindex="10" size="25" type="text" value="<%= @todo.context.name %>" />
<div class="page_name_auto_complete" id="<%= dom_id(@todo, 'context_list') %>" style="display:none"></div></td>
<script type="text/javascript">
editFormContextAutoCompleter = new Autocompleter.Local('<%= dom_id(@item, 'context_name') %>', '<%= dom_id(@item, 'context_list') %>', <%= context_names_for_autocomplete %>, {choices:100,autoSelect:true});
Event.observe($('<%= dom_id(@item, 'context_name') %>'), "focus", editFormContextAutoCompleter.activate.bind(editFormContextAutoCompleter));
Event.observe($('<%= dom_id(@item, 'context_name') %>'), "click", editFormContextAutoCompleter.activate.bind(editFormContextAutoCompleter));
editFormContextAutoCompleter = new Autocompleter.Local('<%= dom_id(@todo, 'context_name') %>', '<%= dom_id(@todo, 'context_list') %>', <%= context_names_for_autocomplete %>, {choices:100,autoSelect:true});
Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "focus", editFormContextAutoCompleter.activate.bind(editFormContextAutoCompleter));
Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "click", editFormContextAutoCompleter.activate.bind(editFormContextAutoCompleter));
</script>
</tr>
<tr>
<td class="label"><label for="<%= dom_id(@item, 'project_name') %>">Project</label></td>
<td class="label"><label for="<%= dom_id(@todo, 'project_name') %>">Project</label></td>
<td>
<input id="<%= dom_id(@item, 'project_name') %>" name="project_name" autocomplete="off" tabindex="11" size="25" type="text" value="<%= @item.project.nil? ? 'None' : @item.project.name %>" />
<div class="page_name_auto_complete" id="<%= dom_id(@item, 'project_list') %>" style="display:none"></div>
<input id="<%= dom_id(@todo, 'project_name') %>" name="project_name" autocomplete="off" tabindex="11" size="25" type="text" value="<%= @todo.project.nil? ? 'None' : @todo.project.name %>" />
<div class="page_name_auto_complete" id="<%= dom_id(@todo, 'project_list') %>" style="display:none"></div>
</td>
<script type="text/javascript">
editFormProjectAutoCompleter = new Autocompleter.Local('<%= dom_id(@item, 'project_name') %>', '<%= dom_id(@item, 'project_list') %>', <%= project_names_for_autocomplete %>, {choices:100,autoSelect:true});
Event.observe($('<%= dom_id(@item, 'project_name') %>'), "focus", editFormProjectAutoCompleter.activate.bind(editFormProjectAutoCompleter));
Event.observe($('<%= dom_id(@item, 'project_name') %>'), "click", editFormProjectAutoCompleter.activate.bind(editFormProjectAutoCompleter));
editFormProjectAutoCompleter = new Autocompleter.Local('<%= dom_id(@todo, 'project_name') %>', '<%= dom_id(@todo, 'project_list') %>', <%= project_names_for_autocomplete %>, {choices:100,autoSelect:true});
Event.observe($('<%= dom_id(@todo, 'project_name') %>'), "focus", editFormProjectAutoCompleter.activate.bind(editFormProjectAutoCompleter));
Event.observe($('<%= dom_id(@todo, 'project_name') %>'), "click", editFormProjectAutoCompleter.activate.bind(editFormProjectAutoCompleter));
</script>
</tr>
<tr>
<td class="label"><label for="<%= dom_id(@item, 'tag_list') %>">Tags (separate with commas)</label></td>
<td><%= text_field_tag "tag_list", @item.tags.collect{|t| t.name}.join(", "), :size => 40, :tabindex => 12 %></td>
<td class="label"><label for="<%= dom_id(@todo, 'tag_list') %>">Tags (separate with commas)</label></td>
<td><%= text_field_tag "tag_list", @todo.tags.collect{|t| t.name}.join(", "), :size => 40, :tabindex => 12 %></td>
</tr>
<tr>
<td class="label"><label for="<%= dom_id(@item, 'due') %>">Due</td>
<td><input name="item[due]" id="<%= dom_id(@item, 'due') %>" type="text" value="<%= format_date(@item.due) %>" tabindex="13" size="10" onfocus="Calendar.setup" autocomplete="off" class="Date" /></td>
<td class="label"><label for="<%= dom_id(@todo, 'due') %>">Due</td>
<td><input name="todo[due]" id="<%= dom_id(@todo, 'due') %>" type="text" value="<%= format_date(@todo.due) %>" tabindex="13" size="10" onfocus="Calendar.setup" autocomplete="off" class="Date" /></td>
</tr>
<tr>
<td class="label"><label for="<%= dom_id(@item, 'show_from') %>">Show from</td>
<td><input name="item[show_from]" id="<%= dom_id(@item, 'show_from') %>" type="text" value="<%= format_date(@item.show_from) %>" tabindex="14" size="10" onfocus="Calendar.setup" autocomplete="off" class="Date" /></td>
<td class="label"><label for="<%= dom_id(@todo, 'show_from') %>">Show from</td>
<td><input name="todo[show_from]" id="<%= dom_id(@todo, 'show_from') %>" type="text" value="<%= format_date(@todo.show_from) %>" tabindex="14" size="10" onfocus="Calendar.setup" autocomplete="off" class="Date" /></td>
</tr>
<% if controller.controller_name == "project" || @item.deferred? -%>
<% if controller.controller_name == "project" || @todo.deferred? -%>
<input type="hidden" name="on_project_page" value="true" />
<% end -%>
<tr>
<td colspan="2"><input type="submit" value="Update" tabindex="14" />
<a href="javascript:void(0);" onclick="Element.toggle('<%= dom_id(@item, 'line') %>');Element.toggle('<%= dom_id(@item, 'edit') %>');">Cancel</a></td>
<a href="javascript:void(0);" onclick="Element.toggle('<%= dom_id(@todo, 'line') %>');Element.toggle('<%= dom_id(@todo, 'edit') %>');">Cancel</a></td>
</tr>
</table>
<%= calendar_setup( dom_id(@item, 'due') ) %>
<%= calendar_setup( dom_id(@item, 'show_from') ) %>
<%= calendar_setup( dom_id(@todo, 'due') ) %>
<%= calendar_setup( dom_id(@todo, 'show_from') ) %>

View file

@ -1,22 +0,0 @@
<% Tag %>
<div id="<%= dom_id(item) %>" class="item-container">
<div id="<%= dom_id(item, 'line') %>">
<%= remote_delete_icon( item ) %>
<%= remote_edit_icon( item ) %>
<%= remote_toggle_checkbox( item ) unless source_view_is :deferred %>
<div class="description<%= staleness_class( item ) %>">
<%= date_span( item ) %>
<%= sanitize(item.description) %>
<%= tag_list( item ) %>
<%= deferred_due_date( item ) %>
<%= project_and_context_links( item, parent_container_type ) %>
<%= render(:partial => "todos/toggle_notes", :locals => { :item => item }) if item.notes? %>
</div>
</div>
<div id="<%= dom_id(item, 'edit') %>" class="edit-form" style="display:none">
<% form_remote_tag_edit_todo( item ) do -%>
<% #note: edit form will load here remotely -%>
<div class="placeholder"> </div>
<% end -%>
</div>
</div>

View file

@ -0,0 +1,25 @@
<%
@todo = todo
Tag
%>
<div id="<%= dom_id(todo) %>" class="item-container">
<div id="<%= dom_id(todo, 'line') %>">
<%= remote_delete_icon %>
<%= remote_edit_icon %>
<%= remote_toggle_checkbox unless source_view_is :deferred %>
<div class="description<%= staleness_class( todo ) %>">
<%= date_span %>
<%= sanitize(todo.description) %>
<%= tag_list %>
<%= deferred_due_date %>
<%= project_and_context_links( parent_container_type ) %>
<%= render(:partial => "todos/toggle_notes", :locals => { :item => todo }) if todo.notes? %>
</div>
</div>
<div id="<%= dom_id(todo, 'edit') %>" class="edit-form" style="display:none">
<% form_remote_tag_edit_todo do -%>
<% #note: edit form will load here remotely -%>
<div class="placeholder"> </div>
<% end -%>
</div>
</div>

View file

@ -1,7 +1,7 @@
if @saved
page.hide 'status'
status_message = 'Added new next action'
status_message += ' to tickler' if @item.deferred?
status_message += ' to tickler' if @todo.deferred?
status_message = 'Added new project / ' + status_message if @new_project_created
status_message = 'Added new context / ' + status_message if @new_context_created
page.notify :notice, status_message, 5.0
@ -11,15 +11,15 @@ if @saved
page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}" if @new_project_created
if should_show_new_item()
if @new_context_created
page.insert_html :top, 'display_box', :partial => 'contexts/context', :locals => { :context => @item.context, :collapsible => true }
page.insert_html :top, 'display_box', :partial => 'contexts/context', :locals => { :context => @todo.context, :collapsible => true }
else
page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}" if source_view_is(:todo)
page.insert_html :bottom, item_container_id, :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type, :source_view => @source_view }
page.visual_effect :highlight, dom_id(@item), :duration => 3
page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@todo.context_id}" if source_view_is(:todo)
page.insert_html :bottom, item_container_id, :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type, :source_view => @source_view }
page.visual_effect :highlight, dom_id(@todo), :duration => 3
page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil?
end
end
else
page.show 'status'
page.replace_html 'status', "#{error_messages_for('item')}"
page.replace_html 'status', "#{error_messages_for('todo')}"
end

View file

@ -1,8 +1,8 @@
if @saved
page[@item].remove
page[@todo].remove
page['badge_count'].replace_html @down_count
page.visual_effect :fade, item_container_id, :duration => 0.4 if source_view_is(:todo) && @remaining_undone_in_context == 0
page[empty_container_msg_div_id].show if !empty_container_msg_div_id.nil? && @down_count == 0
else
page.notify :error, "There was an error deleting the item #{@item.description}", 8.0
page.notify :error, "There was an error deleting the item #{@todo.description}", 8.0
end

View file

@ -1,4 +1,4 @@
page[dom_id(@item, 'form')].down('.placeholder').replace_html :partial => 'todos/edit_form'
page[dom_id(@item, 'line')].hide
page[dom_id(@item, 'edit')].show
page[dom_id(@item, 'form')].down('table').down('input').focus
page[dom_id(@todo, 'form')].down('.placeholder').replace_html :partial => 'todos/edit_form'
page[dom_id(@todo, 'line')].hide
page[dom_id(@todo, 'edit')].show
page[dom_id(@todo, 'form')].down('table').down('input').focus

View file

@ -8,7 +8,7 @@
<div class="message"><p>Currently there are no deferred actions</p></div>
</div>
<%= render :partial => "todos/item", :collection => @tickles, :locals => { :parent_container_type => 'tickler' } %>
<%= render :partial => "todos/todo", :collection => @tickles, :locals => { :parent_container_type => 'tickler' } %>
</div><!-- [end:items] -->
</div><!-- [end:tickler] -->

View file

@ -8,7 +8,7 @@
<div id="t_empty-nd" style="display:<%= @todos.empty? ? 'block' : 'none'%>;">
<div class="message"><p>Currently there are no actions tagged with <%= @tag %></p></div>
</div>
<%= render :partial => "todos/item", :collection => @todos, :locals => { :parent_container_type => "tag" } %>
<%= render :partial => "todos/todo", :collection => @todos, :locals => { :parent_container_type => "tag" } %>
</div><!-- [end:items] -->
</div><!-- [end:t-->

View file

@ -8,7 +8,7 @@
<div class="message"><p>Currently there are no deferred actions</p></div>
</div>
<%= render :partial => "todo/item", :collection => @tickles, :locals => { :parent_container_type => 'tickler' } %>
<%= render :partial => "todos/todo", :collection => @tickles, :locals => { :parent_container_type => 'tickler' } %>
</div><!-- [end:items] -->
</div><!-- [end:tickler] -->

View file

@ -1,10 +1,10 @@
if @saved
page[@item].remove
if @item.completed?
page[@todo].remove
if @todo.completed?
# Don't try to insert contents into a non-existent container!
unless @user.prefs.hide_completed_actions?
page.insert_html :top, "completed", :partial => 'todos/item', :locals => { :parent_container_type => "completed" }
page.visual_effect :highlight, dom_id(@item, 'line'), {'startcolor' => "'#99ff99'"}
page.insert_html :top, "completed", :partial => 'todos/todo', :locals => { :parent_container_type => "completed" }
page.visual_effect :highlight, dom_id(@todo, 'line'), {'startcolor' => "'#99ff99'"}
page[empty_container_msg_div_id].show if @down_count == 0 && !empty_container_msg_div_id.nil?
page.show 'tickler-empty-nd' if source_view_is(:project) && @deferred_count == 0
page.hide 'empty-d' # If we've checked something as done, completed items can't be empty
@ -14,13 +14,13 @@ if @saved
end
else
page.call "todoItems.ensureVisibleWithEffectAppear", item_container_id
page.insert_html :bottom, item_container_id, :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type }
page.visual_effect :highlight, dom_id(@item, 'line'), {'startcolor' => "'#99ff99'"}
page.insert_html :bottom, item_container_id, :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type }
page.visual_effect :highlight, dom_id(@todo, 'line'), {'startcolor' => "'#99ff99'"}
page.show "empty-d" if @completed_count == 0
page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil? # If we've checked something as undone, uncompleted items can't be empty
end
page.hide "status"
page.replace_html "badge_count", @down_count
else
page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }), "id" => "errorExplanation", "class" => "errorExplanation")
page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@todo.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @todo.errors.each_full { |msg| content_tag("li", msg) }), "id" => "errorExplanation", "class" => "errorExplanation")
end

View file

@ -1,64 +1,64 @@
if @saved
status_message = 'Action saved'
status_message += ' to tickler' if @item.deferred?
status_message += ' to tickler' if @todo.deferred?
status_message = 'Added new project / ' + status_message if @new_project_created
status_message = 'Added new context / ' + status_message if @new_context_created
page.notify :notice, status_message, 5.0
page << "contextAutoCompleter.options.array = #{context_names_for_autocomplete}; contextAutoCompleter.changed = true" if @new_context_created
page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}; projectAutoCompleter.changed = true" if @new_project_created
if source_view_is_one_of [:todo, :context]
if @context_changed || @item.deferred?
page[@item].remove
if @context_changed || @todo.deferred?
page[@todo].remove
if (@remaining_undone_in_context == 0)
source_view do |from|
from.todo { page.visual_effect :fade, "c#{@original_item_context_id}", :duration => 0.4 }
from.context { page.show "c#{@original_item_context_id}empty-nd" }
end
end
if source_view_is(:todo) && @item.active?
page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}"
page.call "todoItems.expandNextActionListingByContext", "c#{@item.context_id}items", true
page.insert_html :bottom, "c#{@item.context_id}items", :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type }
if source_view_is(:todo) && @todo.active?
page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@todo.context_id}"
page.call "todoItems.expandNextActionListingByContext", "c#{@todo.context_id}items", true
page.insert_html :bottom, "c#{@todo.context_id}items", :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type }
end
page.replace_html("badge_count", @remaining_undone_in_context) if source_view_is :context
page.delay(0.5) do
page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items"
if source_view_is(:todo) && @item.active?
page.call "todoItems.ensureContainerHeight", "c#{@item.context_id}items"
page.visual_effect :highlight, dom_id(@item), :duration => 3
if source_view_is(:todo) && @todo.active?
page.call "todoItems.ensureContainerHeight", "c#{@todo.context_id}items"
page.visual_effect :highlight, dom_id(@todo), :duration => 3
end
end
else
page.replace dom_id(@item), :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type }
page.visual_effect :highlight, dom_id(@item), :duration => 3
page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type }
page.visual_effect :highlight, dom_id(@todo), :duration => 3
end
elsif source_view_is :project
if @project_changed
page[@item].remove
page[@todo].remove
page.show("p#{@original_item_project_id}empty-nd") if (@remaining_undone_in_project == 0)
page.replace_html "badge_count", @remaining_undone_in_project
elsif @item.deferred?
page[@item].remove
elsif @todo.deferred?
page[@todo].remove
page.show("p#{@original_item_project_id}empty-nd") if (@remaining_undone_in_project == 0)
page.insert_html :bottom, "tickler", :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type }
page.insert_html :bottom, "tickler", :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type }
page['tickler-empty-nd'].hide
page.replace_html "badge_count", @down_count
elsif @item_was_activated_from_deferred_state
page[@item].remove
elsif @todo_was_activated_from_deferred_state
page[@todo].remove
page['tickler-empty-nd'].show if (@deferred_count == 0)
page.insert_html :bottom, "p#{@item.project_id}", :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type }
page["p#{@item.project_id}empty-nd"].hide
page.insert_html :bottom, "p#{@todo.project_id}", :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type }
page["p#{@todo.project_id}empty-nd"].hide
page.replace_html "badge_count", @down_count
else
page.replace dom_id(@item), :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type }
page.visual_effect :highlight, dom_id(@item), :duration => 3
page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type }
page.visual_effect :highlight, dom_id(@todo), :duration => 3
end
elsif source_view_is :deferred
if @item.deferred?
page.replace dom_id(@item), :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type }
page.visual_effect :highlight, dom_id(@item), :duration => 3
if @todo.deferred?
page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type }
page.visual_effect :highlight, dom_id(@todo), :duration => 3
else
page[@item].remove
page[@todo].remove
page.show(empty_container_msg_div_id) if (@down_count == 0)
page.replace_html "badge_count", @down_count
end

View file

@ -18,10 +18,10 @@ class MobileControllerTest < Test::Unit::TestCase
assert_redirected_to :controller => 'login', :action => 'login'
end
def test_create_item
def test_create_todo
@count = Todo.find(:all)
@request.session['user_id'] = users(:admin_user).id
xhr :post, :update, "item"=>{"context_id"=>"1", "project_id"=>"2", "notes"=>"", "description"=>"Invest in spam stock offer", "due"=>"01/01/2007", "show_from"=>"", "state"=>"0"}
xhr :post, :update, "todo"=>{"context_id"=>"1", "project_id"=>"2", "notes"=>"", "description"=>"Invest in spam stock offer", "due"=>"01/01/2007", "show_from"=>"", "state"=>"0"}
@todos = Todo.find(:all)
assert_equal @count.size+1, @todos.size
t = Todo.find(:first, :conditions => ['description = ?', "Invest in spam stock offer"])
@ -33,10 +33,10 @@ class MobileControllerTest < Test::Unit::TestCase
assert_equal "active", t.state
end
def test_update_item
def test_update_todo
t = Todo.find(1)
@request.session['user_id'] = users(:admin_user).id
xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"11/30/2006"}
xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"11/30/2006"}
t = Todo.find(1)
assert_equal "Call Warren Buffet to find out how much he makes per day", t.description
assert_equal Date.parse("11/30/2006"), t.due
@ -44,10 +44,10 @@ class MobileControllerTest < Test::Unit::TestCase
assert_equal "active", t.state
end
def test_complete_item
def test_complete_todo
t = Todo.find(1)
@request.session['user_id'] = users(:admin_user).id
xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Bill Gates to find out how much he makes per day", "state"=>"1"}
xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Bill Gates to find out how much he makes per day", "state"=>"1"}
t = Todo.find(1)
assert_equal "completed", t.state
end

View file

@ -57,34 +57,47 @@ class TodosControllerTest < Test::Unit::TestCase
assert_equal 0, assigns['deferred_count']
end
def test_destroy_item
def test_destroy_todo
@request.session['user_id'] = users(:admin_user).id
xhr :post, :destroy, :id => 1, :_source_view => 'todo'
assert_rjs :page, "todo_1", :remove
#assert_rjs :replace_html, "badge-count", '9'
end
def test_update_item_project
def test_create_todo
original_todo_count = Todo.count
@request.session['user_id'] = users(:admin_user).id
put :create, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
assert_equal original_todo_count + 1, Todo.count
end
def test_create_deferred_todo
original_todo_count = Todo.count
@request.session['user_id'] = users(:admin_user).id
put :create, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2026", 'show_from' => '30/10/2026'}, "tag_list"=>"foo bar"
assert_equal original_todo_count + 1, Todo.count
end
def test_update_todo_project
t = Todo.find(1)
@request.session['user_id'] = users(:admin_user).id
xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "item"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
t = Todo.find(1)
assert_equal 1, t.project_id
end
def test_update_item_project_to_none
def test_update_todo_project_to_none
t = Todo.find(1)
@request.session['user_id'] = users(:admin_user).id
xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"None", "item"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"None", "todo"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
t = Todo.find(1)
assert_nil t.project_id
end
def test_update_item
def test_update_todo
t = Todo.find(1)
@request.session['user_id'] = users(:admin_user).id
xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
#assert_rjs :page, "todo_1", :visual_effect, :highlight, :duration => '1'
xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
t = Todo.find(1)
assert_equal "Call Warren Buffet to find out how much he makes per day", t.description
expected = Date.new(2006,11,30).to_time.utc.to_date
@ -92,14 +105,14 @@ class TodosControllerTest < Test::Unit::TestCase
assert_equal expected, actual, "Expected #{expected.to_s(:db)}, was #{actual.to_s(:db)}"
end
def test_tag
@request.session['user_id'] = users(:admin_user).id
@user = User.find(@request.session['user_id'])
@tagged = Todo.find_tagged_with('foo', @user).size
get :tag, :id => 'foo'
assert_response :success
assert_equal 2, @tagged
end
# def test_tag
# @request.session['user_id'] = users(:admin_user).id
# @user = User.find(@request.session['user_id'])
# @tagged = Todo.find_tagged_with('foo', @user).size
# get :tag, :id => 'foo'
# assert_response :success
# assert_equal 2, @tagged
# end
end

View file

@ -2,3 +2,4 @@ type "todo_description", "choose era"
type "todo_show_from", "1/1/2030"
click "//input[@value='Add item']"
wait_for_element_present "xpath=//div[@id='tickler'] //div[@class='item-container']"
wait_for_element_present "xpath=//div[@id='tickler'] //div[@class='item-container'] //a[@title='01/01/2030']"

View file

@ -1,5 +1,5 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
open "/projects/Build_a_working_time_machine"
open "/projects/Make_more_money_than_Billy_Gates"
include_partial 'project_detail/add_deferred_todo'
assert_not_visible "tickler-empty-nd"

View file

@ -40,6 +40,10 @@ class Test::Unit::TestCase
assert_select(*args)
end
def next_week
1.week.from_now.utc.to_date
end
end
class ActionController::IntegrationTest

View file

@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper'
require 'date'
class TodoTest < Test::Unit::TestCase
fixtures :todos
fixtures :todos, :users, :contexts
def setup
@not_completed1 = Todo.find(1)
@not_completed2 = Todo.find(2)
@completed = Todo.find(8)
@not_completed1 = Todo.find(1).reload
@not_completed2 = Todo.find(2).reload
@completed = Todo.find(8).reload
end
# Test loading a todo item
@ -56,4 +56,22 @@ class TodoTest < Test::Unit::TestCase
assert_equal 1, @not_completed2.errors.count
assert_equal "is too long (maximum is 60000 characters)", @not_completed2.errors.on(:notes)
end
def test_defer_an_existing_todo
@not_completed2
assert_equal :active, @not_completed2.current_state
@not_completed2.show_from = next_week
assert @not_completed2.save, "should have saved successfully" + @not_completed2.errors.to_xml
assert_equal :deferred, @not_completed2.current_state
end
def test_create_a_new_deferred_todo
user = users(:other_user)
item = user.todos.build
item.show_from = next_week
item.context_id = 1
item.description = 'foo'
assert item.save, "should have saved successfully" + item.errors.to_xml
assert_equal :deferred, item.current_state
end
end