mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-09 06:02:36 +01:00
http://blog.andreasaderhold.com/2006/07/rails-notifications All flash messages now show up as an overlay on the right hand side of the navigation header, and also fade automatically, so that you don't have to refresh the page. Errors (i.e. validation errors) are shown as close to the originating form as possible. Two new notify methods (one for controllers, and one for RJS templates) help construct the flash of whatever type you like. e.g. In controllers: notify :warning, "This is the message" In RJS: notify :warning, "This is the message", 5.0 git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@351 a4c988fc-2ded-0310-b66e-134b36920a42
101 lines
2.9 KiB
Ruby
101 lines
2.9 KiB
Ruby
class MobileController < ApplicationController
|
|
|
|
model :user
|
|
model :project
|
|
model :context
|
|
model :todo
|
|
|
|
layout 'mobile'
|
|
|
|
prepend_before_filter :login_required
|
|
before_filter :init, :except => :update
|
|
|
|
# Plain list of all next actions, paginated 6 per page
|
|
# Sorted by due date, then creation date
|
|
#
|
|
def index
|
|
@page_title = @desc = "All actions"
|
|
@todos_pages, @todos = paginate( :todos, :order => 'due IS NULL, due ASC, created_at ASC',
|
|
:conditions => ['user_id = ? and state = ?', @user.id, "active"],
|
|
:per_page => 6 )
|
|
@count = @all_todos.reject { |x| !x.active? || x.context.hide? }.size
|
|
end
|
|
|
|
def detail
|
|
@item = check_user_return_item
|
|
@place = @item.context.id
|
|
end
|
|
|
|
def update
|
|
if params[:id]
|
|
@item = check_user_return_item
|
|
@item.update_attributes params[:item]
|
|
if params[:item][:state] == "1"
|
|
@item.state = "completed"
|
|
else
|
|
@item.state = "active"
|
|
end
|
|
else
|
|
if params[:item][:"show_from(1i)"] == ""
|
|
@item = Todo.create(params[:item]) if params[:item]
|
|
else
|
|
@item = Todo.create(params[:item]) if params[:item]
|
|
@item.defer!
|
|
end
|
|
end
|
|
|
|
@item.user_id = @user.id
|
|
|
|
if @item.save
|
|
redirect_to :action => 'index'
|
|
else
|
|
self.init
|
|
if params[:id]
|
|
render :partial => 'mobile_edit'
|
|
else
|
|
render :action => 'show_add_form'
|
|
end
|
|
end
|
|
end
|
|
|
|
def show_add_form
|
|
# Just render the view
|
|
end
|
|
|
|
def filter
|
|
@type = params[:type]
|
|
case params[:type]
|
|
when 'context'
|
|
@context = Context.find( params[:context][:id] )
|
|
@page_title = @desc = "#{@context.name}"
|
|
@todos = Todo.find( :all, :order => 'due IS NULL, due ASC, created_at ASC',
|
|
:conditions => ['user_id = ? and state = ? and context_id = ?', @user.id, "active", @context.id] )
|
|
@count = @all_todos.reject { |x| x.completed? || x.context_id != @context.id }.size
|
|
when 'project'
|
|
@project = Project.find( params[:project][:id] )
|
|
@page_title = @desc = "#{@project.name}"
|
|
@todos = Todo.find( :all, :order => 'due IS NULL, due ASC, created_at ASC',
|
|
:conditions => ['user_id = ? and state = ? and project_id = ?', @user.id, "active", @project.id] )
|
|
@count = @all_todos.reject { |x| x.completed? || x.project_id != @project.id }.size
|
|
end
|
|
end
|
|
|
|
protected
|
|
|
|
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
|
|
|
|
def init
|
|
@contexts = @user.contexts.find(:all, :order => 'position ASC')
|
|
@projects = @user.projects.find_in_state(:all, :active, :order => 'position ASC')
|
|
@all_todos = @user.todos.find(:all, :conditions => ['state = ? or state = ?', "active", "completed"])
|
|
end
|
|
|
|
end
|