* Replaced select widgets with AutoCompleters for project & context in new item and edit forms. You can now create a new project and/or context on the fly as you're adding an item.

* Rolled Deferred controller, views & helper into Todo.
* Made the show_from field always available on the add new item and edit forms.
* Added validation to Todo to make sure a context is specified.
* Set initial state of Todo to :deferred when show_from is specified (I still need to make handle setting show_from during an edit).
* Created a generic rescue_action in ApplicationController and removed boilerplate rescue code from a few actions in TodoController.
* Made all Todo creation requests use the TodoController, removing duplicate logic from ContextController and ContextController
* Removed unused lightbox-style add item form
* Remove unused update_context and update_project actions
* Updated rails javascripts to the same as our vendor/rails



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@352 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2006-11-20 04:31:00 +00:00
parent 5d51ca84ba
commit bb1cfe613a
36 changed files with 627 additions and 720 deletions

View file

@ -54,6 +54,18 @@ class ApplicationController < ActionController::Base
render :text => message, :status => status
end
def rescue_action(exception)
log_error(exception) if logger
respond_to do |wants|
wants.html do
notify :warning, "An error occurred on the server."
render :action => "index"
end
wants.js { render :action => 'error' }
wants.xml { render :text => 'An error occurred on the server.' + $! }
end
end
private
def get_current_user

View file

@ -61,46 +61,6 @@ class ContextController < ApplicationController
end
end
# Called by a form button
# Parameters from form fields are passed to create new action
# in the selected context.
def add_item
self.init
@item = @user.todos.build
@item.attributes = params["todo"]
if @item.due?
@date = parse_date_per_user_prefs(params["todo"]["due"])
@item.due = @date.to_s(:db)
else
@item.due = ""
end
@saved = @item.save
if @saved
@up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.state = ? and todos.context_id = ?", @user.id, 'active', @item.context_id]).size.to_s
end
return if request.xhr?
# fallback for standard requests
if @saved
notify :notice, 'Added new next action.'
redirect_to :controller => 'todo', :action => 'list'
else
notify :warning, 'The next action was not added. Please try again.'
redirect_to :controller => 'todo', :action => 'list'
end
rescue
if request.xhr? # be sure to include an error.rjs
render :action => 'error'
else
notify :warning, 'An error occurred on the server.'
redirect_to :controller => 'todo', :action => 'list'
end
end
# Edit the details of the context
#
def update

View file

@ -1,131 +0,0 @@
class DeferredController < ApplicationController
model :user
model :project
model :context
helper :todo
prepend_before_filter :login_required
layout "standard"
def index
@source_view = 'deferred'
init_data_for_sidebar
@page_title = "TRACKS::Tickler"
@tickles = @user.todos.find_in_state(:all, :deferred, :order => "show_from ASC")
@count = @tickles.size
end
def create
@source_view = 'deferred'
@item = Todo.new_deferred
@item.attributes = params["todo"]
if params["todo"]["show_from"]
@item.show_from = parse_date_per_user_prefs(params["todo"]["show_from"])
end
@item.user_id = @user.id
if @item.due?
@item.due = parse_date_per_user_prefs(params["todo"]["due"])
else
@item.due = ""
end
@saved = @item.save
if @saved
@up_count = @user.todos.count_in_state(:deferred)
end
respond_to do |wants|
wants.html { redirect_to :action => "index" }
wants.js
wants.xml { render :xml => @item.to_xml( :root => 'todo', :except => :user_id ) }
end
end
def edit
@source_view = 'deferred'
init_projects_and_contexts
@item = check_user_return_item
render :template => 'todo/edit.rjs'
end
def update
@source_view = 'deferred'
@item = check_user_return_item
@original_item_context_id = @item.context_id
@item.attributes = params["item"]
if params["item"]["show_from"]
@item.show_from = parse_date_per_user_prefs(params["item"]["show_from"])
end
if @item.due?
@item.due = parse_date_per_user_prefs(params["item"]["due"])
else
@item.due = ""
end
@saved = @item.save
end
def destroy
@item = check_user_return_item
context_id = @item.context_id
@saved = @item.destroy
respond_to do |wants|
wants.html do
notify :notice, 'Successfully deleted next action' if @saved
redirect_to :action => "index"
end
wants.js do
@down_count = @user.todos.count_in_state(:deferred) if @saved
render
end
wants.xml { render :xml => @item.to_xml( :root => 'todo', :except => :user_id ) }
end
rescue
respond_to do |wants|
wants.html do
notify :warning, 'An error occurred on the server.'
redirect_to :action => "index"
end
wants.js { render :action => 'error' }
wants.xml { render :text => "500 Server Error: There was an error deleting the action.", :status => 500 }
end
end
# Check for any due tickler items, activate them
# Called by periodically_call_remote
def check_tickler
now = Date.today()
@due_tickles = @user.todos.find_in_state(:all, :deferred, :conditions => ['show_from < ? OR show_from = ?', now, now ], :order => "show_from ASC")
# Change the due tickles to active
@due_tickles.each do |t|
t.activate!
t.save
end
respond_to do |wants|
wants.html { redirect_to :controller => 'todo', :action => 'index' }
wants.js
end
end
private
def check_user_return_item
item = Todo.find( params['id'] )
if @user == item.user
return item
else
notify :warning, "Item and session user mis-match: #{item.user.name} and #{@user.name}!"
render_text ""
end
end
end

