Class: Admin::MenuItemsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/menu_items_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
# File 'app/controllers/admin/menu_items_controller.rb', line 20

def create

	add_breadcrumb "New", :new_admin_page_path
	@menu_item = SpudMenuItem.new(params[:spud_menu_item])
	@menu_item.spud_menu_id = @menu.id
	if params[:spud_menu_item][:parent_id].blank?
		@menu_item.parent_id = @menu.id
		@menu_item.parent_type = "SpudMenu"
	else
		@menu_item.parent_type = "SpudMenuItem"
	end
	if @menu_item.name.blank? && !@menu_item.spud_page.blank?
		@menu_item.name = @menu_item.spud_page.name
	end
	if @menu_item.menu_order.blank?
		highest_sibling = @menu_item.parent.spud_menu_items.order("menu_order desc").first
		if !highest_sibling.blank?
			@menu_item.menu_order = highest_sibling.menu_order + 1
		end
	end
	flash[:notice] = "Menu Created successfully!" if @menu_item.save



	respond_with @menu_item,:location => admin_menu_menu_items_url
end

#destroyObject



71
72
73
74
75
76
# File 'app/controllers/admin/menu_items_controller.rb', line 71

def destroy

	flash[:notice] = "Menu Item removed!" if @menu_item.destroy

	respond_with @menu_item,:location => admin_menu_menu_items_url
end

#editObject



47
48
49
50
51
52
53
# File 'app/controllers/admin/menu_items_controller.rb', line 47

def edit
	add_breadcrumb "Edit #{@menu_item.name}", :edit_admin_menu_menu_item_path
	if @menu_item.parent_type == "SpudMenu"
		@menu_item.parent_id = nil
	end
	respond_with @menu_item
end

#indexObject



8
9
10
11
# File 'app/controllers/admin/menu_items_controller.rb', line 8

def index
	@menu_items = @menu.spud_menu_items.order(:menu_order).includes(:spud_menu_items)
	respond_with @menu_items
end

#newObject



13
14
15
16
17
18
# File 'app/controllers/admin/menu_items_controller.rb', line 13

def new
	add_breadcrumb "New", :new_admin_page_path

	@menu_item = @menu.spud_menu_items.new
	respond_with @menu_item
end

#reorderObject



78
79
80
81
82
83
84
85
86
# File 'app/controllers/admin/menu_items_controller.rb', line 78

def reorder
	#id param
	#source position
	#destination position
	#parent
			# @menu_items = @menu.spud_menu_items.order(:menu_order).includes(:spud_menu_items).paginate :page => params[:page]


end

#updateObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/admin/menu_items_controller.rb', line 55

def update

	add_breadcrumb "Edit #{@menu_item.name}", :edit_admin_menu_menu_item_path
	if params[:spud_menu_item][:parent_id].blank?
		params[:spud_menu_item][:parent_type] = "SpudMenu"
		params[:spud_menu_item][:parent_id] = @menu.id
	else
		params[:spud_menu_item][:parent_type] = "SpudMenuItem"
	end
	@menu_item.attributes = params[:spud_menu_item]
	@menu_item.spud_menu_id = @menu.id
	flash[:notice] = "Menu saved successfully!" if @menu_item.save

	respond_with @menu_item,:location => admin_menu_menu_items_url
end