collab/app/controllers/tasks_controller.rb

101 lines
2.4 KiB
Ruby
Raw Normal View History

2010-03-04 06:22:45 +00:00
class TasksController < ApplicationController
before_filter :load_project
def load_project
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
flash[:error] = "There was an error finding the parent project"
redirect_to projects_path
end
# GET /tasks
# GET /tasks.xml
def index
2010-03-04 22:42:09 +00:00
@tasks = Task.parents.paginate(:per_page => 30, :page => params[:page], :include => :project)
2010-03-04 06:22:45 +00:00
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @tasks }
end
end
# GET /tasks/1
# GET /tasks/1.xml
def show
2010-03-04 22:42:09 +00:00
@task = Task.find(params[:id], :include => :tasks)
@tasks = @task.tasks
2010-03-04 06:22:45 +00:00
respond_to do |format|
format.html # show.html.erb
2010-03-04 22:42:09 +00:00
format.xml { render :xml => @task, :include => :tasks }
2010-03-04 06:22:45 +00:00
end
end
# GET /tasks/new
# GET /tasks/new.xml
def new
@task = Task.new
2010-03-04 22:42:09 +00:00
@task.parent = params[:parent].nil? ? nil : params[:parent]
2010-03-04 06:22:45 +00:00
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @task }
end
end
# GET /tasks/1/edit
def edit
@task = Task.find(params[:id])
end
# POST /tasks
# POST /tasks.xml
def create
params[:task][:project] = @project.id
@task = Task.new(params[:task])
respond_to do |format|
if @task.save
flash[:success] = 'Task was successfully created.'
format.html { redirect_to project_task_path(@project, @task) }
format.xml { render :xml => @task, :status => :created, :location => @task }
else
format.html { render :action => "new" }
format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
end
end
end
# PUT /tasks/1
# PUT /tasks/1.xml
def update
params[:task][:project] = @project
@task = Task.find(params[:id])
respond_to do |format|
if @task.update_attributes(params[:task])
flash[:success] = 'Task was successfully updated.'
format.html { redirect_to project_task_path(@project, @task) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /tasks/1
# DELETE /tasks/1.xml
def destroy
@task = Task.find(params[:id])
@task.destroy
respond_to do |format|
format.html { redirect_to(tasks_url) }
format.xml { head :ok }
end
end
end