-
Notifications
You must be signed in to change notification settings - Fork 0
/
checklist_templates_controller.rb
96 lines (81 loc) · 2.73 KB
/
checklist_templates_controller.rb
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class ChecklistTemplatesController < ApplicationController
before_filter :login_required
layout 'settings'
def index
@checklists = ChecklistTemplate.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @checklists }
format.json { render :json => @checklists }
end
end
def show
@checklist = ChecklistTemplate.find(params[:id])
@device_types = DeviceType.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @checklist }
format.json { render :json => @checklist }
end
end
def add_assocation
@checklist = ChecklistTemplate.find(params[:checklist_template_id])
@associate = DeviceType.find(params[:id])
@checklist.device_types << @associate
redirect_to(@checklist)
end
def remove_assocation
@checklist = ChecklistTemplate.find(params[:checklist_template_id])
@associate = DeviceType.find(params[:id])
@checklist.device_types.delete(@associate)
redirect_to(@checklist)
end
def new
@checklist = ChecklistTemplate.new
@checklist.checklist_template_questions.build
end
def edit
@checklist = ChecklistTemplate.find(params[:id])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @checklist }
format.json { render :json => @checklist }
end
end
def create
@checklist = ChecklistTemplate.new(params[:checklist_template])
respond_to do |format|
if @checklist.save
flash[:notice] = 'Checklist was successfully created.'
format.html { redirect_to(@checklist) }
format.xml { render :xml => @checklist, :status => :created, :location => @checklist }
else
flash[:notice] = @checklist.errors.inspect
format.html { render :action => "new" }
format.xml { render :xml => @checklist.errors, :status => :unprocessable_entity }
end
end
end
def update
params[:checklist_template][:existing_checklist_template_question_attributes] ||= {}
@checklist = ChecklistTemplate.find(params[:id])
respond_to do |format|
if @checklist.update_attributes params[:checklist_template]
flash[:notice] = 'Checklist was successfully updated.'
format.html { redirect_to(@checklist) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @checklist.errors, :status => :unprocessable_entity }
end
end
end
def destroy
@checklist = ChecklistTemplate.find(params[:id])
@checklist.destroy
respond_to do |format|
format.html { redirect_to(checklists_url) }
format.xml { head :ok }
end
end
end