Class: Lipsiadmin::AccessControl::Menu

Inherits:
Object
  • Object
show all
Includes:
ActionController::UrlWriter, Helper
Defined in:
lib/access_control/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#recognize_path

Constructor Details

#initialize(name, path = nil, options = {}) {|_self| ... } ⇒ Menu

:nodoc:

Yields:

  • (_self)

Yield Parameters:



187
188
189
190
191
192
193
194
195
# File 'lib/access_control/base.rb', line 187

def initialize(name, path=nil, options={}, &block)#:nodoc:
  @name    = name
  @url     = path
  @options = options
  @allowed = []
  @items   = []
  @allowed << { :controller => recognize_path(path)[:controller] } if @url
  yield self if block_given?
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



185
186
187
# File 'lib/access_control/base.rb', line 185

def items
  @items
end

#nameObject (readonly)

Returns the value of attribute name.



185
186
187
# File 'lib/access_control/base.rb', line 185

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



185
186
187
# File 'lib/access_control/base.rb', line 185

def options
  @options
end

Instance Method Details

#add(name, path = nil, options = {}, &block) ⇒ Object

Add a new submenu to the menu



203
204
205
# File 'lib/access_control/base.rb', line 203

def add(name, path=nil, options={}, &block)
  @items << Menu.new(name, path, options, &block)
end

#allowedObject

Return allowed controllers



208
209
210
211
# File 'lib/access_control/base.rb', line 208

def allowed
  @items.each { |i| @allowed.concat i.allowed }
  @allowed.uniq
end

#configObject

Return ExtJs Config for this menu



224
225
226
227
228
229
230
231
232
233
# File 'lib/access_control/base.rb', line 224

def config
  if @url.blank? && @items.empty?
    options = human_name
  else
    options = @options.merge(:text => human_name)
    options.merge!(:menu => @items.collect(&:config)) if @items.size > 0
    options.merge!(:handler => "function(){ Backend.app.load('#{url}') }".to_l) if !@url.blank?
  end
  options
end

#human_nameObject

Return the original name or try to translate or humanize the symbol



214
215
216
# File 'lib/access_control/base.rb', line 214

def human_name
  @name.is_a?(Symbol) ? I18n.t("backend.menus.#{@name}", :default => @name.to_s.humanize) : @name
end

#uidObject

Return a unique id for the given project module



219
220
221
# File 'lib/access_control/base.rb', line 219

def uid
  @name.to_s.downcase.gsub(/[^a-z0-9]+/, '').gsub(/-+$/, '').gsub(/^-+$/, '')
end

#urlObject

Return the url of this menu



198
199
200
# File 'lib/access_control/base.rb', line 198

def url
  @url.is_a?(Hash) ? url_for(@url.merge(:only_path => true)) : @url
end