diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb
index a9e39020..f7c8c1b2 100644
--- a/tracks/app/controllers/application.rb
+++ b/tracks/app/controllers/application.rb
@@ -50,22 +50,6 @@ class ApplicationController < ActionController::Base
end
end
- def redirect_with_notice( message, options = {})
- options['flash_target'] = 'notice'
- redirect_with_flash message, options
- end
-
- def redirect_with_flash( message, options )
- flash[options['flash_target']] = message
- options.delete 'flash_target'
- redirect_to options
- end
-
- def redirect_with_warning( message, options = {})
- options['flash_target'] = 'warning'
- redirect_with_flash message, options
- end
-
def render_failure message, status = 404
render :text => message, :status => status
end
@@ -107,4 +91,12 @@ class ApplicationController < ActionController::Base
end
end
+ # Set the contents of the flash message from a controller
+ # Usage: notify :warning, "This is the message"
+ # Sets the flash of type 'warning' to "This is the message"
+ def notify(type, message)
+ flash[type] = message
+ logger.error("ERROR: #{message}") if type == :error
+ end
+
end
diff --git a/tracks/app/controllers/context_controller.rb b/tracks/app/controllers/context_controller.rb
index 621e4ace..a646c7b8 100644
--- a/tracks/app/controllers/context_controller.rb
+++ b/tracks/app/controllers/context_controller.rb
@@ -3,7 +3,7 @@ class ContextController < ApplicationController
helper :todo
prepend_before_filter :login_required
- layout "standard"
+ layout "standard", :except => :date_preview
def index
list
@@ -78,19 +78,17 @@ class ContextController < ApplicationController
@saved = @item.save
if @saved
- # This reports real count +1 for some reason that I don't understand
- # Almost identical code for add_item in projects reports correct num
- @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.context_id IN (?)", @user.id, false, @item.context_id]).size.to_s
+ @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
- flash[:notice] = 'Added new next action.'
+ notify :notice, 'Added new next action.'
redirect_to :controller => 'todo', :action => 'list'
else
- flash[:warning] = 'The next action was not added. Please try again.'
+ notify :warning, 'The next action was not added. Please try again.'
redirect_to :controller => 'todo', :action => 'list'
end
@@ -98,7 +96,7 @@ class ContextController < ApplicationController
if request.xhr? # be sure to include an error.rjs
render :action => 'error'
else
- flash[:warning] = 'An error occurred on the server.'
+ notify :warning, 'An error occurred on the server.'
redirect_to :controller => 'todo', :action => 'list'
end
end
@@ -113,7 +111,7 @@ class ContextController < ApplicationController
if @context.save
render :partial => 'context_listing', :object => @context
else
- flash[:warning] = "Couldn't update new context"
+ notify :warning, "Couldn't update new context"
render :text => ""
end
end
@@ -126,7 +124,7 @@ class ContextController < ApplicationController
if @context.destroy
render_text ""
else
- flash[:warning] = "Couldn't delete context \"#{@context.name}\""
+ notify :warning, "Couldn't delete context \"#{@context.name}\""
redirect_to( :controller => "context", :action => "list" )
end
end
@@ -156,7 +154,7 @@ class ContextController < ApplicationController
return @context
else
@context = nil # Should be nil anyway.
- flash[:warning] = "Item and session user mis-match: #{@context.user_id} and #{@user.id}!"
+ notify :warning, "Item and session user mis-match: #{@context.user_id} and #{@user.id}!"
render_text ""
end
end
@@ -167,7 +165,7 @@ class ContextController < ApplicationController
return @context
else
@context = nil
- flash[:warning] = "Project and session user mis-match: #{@context.user_id} and #{@user.id}!"
+ notify :warning, "Project and session user mis-match: #{@context.user_id} and #{@user.id}!"
render_text ""
end
end
@@ -177,7 +175,7 @@ class ContextController < ApplicationController
if @user == item.user
return item
else
- flash[:warning] = "Item and session user mis-match: #{item.user.name} and #{@user.name}!"
+ notify :warning, "Item and session user mis-match: #{item.user.name} and #{@user.name}!"
render_text ""
end
end
diff --git a/tracks/app/controllers/deferred_controller.rb b/tracks/app/controllers/deferred_controller.rb
index 35c8bfd2..f8a4c2ee 100644
--- a/tracks/app/controllers/deferred_controller.rb
+++ b/tracks/app/controllers/deferred_controller.rb
@@ -79,7 +79,7 @@ class DeferredController < ApplicationController
respond_to do |wants|
wants.html do
- flash[:notice] = 'Successfully deleted next action' if @saved
+ notify :notice, 'Successfully deleted next action' if @saved
redirect_to :action => "index"
end
wants.js do
@@ -92,7 +92,7 @@ class DeferredController < ApplicationController
rescue
respond_to do |wants|
wants.html do
- flash[:warning] = 'An error occurred on the server.'
+ notify :warning, 'An error occurred on the server.'
redirect_to :action => "index"
end
wants.js { render :action => 'error' }
@@ -123,7 +123,7 @@ class DeferredController < ApplicationController
if @user == item.user
return item
else
- flash[:warning] = "Item and session user mis-match: #{item.user.name} and #{@user.name}!"
+ notify :warning, "Item and session user mis-match: #{item.user.name} and #{@user.name}!"
render_text ""
end
end
diff --git a/tracks/app/controllers/login_controller.rb b/tracks/app/controllers/login_controller.rb
index 6d89c35f..96128963 100644
--- a/tracks/app/controllers/login_controller.rb
+++ b/tracks/app/controllers/login_controller.rb
@@ -14,12 +14,12 @@ class LoginController < ApplicationController
# of inactivity
session['noexpiry'] = params['user_noexpiry']
msg = (should_expire_sessions?) ? "will expire after 1 hour of inactivity." : "will not expire."
- flash[:notice] = "Login successful: session #{msg}"
+ notify :notice, "Login successful: session #{msg}"
cookies[:tracks_login] = { :value => @user.login, :expires => Time.now + 1.year }
redirect_back_or_default :controller => "todo", :action => "index"
else
@login = params['user_login']
- flash[:warning] = "Login unsuccessful"
+ notify :warning, "Login unsuccessful"
end
end
end
@@ -37,7 +37,7 @@ class LoginController < ApplicationController
# redirect to the server
redirect_to open_id_response.redirect_url((request.protocol + request.host_with_port + "/"), url_for(:action => 'complete'))
else
- flash[:warning] = "Unable to find openid server for #{params[:openid_url]}
"
+ notify :warning, "Unable to find openid server for #{params[:openid_url]}
"
redirect_to :action => 'login'
end
end
@@ -49,11 +49,11 @@ class LoginController < ApplicationController
# URL that we were verifying. We include it in the error
# message to help the user figure out what happened.
if open_id_response.identity_url
- flash[:message] = "Verification of #{open_id_response.identity_url} failed. "
+ msg = "Verification of #{open_id_response.identity_url} failed. "
else
- flash[:message] = "Verification failed. "
+ msg = "Verification failed. "
end
- flash[:message] += open_id_response.msg.to_s
+ notify :error, open_id_response.msg.to_s + msg
when OpenID::SUCCESS
# Success means that the transaction completed without
@@ -61,18 +61,18 @@ class LoginController < ApplicationController
# the verification.
@user = User.find_by_open_id_url(open_id_response.identity_url)
unless (@user.nil?)
- flash[:message] = "You have successfully verified #{open_id_response.identity_url} as your identity."
+ notify :notice, "You have successfully verified #{open_id_response.identity_url} as your identity."
session['user_id'] = @user.id
redirect_back_or_default :controller => 'todo', :action => 'index'
else
- flash[:warning] = "You have successfully verified #{open_id_response.identity_url} as your identity, but you do not have a Tracks account. Please ask your administrator to sign you up."
+ notify :warning, "You have successfully verified #{open_id_response.identity_url} as your identity, but you do not have a Tracks account. Please ask your administrator to sign you up."
end
when OpenID::CANCEL
- flash[:message] = "Verification cancelled."
+ notify :warning, "Verification cancelled."
else
- flash[:warning] = "Unknown response status: #{open_id_response.status}"
+ notify :warning, "Unknown response status: #{open_id_response.status}"
end
redirect_to :action => 'login' unless performed?
end
@@ -107,7 +107,7 @@ class LoginController < ApplicationController
@user = User.authenticate(user.login, params['user']['password'])
@user.create_preference
@user.save
- flash[:notice] = "Signup successful for user #{@user.login}."
+ notify :notice, "Signup successful for user #{@user.login}."
redirect_back_or_default :controller => "todo", :action => "index"
end
end
@@ -124,7 +124,7 @@ class LoginController < ApplicationController
def logout
session['user_id'] = nil
reset_session
- flash[:notice] = "You have been logged out of Tracks."
+ notify :notice, "You have been logged out of Tracks."
redirect_to :action => "login"
end
diff --git a/tracks/app/controllers/mobile_controller.rb b/tracks/app/controllers/mobile_controller.rb
index 2d257e40..221e76cd 100644
--- a/tracks/app/controllers/mobile_controller.rb
+++ b/tracks/app/controllers/mobile_controller.rb
@@ -87,7 +87,7 @@ class MobileController < ApplicationController
if @user == item.user
return item
else
- flash[:warning] = "Item and session user mis-match: #{item.user.name} and #{@user.name}!"
+ notify :warning, "Item and session user mis-match: #{item.user.name} and #{@user.name}!"
render_text ""
end
end
diff --git a/tracks/app/controllers/note_controller.rb b/tracks/app/controllers/note_controller.rb
index 74a06a62..64467493 100644
--- a/tracks/app/controllers/note_controller.rb
+++ b/tracks/app/controllers/note_controller.rb
@@ -37,7 +37,7 @@ class NoteController < ApplicationController
if note.destroy
render :text => ''
else
- flash[:warning] = "Couldn't delete note \"#{note.id.to_s}\""
+ notify :warning, "Couldn't delete note \"#{note.id.to_s}\""
render :text => ''
end
end
@@ -48,7 +48,7 @@ class NoteController < ApplicationController
if note.save
render :partial => 'notes', :object => note
else
- flash[:warning] = "Couldn't update note \"#{note.id.to_s}\""
+ notify :warning, "Couldn't update note \"#{note.id.to_s}\""
render :text => ''
end
end
diff --git a/tracks/app/controllers/project_controller.rb b/tracks/app/controllers/project_controller.rb
index 0e6db1c6..deceb4c0 100644
--- a/tracks/app/controllers/project_controller.rb
+++ b/tracks/app/controllers/project_controller.rb
@@ -5,7 +5,7 @@ class ProjectController < ApplicationController
helper :todo
prepend_before_filter :login_required
- layout "standard"
+ layout "standard", :except => :date_preview
def index
list
@@ -35,7 +35,7 @@ class ProjectController < ApplicationController
@page_title = "TRACKS::Project: #{@project.name}"
if @contexts.empty?
- flash[:warning] = 'You must add at least one context before adding next actions.'
+ notify :warning, 'You must add at least one context before adding next actions.'
end
if @not_done.empty?
@@ -103,17 +103,17 @@ class ProjectController < ApplicationController
@saved = @item.save
if @saved
- @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.project_id IN (?)", @user.id, false, @item.project_id]).size.to_s
+ @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
- flash[:notice] = 'Added new next action.'
+ notify :notice, 'Added new next action.'
redirect_to :controller => 'todo', :action => 'index'
else
- flash[:warning] = 'The next action was not added. Please try again.'
+ notify :warning, 'The next action was not added. Please try again.'
redirect_to :controller => 'todo', :action => 'index'
end
@@ -121,7 +121,7 @@ class ProjectController < ApplicationController
if request.xhr? # be sure to include an error.rjs
render :action => 'error'
else
- flash[:warning] = 'An error occurred on the server.'
+ notify :warning, 'An error occurred on the server.'
redirect_to :controller => 'todo', :action => 'index'
end
end
@@ -148,7 +148,7 @@ class ProjectController < ApplicationController
render :text => 'Success'
end
else
- flash[:warning] = "Couldn't update project"
+ notify :warning, "Couldn't update project"
render :text => ''
end
end
@@ -171,7 +171,7 @@ class ProjectController < ApplicationController
if @project.destroy
render :text => ''
else
- flash[:warning] = "Couldn't delete project \"#{@project.name}\""
+ notify :warning, "Couldn't delete project \"#{@project.name}\""
redirect_to( :controller => "project", :action => "list" )
end
end
@@ -201,7 +201,7 @@ class ProjectController < ApplicationController
return @project
else
@project = nil # Should be nil anyway
- flash[:warning] = "Project and session user mis-match: #{@project.user_id} and #{@user.id}!"
+ notify :warning, "Project and session user mis-match: #{@project.user_id} and #{@user.id}!"
render :text => ''
end
end
@@ -212,7 +212,7 @@ class ProjectController < ApplicationController
return @project
else
@project = nil
- flash[:warning] = "Project and session user mis-match: #{@project.user_id} and #{@user.id}!"
+ notify :warning, "Project and session user mis-match: #{@project.user_id} and #{@user.id}!"
render :text => ''
end
end
@@ -222,7 +222,7 @@ class ProjectController < ApplicationController
if @user == item.user
return item
else
- flash[:warning] = "Item and session user mis-match: #{item.user.name} and #{@user.name}!"
+ notify :warning, "Item and session user mis-match: #{item.user.name} and #{@user.name}!"
render :text => ''
end
end
diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb
index 0f46261e..5de57808 100644
--- a/tracks/app/controllers/todo_controller.rb
+++ b/tracks/app/controllers/todo_controller.rb
@@ -35,7 +35,7 @@ class TodoController < ApplicationController
@contexts_to_show = @contexts.reject {|x| x.hide? }
if @contexts.empty?
- flash[:warning] = 'You must add at least one context before adding next actions.'
+ notify :warning, "You must add at least one context before adding next actions."
end
# Set count badge to number of not-done, not hidden context items
@@ -90,7 +90,7 @@ class TodoController < ApplicationController
rescue
respond_to do |wants|
wants.html do
- flash[:warning] = 'An error occurred on the server.'
+ notify :warning, "An error occurred on the server."
render :action => "index"
end
wants.js { render :action => 'error' }
@@ -130,9 +130,12 @@ class TodoController < ApplicationController
return if request.xhr?
if @saved
- redirect_with_notice "The action '#{@item.description}' was marked as #{@item.completed? ? 'complete' : 'incomplete' }", :action => "index"
+ # TODO: I think this will work, but can't figure out how to test it
+ notify :notice, "The action '#{@item.description}' was marked as #{@item.completed? ? 'complete' : 'incomplete' }"
+ redirect_to :action => "index"
else
- redirect_with_notice "The action '#{@item.description}' was NOT marked as #{@item.completed? ? 'complete' : 'incomplete' } due to an error on the server.", :action => "index"
+ notify :notice, "The action '#{@item.description}' was NOT marked as #{@item.completed? ? 'complete' : 'incomplete' } due to an error on the server.", "index"
+ redirect_to :action => "index"
end
end
@@ -166,7 +169,7 @@ class TodoController < ApplicationController
render :action => 'update'
else
render :update do |page|
- page.replace_html "info", 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.", "class" => "warning")
+ 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
@@ -183,7 +186,7 @@ class TodoController < ApplicationController
render :action => 'update'
else
render :update do |page|
- page.replace_html "info", 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.", "class" => "warning")
+ 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
@@ -198,9 +201,11 @@ class TodoController < ApplicationController
wants.html do
if @saved
- redirect_with_notice 'Successfully deleted next action', :action => 'index'
+ notify :notice, "Successfully deleted next action", 2.0
+ redirect_to :action => 'index'
else
- redirect_with_warning 'Failed to delete the action.', :action => 'index'
+ notify :error, "Failed to delete the action", 2.0
+ redirect_to :action => 'index'
end
end
@@ -223,7 +228,7 @@ class TodoController < ApplicationController
rescue
respond_to do |wants|
wants.html do
- flash[:warning] = 'An error occurred on the server.'
+ notify :error, 'An error occurred on the server.', 8.0
redirect_to :action => 'index'
end
wants.js { render :action => 'error' }
@@ -255,7 +260,7 @@ class TodoController < ApplicationController
@error_message = 'Item and session user mis-match: #{item.user.name} and #{@user.name}!'
respond_to do |wants|
wants.html do
- flash[:warning] = @error_message
+ notify :error, @error_message, 8.0
render :action => "index"
end
wants.js { render :action => 'error' }
diff --git a/tracks/app/controllers/user_controller.rb b/tracks/app/controllers/user_controller.rb
index 1c0d9df2..e185f6f2 100644
--- a/tracks/app/controllers/user_controller.rb
+++ b/tracks/app/controllers/user_controller.rb
@@ -75,6 +75,7 @@ class UserController < ApplicationController
redirect_to :controller => 'user', :action => 'preferences'
else
redirect_to :controller => 'user', :action => 'change_password'
+ notify :warning, "There was a problem saving the password. Please retry."
end
end
@@ -92,17 +93,17 @@ class UserController < ApplicationController
# redirect to the server
redirect_to open_id_response.redirect_url((request.protocol + request.host_with_port + "/"), url_for(:action => 'complete'))
else
- flash[:warning] = "Unable to find openid server for #{params[:openid_url]}
"
+ notify :warning, "Unable to find openid server for #{params[:openid_url]}
"
redirect_to :action => 'change_auth_type'
end
return
end
@user.auth_type = params[:user][:auth_type]
if @user.save
- flash[:notice] = "Authentication type updated."
+ notify :notice, "Authentication type updated."
redirect_to :controller => 'user', :action => 'preferences'
else
- flash[:warning] = "There was a problem updating your authentication type: #{ @user.errors.full_messages.join(', ')}"
+ notify :warning, "There was a problem updating your authentication type: #{ @user.errors.full_messages.join(', ')}"
redirect_to :controller => 'user', :action => 'change_auth_type'
end
end
@@ -114,11 +115,11 @@ class UserController < ApplicationController
# URL that we were verifying. We include it in the error
# message to help the user figure out what happened.
if open_id_response.identity_url
- flash[:message] = "Verification of #{open_id_response.identity_url} failed. "
+ msg = "Verification of #{open_id_response.identity_url} failed. "
else
- flash[:message] = "Verification failed. "
+ msg = "Verification failed. "
end
- flash[:message] += open_id_response.msg.to_s
+ notify :error, open_id_response.msg.to_s + msg
when OpenID::SUCCESS
# Success means that the transaction completed without
@@ -127,17 +128,17 @@ class UserController < ApplicationController
@user.auth_type = 'open_id'
@user.open_id_url = open_id_response.identity_url
if @user.save
- flash[:message] = "You have successfully verified #{open_id_response.identity_url} as your identity and set your authentication type to Open ID."
+ notify :notice, "You have successfully verified #{open_id_response.identity_url} as your identity and set your authentication type to Open ID."
else
- flash[:warning] = "You have successfully verified #{open_id_response.identity_url} as your identity but there was a problem saving your authentication preferences."
+ notify :warning, "You have successfully verified #{open_id_response.identity_url} as your identity but there was a problem saving your authentication preferences."
end
redirect_to :action => 'preferences'
when OpenID::CANCEL
- flash[:message] = "Verification cancelled."
+ notify :warning, "Verification cancelled."
else
- flash[:warning] = "Unknown response status: #{open_id_response.status}"
+ notify :warning, "Unknown response status: #{open_id_response.status}"
end
redirect_to :action => 'change_auth_type' unless performed?
end
@@ -146,6 +147,7 @@ class UserController < ApplicationController
def refresh_token
@user.crypt_word
@user.save
+ notify :notice, "New token successfully generated"
redirect_to :controller => 'user', :action => 'preferences'
end
@@ -154,10 +156,10 @@ class UserController < ApplicationController
def do_change_password_for(user)
user.change_password(params[:updateuser][:password], params[:updateuser][:password_confirmation])
if user.save
- flash[:notice] = "Password updated."
+ notify :notice, "Password updated."
return true
else
- flash[:warning] = 'There was a problem saving the password. Please retry.'
+ notify :error, 'There was a problem saving the password. Please retry.'
return false
end
end
diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb
index 2635e54c..b532d557 100644
--- a/tracks/app/helpers/application_helper.rb
+++ b/tracks/app/helpers/application_helper.rb
@@ -148,4 +148,13 @@ module ApplicationHelper
render :partial => 'shared/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', "