Class: Knitkit::ErpApp::Desktop::AppController

Inherits:
ErpApp::Desktop::BaseController
  • Object
show all
Defined in:
app/controllers/knitkit/erp_app/desktop/app_controller.rb

Constant Summary collapse

KNIT_KIT_ROOT =
Knitkit::Engine.root.to_s

Instance Method Summary collapse

Instance Method Details

#available_rolesObject



7
8
9
# File 'app/controllers/knitkit/erp_app/desktop/app_controller.rb', line 7

def available_roles
  render :json => {:success => true, :availableRoles => SecurityRole.order('description ASC').all.collect{|role| role.to_hash(:only => [:internal_identifier, :description])}}
end

#websitesObject



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 => []
    }

    #handle hosts
    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

    #handle sections
    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

    #handle menus
    menus_hash = {:text => 'Menus', :iconCls => 'icon-content', :isMenuRoot => true, :websiteId => website.id, :leaf => false, :children => []}
    website.website_navs.each do |website_nav|
      menu_hash = {:text => website_nav.name, :websiteNavId => website_nav.id, :websiteId => website.id, :canAddMenuItems => true, :iconCls => 'icon-index', :isWebsiteNav => true, :leaf => false, :children => []}
      menu_hash[:children] = website_nav.website_nav_items.positioned.map{|item|build_menu_item_hash(website, item)}
      menus_hash[:children] << menu_hash
    end

    website_hash[:children] << menus_hash

    #added website to main tree
    tree << website_hash
  end

  render :json => tree
end