Class: Caboose::MediaCategoriesController
Instance Method Summary
collapse
#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_edit, #admin_index, #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_add ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/controllers/caboose/media_categories_controller.rb', line 51
def admin_add
return unless user_is_allowed('mediacategories', 'add')
resp = Caboose::StdClass.new
cat = MediaCategory.new(
:site_id => @site.id,
:parent_id => params[:parent_id],
:name => params[:name]
)
if !cat.save
resp.error = cat.errors.first[1]
else
Caboose::ChangeLog.create(:site_id => @site.id, :description => "Media Category: #{cat.name}", :is_field => true, :user_id => logged_in_user.id, :media_id => cat.id, :timestamp => DateTime.now, :action => 'created') if @site.use_change_logs
resp.new_id = cat.id
resp.refresh = true
end
render :json => resp
end
|
#admin_attach ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'app/controllers/caboose/media_categories_controller.rb', line 114
def admin_attach
return unless user_is_allowed('mediacategories', 'view')
media_category_id = params[:id]
ids = params[:media_id]
ids = [ids] if !ids.is_a?(Array)
ids.each do |id|
m = Media.where(:id => id).first
next if m.nil?
if @site.use_change_logs
mc1 = Caboose::MediaCategory.where(:id => m.media_category_id).first
mc2 = Caboose::MediaCategory.where(:id => media_category_id).first
ov = mc1 ? mc1.name : "N/A"
nv = mc2 ? mc2.name : "N/A"
Caboose::ChangeLog.create(:site_id => @site.id, :description => "Category", :user_id => logged_in_user.id, :media_id => m.id, :timestamp => DateTime.now, :action => 'edited', :old_value => ov, :new_value => nv)
end
m.update_attribute(:media_category_id, media_category_id)
p = Product.where(:media_category_id => media_category_id).last
if p
pi = ProductImage.where(:media_id => id).exists? ? ProductImage.where(:media_id => id).first : ProductImage.create(:media_id => id, :product_id => p.id)
pi.product_id = p.id
pi.save
ProductImageVariant.where(:product_image_id => pi.id).destroy_all
end
end
render :json => { :success => true }
end
|
#admin_delete ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'app/controllers/caboose/media_categories_controller.rb', line 99
def admin_delete
return unless user_is_allowed('mediacategories', 'delete')
cat = MediaCategory.find(params[:id])
if MediaCategory.top_category(@site.id).id != cat.id
Media.where(:media_category_id => cat.id).update_all(:deleted => true)
cat.parent_id = 0
cat.save
if @site.use_change_logs
Caboose::ChangeLog.create(:site_id => @site.id, :description => "Media Category: #{cat.name}", :is_field => true, :user_id => logged_in_user.id, :media_id => cat.id, :timestamp => DateTime.now, :action => 'deleted') if @site.use_change_logs
end
end
render :json => { :success => true }
end
|
#admin_flat_tree ⇒ Object
13
14
15
16
17
18
|
# File 'app/controllers/caboose/media_categories_controller.rb', line 13
def admin_flat_tree
return unless user_is_allowed('mediacategories', 'view')
prefix = params[:prefix] ? params[:prefix] : '- '
tree = Caboose::MediaCategory.flat_tree(@site.id, prefix)
render :json => tree
end
|
#admin_json ⇒ Object
6
7
8
9
10
|
# File 'app/controllers/caboose/media_categories_controller.rb', line 6
def admin_json
return unless user_is_allowed('mediacategories', 'view')
tree = Caboose::MediaCategory.flat_tree(@site.id)
render :json => tree
end
|
#admin_options ⇒ Object
21
22
23
24
25
26
27
|
# File 'app/controllers/caboose/media_categories_controller.rb', line 21
def admin_options
return unless user_is_allowed('mediacategories', 'view')
prefix = params[:prefix] ? params[:prefix] : '- '
tree = Caboose::MediaCategory.flat_tree(@site.id, prefix)
options = tree.collect{ |mc| { 'value' => mc[:id], 'text' => mc[:name] }}
render :json => options
end
|
#admin_tree ⇒ Object
30
31
32
33
|
# File 'app/controllers/caboose/media_categories_controller.rb', line 30
def admin_tree
return unless user_is_allowed('mediacategories', 'view')
render :json => Caboose::MediaCategory.tree_hash(@site.id)
end
|
#admin_update ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'app/controllers/caboose/media_categories_controller.rb', line 73
def admin_update
return unless user_is_allowed('mediacategories', 'edit')
resp = StdClass.new
cat = MediaCategory.find(params[:id])
save = true
params.each do |name, value|
case name
when 'name' then cat.name = value
when 'parent_id'
parent = MediaCategory.find(value.to_i)
if cat.is_ancestor_of?(parent)
resp.error = "The new parent cannot be a child of itself."
save = false
else
cat.parent_id = value
end
end
end
resp.success = save && cat.save
render :json => resp
end
|
#admin_update_sort_order ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/caboose/media_categories_controller.rb', line 36
def admin_update_sort_order
return unless user_is_allowed('mediacategories', 'edit')
resp = Caboose::StdClass.new
mc = MediaCategory.find(params[:id])
sort = params[:sort].to_a
sort.each_with_index do |s,i|
m = Media.where(:id => s.to_i).first
m.sort_order = i
m.save
end
resp.success = true
render :json => resp
end
|