Skip to content

Commit

Permalink
Merge remote branch 'core/fix-automenu-locking' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Oct 1, 2010
2 parents 17a2a8f + 290715c commit 418a5c3
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions app/controllers/editor/menu_controller.rb
Expand Up @@ -63,12 +63,17 @@ def menu_save
end

class AutomenuOptions < HashModel
default_options :root_page => nil, :levels => nil, :excluded => [],:lock_level => 'no', :included => [], :include_path => false
default_options :root_page => nil, :levels => nil, :excluded => [],:lock_level => 'no', :included => [], :include_path => false

boolean_options :include_path
integer_options :levels, :root_page
validates_presence_of :root_page
validates_presence_of :levels
boolean_options :include_path
integer_options :levels, :root_page
validates_presence_of :root_page
validates_presence_of :levels
integer_array_options :included, :excluded

def is_locked?
self.lock_level != 'no'
end
end

def build_preview(root,levels,excluded,cur_level=1)
Expand Down Expand Up @@ -102,15 +107,10 @@ def build_preview(root,levels,excluded,cur_level=1)

def automenu
data = params[:menu] || @paragraph.data
data[:excluded] = ( data[:excluded] || []).collect { |elm| elm.to_i }.uniq
data[:root_page] = data[:root_page].to_i if data[:root_page]
data[:levels] = (data[:levels] || 0).to_i
@menu = AutomenuOptions.new(data)

@preview, @elem_ids = build_preview(data[:root_page],data[:levels].to_i,data[:excluded] || []) if data[:root_page]



@pages = [['---Select Page---'.t,'']] + SiteNode.page_and_group_options("Site Root".t)
@levels = [ ["1 Level",1] ] +
( 2..5 ).to_a.collect do |num|
Expand All @@ -129,15 +129,20 @@ def automenu
return
end
end
if @menu.lock_level == 'yes' && !request.post?

if @menu.is_locked? && ! request.post?
included = @menu.included || []
@elem_ids.each { |elm| @menu.excluded << elm if !included.include?(elm) }
@elem_ids.each do |elm|
unless included.include?(elm)
@menu.excluded << elm
@preview.each { |item| item[:excluded] = true if item[:node_id] == elm }
end
end
@menu.excluded.uniq!
end

@excluded = @menu.excluded

render :action => 'automenu'
end

Expand Down

0 comments on commit 418a5c3

Please sign in to comment.