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
|
# File 'lib/qadmin/helper.rb', line 13
def admin_controls(name, options = {}, &block)
return if respond_to?(:overlay?) && overlay?
controller = options[:controller] || name.to_s.tableize
assumed_object = self.instance_variable_get "@#{name}"
obj = options[:object] || assumed_object || nil
parent = options[:parent] || false
parent_link_attributes = parent ? {parent.class.to_s.foreign_key => parent.id} : {}
general_link_attributes = {:controller => controller}.merge(parent_link_attributes)
control_links = {
:index => link_to(image_tag('admin/icon_list.png') + " Back to List", general_link_attributes.merge(:action => 'index')),
:new => link_to(image_tag('admin/icon_new.png') + " New", general_link_attributes.merge(:action => 'new')),
:edit => link_to(image_tag('admin/icon_edit.png') + " Edit", general_link_attributes.merge(:action => 'edit', :id => obj)),
:show => link_to(image_tag('admin/icon_show.png') + " View", general_link_attributes.merge(:action => 'show', :id => obj)),
:destroy => link_to(image_tag('admin/icon_destroy.png') + " Delete", general_link_attributes.merge(:action => 'destroy', :id => obj), :confirm => 'Are you sure?', :method => :delete),
:ports => link_to(image_tag('admin/icon_export.png') + " Import/Export", general_link_attributes.merge(:action => 'ports')),
:export => link_to(image_tag('admin/icon_export.png') + " Export", general_link_attributes.merge(:action => 'export'))
}
control_sets = {
:index => [:new],
:new => [:index],
:edit => [:index,:new,:show,:destroy],
:show => [:index,:new,:edit,:destroy]
}
control_set = (options[:controls] || []).dup
control_set.unshift(control_sets[options[:for]]) if options[:for]
control_set << :ports if options[:ports]
controls = [control_set].flatten.collect {|c| control_links[c] }.compact
html = ""
html << %{<ul class="admin_controls">}
controls.each {|control| html << li(control) }
if block_given?
html << capture(&block)
html << %{</ul>}
concat(html)
else
html << %{</ul>}
html
end
end
|