Class: CamaleonCms::Admin::Appearances::NavMenusController
Instance Method Summary
collapse
#ajax, #cama_get_i18n_frontend, #dashboard, #search
Instance Method Details
#add_items ⇒ Object
add items to specific nav-menu
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 106
def add_items
items = []
@nav_menu = current_site..find(params[:nav_menu_id])
external_params = params[:external]
if external_params.present?
external_item = @nav_menu.((external_params))
external_item.set_options(permitted_external_options(external_params)) if external_params[:options].present?
items << external_item
end
if params[:custom_items].present? params[:custom_items].each_value do |custom_item|
type = custom_item['kind'].presence || 'external'
items << @nav_menu.({ label: custom_item['label'], link: custom_item['url'], type: type })
end
end
if params[:items].present?
params[:items].each_value do |item|
item = @nav_menu.({ label: 'auto', link: item['id'], type: item['kind'] })
items << item
end
end
render partial: 'menu_items', locals: { items: items, nav_menu: @nav_menu }
end
|
#create ⇒ Object
29
30
31
32
33
34
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 29
def create
= current_site..new()
.save
flash[:notice] = t('.created_menu', default: 'Created Menu')
redirect_to action: :index, id: .id
end
|
#custom_settings ⇒ Object
54
55
56
57
58
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 54
def custom_settings
@nav_menu = current_site..find(params[:nav_menu_id])
@nav_menu_item = current_site..find(params[:id])
render '_custom_fields', layout: 'camaleon_cms/admin/_ajax'
end
|
84
85
86
87
88
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 84
def
current_site..find(params[:id]).destroy
head :ok
end
|
#destroy ⇒ Object
48
49
50
51
52
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 48
def destroy
current_site..find(params[:id]).destroy
flash[:notice] = t('.deleted_menu', default: 'Menu destroyed')
redirect_to action: :index
end
|
#edit ⇒ Object
43
44
45
46
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 43
def edit
@nav_menu = current_site..find(params[:id])
render partial: 'form'
end
|
render edit external menu item
67
68
69
70
71
72
73
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 67
def
render '_external_menu', layout: false,
locals: {
nav_menu: current_site..find(params[:nav_menu_id]),
menu_item: current_site..find(params[:id])
}
end
|
#index ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 11
def index
@nav_menu = if params[:id].present?
current_site..find_by(id: params[:id])
elsif params[:slug].present?
current_site..find_by_slug(params[:slug]) else
current_site..first
end
@post_types = current_site.post_types
add_asset_library('nav_menu')
render 'index'
end
|
#new ⇒ Object
24
25
26
27
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 24
def new
@nav_menu = current_site..new
render partial: 'form'
end
|
#reorder_items(items = nil, parent_id = nil, is_root = true) ⇒ Object
update the reorder of items
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 91
def reorder_items(items = nil, parent_id = nil, is_root = true)
items = params[:items] if items.nil?
parent_id = current_site..find(params[:nav_menu_id]).id if parent_id.nil?
items.each do |index, _item|
item = current_site..find(_item['id'])
item.update(parent_id: parent_id, term_order: index)
reorder_items(_item['children'], _item['id'], false) if _item['children'].present?
end
render(inline: '') if is_root
end
|
#save_custom_settings ⇒ Object
60
61
62
63
64
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 60
def save_custom_settings
@nav_menu_item = current_site..find(params[:id])
@nav_menu_item.set_field_values(cama_permitted_field_options('NavMenuItem'))
head :ok
end
|
#update ⇒ Object
36
37
38
39
40
41
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 36
def update
= current_site..find(params[:id])
.update()
flash[:notice] = t('.updated_menu', default: 'Menu updated')
redirect_to action: :index, id: .id
end
|
update an external menu item
76
77
78
79
80
81
82
|
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 76
def
@nav_menu = current_site..find(params[:nav_menu_id])
item = current_site..find(params[:id])
item.((params))
item.set_options(permitted_external_options) if params[:options].present?
render partial: 'menu_items', locals: { items: [item], nav_menu: @nav_menu }
end
|