class TodoController < ApplicationController

    # set up in-place editing for task
    #
    # the first and second arguments (there could also be an options
    # hash) are the names of an object and one of it's attributes that
    # will be  shown and edited in place.  In this case the task.task
    # field.
    #
    in_place_edit_for(:task, :task)

    # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
    verify :method => :post,
           :only => [ :destroy, :create, :update ],
           :redirect_to => { :action => :list }



#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# index - the default action is the 'list' action                             #
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
def index
    list
    render :action => 'list'
end



#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# create                                                                      #
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
def create
    @task = Task.new(params[:task])
    if @task.save
        flash[:notice] = 'Task was successfully created.'
        redirect_to :action => 'list'
    else
        render :action => 'new'
    end
end



#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# destroy                                                                     #
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
def destroy
    Task.find(params[:id]).destroy
    redirect_to :action => 'list'
end



#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# edit                                                                        #
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
def edit
    @task = Task.find(params[:id])
end



#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# list - retrieves task data to be displayed                                  #
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
def list
    # check the filter type
    if params[:filter].nil?
        @task_filter = 0
    else
        @task_filter = params[:filter].to_i
    end
    if (@task_filter == -1)
#        @task_pages, @tasks = paginate :tasks, :per_page => 20
        @tasks = Task.find(:all)
    else
#        @task_pages, @tasks = paginate :tasks, :per_page => 20, :conditions => "status = #{@task_filter}"
        @tasks = Task.find :all, :conditions => "status = #{@task_filter}"
    end
end



#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# new                                                                         #
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
def new
    @task = Task.new
end



#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# show                                                                        #
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
def show
    @task = Task.find(params[:id])
end



#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# state - update an individual task's status                                  #
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
def state
    @task = Task.find(params[:id])
    @task.toggle_state
    @task.save
    list
#    render :action => 'list'
end



#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# update                                                                      #
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
def update
    @task = Task.find(params[:id])
    if @task.update_attributes(params[:task])
        flash[:notice] = 'Task was successfully updated.'
        redirect_to :action => 'show', :id => @task
    else
        render :action => 'edit'
    end
end


end # end of class TodoController


  Copyright © Thundernet Development Group Inc., 2003.
All rights reserved.