Class: Admin::CyclesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/cycles_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) clone

Create a doc



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
# File 'app/controllers/admin/cycles_controller.rb', line 52

def clone
  @cycle = Cycle.new(params[:cycle])
  @other_cycle = Cycle.find(params[:id])
  @cycle.program = @other_cycle.program
  res = []
  res << @cycle.save
  if res.all?
    SystemControl.where(:cycle_id => @other_cycle).each do |sc|
      res << SystemControl.create(:control => sc.control, :system => sc.system, :cycle => @cycle)
    end
  end

  respond_to do |format|
    if res.all?
      format.html { redirect_to(edit_cycle_path(@cycle), :notice => 'Cycle was successfully created.') }
      format.xml  { render :xml => @cycle, :status => :created, :location => @cycle }
    elsif res[0]
      format.html { redirect_to(edit_cycle_path(@cycle), :error => 'Could not copy some System-Control connections.') }
      format.xml  { render :xml => @cycle.errors, :status => :unprocessable_entity }
    else
      flash.now[:error] = "Could not create."
      format.html { render :action => "new_clone" }
      format.xml  { render :xml => @cycle.errors, :status => :unprocessable_entity }
    end
  end
end

- (Object) create

Create a doc



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/admin/cycles_controller.rb', line 80

def create
  @cycle = Cycle.new(params[:cycle])

  respond_to do |format|
    if @cycle.save
      format.html { redirect_to(edit_cycle_path(@cycle), :notice => 'Cycle was successfully created.') }
      format.xml  { render :xml => @cycle, :status => :created, :location => @cycle }
    else
      flash.now[:error] = "Could not create."
      format.html { render :action => "new" }
      format.xml  { render :xml => @cycle.errors, :status => :unprocessable_entity }
    end
  end
end

- (Object) destroy

Delete a doc



112
113
114
115
116
117
118
119
120
# File 'app/controllers/admin/cycles_controller.rb', line 112

def destroy
  @cycle = Cycle.find(params[:id])
  @cycle.destroy

  respond_to do |format|
    format.html { redirect_to(cycles_url) }
    format.xml  { head :ok }
  end
end

- (Object) edit

Edit doc form



47
48
49
# File 'app/controllers/admin/cycles_controller.rb', line 47

def edit
  @cycle = Cycle.find(params[:id])
end

- (Object) index

List cycles



5
6
7
8
9
10
11
12
# File 'app/controllers/admin/cycles_controller.rb', line 5

def index
  @cycles = Cycle.order([:program_id, :start_at])

  respond_to do |format|
    format.html
    format.xml  { render :xml => @cycles }
  end
end

- (Object) new

New doc form



25
26
27
28
29
30
31
32
# File 'app/controllers/admin/cycles_controller.rb', line 25

def new
  @cycle = Cycle.new

  respond_to do |format|
    format.html
    format.xml  { render :xml => @cycle }
  end
end

- (Object) new_clone



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/admin/cycles_controller.rb', line 34

def new_clone
  @other_cycle = Cycle.find(params[:id])
  @cycle = Cycle.new
  @cycle.program = @other_cycle.program
  @cycle.start_at ||= @other_cycle.start_at

  respond_to do |format|
    format.html
    format.xml  { render :xml => @cycle }
  end
end

- (Object) show

Show a doc



15
16
17
18
19
20
21
22
# File 'app/controllers/admin/cycles_controller.rb', line 15

def show
  @cycle = Cycle.find(params[:id])

  respond_to do |format|
    format.html
    format.xml  { render :xml => @cycle }
  end
end

- (Object) update

Update a doc



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/admin/cycles_controller.rb', line 96

def update
  @cycle = Cycle.find(params[:id])

  respond_to do |format|
    if @cycle.update_attributes(params[:cycle])
      format.html { redirect_to(edit_cycle_path(@cycle), :notice => 'Cycle was successfully updated.') }
      format.xml  { head :ok }
    else
      flash.now[:error] = "Could not update."
      format.html { render :action => "edit" }
      format.xml  { render :xml => @cycle.errors, :status => :unprocessable_entity }
    end
  end
end