Class: CamaleonCms::Admin::Appearances::NavMenusController

Inherits:
CamaleonCms::AdminController
  • Object
show all
Defined in:
app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb

Overview

Camaleon CMS is a content management system

Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the  GNU Affero General Public License (GPLv3) for more details.

Instance Method Summary collapse

Instance Method Details

#formObject

show external menu form


77
78
79
80
81
82
83
84
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 77

def form
  if params[:custom_fields].present?
    @nav_menu = current_site.nav_menus.find_by_id(params[:menu_id])
    render "_custom_fields", layout: "camaleon_cms/admin/_ajax"
  else
    render "_external_menu", layout: false, locals: {submit: true}
  end
end

12
13
14
15
16
17
18
19
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/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 12

def menu
  authorize! :manager, :menu
  unless params[:new].present?
    if params[:id].present?
      @nav_menu = current_site.nav_menus.find_by_id(params[:id])
      if request.delete? && @nav_menu.present?
        @nav_menu.destroy
        flash[:notice] = t('camaleon_cms.admin.menus.message.deleted')
        redirect_to action: :menu
        return
      end
    end

    unless @nav_menu.present?
      if params[:slug].present?
        @nav_menu = current_site.nav_menus.where({slug: params[:slug]}).first
      else
        @nav_menu = current_site.nav_menus.last
      end
    end

  end
  @nav_menu = current_site.nav_menus.new unless @nav_menu.present?
  items = []
  unless @nav_menu.new_record?
    items = get_nav_items(@nav_menu.children)
  end
  @items = items

  @nav_menus = current_site.nav_menus.all
  @post_types = current_site.post_types
  add_asset_library("nav_menu")
  render "index"
end

#saveObject

save changes of the menu


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 48

def save
  authorize! :manager, :menu
  unless params[:nav_menu][:id].present?   # new
    menu_data = params[:nav_menu]
    @nav_menu = current_site.nav_menus.new(menu_data)
    if @nav_menu.save
      flash[:notice] = t('camaleon_cms.admin.menus.message.created')
      render json: {new: 1, nav_menu: @nav_menu, redirect: cama_admin_appearances_nav_menus_menu_path({id: @nav_menu.id})}
    else
      render json: {error: t('camaleon_cms.admin.menus.message.error_menu')}
    end
  else
    @nav_menu = current_site.nav_menus.find(params[:nav_menu][:id])
    if @nav_menu.update(params[:nav_menu])
      @nav_menu.add_menu_items(params[:menu_data])

      if params[:nav_menu_location].present?
        params[:nav_menu_location].each do |location|
          current_site.set_option("_nav_menu_#{location}", @nav_menu.id)
        end
      end
      render json: {update: 1, nav_menu: @nav_menu}
    else
      render json: {error: t('camaleon_cms.admin.menus.message.error_menu')}
    end
  end
end