Class: Knitkit::ErpApp::Desktop::WebsiteHostController
- Inherits:
-
AppController
- Object
- ErpApp::Desktop::BaseController
- AppController
- Knitkit::ErpApp::Desktop::WebsiteHostController
show all
- Defined in:
- app/controllers/knitkit/erp_app/desktop/website_host_controller.rb
Constant Summary
AppController::KNIT_KIT_ROOT
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
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
|
# 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])
existing_website_host = WebsiteHost.find_by_host(params[:host])
if existing_website_host
website_name = existing_website_host.website.name
raise "Host #{existing_website_host.host} already used by #{website_name}"
end
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
|
#destroy ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'app/controllers/knitkit/erp_app/desktop/website_host_controller.rb', line 76
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
|
#index ⇒ Object
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
|
#update ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/knitkit/erp_app/desktop/website_host_controller.rb', line 55
def update
begin
current_user.with_capability('edit', 'WebsiteHost') do
website_host = WebsiteHost.find(params[:id])
existing_website_host = WebsiteHost.find_by_host(params[:host])
if existing_website_host
website_name = existing_website_host.website.name
raise "Host #{existing_website_host.host} already used by #{website_name}"
end
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}
rescue => ex
render :json => {:success => false, :message => ex.message}
end
end
|