Class: ColumnsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/columns_controller.rb

Instance Method Summary collapse

Methods included from Zena::App

included

Instance Method Details

#createObject

POST /columns POST /columns.xml



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/columns_controller.rb', line 68

def create
  @column = Column.new(params[:column])

  respond_to do |format|
    if @column.save
      flash.now[:notice] = _('Column was successfully created.')
      format.html { redirect_to(@column) }
      format.js
      format.xml  { render :xml => @column, :status => :created, :location => @column }
    else
      format.html { render :action => "new" }
      format.js
      format.xml  { render :xml => @column.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /columns/1 DELETE /columns/1.xml



104
105
106
107
108
109
110
111
112
# File 'app/controllers/columns_controller.rb', line 104

def destroy
  @column.destroy

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

#editObject

GET /columns/1/edit



59
60
61
62
63
64
# File 'app/controllers/columns_controller.rb', line 59

def edit
  respond_to do |format|
    format.html { render :partial => 'columns/form' }
    format.js   { render :partial => 'columns/form', :layout => false }
  end
end

#indexObject

GET /columns GET /columns.xml



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
# File 'app/controllers/columns_controller.rb', line 9

def index
  roles = {}
  secure(Column) do
    @columns = Column.paginate(:all, :order => 'role_id ASC, name ASC', :per_page => 200, :page => params[:page])
  end

  @columns.sort! do |a, b|
    role_a = (roles[a.role_id] ||= a.role)
    role_b = (roles[b.role_id] ||= b.role)

    if role_a == role_b
      a.name <=> b.name
    elsif role_a.kpath == role_b.kpath
      role_a.name <=> role_b.name
    else
      role_a.kpath <=> role_b.kpath
    end
  end

  @column  = Column.new

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @columns }
  end
end

#newObject

GET /columns/new GET /columns/new.xml



49
50
51
52
53
54
55
56
# File 'app/controllers/columns_controller.rb', line 49

def new
  @column = Column.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @column }
  end
end

#showObject

GET /columns/1 GET /columns/1.xml



38
39
40
41
42
43
44
45
# File 'app/controllers/columns_controller.rb', line 38

def show

  respond_to do |format|
    format.html # show.html.erb
    format.js
    format.xml  { render :xml => @column }
  end
end

#updateObject

PUT /columns/1 PUT /columns/1.xml



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/columns_controller.rb', line 87

def update
  respond_to do |format|
    if @column.update_attributes(params[:column])
      flash.now[:notice] = _('Column was successfully updated.')
      format.html { redirect_to(@column) }
      format.js
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.js
      format.xml  { render :xml => @column.errors, :status => :unprocessable_entity }
    end
  end
end