Class: OgAdminController

Inherits:
Nitro::Controller show all
Defined in:
lib/part/admin/og/controller.rb

Overview

The Controller for the OgBrowser Admin module.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Nitro::Controller

current, mounted, replace_current

Methods included from Nitro::Helpers

append_features

Methods included from Nitro::Caching

included

Methods included from Nitro::Scaffolding

class_to_list, class_to_method, class_to_path, included

Methods included from Nitro::Publishable

included

Class Method Details

.setup_template_root(path) ⇒ Object



32
33
34
35
# File 'lib/part/admin/og/controller.rb', line 32

def self.setup_template_root(path)
  super
  @template_root << File.join(File.dirname(__FILE__),  'template')
end

Instance Method Details

#create(name) ⇒ Object



71
72
73
74
# File 'lib/part/admin/og/controller.rb', line 71

def create(name)
  klass = name_to_class(name)
  @obj = klass.allocate
end

#delete(name, oid) ⇒ Object



108
109
110
111
112
# File 'lib/part/admin/og/controller.rb', line 108

def delete(name, oid)
  klass = name_to_class(name)
  klass.delete(oid)
  redirect_to_referer
end

#delete_class(name) ⇒ Object



61
62
63
64
# File 'lib/part/admin/og/controller.rb', line 61

def delete_class(name)
  name_to_class(name).delete_all
  redirect_to_referer
end

#destroy_class(name) ⇒ Object



66
67
68
69
# File 'lib/part/admin/og/controller.rb', line 66

def destroy_class(name)
  name_to_class(name).destroy
  redirect_to_referer
end

#indexObject



37
38
39
# File 'lib/part/admin/og/controller.rb', line 37

def index
  @classes = Og.manager.managed_classes.sort { |x, y| x.name <=> y.name }
end

#list(name) ⇒ Object



42
43
44
45
# File 'lib/part/admin/og/controller.rb', line 42

def list(name)
  @klass = name_to_class(name)
  @objects, @pager = paginate(@klass, :per_page => Scaffolding.per_page)
end

#read(name, oid) ⇒ Object



78
79
# File 'lib/part/admin/og/controller.rb', line 78

def read(name, oid)
end

#saveObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/part/admin/og/controller.rb', line 87

def save
  klass = name_to_class(request['object_class_name'].to_s)

  if oid = request['oid']
    obj = klass[oid.to_s]
    obj.assign(request, :assign_relations => true, :force_boolean => true)
  else
    obj = klass.create
    obj.assign(request, :assign_relations => true)
  end
  
  unless obj.valid?
    flash.concat :ERRORS, obj.errors
    redirect_to_referer
  end

  obj.save

  redirect :list, :name, obj.class
end

#search(name) ⇒ Object



48
49
50
51
# File 'lib/part/admin/og/controller.rb', line 48

def search(name)
  @klass = name_to_class(name)
  @obj = @klass.allocate
end

#search_resultsObject



54
55
56
57
# File 'lib/part/admin/og/controller.rb', line 54

def search_results
  @klass = name_to_class(request.params.delete('object_class_name').to_s)
  @objects, @pager = paginate(@klass.query_by_example(request.params), :per_page => Scaffolding.per_page)
end

#update(name, oid) ⇒ Object



81
82
83
84
# File 'lib/part/admin/og/controller.rb', line 81

def update(name, oid)
  klass = name_to_class(name)
  @obj = klass[oid]
end