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
|
# File 'app/controllers/knitkit/erp_app/desktop/app_controller.rb', line 11
def websites
websites = Website.order('name ASC').all
tree = []
websites.each do |website|
@website_primary_host = website.config_value('primary_host')
website_hash = {
:text => website.name,
:configurationId => website.configurations.first.id,
:iconCls => 'icon-globe_disconnected',
:id => "website_#{website.id}",
:leaf => false,
:url => "http://#{@website_primary_host}",
:name => website.name,
:title => website.title,
:subtitle => website.subtitle,
:isWebsite => true,
:siteName => website.name,
:children => []
}
hosts_hash = {:text => 'Hosts', :iconCls => 'icon-gear', :isHostRoot => true, :websiteId => website.id, :leaf => false, :children => []}
website.hosts.each do |website_host|
hosts_hash[:children] << {:text => website_host.attributes['host'], :websiteHostId => website_host.id, :host => website_host.attributes['host'], :iconCls => 'icon-globe', :url => "http://#{website_host.attributes['host']}", :isHost => true, :leaf => true, :children => []}
end
website_hash[:children] << hosts_hash
sections_hash = {:text => 'Sections', :isSectionRoot => true, :websiteId => website.id, :iconCls => 'icon-content', :leaf => false, :children => []}
website.website_sections.positioned.each do |website_section|
sections_hash[:children] << build_section_hash(website_section, website)
end
website_hash[:children] << sections_hash
= {:text => 'Menus', :iconCls => 'icon-content', :isMenuRoot => true, :websiteId => website.id, :leaf => false, :children => []}
website.website_navs.each do |website_nav|
= {:text => website_nav.name, :websiteNavId => website_nav.id, :websiteId => website.id, :canAddMenuItems => true, :iconCls => 'icon-index', :isWebsiteNav => true, :leaf => false, :children => []}
[:children] = website_nav.website_nav_items.positioned.map{|item|(website, item)}
[:children] <<
end
website_hash[:children] <<
tree << website_hash
end
render :json => tree
end
|