Class: Caboose::BlockTypeSourcesController
Instance Method Summary
collapse
#add_ga_event, #admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_json, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_create ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 53
def admin_create
return unless user_is_allowed('blocktypesources', 'add')
resp = Caboose::StdClass.new
max_priority = BlockTypeSource.maximum(:priority)
max_priority = 0 if max_priority.nil?
bts = BlockTypeSource.new(
:name => params[:name],
:priority => max_priority + 1,
:active => true
)
bts.save
resp.redirect = "/admin/block-types/store/sources/#{bts.id}/edit"
render :json => resp
end
|
#admin_delete ⇒ Object
94
95
96
97
98
99
100
101
|
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 94
def admin_delete
return unless user_is_allowed('blocktypesources', 'delete')
BlockTypeSource.find(params[:id]).destroy
resp = StdClass.new({
'redirect' => "/admin/block-types/store/sources"
})
render :json => resp
end
|
#admin_edit ⇒ Object
46
47
48
49
50
|
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 46
def admin_edit
return unless user_is_allowed('blocktypesources', 'edit')
@block_type_source = BlockTypeSource.find(params[:id])
render :layout => 'caboose/admin'
end
|
#admin_index ⇒ Object
9
10
11
12
13
|
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 9
def admin_index
return if !user_is_allowed('blocktypesources', 'view')
@block_type_sources = BlockTypeSource.reorder("priority, name").all
render :layout => 'caboose/admin'
end
|
#admin_new ⇒ Object
16
17
18
19
|
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 16
def admin_new
return unless user_is_allowed('blocktypesources', 'add')
render :layout => 'caboose/admin'
end
|
#admin_options ⇒ Object
37
38
39
40
41
42
43
|
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 37
def admin_options
return unless user_is_allowed('blocktypesources', 'edit')
options = BlockType.reorder(:name).all.collect do |bts|
{ 'value' => bts.id, 'text' => bts.name }
end
render :json => options
end
|
#admin_refresh ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 22
def admin_refresh
return unless user_is_allowed('blocktypesources', 'edit')
resp = StdClass.new
bts = BlockTypeSource.find(params[:id])
if bts.refresh_summaries
resp.success = "Block types from the source have been refreshed successfully."
else
resp.error = "There was an error refreshing block types from the source."
end
render :json => resp
end
|
#admin_update ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/controllers/caboose/block_type_sources_controller.rb', line 72
def admin_update
return unless user_is_allowed('blocktypesources', 'edit')
resp = StdClass.new({'attributes' => {}})
bts = BlockTypeSource.find(params[:id])
save = true
params.each do |k,v|
case k
when 'name' then bts.name = v
when 'url' then bts.url = v
when 'token' then bts.token = v
when 'priority' then bts.priority = v
when 'active' then bts.active = v
end
end
resp.success = save && bts.save
render :json => resp
end
|