Class: Goldberg::MenuItemsController

Inherits:
ApplicationController show all
Includes:
Controller
Defined in:
lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb

Instance Method Summary collapse

Methods included from Controller

included

Methods included from Six::Import::Controller::ClassMethods

#copy, #six_local_auto_login

Methods inherited from ActionController::Base

#active_scaffold_render_secure_download, #assign_names_with_active_scaffold, #render_with_active_scaffold, #search_generic_view_paths?

Instance Method Details

#createObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 41

def create
  # Flash an error if neither an action nor a page has been selected
  if (params[:menu_item][:controller_action_id] == nil or
      params[:menu_item][:controller_action_id].length == 0 ) and
      (params[:menu_item][:content_page_id] == nil or
       params[:menu_item][:content_page_id].length == 0 )
    flash[:error] = "You must specify either an Action or a Page!"
    @menu_item = MenuItem.new(params[:menu_item])
    @parent_item = MenuItem.find(params[:menu_item][:parent_id])
    foreign
    @can_change_parent = false
    render :action => 'new', :id => params[:id]
    return
  end

  @menu_item = MenuItem.new(params[:menu_item])
  @menu_item.seq = MenuItem.next_seq(@menu_item.parent_id)
  
  if @menu_item.save
    flash[:notice] = 'MenuItem was successfully created.'
    Role.rebuild_cache
    redirect_to :action => 'list'
  else
    foreign
    render :action => 'new'
  end
end

#destroyObject



139
140
141
142
143
144
145
146
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 139

def destroy
  @menu_item = MenuItem.find(params[:id])
  repack_for = @menu_item.parent_id
  @menu_item.destroy
  MenuItem.repack(repack_for)
  Role.rebuild_cache
  redirect_to :action => 'list'
end

#editObject



69
70
71
72
73
74
75
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 69

def edit
  @menu_item = MenuItem.find(params[:id])
  foreign
  @menu = Menu.new
  @items = @menu.get_menu(0)
  @can_change_parent = true
end

#indexObject



10
11
12
13
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 10

def index
  list
  render :action => 'list'
end


148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 148

def link
  item_name = params[:name].join('/')
  node = Goldberg.menu.select(item_name)
  if node
    session[:goldberg][:menu_item] = item_name
    session[:goldberg][:menu_history] ||= Hash.new
    session[:goldberg][:menu_history][node.url] = item_name
    redirect_to node.url
  else
    logger.error "(error in menu)"
    redirect_to "/"
  end
end

#listObject



15
16
17
18
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 15

def list
  @menu = Menu.new
  @items = @menu.get_menu(0)
end

#move_downObject



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 127

def move_down
  @menu_item = MenuItem.find(params[:id])
  @below = @menu_item.below

  if @below
    @menu_item.update_attribute :seq, (@menu_item.seq + 1)
    @below.update_attribute :seq, (@below.seq - 1)
    Role.rebuild_cache
  end
  redirect_to :action => 'list'
end

#move_upObject



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 115

def move_up
  @menu_item = MenuItem.find(params[:id])
  @above = @menu_item.above

  if @above
    @menu_item.update_attribute :seq, (@menu_item.seq - 1)
    @above.update_attribute :seq, (@above.seq + 1)
    Role.rebuild_cache
  end
  redirect_to :action => 'list'
end

#newObject



24
25
26
27
28
29
30
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 24

def new
  @menu_item = MenuItem.new
  @menu = Menu.new
  @items = @menu.get_menu(0)
  foreign
  @can_change_parent = false
end

#new_forObject



32
33
34
35
36
37
38
39
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 32

def new_for
  @parent_item = MenuItem.find(params[:id])
  @menu_item = MenuItem.new
  @menu_item.parent_id = @parent_item.id
  foreign
  @can_change_parent = false
  render :action => 'new'
end

#showObject



20
21
22
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 20

def show
  @menu_item = MenuItem.find(params[:id])
end

#updateObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/menu_items_controller.rb', line 77

def update
  # Flash an error if neither an action nor a page has been selected
  if (params[:menu_item][:controller_action_id] == nil or
      params[:menu_item][:controller_action_id].length == 0 ) and
      (params[:menu_item][:content_page_id] == nil or
       params[:menu_item][:content_page_id].length == 0 )
    flash[:error] = "You must specify either an Action or a Page!"
    edit
    render :action => 'edit'
    return
  end

  @menu_item = MenuItem.find(params[:id])
  # If this has been moved from another parent, need to repack
  # that parent
  if params[:parent_id] != @menu_item.parent_id 
    do_repack = true
    repack_for = @menu_item.parent_id
    # Put at the end of new parent's list
    params[:menu_item][:seq] = MenuItem.next_seq(params[:menu_item][:parent_id])
  else
    do_repack = false
  end

  if @menu_item.update_attributes(params[:menu_item])
    flash[:notice] = 'MenuItem was successfully updated.'
    if do_repack
      MenuItem.repack(repack_for)
    end
    Role.rebuild_cache
    # redirect_to :action => 'show', :id => @menu_item
    redirect_to :action => 'list'
  else
    foreign
    render :action => 'edit'
  end
end