View file

@ -86,46 +86,6 @@ class ProjectController < ApplicationController
end
end
# Called by a form button
# Parameters from form fields are passed to create new action
# in the selected context.
def add_item
self.init
@item = @user.todos.build
@item.attributes = params["todo"]
if @item.due?
@date = parse_date_per_user_prefs(params["todo"]["due"])
@item.due = @date.to_s(:db)
else
@item.due = ""
end
@saved = @item.save
if @saved
@up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.state = ? and todos.project_id = ?", @user.id, 'active', @item.project_id]).size.to_s
end
return if request.xhr?
# fallback for standard requests
if @saved
notify :notice, 'Added new next action.'
redirect_to :controller => 'todo', :action => 'index'
else
notify :warning, 'The next action was not added. Please try again.'
redirect_to :controller => 'todo', :action => 'index'
end
rescue
if request.xhr? # be sure to include an error.rjs
render :action => 'error'
else
notify :warning, 'An error occurred on the server.'
redirect_to :controller => 'todo', :action => 'index'
end
end
# Edit the details of the project
#
def update

View file

@ -62,15 +62,41 @@ class TodoController < ApplicationController
def create
init
@item = @user.todos.build
p = params['todo'] || params['request']['todo']
@item.attributes = p
p = params['request'] || params
@item.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)
unless project
project = @user.projects.build
project.name = p['project_name'].strip
project.save
@new_project_created = true
end
@item.project_id = project.id
end
if p['todo']['context_id'].blank? && !p['context_name'].blank?
context = @user.contexts.find_by_name(p['context_name'].strip)
unless context
context = @user.contexts.build
context.name = p['context_name'].strip
context.save
@new_context_created = true
end
@item.context_id = context.id
end
if @item.due?
@date = parse_date_per_user_prefs(p["due"])
@date = parse_date_per_user_prefs(p['todo']['due'])
@item.due = @date.to_s(:db)
else
@item.due = ""
end
if p['todo']['show_from']
@item.show_from = parse_date_per_user_prefs(p['todo']['show_from'])
end
@saved = @item.save
@ -78,28 +104,12 @@ class TodoController < ApplicationController
wants.html { redirect_to :action => "index" }
wants.js do
if @saved
init_todos
@up_count = @todos.reject { |x| !x.active? or x.context.hide? }.size.to_s
determine_down_count
end
render :action => 'create'
end
wants.xml { render :xml => @item.to_xml( :root => 'todo', :except => :user_id ) }
end
# if you're seeing the message 'An error occurred on the server.' and you want to debug, comment out the rescue section and check the Ajax response for an exception message
rescue
respond_to do |wants|
wants.html do
notify :warning, "An error occurred on the server."
render :action => "index"
end
wants.js { render :action => 'error' }
wants.xml { render :text => 'An error occurred on the server.' + $! }
end
end
def add_item
create
end
def edit
@ -119,7 +129,6 @@ class TodoController < ApplicationController
#
def toggle_check
init
logger.info "source view is " + @source_view
@item = check_user_return_item
@item.toggle_completion()
@saved = @item.save
@ -144,7 +153,28 @@ class TodoController < ApplicationController
@item = check_user_return_item
@original_item_context_id = @item.context_id
@original_item_project_id = @item.project_id
@item.attributes = params["item"]
if params['item']['project_id'].blank? && !params['project_name'].blank? && params['project_name'] != 'None'
project = @user.projects.find_by_name(params['project_name'].strip)
unless project
project = @user.projects.build
project.name = params['project_name'].strip
project.save
@new_project_created = true
end
params["item"]["project_id"] = project.id
end
if params['item']['context_id'].blank? && !params['context_name'].blank?
context = @user.contexts.find_by_name(params['context_name'].strip)
unless context
context = @user.contexts.build
context.name = params['context_name'].strip
context.save
@new_context_created = true
end
params["item"]["context_id"] = context.id
end
if params["item"].has_key?("due")
params["item"]["due"] = parse_date_per_user_prefs(params["item"]["due"])
else
@ -155,42 +185,9 @@ class TodoController < ApplicationController
if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todos.length; end
@project_changed = @original_item_project_id != @item.project_id
if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = @user.projects.find(@original_item_project_id).not_done_todos.length; end
determine_down_count
end
def update_context
init
@item = check_user_return_item
context = Context.find(params['context_id']);
if @user == context.user
@original_item_context_id = @item.context_id
@item.context_id = context.id
@item.context = context
@saved = @item.save
render :action => 'update'
else
render :update do |page|
page.notify :warning, content_tag("div", "Error updating the context of the dragged item. Item and context user mis-match: #{@item.user.name} and #{@context.user.name}! - refresh the page to see them."), 8.0
end
end
end
def update_project
init
@item = check_user_return_item
project = Project.find(params['project_id']);
if @user == project.user
@original_item_context_id = @item.context_id
@item.project_id = project.id
@item.project = project
@saved = @item.save
render :action => 'update'
else
render :update do |page|
page.notify :warning, content_tag("div", "Error updating the project of the dragged item. Item and project user mis-match: #{@item.user.name} and #{@project.user.name}! - refresh the page to see them."), 8.0
end
end
end
def destroy
@item = check_user_return_item
@context_id = @item.context_id
@ -224,16 +221,6 @@ class TodoController < ApplicationController
wants.xml { render :text => '200 OK. Action deleted.', :status => 200 }
end
rescue
respond_to do |wants|
wants.html do
notify :error, 'An error occurred on the server.', 8.0
redirect_to :action => 'index'
end
wants.js { render :action => 'error' }
wants.xml { render :text => 'An error occurred on the server.' + $! }
end
end
def completed
@ -250,6 +237,31 @@ class TodoController < ApplicationController
@done_archive = @done.completed_more_than 28.day.ago
end
def tickler
init
@source_view = 'deferred'
@page_title = "TRACKS::Tickler"
@tickles = @user.todos.find_in_state(:all, :deferred, :order => "show_from ASC")
@count = @tickles.size
end
# Check for any due tickler items, activate them
# Called by periodically_call_remote
def check_tickler
now = Date.today()
@due_tickles = @user.todos.find_in_state(:all, :deferred, :conditions => ['show_from < ? OR show_from = ?', now, now ], :order => "show_from ASC")
# Change the due tickles to active
@due_tickles.each do |t|
t.activate!
t.save
end
respond_to do |wants|
wants.html { redirect_to :controller => 'todo', :action => 'index' }
wants.js
end
end
private
def check_user_return_item
@ -296,6 +308,9 @@ class TodoController < ApplicationController
@down_count = @user.projects.find(@item.project_id).todos.count_in_state(:active)
end
end
from.deferred do
@down_count = @user.todos.count_in_state(:deferred)
end
end
end