Class: Knitkit::ErpApp::Desktop::WebsiteHostController

Inherits:
AppController
  • Object
show all
Defined in:
app/controllers/knitkit/erp_app/desktop/website_host_controller.rb

Constant Summary

Constants inherited from AppController

AppController::KNIT_KIT_ROOT

Instance Method Summary collapse

Methods inherited from AppController

#available_roles

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/knitkit/erp_app/desktop/website_host_controller.rb', line 25

def create
  begin
    current_user.with_capability('create', 'WebsiteHost') do
      website = Website.find(params[:website_id])
      website_host = WebsiteHost.create(:host => params[:host])
      website.hosts << website_host
      website.save

      render :json => {
          :success => true,
          :node => {
              :text => website_host.attributes['host'],
              :websiteHostId => website_host.id,
              :host => website_host.attributes['host'],
              :iconCls => 'icon-globe',
              :url => "http://#{website_host.attributes['host']}",
              :leaf => true}
      }
    end
  rescue => ex
    Rails.logger.error("#{ex.message} + #{ex.backtrace}")
    render :json => {:success => false, :message => ex.message}
  end
end

#destroyObject



64
65
66
67
68
69
70
71
72
# File 'app/controllers/knitkit/erp_app/desktop/website_host_controller.rb', line 64

def destroy
  begin
    current_user.with_capability('delete', 'WebsiteHost') do
      render :json => WebsiteHost.destroy(params[:id]) ? {:success => true} : {:success => false}
    end
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
    render :json => {:success => false, :message => ex.message}
  end
end

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/knitkit/erp_app/desktop/website_host_controller.rb', line 8

def index
  tree = []

  if @website
    @website.hosts.each do |website_host|

      tree << {:text => website_host.attributes['host'], :websiteHostId => website_host.id,
               :host => website_host.attributes['host'], :iconCls => 'icon-globe',
               :url => "http://#{website_host.attributes['host']}", :leaf => true}


    end
  end

  render :json => tree
end

#updateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/knitkit/erp_app/desktop/website_host_controller.rb', line 50

def update
  begin
    current_user.with_capability('edit', 'WebsiteHost') do
      website_host = WebsiteHost.find(params[:id])
      website_host.host = params[:host]
      website_host.save

      render :json => {:success => true}
    end
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
    render :json => {:success => false, :message => ex.message}
  end
end