tasks_controller.rb
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class TasksController < MyProfileController
protect 'perform_task', :profile
def index
@tasks = profile.all_pending_tasks.sort_by(&:created_at)
end
def processed
@tasks = profile.all_finished_tasks.sort_by(&:created_at)
end
VALID_DECISIONS = [ 'finish', 'cancel' ]
def close
decision = params[:decision]
if request.post? && VALID_DECISIONS.include?(decision) && params[:id]
task = profile.find_in_all_tasks(params[:id])
task.update_attributes(params[:task])
begin
task.send(decision)
rescue Exception => ex
session[:notice] = ex.clean_message
end
end
redirect_to :action => 'index'
end
def new
@ticket = Ticket.new(params[:ticket])
if params[:target_id]
@ticket.target = profile.friends.find(params[:target_id])
end
@ticket.requestor = profile
if request.post?
if @ticket.save
redirect_to :action => 'index'
end
end
end
def list_requested
@tasks = Task.find_all_by_requestor_id(profile.id)
end
def ticket_details
@ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]])
end
end